4 * This is pretty trivial.
6 * Copyright (C) 2003 Transmeta Corp.
7 * 2003-2004 Linus Torvalds
9 * Licensed under the Open Software License version 1.1
20 static struct scope builtin_scope
= { .next
= &builtin_scope
};
22 struct scope
*block_scope
= &builtin_scope
, // regular automatic variables etc
23 *function_scope
= &builtin_scope
, // labels, arguments etc
24 *file_scope
= &builtin_scope
, // static
25 *global_scope
= &builtin_scope
; // externally visible
27 void bind_scope(struct symbol
*sym
, struct scope
*scope
)
30 add_symbol(&scope
->symbols
, sym
);
33 static void start_scope(struct scope
**s
)
35 struct scope
*scope
= __alloc_scope(0);
36 memset(scope
, 0, sizeof(*scope
));
41 void start_file_scope(void)
43 struct scope
*scope
= __alloc_scope(0);
46 memset(scope
, 0, sizeof(*scope
));
47 scope
->next
= &builtin_scope
;
50 /* top-level stuff defaults to file scopt, "extern" etc will choose global scope */
51 function_scope
= scope
;
54 /* Make the builtin macros visible again */
55 FOR_EACH_PTR(builtin_scope
.symbols
, sym
) {
56 if (sym
->namespace == NS_INVISIBLEMACRO
)
57 sym
->namespace = NS_MACRO
;
58 } END_FOR_EACH_PTR(sym
);
61 void start_symbol_scope(void)
63 start_scope(&block_scope
);
66 void start_function_scope(void)
68 start_scope(&function_scope
);
69 start_scope(&block_scope
);
72 static void remove_symbol_scope(struct symbol
*sym
)
74 struct symbol
**ptr
= sym
->id_list
;
77 ptr
= &(*ptr
)->next_id
;
81 static void end_scope(struct scope
**s
)
83 struct scope
*scope
= *s
;
84 struct symbol_list
*symbols
= scope
->symbols
;
88 scope
->symbols
= NULL
;
89 FOR_EACH_PTR(symbols
, sym
) {
90 remove_symbol_scope(sym
);
91 } END_FOR_EACH_PTR(sym
);
94 void end_file_scope(void)
96 end_scope(&file_scope
);
99 void end_symbol_scope(void)
101 end_scope(&block_scope
);
104 void end_function_scope(void)
106 end_scope(&block_scope
);
107 end_scope(&function_scope
);