diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index ef8e3322f..ca1cfaae6 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -30,6 +30,7 @@ static const std::string ArraySubscriptExpr = "ArraySubscriptExpr"; static const std::string BinaryOperator = "BinaryOperator"; static const std::string BreakStmt = "BreakStmt"; static const std::string CallExpr = "CallExpr"; +static const std::string CaseStmt = "CaseStmt"; static const std::string CharacterLiteral = "CharacterLiteral"; static const std::string ClassTemplateDecl = "ClassTemplateDecl"; static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl"; @@ -511,6 +512,13 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == CallExpr) return createTokensCall(tokenList); + if (nodeType == CaseStmt) { + addtoken(tokenList, "case"); + children[0]->createTokens(tokenList); + addtoken(tokenList, ":"); + children[2]->createTokens(tokenList); + return nullptr; + } if (nodeType == ClassTemplateDecl) { for (AstNodePtr child: children) { if (child->nodeType == ClassTemplateSpecializationDecl) diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 948fc9e6c..752bd9803 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -31,6 +31,7 @@ public: private: void run() OVERRIDE { TEST_CASE(breakStmt); + TEST_CASE(caseStmt1); TEST_CASE(characterLiteral); TEST_CASE(class1); TEST_CASE(classTemplateDecl1); @@ -103,6 +104,36 @@ private: ASSERT_EQUALS("void foo ( ) { while ( 0 ) { break ; } }", parse(clang)); } + void caseStmt1() { + const char clang[] = "`-FunctionDecl 0x2444b60 <1.c:1:1, line:8:1> line:1:6 foo 'void (int)'\n" + " |-ParmVarDecl 0x2444aa0 col:14 used x 'int'\n" + " `-CompoundStmt 0x2444e00 \n" + " `-SwitchStmt 0x2444c88 \n" + " |-<<>>\n" + " |-<<>>\n" + " |-ImplicitCastExpr 0x2444c70 'int' \n" + " | `-DeclRefExpr 0x2444c48 'int' lvalue ParmVar 0x2444aa0 'x' 'int'\n" + " `-CompoundStmt 0x2444de0 \n" + " |-CaseStmt 0x2444cd8 \n" + " | |-IntegerLiteral 0x2444cb8 'int' 16\n" + " | |-<<>>\n" + " | `-CaseStmt 0x2444d30 \n" + " | |-IntegerLiteral 0x2444d10 'int' 32\n" + " | |-<<>>\n" + " | `-BinaryOperator 0x2444db0 'int' '='\n" + " | |-DeclRefExpr 0x2444d68 'int' lvalue ParmVar 0x2444aa0 'x' 'int'\n" + " | `-IntegerLiteral 0x2444d90 'int' 123\n" + " `-BreakStmt 0x2444dd8 "; + ASSERT_EQUALS("void foo ( int x@1 ) {\n" + "switch ( x@1 ) {\n" + "case 16 :\n" + "case 32 :\n" + "x@1 = 123 ;\n" + "\n" + "\n" + "break ; } }", parse(clang)); + } + void characterLiteral() { const char clang[] = "`-VarDecl 0x3df8608 col:6 c 'char' cinit\n" " `-CharacterLiteral 0x3df86a8 'char' 120";