diff options
author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-04-18 16:32:41 +0200 |
---|---|---|
committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2020-05-21 17:27:45 +0200 |
commit | 91de00e92952a61a745be95c56e8595b506d866a (patch) | |
tree | 739b9f8bbabdb09d01d0ba9af089975119e3e625 | |
parent | 93ec535db78b56aa1dda92f5754126caff1d6ef6 (diff) | |
download | sparse-91de00e92952a61a745be95c56e8595b506d866a.tar.gz |
scope: extract bind_symbol_with_scope() from bind_symbol()
In most cases, the scope that must be used for a symbol is
given by its namespace.
However, in some situations a different scope must be used.
This is then set, for example by doing the lookup with
the wrong namespace (but corresponding to the desired scope)
and changing it just after to its correct value.
To avoid these contortions, extract from bind_symbol() a version
where the scope can be explicitly given: bind_symbol_with_scope().
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r-- | symbol.c | 13 | ||||
-rw-r--r-- | symbol.h | 1 |
2 files changed, 10 insertions, 4 deletions
@@ -671,9 +671,8 @@ static void inherit_static(struct symbol *sym) } } -void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) +void bind_symbol_with_scope(struct symbol *sym, struct ident *ident, enum namespace ns, struct scope *scope) { - struct scope *scope; if (sym->bound) { sparse_error(sym->pos, "internal error: symbol type already bound"); return; @@ -690,7 +689,6 @@ void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) sym->ident = ident; sym->bound = 1; - scope = block_scope; if (ns == NS_SYMBOL && toplevel(scope)) { unsigned mod = MOD_ADDRESSABLE | MOD_TOPLEVEL; @@ -704,11 +702,18 @@ void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) } sym->ctype.modifiers |= mod; } + bind_scope(sym, scope); +} + +void bind_symbol(struct symbol *sym, struct ident *ident, enum namespace ns) +{ + struct scope *scope = block_scope;; + if (ns == NS_MACRO) scope = file_scope; if (ns == NS_LABEL) scope = function_scope; - bind_scope(sym, scope); + bind_symbol_with_scope(sym, ident, ns, scope); } struct symbol *create_symbol(int stream, const char *name, int type, int namespace) @@ -332,6 +332,7 @@ extern void show_type_list(struct symbol *); extern void show_symbol_list(struct symbol_list *, const char *); extern void add_symbol(struct symbol_list **, struct symbol *); extern void bind_symbol(struct symbol *, struct ident *, enum namespace); +extern void bind_symbol_with_scope(struct symbol *, struct ident *, enum namespace, struct scope *); extern struct symbol *examine_symbol_type(struct symbol *); extern struct symbol *examine_pointer_target(struct symbol *); |