inlining: don't copy an initializer expression for a symbol that
[smatch.git] / scope.c
blob58dd1ee3b349ea49060da77e6f256b7ae52443cd
1 /*
2 * Symbol scoping.
4 * This is pretty trivial.
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003-2004 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
11 #include <stdlib.h>
12 #include <string.h>
14 #include "lib.h"
15 #include "allocate.h"
16 #include "symbol.h"
17 #include "scope.h"
19 static struct scope toplevel_scope = { .next = &toplevel_scope };
21 struct scope *block_scope = &toplevel_scope,
22 *function_scope = &toplevel_scope,
23 *file_scope = &toplevel_scope;
25 void bind_scope(struct symbol *sym, struct scope *scope)
27 sym->scope = scope;
28 add_symbol(&scope->symbols, sym);
31 static void start_scope(struct scope **s)
33 struct scope *scope = __alloc_scope(0);
34 memset(scope, 0, sizeof(*scope));
35 scope->next = *s;
36 *s = scope;
39 void start_symbol_scope(void)
41 start_scope(&block_scope);
44 void start_function_scope(void)
46 start_scope(&function_scope);
47 start_scope(&block_scope);
50 static void remove_symbol_scope(struct symbol *sym)
52 struct symbol **ptr = sym->id_list;
54 while (*ptr != sym)
55 ptr = &(*ptr)->next_id;
56 *ptr = sym->next_id;
59 static void end_scope(struct scope **s)
61 struct scope *scope = *s;
62 struct symbol_list *symbols = scope->symbols;
63 struct symbol *sym;
65 *s = scope->next;
66 scope->symbols = NULL;
67 FOR_EACH_PTR(symbols, sym) {
68 remove_symbol_scope(sym);
69 } END_FOR_EACH_PTR(sym);
72 void end_symbol_scope(void)
74 end_scope(&block_scope);
77 void end_function_scope(void)
79 end_scope(&block_scope);
80 end_scope(&function_scope);