Clang import: Fix syntax tree for 'case 1'

This commit is contained in:
Daniel Marjamäki 2020-10-04 19:33:16 +02:00
parent d37ddc7114
commit e3ab688597
2 changed files with 5 additions and 4 deletions

View File

@ -558,8 +558,9 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
if (nodeType == CallExpr)
return createTokensCall(tokenList);
if (nodeType == CaseStmt) {
addtoken(tokenList, "case");
children[0]->createTokens(tokenList);
Token *caseToken = addtoken(tokenList, "case");
Token *exprToken = children[0]->createTokens(tokenList);
caseToken->astOperand1(exprToken);
addtoken(tokenList, ":");
children.back()->createTokens(tokenList);
return nullptr;
@ -604,7 +605,7 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
return nullptr;
}
if (nodeType == ConstantExpr)
return children[0]->createTokens(tokenList);
return children.back()->createTokens(tokenList);
if (nodeType == ContinueStmt)
return addtoken(tokenList, "continue");
if (nodeType == CStyleCastExpr) {

View File

@ -89,7 +89,7 @@ def test_ast_calculations():
def test_ast_control_flow():
check_ast('void foo(int x) { if (x > 5){} }')
check_ast('int dostuff() { for (int x = 0; x < 10; x++); }')
todo_check_ast('void foo(int x) { switch (x) {case 1: break; } }')
check_ast('void foo(int x) { switch (x) {case 1: break; } }')