-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscope.h
43 lines (31 loc) · 1.02 KB
/
scope.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#ifndef SCOPE_H
#define SCOPE_H
#include "symbol.h"
#include "hash_table.h"
extern int level;
extern int resolve_error_count;
extern int type_error_count;
struct scope {
struct hash_table *h; /* each hash table corresponds a scope and maps an identifier to a symbol. */
struct scope *next;
};
/*
* a singly linked list of hash tables, each hash table corresponds a scope and maps an identifier to a symbol.
* the closest scope is at the beginning of the linked list.
*/
extern struct scope *head;
/*
* Increase the scope level;
* Create a new scope which inclues a pointer to a new hash table, put it into the beginning of the scope list.
*/
void scope_enter();
void scope_exit();
int scope_level();
void scope_bind(const char *name, struct symbol *s);
void scope_rebind(const char *name, struct symbol *s);
struct symbol *scope_lookup(const char *name, int line, int resolving);
struct symbol *scope_lookup_local(const char *name);
void scope_init();
void scope_print();
void hash_table_traverse(struct hash_table *h);
#endif