aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scope.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-03-20 10:54:14 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 20:59:31 -0700
commit0474cdb18bbe72035ca493487776dbb5a8b325b5 (patch)
tree7fe9d5badef603bb00f56a97ce2d031b16824284 /scope.c
parent15f971e49f7bf7b8b9576a15bf2b3982f4a59ac8 (diff)
downloadsparse-0474cdb18bbe72035ca493487776dbb5a8b325b5.tar.gz
Add symbol scoping for proper parsing.
Diffstat (limited to 'scope.c')
-rw-r--r--scope.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/scope.c b/scope.c
new file mode 100644
index 00000000..3f86f622
--- /dev/null
+++ b/scope.c
@@ -0,0 +1,47 @@
+/*
+ * Symbol scoping.
+ *
+ * This is pretty trivial.
+ */
+#include <stdlib.h>
+#include <string.h>
+
+#include "lib.h"
+#include "symbol.h"
+#include "scope.h"
+
+static struct scope
+ base_scope = { .next = &base_scope },
+ *current_scope = &base_scope;
+
+void bind_scope(struct symbol *sym)
+{
+ add_symbol(&current_scope->symbols, sym);
+}
+
+void start_symbol_scope(void)
+{
+ struct scope *scope = __alloc_bytes(sizeof(*scope));
+ memset(scope, 0, sizeof(*scope));
+ scope->next = current_scope;
+ current_scope = scope;
+}
+
+static void remove_symbol_scope(struct symbol *sym)
+{
+ struct symbol **ptr = sym->id_list;
+
+ while (*ptr != sym)
+ ptr = &(*ptr)->next_id;
+ *ptr = sym->next_id;
+}
+
+void end_symbol_scope(void)
+{
+ struct scope *scope = current_scope;
+ struct symbol_list *symbols = scope->symbols;
+
+ current_scope = scope->next;
+ scope->symbols = NULL;
+ symbol_iterate(symbols, remove_symbol_scope);
+}