blob: c13fe5eea33d5378a5816e4a904c54d22127fb00 (
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
48
49
|
/*
* Symbol scoping.
*
* This is pretty trivial.
*
* Copyright (C) 2003 Linus Torvalds, all rights reserved.
*/
#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, void *data, int flags)
{
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, NULL);
}
|