diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-10-10 11:57:39 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-10-10 12:04:35 +0300 |
commit | 250d9aab8f79ebd7a2f2535de9db60172df51598 (patch) | |
tree | 8cb00af0546ba73a53f6495cf021d545438f47c3 /src | |
parent | ca94bd309cb7dc9d33e4c06d95b6fc44714ffe9d (diff) | |
download | cflow-250d9aab8f79ebd7a2f2535de9db60172df51598.tar.gz cflow-250d9aab8f79ebd7a2f2535de9db60172df51598.tar.bz2 |
Improve local symbol detection.
* src/cflow.h (install): Change prototype.
* src/parser.c (skip_balanced): Don't put extra token back.
* src/symbol.c (install): Take two arguments, the 2nd one
specifying whether the symbol can be local to the compilation
unit. All uses updated.
(delete_symbol): Don't delete symbol in reverse tree mode, if
its callee list is not empty.
Diffstat (limited to 'src')
-rw-r--r-- | src/c.l | 6 | ||||
-rw-r--r-- | src/cflow.h | 2 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/parser.c | 8 | ||||
-rw-r--r-- | src/symbol.c | 16 |
5 files changed, 16 insertions, 18 deletions
@@ -206,20 +206,20 @@ init_lex(int debug_level) obstack_init(&string_stk); for (i = 0; i < NUMITEMS(keywords); i++) { - sp = install(keywords[i]); + sp = install(keywords[i], 0); sp->type = SymToken; sp->token_type = WORD; } for (i = 0; i < NUMITEMS(types); i++) { - sp = install(types[i]); + sp = install(types[i], 0); sp->type = SymToken; sp->token_type = TYPE; sp->source = NULL; sp->def_line = -1; sp->ref_line = NULL; } - sp = install("..."); + sp = install("...", 0); sp->type = SymToken; sp->token_type = IDENTIFIER; sp->source = NULL; diff --git a/src/cflow.h b/src/cflow.h index 986f42e..1749ada 100644 --- a/src/cflow.h +++ b/src/cflow.h @@ -166,7 +166,7 @@ extern int symbol_count; extern unsigned input_file_count; Symbol *lookup(char*); -Symbol *install(char*); +Symbol *install(char*, int); Symbol *install_ident(char *name, enum storage storage); void ident_change_storage(Symbol *sp, enum storage storage); void delete_autos(int level); @@ -274,7 +274,7 @@ symbol_override(const char *str) } } name = strndup(str, ptr - str); - sp = install(name); + sp = install(name, 0); sp->type = SymToken; sp->token_type = type; sp->source = NULL; diff --git a/src/parser.c b/src/parser.c index ae3c75b..8ba1747 100644 --- a/src/parser.c +++ b/src/parser.c @@ -326,7 +326,6 @@ skip_balanced(int open_tok, int close_tok, int level) { if (level == 0) { if (nexttoken() != open_tok) { - putback(); return 1; } } @@ -1076,17 +1075,14 @@ declare_type(Ident *ident) if (sp->type == SymToken && sp->token_type == TYPE) break; if (!sp) - sp = install(ident->name); + sp = install(ident->name, 1); sp->type = SymToken; sp->token_type = TYPE; sp->source = filename; sp->def_line = ident->line; sp->ref_line = NULL; if (debug) - printf(_("%s:%d: type %s\n"), - filename, - line_num, - ident->name); + printf(_("%s:%d: type %s\n"), filename, line_num, ident->name); } Symbol * diff --git a/src/symbol.c b/src/symbol.c index c9e8720..e26e9c5 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -76,8 +76,10 @@ lookup(char *name) return tp ? tp->sym : NULL; } +/* Install a new symbol `NAME'. If UNIT_LOCAL is set, this symbol can + be local to the current compilation unit. */ Symbol * -install(char *name) +install(char *name, int unit_local) { Symbol *sym; struct table_entry *tp, *ret; @@ -90,9 +92,11 @@ install(char *name) tp = xmalloc(sizeof(*tp)); tp->sym = sym; - if (canonical_filename && strcmp(filename, canonical_filename)) + if (unit_local && + canonical_filename && strcmp(filename, canonical_filename)) { sym->flag = symbol_temp; - else + append_symbol(&static_symbol_list, sym); + } else sym->flag = symbol_none; if (! ((symbol_table @@ -109,8 +113,6 @@ install(char *name) free(tp); } sym->owner = ret; - if (sym->flag == symbol_temp) - append_symbol(&static_symbol_list, sym); return sym; } @@ -140,7 +142,7 @@ install_ident(char *name, enum storage storage) { Symbol *sp; - sp = install(name); + sp = install(name, storage != AutoStorage); sp->type = SymIdentifier; sp->arity = -1; sp->storage = ExternStorage; @@ -183,7 +185,7 @@ delete_symbol(Symbol *sym) unlink_symbol(sym); /* The symbol could have been referenced even if it is static in -i^s mode. See tests/static.at for details. */ - if (sym->ref_line == NULL) { + if (sym->ref_line == NULL && !(reverse_tree && sym->callee)) { linked_list_destroy(&sym->ref_line); linked_list_destroy(&sym->caller); linked_list_destroy(&sym->callee); |