diff options
author | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2011-01-05 20:44:05 +0200 |
---|---|---|
committer | George Kiagiadakis <george.kiagiadakis@collabora.co.uk> | 2011-01-05 20:44:05 +0200 |
commit | be247877c0c53d78139e0cb3a8235c98cd5eca16 (patch) | |
tree | f1651bb6b6a0a3970e53bdb5454cb8ff7ade3f66 | |
parent | d6c406bbf66c1fa9890090365b76d370936a333f (diff) |
codegen: treat namespace and class declarations as normal tokens.
This fixes a bug in the case that the lexer looks ahead of a token
and hits a new class or namespace declaration, and then the parser
executes the handler for this token, believing that the current
class or namespace is the next one.
-rw-r--r-- | codegen/analyzer.l | 8 | ||||
-rw-r--r-- | codegen/parser.y | 17 |
2 files changed, 20 insertions, 5 deletions
diff --git a/codegen/analyzer.l b/codegen/analyzer.l index 799ece3..2a06b40 100644 --- a/codegen/analyzer.l +++ b/codegen/analyzer.l @@ -104,16 +104,16 @@ Q[A-Z]+_WRAPPER_FAKE_SUBCLASS\( { yy_push_state(REGISTER_WRAPPER); return R . } -[[:space:]]namespace { yy_push_state(NAMESPACE); } +[[:space:]]namespace { yy_push_state(NAMESPACE); return NAMESPACE_KEYWORD; } <NAMESPACE>{ - {id} { codegen->setCurrentNameSpace(yytext); yy_pop_state(); } + {id} { yylval.Id = new QByteArray(yytext); yy_pop_state(); return IDENTIFIER; } [[:space:]]* . { yyerror(codegen, "Expected identifier after namespace keyword"); } } -[[:space:]]class { yy_push_state(CLASS); } +[[:space:]]class { yy_push_state(CLASS); return CLASS_KEYWORD; } <CLASS>{ - {id} { codegen->setCurrentClass(yytext); yy_pop_state(); } + {id} { yylval.Id = new QByteArray(yytext); yy_pop_state(); return IDENTIFIER; } [[:space:]]* . { yyerror(codegen, "Expected identifier after class keyword"); } } diff --git a/codegen/parser.y b/codegen/parser.y index 6c75bd2..1417d99 100644 --- a/codegen/parser.y +++ b/codegen/parser.y @@ -41,6 +41,8 @@ void yyerror(CodeGen *codegen, const char *msg); INSTRUCTIONS_SEPARATOR INSTRUCTIONS_END ENUM_KEYWORD + NAMESPACE_KEYWORD + CLASS_KEYWORD LEFT_BRACE RIGHT_BRACE COMMA @@ -68,7 +70,7 @@ void yyerror(CodeGen *codegen, const char *msg); header: header expression | expression | /*empty*/; -expression : enum_def | type_registration | wrapper_definition; +expression : enum_def | class_def | namespace_def | type_registration | wrapper_definition; enum_def: ENUM_KEYWORD IDENTIFIER LEFT_BRACE optional_instructions enum_list RIGHT_BRACE SEMICOLON @@ -93,6 +95,19 @@ enum_list: delete $1; }; +class_def: + CLASS_KEYWORD IDENTIFIER + { + codegen->setCurrentClass(*$2); + delete $2; + }; + +namespace_def: + NAMESPACE_KEYWORD IDENTIFIER + { + codegen->setCurrentNameSpace(*$2); + delete $2; + }; type_registration: REGISTER_TYPE_BEGIN IDENTIFIER SCOPE_RESOLUTION_OPERATOR IDENTIFIER optional_enum_id REGISTER_TYPE_END optional_instructions |