diff options
Diffstat (limited to 'src/scope.c')
| -rw-r--r-- | src/scope.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/scope.c b/src/scope.c index 52028a8..282018c 100644 --- a/src/scope.c +++ b/src/scope.c @@ -39,6 +39,10 @@ struct scope *create_scope() scope->macros = visible_create(); scope->types = visible_create(); + scope->exported_symbols = exported_create(); + scope->exported_macros = exported_create(); + scope->exported_types = exported_create(); + scope->number = counter++; return scope; } @@ -59,9 +63,12 @@ void destroy_scope(struct scope *scope) expanded_destroy(&scope->expanded); + exported_destroy(&scope->exported_symbols); + exported_destroy(&scope->exported_macros); + exported_destroy(&scope->exported_types); + struct scope *prev = scope->children, *cur; - if (prev) - do { + if (prev) do { cur = prev->next; destroy_scope(prev); } while ((prev = cur)); @@ -87,7 +94,7 @@ struct ast **create_type(struct scope *scope, char *id, struct ast *type) } struct ast **create_expanded(struct scope *scope, struct ast *def, - struct type *types, struct ast *expd) + struct type *types, struct ast *expd) { struct expanded_key key = {.def = def, .types = types}; return expanded_insert(&scope->expanded, key, expd); @@ -449,3 +456,39 @@ void scope_add_scope(struct scope *parent, struct scope *child) child->next = parent->children; parent->children = child; } + +bool is_exported_type(struct scope *scope, struct ast *def) +{ + struct ast **found = exported_find(&scope->exported_types, def); + if (found) + return true; + + if (scope->parent) + return is_exported_type(scope->parent, def); + + return false; +} + +bool is_exported_symbol(struct scope *scope, struct ast *def) +{ + struct ast **found = exported_find(&scope->exported_symbols, def); + if (found) + return true; + + if (scope->parent) + return is_exported_symbol(scope->parent, def); + + return false; +} + +bool is_exported_macro(struct scope *scope, struct ast *def) +{ + struct ast **found = exported_find(&scope->exported_macros, def); + if (found) + return true; + + if (scope->parent) + return is_exported_macro(scope->parent, def); + + return false; +} |
