Catching more context changes

This commit is contained in:
Pierre Pronchery 2008-06-21 19:11:05 +00:00
parent 292fcbee08
commit 8ed9d8b577
3 changed files with 27 additions and 9 deletions

View File

@ -341,9 +341,15 @@ int code_context_set(Code * code, CodeContext context)
size_t i; size_t i;
CodeIdentifier * ci; CodeIdentifier * ci;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() 0x%x\n", __func__, context);
#endif
code->context = context; code->context = context;
switch(context) switch(context)
{ {
case CODE_CONTEXT_ASSIGNMENT:
_code_context_flush(code);
break;
case CODE_CONTEXT_DECLARATION: case CODE_CONTEXT_DECLARATION:
/* handle any DECLARATION_OR_FUNCTION identifier */ /* handle any DECLARATION_OR_FUNCTION identifier */
for(i = 0; i < code->identifiers_cnt; i++) for(i = 0; i < code->identifiers_cnt; i++)
@ -396,6 +402,10 @@ int code_context_set(Code * code, CodeContext context)
code->identifiers[0].name); code->identifiers[0].name);
} }
_code_context_flush(code); _code_context_flush(code);
break;
case CODE_CONTEXT_STATEMENT:
_code_context_flush(code);
break;
default: default:
break; break;
} }
@ -418,6 +428,7 @@ int code_context_set_identifier(Code * code, char const * identifier)
char const * str[CODE_CONTEXT_COUNT] = char const * str[CODE_CONTEXT_COUNT] =
{ {
"NULL", "NULL",
"assignment",
"declaration", "declaration",
"declaration end", "declaration end",
"declaration or function", "declaration or function",
@ -431,9 +442,11 @@ int code_context_set_identifier(Code * code, char const * identifier)
"function end", "function end",
"function parameters", "function parameters",
"function start", "function start",
"label",
"parameters", "parameters",
"parameters type", "parameters type",
"primary expr", "primary expr",
"statement",
"struct", "struct",
"union" "union"
}; };
@ -490,7 +503,7 @@ int code_context_set_storage(Code * code, CodeStorage storage)
size_t i; size_t i;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%s)\n", __func__, str[storage]); fprintf(stderr, "DEBUG: %s(0x%x)\n", __func__, storage);
#endif #endif
if(!(code->storage & storage)) if(!(code->storage & storage))
{ {

View File

@ -32,6 +32,7 @@ typedef struct _Code Code;
typedef enum _CodeContext typedef enum _CodeContext
{ {
CODE_CONTEXT_NULL = 0, CODE_CONTEXT_NULL = 0,
CODE_CONTEXT_ASSIGNMENT,
CODE_CONTEXT_DECLARATION, CODE_CONTEXT_DECLARATION,
CODE_CONTEXT_DECLARATION_END, CODE_CONTEXT_DECLARATION_END,
CODE_CONTEXT_DECLARATION_OR_FUNCTION, CODE_CONTEXT_DECLARATION_OR_FUNCTION,
@ -49,6 +50,7 @@ typedef enum _CodeContext
CODE_CONTEXT_PARAMETERS, CODE_CONTEXT_PARAMETERS,
CODE_CONTEXT_PARAMETERS_TYPE, CODE_CONTEXT_PARAMETERS_TYPE,
CODE_CONTEXT_PRIMARY_EXPR, CODE_CONTEXT_PRIMARY_EXPR,
CODE_CONTEXT_STATEMENT,
CODE_CONTEXT_STRUCT, CODE_CONTEXT_STRUCT,
CODE_CONTEXT_UNION CODE_CONTEXT_UNION
} CodeContext; } CodeContext;

View File

@ -1019,6 +1019,7 @@ static int _assignment_expr(C99 * c99)
ret |= _conditional_expr(c99); ret |= _conditional_expr(c99);
if(!_parse_in_set(c99, c99set_assignment_operator)) if(!_parse_in_set(c99, c99set_assignment_operator))
return ret; return ret;
ret |= code_context_set(c99->code, CODE_CONTEXT_ASSIGNMENT);
ret |= _assignment_operator(c99); ret |= _assignment_operator(c99);
} }
return ret; return ret;
@ -1583,21 +1584,23 @@ static int _statement(C99 * c99)
* iteration-statement * iteration-statement
* jump-statement */ * jump-statement */
{ {
int ret;
DEBUG_GRAMMAR(); DEBUG_GRAMMAR();
ret = code_context_set(c99->code, CODE_CONTEXT_STATEMENT);
if(_parse_in_set(c99, c99set_labeled_statement)) if(_parse_in_set(c99, c99set_labeled_statement))
return _labeled_statement(c99); ret |= _labeled_statement(c99);
else if(_parse_in_set(c99, c99set_compound_statement)) else if(_parse_in_set(c99, c99set_compound_statement))
return _compound_statement(c99); ret |= _compound_statement(c99);
else if(_parse_in_set(c99, c99set_expression_statement)) else if(_parse_in_set(c99, c99set_expression_statement))
return _expression_statement(c99); ret |= _expression_statement(c99);
else if(_parse_in_set(c99, c99set_selection_statement)) else if(_parse_in_set(c99, c99set_selection_statement))
return _selection_statement(c99); ret |= _selection_statement(c99);
else if(_parse_in_set(c99, c99set_iteration_statement)) else if(_parse_in_set(c99, c99set_iteration_statement))
return _iteration_statement(c99); ret |= _iteration_statement(c99);
else if(_parse_in_set(c99, c99set_jump_statement)) else if(_parse_in_set(c99, c99set_jump_statement))
return _jump_statement(c99); ret |= _jump_statement(c99);
/* XXX should be code bloat now */ return ret;
return _parse_error(c99, "Expected statement");
} }