aboutsummaryrefslogtreecommitdiff
path: root/src/scope.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-01-16 11:27:23 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2025-01-16 11:27:23 +0200
commit8b8ed7282a0fa5e17b83f0eaae404aa5f231b66a (patch)
tree15ce178c691d2df7829973e595ebdb84732276b1 /src/scope.c
parent4d812e9b9bcf2530ab5a3275be85365ee277bea8 (diff)
downloadek-8b8ed7282a0fa5e17b83f0eaae404aa5f231b66a.tar.gz
ek-8b8ed7282a0fa5e17b83f0eaae404aa5f231b66a.zip
start adding exported defs
Diffstat (limited to 'src/scope.c')
-rw-r--r--src/scope.c49
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;
+}