From 13e11b2fafe60cad7d04d80c602adc12d6080036 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 22 Apr 2011 18:24:59 -0400 Subject: Handle symbol aliases in dmnsn_find_symbol() directly. Fixes infinite loops when macro arguments have the same name as existing symbols. --- dimension/common.rules | 8 +------- dimension/parse.c | 9 +++++++-- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'dimension') diff --git a/dimension/common.rules b/dimension/common.rules index 9383d4b..a987c69 100644 --- a/dimension/common.rules +++ b/dimension/common.rules @@ -22,14 +22,8 @@ /* Fundamental language elements */ IDENTIFIER: "identifier" { - const char *id = $1; - dmnsn_astnode *symbol = dmnsn_find_symbol(symtable, id); - while (symbol && symbol->type == DMNSN_AST_IDENTIFIER) { - id = symbol->ptr; - symbol = dmnsn_find_symbol(symtable, id); - } $$ = dmnsn_new_astleaf(DMNSN_AST_IDENTIFIER, @$); - $$.ptr = dmnsn_strdup(id); + $$.ptr = dmnsn_strdup($1); dmnsn_free($1); } ; diff --git a/dimension/parse.c b/dimension/parse.c index 74075a7..6651d41 100644 --- a/dimension/parse.c +++ b/dimension/parse.c @@ -131,8 +131,13 @@ dmnsn_find_symbol(dmnsn_symbol_table *symtable, const char *id) DMNSN_ARRAY_FOREACH_REVERSE (dmnsn_dictionary **, dict, symtable) { symbol = dmnsn_dictionary_at(*dict, id); - if (symbol) - break; + if (symbol) { + if (symbol->type == DMNSN_AST_IDENTIFIER) { + id = symbol->ptr; + } else { + break; + } + } } return symbol; -- cgit v1.2.3