diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 89b527771..ef8e3322f 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -68,6 +68,7 @@ static const std::string ParmVarDecl = "ParmVarDecl"; static const std::string RecordDecl = "RecordDecl"; static const std::string ReturnStmt = "ReturnStmt"; static const std::string StringLiteral = "StringLiteral"; +static const std::string SwitchStmt = "SwitchStmt"; static const std::string TemplateArgument = "TemplateArgument"; static const std::string TypedefDecl = "TypedefDecl"; static const std::string UnaryOperator = "UnaryOperator"; @@ -782,6 +783,18 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == StringLiteral) return addtoken(tokenList, mExtTokens.back()); + if (nodeType == SwitchStmt) { + Token *tok1 = addtoken(tokenList, "switch"); + Token *par1 = addtoken(tokenList, "("); + Token *expr = children[children.size() - 2]->createTokens(tokenList); + Token *par2 = addtoken(tokenList, ")"); + par1->link(par2); + par2->link(par1); + par1->astOperand1(tok1); + par1->astOperand1(expr); + createScope(tokenList, Scope::ScopeType::eSwitch, children.back()); + return nullptr; + } if (nodeType == TypedefDecl) { addtoken(tokenList, "typedef"); addTypeTokens(tokenList, getType()); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 3bb470fad..948fc9e6c 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -63,6 +63,7 @@ private: TEST_CASE(memberExpr); TEST_CASE(namespaceDecl); TEST_CASE(recordDecl); + TEST_CASE(switchStmt); TEST_CASE(typedefDecl1); TEST_CASE(typedefDecl2); TEST_CASE(typedefDecl3); @@ -516,6 +517,21 @@ private: parse(clang)); } + void switchStmt() { + const char clang[] = "`-FunctionDecl 0x2796ba0 <1.c:1:1, col:35> col:6 foo 'void (int)'\n" + " |-ParmVarDecl 0x2796ae0 col:14 used x 'int'\n" + " `-CompoundStmt 0x2796d18 \n" + " |-SwitchStmt 0x2796cc8 \n" + " | |-<<>>\n" + " | |-<<>>\n" + " | |-ImplicitCastExpr 0x2796cb0 'int' \n" + " | | `-DeclRefExpr 0x2796c88 'int' lvalue ParmVar 0x2796ae0 'x' 'int'\n" + " | `-CompoundStmt 0x2796cf8 \n" + " `-NullStmt 0x2796d08 "; + ASSERT_EQUALS("void foo ( int x@1 ) { switch ( x@1 ) { } ; }", + parse(clang)); + } + void typedefDecl1() { const char clang[] = "|-TypedefDecl 0x2d60180 <> implicit __int128_t '__int128'\n" "| `-BuiltinType 0x2d5fe80 '__int128'";