Import upstream sources.
[cparse] / scope.c
CommitLineData
3cd4b0f8
MW
1#include "cparse.h"
2
3static struct scope *scope;
4
5void enter_scope(void) {
6 struct scope *new_scope;
7
8 NEW(new_scope);
9 new_scope->parent = scope;
10 scope = new_scope;
11}
12
13void exit_scope(void) {
14 scope = scope->parent;
15}
16
17/* might be called before the declaration_specifiers have been filled in */
18void add_declaration(struct declarator *d) {
19 /* skip nameless declarators to simplify some callers */
20 if(d->name) {
21 if(!scope->declarations)
22 scope->declarations = dict_new();
23 dict_add(scope->declarations, d->name, d);
24 }
25 /* XXX redeclaration */
26}
27
28struct declarator *lookup(const char *name) {
29 const struct scope *s;
30 struct declarator *d;
31
32 for(s = scope; s; s = s->parent)
33 if(s->declarations && (d = dict_get(s->declarations, name)))
34 return d;
35 return 0;
36}
37
38void scope_init(void) {
39 scope = 0;
40 enter_scope();
41}
42
43/*
44Local Variables:
45c-basic-offset:2
46comment-column:40
47fill-column:79
48End:
49*/