Remove the phi node rewriting.
[smatch.git] / scope.c
blobceeea7e249ca500942226bf57746bc50ba32130c
1 /*
2 * Symbol scoping.
4 * This is pretty trivial.
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003 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 "symbol.h"
16 #include "scope.h"
18 static struct scope toplevel_scope = { .next = &toplevel_scope };
20 struct scope *block_scope = &toplevel_scope,
21 *function_scope = &toplevel_scope,
22 *file_scope = &toplevel_scope;
24 void bind_scope(struct symbol *sym, struct scope *scope)
26 sym->scope = scope;
27 add_symbol(&scope->symbols, sym);
30 static void start_scope(struct scope **s)
32 struct scope *scope = __alloc_scope(0);
33 memset(scope, 0, sizeof(*scope));
34 scope->next = *s;
35 *s = scope;
38 void start_symbol_scope(void)
40 start_scope(&block_scope);
43 void start_function_scope(void)
45 start_scope(&function_scope);
46 start_scope(&block_scope);
49 static void remove_symbol_scope(struct symbol *sym)
51 struct symbol **ptr = sym->id_list;
53 while (*ptr != sym)
54 ptr = &(*ptr)->next_id;
55 *ptr = sym->next_id;
58 static void end_scope(struct scope **s)
60 struct scope *scope = *s;
61 struct symbol_list *symbols = scope->symbols;
62 struct symbol *sym;
64 *s = scope->next;
65 scope->symbols = NULL;
66 FOR_EACH_PTR(symbols, sym) {
67 remove_symbol_scope(sym);
68 } END_FOR_EACH_PTR(sym);
71 void end_symbol_scope(void)
73 end_scope(&block_scope);
76 void end_function_scope(void)
78 end_scope(&block_scope);
79 end_scope(&function_scope);