Simplify typedef testing, and don't mess with MOD_EXTERNAL testing
[smatch.git] / scope.c
blobde240f08c6ebc2a2b5c26583359f9547884b81ae
1 /*
2 * Symbol scoping.
4 * This is pretty trivial.
6 * Copyright (C) 2003 Transmeta Corp, all rights reserved.
7 */
8 #include <stdlib.h>
9 #include <string.h>
11 #include "lib.h"
12 #include "symbol.h"
13 #include "scope.h"
15 static struct scope toplevel_scope = { .next = &toplevel_scope };
17 struct scope *block_scope = &toplevel_scope,
18 *function_scope = &toplevel_scope,
19 *file_scope = &toplevel_scope;
21 void bind_scope(struct symbol *sym, struct scope *scope)
23 add_symbol(&scope->symbols, sym);
26 static void start_scope(struct scope **s)
28 struct scope *scope = __alloc_bytes(sizeof(*scope));
29 memset(scope, 0, sizeof(*scope));
30 scope->next = *s;
31 *s = scope;
34 void start_symbol_scope(void)
36 start_scope(&block_scope);
39 void start_function_scope(void)
41 start_scope(&function_scope);
42 start_scope(&block_scope);
45 static void remove_symbol_scope(struct symbol *sym, void *data, int flags)
47 struct symbol **ptr = sym->id_list;
49 while (*ptr != sym)
50 ptr = &(*ptr)->next_id;
51 *ptr = sym->next_id;
54 static void end_scope(struct scope **s)
56 struct scope *scope = *s;
57 struct symbol_list *symbols = scope->symbols;
59 *s = scope->next;
60 scope->symbols = NULL;
61 symbol_iterate(symbols, remove_symbol_scope, NULL);
64 void end_symbol_scope(void)
66 end_scope(&block_scope);
69 void end_function_scope(void)
71 end_scope(&block_scope);
72 end_scope(&function_scope);