blob: 3f86f622b7caa2d02b697c3a7e85b13ed0ccbc92 (
plain)
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
44
45
46
47
|
/*
* Symbol scoping.
*
* This is pretty trivial.
*/
#include <stdlib.h>
#include <string.h>
#include "lib.h"
#include "symbol.h"
#include "scope.h"
static struct scope
base_scope = { .next = &base_scope },
*current_scope = &base_scope;
void bind_scope(struct symbol *sym)
{
add_symbol(¤t_scope->symbols, sym);
}
void start_symbol_scope(void)
{
struct scope *scope = __alloc_bytes(sizeof(*scope));
memset(scope, 0, sizeof(*scope));
scope->next = current_scope;
current_scope = scope;
}
static void remove_symbol_scope(struct symbol *sym)
{
struct symbol **ptr = sym->id_list;
while (*ptr != sym)
ptr = &(*ptr)->next_id;
*ptr = sym->next_id;
}
void end_symbol_scope(void)
{
struct scope *scope = current_scope;
struct symbol_list *symbols = scope->symbols;
current_scope = scope->next;
scope->symbols = NULL;
symbol_iterate(symbols, remove_symbol_scope);
}
|