Pass the namespace to allocate_entity_zero() instead of setting it later on.
authorChristoph Mallon <christoph.mallon@gmx.de>
Thu, 16 Jun 2011 17:07:58 +0000 (19:07 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Fri, 17 Jun 2011 04:42:11 +0000 (06:42 +0200)
builtins.c
entity.c
entity_t.h
parser.c

index 368ab14..c8e5f5f 100644 (file)
 static entity_t *create_builtin_function(builtin_kind_t kind, const char *name,
                                          type_t *function_type)
 {
-       symbol_t *symbol = symbol_table_insert(name);
-       entity_t *entity = allocate_entity_zero(ENTITY_FUNCTION);
+       symbol_t *const symbol = symbol_table_insert(name);
+       entity_t *const entity = allocate_entity_zero(ENTITY_FUNCTION, NAMESPACE_NORMAL);
        entity->declaration.storage_class          = STORAGE_CLASS_EXTERN;
        entity->declaration.declared_storage_class = STORAGE_CLASS_EXTERN;
        entity->declaration.type                   = function_type;
        entity->declaration.implicit               = true;
-       entity->base.namespc                       = NAMESPACE_NORMAL;
        entity->base.symbol                        = symbol;
        entity->base.source_position               = builtin_source_position;
 
@@ -176,9 +175,8 @@ entity_t *get_builtin_replacement(const entity_t *builtin_entity)
        if (replacement == NULL)
                return NULL;
 
-       entity_t *entity = allocate_entity_zero(ENTITY_FUNCTION);
+       entity_t *const entity = allocate_entity_zero(ENTITY_FUNCTION, NAMESPACE_NORMAL);
        entity->base.symbol           = symbol_table_insert(replacement);
-       entity->base.namespc          = NAMESPACE_NORMAL;
        entity->base.source_position  = builtin_source_position;
        entity->declaration.storage_class          = STORAGE_CLASS_EXTERN;
        entity->declaration.declared_storage_class = STORAGE_CLASS_EXTERN;
index 89d69e3..49f4513 100644 (file)
--- a/entity.c
+++ b/entity.c
@@ -81,11 +81,12 @@ static size_t get_entity_struct_size(entity_kind_t kind)
  *
  * @param kind   the kind of the entity to allocate
  */
-entity_t *allocate_entity_zero(entity_kind_t kind)
+entity_t *allocate_entity_zero(entity_kind_t const kind, entity_namespace_t const namespc)
 {
-       size_t    size   = get_entity_struct_size(kind);
-       entity_t *entity = allocate_ast_zero(size);
-       entity->kind     = kind;
+       size_t    size       = get_entity_struct_size(kind);
+       entity_t *entity     = allocate_ast_zero(size);
+       entity->kind         = kind;
+       entity->base.namespc = namespc;
        return entity;
 }
 
index 364e644..643f316 100644 (file)
@@ -304,7 +304,7 @@ static inline bool is_declaration(const entity_t *entity)
 
 const char *get_entity_kind_name(entity_kind_t kind);
 
-entity_t *allocate_entity_zero(entity_kind_t kind);
+entity_t *allocate_entity_zero(entity_kind_t, entity_namespace_t);
 
 elf_visibility_tag_t get_elf_visibility_from_string(const char *string);
 
index 09e6a4d..ebf8f88 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -2454,10 +2454,8 @@ static compound_t *parse_compound_type_specifier(bool is_struct)
        }
 
        if (entity == NULL) {
-               entity = allocate_entity_zero(kind);
-
+               entity = allocate_entity_zero(kind, NAMESPACE_TAG);
                entity->compound.alignment   = 1;
-               entity->base.namespc         = NAMESPACE_TAG;
                entity->base.source_position = pos;
                entity->base.symbol          = symbol;
                entity->base.parent_scope    = current_scope;
@@ -2503,9 +2501,8 @@ static void parse_enum_entries(type_t *const enum_type)
                        return;
                }
 
-               entity_t *entity             = allocate_entity_zero(ENTITY_ENUM_VALUE);
+               entity_t *const entity = allocate_entity_zero(ENTITY_ENUM_VALUE, NAMESPACE_NORMAL);
                entity->enum_value.enum_type = enum_type;
-               entity->base.namespc         = NAMESPACE_NORMAL;
                entity->base.symbol          = token.symbol;
                entity->base.source_position = token.source_position;
                next_token();
@@ -2567,8 +2564,7 @@ static type_t *parse_enum_specifier(void)
        }
 
        if (entity == NULL) {
-               entity                       = allocate_entity_zero(ENTITY_ENUM);
-               entity->base.namespc         = NAMESPACE_TAG;
+               entity = allocate_entity_zero(ENTITY_ENUM, NAMESPACE_TAG);
                entity->base.source_position = pos;
                entity->base.symbol          = symbol;
                entity->base.parent_scope    = current_scope;
@@ -2807,8 +2803,7 @@ end_error:
 
 static entity_t *create_error_entity(symbol_t *symbol, entity_kind_tag_t kind)
 {
-       entity_t *entity             = allocate_entity_zero(kind);
-       entity->base.namespc         = NAMESPACE_NORMAL;
+       entity_t *const entity = allocate_entity_zero(kind, NAMESPACE_NORMAL);
        entity->base.source_position = *HERE;
        entity->base.symbol          = symbol;
        if (is_declaration(entity)) {
@@ -3286,9 +3281,8 @@ static type_qualifiers_t parse_type_qualifiers(void)
 static void parse_identifier_list(scope_t *scope)
 {
        do {
-               entity_t *entity = allocate_entity_zero(ENTITY_PARAMETER);
+               entity_t *const entity = allocate_entity_zero(ENTITY_PARAMETER, NAMESPACE_NORMAL);
                entity->base.source_position = token.source_position;
-               entity->base.namespc         = NAMESPACE_NORMAL;
                entity->base.symbol          = token.symbol;
                /* a K&R parameter has no type, yet */
                next_token();
@@ -3885,8 +3879,7 @@ static entity_t *parse_declarator(const declaration_specifiers_t *specifiers,
 
        entity_t *entity;
        if (specifiers->storage_class == STORAGE_CLASS_TYPEDEF) {
-               entity                       = allocate_entity_zero(ENTITY_TYPEDEF);
-               entity->base.namespc         = NAMESPACE_NORMAL;
+               entity = allocate_entity_zero(ENTITY_TYPEDEF, NAMESPACE_NORMAL);
                entity->base.symbol          = env.symbol;
                entity->base.source_position = env.source_position;
                entity->typedefe.type        = orig_type;
@@ -3908,7 +3901,7 @@ static entity_t *parse_declarator(const declaration_specifiers_t *specifiers,
        } else {
                /* create a declaration type entity */
                if (flags & DECL_CREATE_COMPOUND_MEMBER) {
-                       entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER);
+                       entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER, NAMESPACE_NORMAL);
 
                        if (env.symbol != NULL) {
                                if (specifiers->is_inline && is_type_valid(type)) {
@@ -3927,10 +3920,9 @@ static entity_t *parse_declarator(const declaration_specifiers_t *specifiers,
                        orig_type = semantic_parameter(&env.source_position, orig_type,
                                                       specifiers, env.symbol);
 
-                       entity = allocate_entity_zero(ENTITY_PARAMETER);
+                       entity = allocate_entity_zero(ENTITY_PARAMETER, NAMESPACE_NORMAL);
                } else if (is_type_function(type)) {
-                       entity = allocate_entity_zero(ENTITY_FUNCTION);
-
+                       entity = allocate_entity_zero(ENTITY_FUNCTION, NAMESPACE_NORMAL);
                        entity->function.is_inline      = specifiers->is_inline;
                        entity->function.elf_visibility = default_visibility;
                        entity->function.parameters     = env.parameters;
@@ -3949,8 +3941,7 @@ static entity_t *parse_declarator(const declaration_specifiers_t *specifiers,
                                }
                        }
                } else {
-                       entity = allocate_entity_zero(ENTITY_VARIABLE);
-
+                       entity = allocate_entity_zero(ENTITY_VARIABLE, NAMESPACE_NORMAL);
                        entity->variable.elf_visibility = default_visibility;
                        entity->variable.thread_local   = specifiers->thread_local;
 
@@ -3986,7 +3977,6 @@ static entity_t *parse_declarator(const declaration_specifiers_t *specifiers,
                } else {
                        entity->base.source_position = specifiers->source_position;
                }
-               entity->base.namespc           = NAMESPACE_NORMAL;
                entity->declaration.type       = orig_type;
                entity->declaration.alignment  = get_type_alignment(orig_type);
                entity->declaration.modifiers  = env.modifiers;
@@ -4400,7 +4390,6 @@ finish:
        assert(current_scope != NULL);
 
        entity->base.parent_scope = current_scope;
-       entity->base.namespc      = NAMESPACE_NORMAL;
        environment_push(entity);
        append_entity(current_scope, entity);
 
@@ -5858,8 +5847,7 @@ static void parse_compound_declarators(compound_t *compound,
                                anchor = &(*anchor)->next;
                        *anchor = specifiers->attributes;
 
-                       entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER);
-                       entity->base.namespc                       = NAMESPACE_NORMAL;
+                       entity = allocate_entity_zero(ENTITY_COMPOUND_MEMBER, NAMESPACE_NORMAL);
                        entity->base.source_position               = source_position;
                        entity->declaration.declared_storage_class = STORAGE_CLASS_NONE;
                        entity->declaration.storage_class          = STORAGE_CLASS_NONE;
@@ -6230,12 +6218,11 @@ static entity_t *create_implicit_function(symbol_t *symbol,
        ntype->function.linkage                = LINKAGE_C;
        type_t *type                           = identify_new_type(ntype);
 
-       entity_t *entity = allocate_entity_zero(ENTITY_FUNCTION);
+       entity_t *const entity = allocate_entity_zero(ENTITY_FUNCTION, NAMESPACE_NORMAL);
        entity->declaration.storage_class          = STORAGE_CLASS_EXTERN;
        entity->declaration.declared_storage_class = STORAGE_CLASS_EXTERN;
        entity->declaration.type                   = type;
        entity->declaration.implicit               = true;
-       entity->base.namespc                       = NAMESPACE_NORMAL;
        entity->base.symbol                        = symbol;
        entity->base.source_position               = *source_position;
 
@@ -7044,9 +7031,8 @@ static label_t *get_label(symbol_t *symbol)
        }
 
        /* otherwise we need to create a new one */
-       label               = allocate_entity_zero(ENTITY_LABEL);
-       label->base.namespc = NAMESPACE_LABEL;
-       label->base.symbol  = symbol;
+       label = allocate_entity_zero(ENTITY_LABEL, NAMESPACE_LABEL);
+       label->base.symbol = symbol;
 
        label_push(label);
 
@@ -10177,10 +10163,8 @@ static statement_t *parse_local_label_declaration(void)
                        errorf(HERE, "multiple definitions of '__label__ %Y' (previous definition %P)",
                               symbol, &entity->base.source_position);
                } else {
-                       entity = allocate_entity_zero(ENTITY_LOCAL_LABEL);
-
+                       entity = allocate_entity_zero(ENTITY_LOCAL_LABEL, NAMESPACE_LABEL);
                        entity->base.parent_scope    = current_scope;
-                       entity->base.namespc         = NAMESPACE_LABEL;
                        entity->base.source_position = token.source_position;
                        entity->base.symbol          = symbol;
 
@@ -10223,10 +10207,9 @@ static void parse_namespace_definition(void)
        }
 
        if (entity == NULL) {
-               entity                       = allocate_entity_zero(ENTITY_NAMESPACE);
+               entity = allocate_entity_zero(ENTITY_NAMESPACE, NAMESPACE_NORMAL);
                entity->base.symbol          = symbol;
                entity->base.source_position = token.source_position;
-               entity->base.namespc         = NAMESPACE_NORMAL;
                entity->base.parent_scope    = current_scope;
        }