Skip to content

Commit bcc2d67

Browse files
committed
Add support for parsing using declarations
- they are handled similar to typedefs
1 parent 4c963ac commit bcc2d67

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

generator/parser/parser.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ bool Parser::parseUsing(DeclarationAST *&node)
645645

646646
CHECK(Token_using);
647647

648+
if (token_stream.lookAhead(1) == '=')
649+
{
650+
return parseUsingTypedef(node);
651+
}
652+
648653
if (token_stream.lookAhead() == Token_namespace)
649654
return parseUsingDirective(node);
650655

@@ -667,6 +672,41 @@ bool Parser::parseUsing(DeclarationAST *&node)
667672
return true;
668673
}
669674

675+
bool Parser::parseUsingTypedef(DeclarationAST*& node)
676+
{
677+
std::size_t start = token_stream.cursor();
678+
679+
DeclaratorAST* decl = 0;
680+
if (!parseDeclarator(decl))
681+
{
682+
return false;
683+
}
684+
685+
InitDeclaratorAST* init_decl = CreateNode<InitDeclaratorAST>(_M_pool);
686+
init_decl->declarator = decl;
687+
init_decl->initializer = 0;
688+
const ListNode<InitDeclaratorAST*>* declarators = 0;
689+
declarators = snoc(declarators, init_decl, _M_pool);
690+
691+
ADVANCE('=', "=");
692+
693+
TypeSpecifierAST* spec = 0;
694+
if (!parseTypeSpecifierOrClassSpec(spec))
695+
{
696+
reportError(("Need a type specifier to declare"));
697+
return false;
698+
}
699+
700+
TypedefAST* ast = CreateNode<TypedefAST>(_M_pool);
701+
ast->type_specifier = spec;
702+
ast->init_declarators = declarators;
703+
704+
UPDATE_POS(ast, start, token_stream.cursor());
705+
node = ast;
706+
707+
return true;
708+
}
709+
670710
bool Parser::parseUsingDirective(DeclarationAST *&node)
671711
{
672712
std::size_t start = token_stream.cursor();

generator/parser/parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ class Parser
175175
bool parseUnqualifiedName(UnqualifiedNameAST *&node,
176176
bool parseTemplateId = true);
177177
bool parseUsing(DeclarationAST *&node);
178+
bool parseUsingTypedef(DeclarationAST*& node);
178179
bool parseUsingDirective(DeclarationAST *&node);
179180
bool parseWhileStatement(StatementAST *&node);
180181
bool parseWinDeclSpec(WinDeclSpecAST *&node);

0 commit comments

Comments
 (0)