diff --git a/src/code.c b/src/code.c index 45be7b1..43b2488 100644 --- a/src/code.c +++ b/src/code.c @@ -371,11 +371,20 @@ int code_context_set(Code * code, CodeContext context) break; case CODE_CONTEXT_FUNCTION: /* handle any DECLARATION_OR_FUNCTION identifier */ - if(code->identifiers_cnt >= 1) - ret |= code_context_set_identifier(code, - code->identifiers[0].name); + /* 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, + code->identifiers[i] + .name); + break; + } 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, code->identifiers[i].name); _code_context_flush(code); @@ -448,6 +457,7 @@ int code_context_set_identifier(Code * code, char const * identifier) "primary expr", "statement", "struct", + "typedef name", "union" }; diff --git a/src/code.h b/src/code.h index c562261..a159376 100644 --- a/src/code.h +++ b/src/code.h @@ -52,6 +52,7 @@ typedef enum _CodeContext CODE_CONTEXT_PRIMARY_EXPR, CODE_CONTEXT_STATEMENT, CODE_CONTEXT_STRUCT, + CODE_CONTEXT_TYPEDEF_NAME, CODE_CONTEXT_UNION } CodeContext; # define CODE_CONTEXT_LAST CODE_CONTEXT_UNION diff --git a/src/parser.c b/src/parser.c index 99e0106..61d31c4 100644 --- a/src/parser.c +++ b/src/parser.c @@ -685,8 +685,15 @@ static int _enumeration_constant(C99 * c99) static int _typedef_name(C99 * c99) /* identifier */ { + int ret; + CodeContext context; + 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; }