some more work towards (c++) namespace support
[cparser] / attribute.c
index 8bca90b..3e42ff2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of cparser.
- * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
+ * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -246,18 +246,32 @@ static void warn_arguments(const attribute_t *attribute)
        }
 }
 
-static void handle_attribute_packed(const attribute_t *attribute,
-                                    entity_t *entity)
+static void handle_attribute_packed_e(const attribute_t *attribute,
+                                      entity_t *entity)
 {
+#if 0
+       if (entity->kind != ENTITY_STRUCT) {
+               warningf(&attribute->source_position,
+                        "packed attribute on %s '%s' ignored",
+                                get_entity_kind_name(entity->kind),
+                                entity->base.symbol->string);
+               return;
+       }
+#endif
+
        warn_arguments(attribute);
+       entity->compound.packed = true;
+}
 
-       if (entity->kind == ENTITY_STRUCT) {
-               entity->compound.packed = true;
-       } else if (warning.other) {
+static void handle_attribute_packed(const attribute_t *attribute, type_t *type)
+{
+       if (type->kind != TYPE_COMPOUND_STRUCT) {
                warningf(&attribute->source_position,
-                        "packed attribute on %s ignored",
-                                get_entity_kind_name(entity->kind));
+                        "packed attribute on type '%T' ignored", type);
+               return;
        }
+
+       handle_attribute_packed_e(attribute, (entity_t*) type->compound.compound);
 }
 
 void handle_entity_attributes(const attribute_t *attributes, entity_t *entity)
@@ -310,8 +324,9 @@ void handle_entity_attributes(const attribute_t *attributes, entity_t *entity)
                case ATTRIBUTE_MS_NOALIAS:       modifiers |= DM_NOALIAS; break;
 
                case ATTRIBUTE_GNU_PACKED:
-                       handle_attribute_packed(attribute, entity);
-                       break;
+                       handle_attribute_packed_e(attribute, entity);
+                       break;
+
                case ATTRIBUTE_MS_ALIGN:
                case ATTRIBUTE_GNU_ALIGNED:
                        handle_attribute_aligned(attribute, entity);
@@ -343,7 +358,7 @@ void handle_entity_attributes(const attribute_t *attributes, entity_t *entity)
 
 static type_t *change_calling_convention(type_t *type, cc_kind_t cconv)
 {
-       if (!is_type_function(type)) {
+       if (is_typeref(type) || !is_type_function(type)) {
                return type;
        }
 
@@ -360,6 +375,9 @@ type_t *handle_type_attributes(const attribute_t *attributes, type_t *type)
        const attribute_t *attribute = attributes;
        for ( ; attribute != NULL; attribute = attribute->next) {
                switch(attribute->kind) {
+               case ATTRIBUTE_GNU_PACKED:
+                       handle_attribute_packed(attribute, type);
+                       break;
                case ATTRIBUTE_GNU_CDECL:
                case ATTRIBUTE_MS_CDECL:
                        type = change_calling_convention(type, CC_CDECL);