Oops. The argument symbol initializers got lost on inlining,
[smatch.git] / scope.c
blob98c74bea741a2c96bcfbe8216baf339592aa74c4
1 /*
2 * Symbol scoping.
4 * This is pretty trivial.
6 * Copyright (C) 2003 Transmeta Corp.
8 * Licensed under the Open Software License version 1.1
9 */
10 #include <stdlib.h>
11 #include <string.h>
13 #include "lib.h"
14 #include "symbol.h"
15 #include "scope.h"
17 static struct scope toplevel_scope = { .next = &toplevel_scope };
19 struct scope *block_scope = &toplevel_scope,
20 *function_scope = &toplevel_scope,
21 *file_scope = &toplevel_scope;
23 void bind_scope(struct symbol *sym, struct scope *scope)
25 sym->scope = scope;
26 add_symbol(&scope->symbols, sym);
29 static void start_scope(struct scope **s)
31 struct scope *scope = __alloc_scope(0);
32 memset(scope, 0, sizeof(*scope));
33 scope->next = *s;
34 *s = scope;
37 void start_symbol_scope(void)
39 start_scope(&block_scope);
42 void start_function_scope(void)
44 start_scope(&function_scope);
45 start_scope(&block_scope);
48 static void remove_symbol_scope(struct symbol *sym, void *data, int flags)
50 struct symbol **ptr = sym->id_list;
52 while (*ptr != sym)
53 ptr = &(*ptr)->next_id;
54 *ptr = sym->next_id;
57 static void end_scope(struct scope **s)
59 struct scope *scope = *s;
60 struct symbol_list *symbols = scope->symbols;
62 *s = scope->next;
63 scope->symbols = NULL;
64 symbol_iterate(symbols, remove_symbol_scope, NULL);
67 void end_symbol_scope(void)
69 end_scope(&block_scope);
72 void end_function_scope(void)
74 end_scope(&block_scope);
75 end_scope(&function_scope);