From e3ab6885979b0a4d385d0e33bdbb3fa3f6c7f59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 4 Oct 2020 19:33:16 +0200 Subject: [PATCH] Clang import: Fix syntax tree for 'case 1' --- lib/clangimport.cpp | 7 ++++--- test/cli/test-clang-import.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 08dc2779a..2d196f168 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -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) { diff --git a/test/cli/test-clang-import.py b/test/cli/test-clang-import.py index b3970f21f..6bb5dadc0 100644 --- a/test/cli/test-clang-import.py +++ b/test/cli/test-clang-import.py @@ -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; } }')