4 * This is pretty trivial.
6 * Copyright (C) 2003 Transmeta Corp.
9 * Licensed under the Open Software License version 1.1
18 static struct scope toplevel_scope
= { .next
= &toplevel_scope
};
20 struct scope
*block_scope
= &toplevel_scope
,
21 *function_scope
= &toplevel_scope
,
22 *file_scope
= &toplevel_scope
;
24 void bind_scope(struct symbol
*sym
, struct scope
*scope
)
27 add_symbol(&scope
->symbols
, sym
);
30 static void start_scope(struct scope
**s
)
32 struct scope
*scope
= __alloc_scope(0);
33 memset(scope
, 0, sizeof(*scope
));
38 void start_symbol_scope(void)
40 start_scope(&block_scope
);
43 void start_function_scope(void)
45 start_scope(&function_scope
);
46 start_scope(&block_scope
);
49 static void remove_symbol_scope(struct symbol
*sym
)
51 struct symbol
**ptr
= sym
->id_list
;
54 ptr
= &(*ptr
)->next_id
;
58 static void end_scope(struct scope
**s
)
60 struct scope
*scope
= *s
;
61 struct symbol_list
*symbols
= scope
->symbols
;
65 scope
->symbols
= NULL
;
66 FOR_EACH_PTR(symbols
, sym
) {
67 remove_symbol_scope(sym
);
68 } END_FOR_EACH_PTR(sym
);
71 void end_symbol_scope(void)
73 end_scope(&block_scope
);
76 void end_function_scope(void)
78 end_scope(&block_scope
);
79 end_scope(&function_scope
);