aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-03-22 16:36:18 +0200
committerKimplul <kimi.h.kuparinen@gmail.com>2025-03-22 16:36:18 +0200
commit350f6c40fa18c35bde9489225175c82de44ba709 (patch)
treed010427fb92a59a901c9a90f7a2b6db64484f0c5 /include
parent199d1342d76b5cae6503fa0a97322d2658d43b5f (diff)
downloadfwd-350f6c40fa18c35bde9489225175c82de44ba709.tar.gz
fwd-350f6c40fa18c35bde9489225175c82de44ba709.zip
use maps in scope
Diffstat (limited to 'include')
-rw-r--r--include/fwd/scope.h31
1 files changed, 8 insertions, 23 deletions
diff --git a/include/fwd/scope.h b/include/fwd/scope.h
index 2e71cdb..e49eb0a 100644
--- a/include/fwd/scope.h
+++ b/include/fwd/scope.h
@@ -13,29 +13,17 @@
#include "ast.h"
#include "debug.h"
-/**
- * An AST node visible to the scope we're in.
- * The same AST node can be referenced by multiple visible nodes,
- * but only the owning scope is allowed to destroy the node.
- * Check that \p owner is identical to the scope the visible node
- * belongs to.
- *
- * Basic linked list for now, can probably be optimized into some kind of hash
- * table later.
- */
-struct visible {
- /** Name of the visible node. */
- char *id;
- /** AST node that is visible. */
- struct ast *node;
- /** Next visible object in the scope we're in. */
- struct visible *next;
-};
-
enum scope_flags {
SCOPE_PROC = (1 << 0),
};
+#define MAP_KEY char *
+#define MAP_TYPE struct ast *
+#define MAP_CMP(a, b) strcmp((a), (b))
+#define MAP_HASH(a) CONTS_MAP_STR_HASH(a)
+#define MAP_NAME visible
+#include <conts/map.h>
+
/**
* Scope.
* Responsible for keeping track of visibilities and
@@ -63,7 +51,7 @@ struct scope {
/** List of child scopes. */
struct scope *children;
- struct visible *symbols;
+ struct visible symbols;
enum scope_flags flags;
};
@@ -194,7 +182,4 @@ struct ast *file_scope_find_symbol(struct scope *scope, char *id);
*/
struct ast *file_scope_find_proc(struct scope *scope, char *id);
-#define foreach_visible(iter, init) \
- for (struct visible *iter = init; iter; iter = iter->next)
-
#endif /* SCOPE_H */