Work-around to support function names in more situations

The context system obviously needs a re-design
This commit is contained in:
Pierre Pronchery 2008-06-22 01:53:48 +00:00
parent 8ac4abef5f
commit ff3e71b477
3 changed files with 23 additions and 5 deletions

View File

@ -371,11 +371,20 @@ int code_context_set(Code * code, CodeContext context)
break; break;
case CODE_CONTEXT_FUNCTION: case CODE_CONTEXT_FUNCTION:
/* handle any DECLARATION_OR_FUNCTION identifier */ /* handle any DECLARATION_OR_FUNCTION identifier */
if(code->identifiers_cnt >= 1) /* XXX ugly hack */
for(i = 0; i < code->identifiers_cnt; i++)
if(code->identifiers[i].context ==
CODE_CONTEXT_TYPEDEF_NAME)
continue;
else
{
ret |= code_context_set_identifier(code, ret |= code_context_set_identifier(code,
code->identifiers[0].name); code->identifiers[i]
.name);
break;
}
code->context = CODE_CONTEXT_FUNCTION_PARAMETERS; code->context = CODE_CONTEXT_FUNCTION_PARAMETERS;
for(i = 1; i < code->identifiers_cnt; i++) for(i++; i < code->identifiers_cnt; i++)
ret |= code_context_set_identifier(code, ret |= code_context_set_identifier(code,
code->identifiers[i].name); code->identifiers[i].name);
_code_context_flush(code); _code_context_flush(code);
@ -448,6 +457,7 @@ int code_context_set_identifier(Code * code, char const * identifier)
"primary expr", "primary expr",
"statement", "statement",
"struct", "struct",
"typedef name",
"union" "union"
}; };

View File

@ -52,6 +52,7 @@ typedef enum _CodeContext
CODE_CONTEXT_PRIMARY_EXPR, CODE_CONTEXT_PRIMARY_EXPR,
CODE_CONTEXT_STATEMENT, CODE_CONTEXT_STATEMENT,
CODE_CONTEXT_STRUCT, CODE_CONTEXT_STRUCT,
CODE_CONTEXT_TYPEDEF_NAME,
CODE_CONTEXT_UNION CODE_CONTEXT_UNION
} CodeContext; } CodeContext;
# define CODE_CONTEXT_LAST CODE_CONTEXT_UNION # define CODE_CONTEXT_LAST CODE_CONTEXT_UNION

View File

@ -685,8 +685,15 @@ static int _enumeration_constant(C99 * c99)
static int _typedef_name(C99 * c99) static int _typedef_name(C99 * c99)
/* identifier */ /* identifier */
{ {
int ret;
CodeContext context;
DEBUG_GRAMMAR(); DEBUG_GRAMMAR();
return _identifier(c99); context = code_context_get(c99->code);
ret = code_context_set(c99->code, CODE_CONTEXT_TYPEDEF_NAME);
ret |= _identifier(c99);
ret |= code_context_set(c99->code, context);
return ret;
} }