Add building of the normal built-in C types (as opposed to the
[smatch.git] / scope.c
blobc13fe5eea33d5378a5816e4a904c54d22127fb00
1 /*
2 * Symbol scoping.
4 * This is pretty trivial.
6 * Copyright (C) 2003 Linus Torvalds, 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
16 base_scope = { .next = &base_scope },
17 *current_scope = &base_scope;
19 void bind_scope(struct symbol *sym)
21 add_symbol(&current_scope->symbols, sym);
24 void start_symbol_scope(void)
26 struct scope *scope = __alloc_bytes(sizeof(*scope));
27 memset(scope, 0, sizeof(*scope));
28 scope->next = current_scope;
29 current_scope = scope;
32 static void remove_symbol_scope(struct symbol *sym, void *data, int flags)
34 struct symbol **ptr = sym->id_list;
36 while (*ptr != sym)
37 ptr = &(*ptr)->next_id;
38 *ptr = sym->next_id;
41 void end_symbol_scope(void)
43 struct scope *scope = current_scope;
44 struct symbol_list *symbols = scope->symbols;
46 current_scope = scope->next;
47 scope->symbols = NULL;
48 symbol_iterate(symbols, remove_symbol_scope, NULL);