aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-10-10 11:57:39 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-10-10 12:04:35 +0300
commit250d9aab8f79ebd7a2f2535de9db60172df51598 (patch)
tree8cb00af0546ba73a53f6495cf021d545438f47c3 /src
parentca94bd309cb7dc9d33e4c06d95b6fc44714ffe9d (diff)
downloadcflow-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.l6
-rw-r--r--src/cflow.h2
-rw-r--r--src/main.c2
-rw-r--r--src/parser.c8
-rw-r--r--src/symbol.c16
5 files changed, 16 insertions, 18 deletions
diff --git a/src/c.l b/src/c.l
index 205a297..be14004 100644
--- a/src/c.l
+++ b/src/c.l
@@ -203,26 +203,26 @@ init_lex(int debug_level)
yy_flex_debug = 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;
sp->def_line = -1;
sp->ref_line = NULL;
}
diff --git a/src/cflow.h b/src/cflow.h
index 986f42e..1749ada 100644
--- a/src/cflow.h
+++ b/src/cflow.h
@@ -163,13 +163,13 @@ extern int token_stack_length;
extern int token_stack_increase;
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);
void delete_statics(void);
void delete_parms(int level);
void move_parms(int level);
diff --git a/src/main.c b/src/main.c
index dff6788..dbb8453 100644
--- a/src/main.c
+++ b/src/main.c
@@ -271,13 +271,13 @@ symbol_override(const char *str)
if (type == 0) {
error(0, 0, _("unknown symbol type: %s"), ptr+1);
return;
}
}
name = strndup(str, ptr - str);
- sp = install(name);
+ sp = install(name, 0);
sp->type = SymToken;
sp->token_type = type;
sp->source = NULL;
sp->def_line = -1;
sp->ref_line = NULL;
}
diff --git a/src/parser.c b/src/parser.c
index ae3c75b..8ba1747 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -323,13 +323,12 @@ skip_to(int c)
int
skip_balanced(int open_tok, int close_tok, int level)
{
if (level == 0) {
if (nexttoken() != open_tok) {
- putback();
return 1;
}
}
while (nexttoken()) {
if (tok.type == open_tok)
level++;
@@ -1073,23 +1072,20 @@ declare_type(Ident *ident)
undo_save_stack();
sp = lookup(ident->name);
for ( ; sp; sp = sp->next)
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 *
get_symbol(char *name)
{
Symbol *sp = lookup(name) ;
diff --git a/src/symbol.c b/src/symbol.c
index c9e8720..e26e9c5 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -73,29 +73,33 @@ lookup(char *name)
s.name = name;
t.sym = &s;
tp = hash_lookup(symbol_table, &t);
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;
sym = xmalloc(sizeof(*sym));
memset(sym, 0, sizeof(*sym));
sym->type = SymUndefined;
sym->name = 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
|| (symbol_table = hash_initialize (0, 0,
hash_symbol_hasher,
hash_symbol_compare, 0)))
@@ -106,14 +110,12 @@ install(char *name)
if (ret->sym->type != SymUndefined)
sym->next = ret->sym;
ret->sym = sym;
free(tp);
}
sym->owner = ret;
- if (sym->flag == symbol_temp)
- append_symbol(&static_symbol_list, sym);
return sym;
}
void
ident_change_storage(Symbol *sp, enum storage storage)
{
@@ -137,13 +139,13 @@ ident_change_storage(Symbol *sp, enum storage storage)
Symbol *
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;
sp->decl = NULL;
sp->source = NULL;
sp->def_line = -1;
@@ -180,13 +182,13 @@ unlink_symbol(Symbol *sym)
static void
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);
free(sym);
}
}

Return to:

Send suggestions and report system problems to the System administrator.