Fix dependencies again, after again having been bitten by me being
[smatch.git] / scope.c
blob3f86f622b7caa2d02b697c3a7e85b13ed0ccbc92
1 /*
2 * Symbol scoping.
4 * This is pretty trivial.
5 */
6 #include <stdlib.h>
7 #include <string.h>
9 #include "lib.h"
10 #include "symbol.h"
11 #include "scope.h"
13 static struct scope
14 base_scope = { .next = &base_scope },
15 *current_scope = &base_scope;
17 void bind_scope(struct symbol *sym)
19 add_symbol(&current_scope->symbols, sym);
22 void start_symbol_scope(void)
24 struct scope *scope = __alloc_bytes(sizeof(*scope));
25 memset(scope, 0, sizeof(*scope));
26 scope->next = current_scope;
27 current_scope = scope;
30 static void remove_symbol_scope(struct symbol *sym)
32 struct symbol **ptr = sym->id_list;
34 while (*ptr != sym)
35 ptr = &(*ptr)->next_id;
36 *ptr = sym->next_id;
39 void end_symbol_scope(void)
41 struct scope *scope = current_scope;
42 struct symbol_list *symbols = scope->symbols;
44 current_scope = scope->next;
45 scope->symbols = NULL;
46 symbol_iterate(symbols, remove_symbol_scope);