diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 439e7cd2f..488dcbaee 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -40,6 +40,7 @@ static const std::string CStyleCastExpr = "CStyleCastExpr"; static const std::string CXXBoolLiteralExpr = "CXXBoolLiteralExpr"; static const std::string CXXConstructorDecl = "CXXConstructorDecl"; static const std::string CXXConstructExpr = "CXXConstructExpr"; +static const std::string CXXForRangeStmt = "CXXForRangeStmt"; static const std::string CXXMemberCallExpr = "CXXMemberCallExpr"; static const std::string CXXMethodDecl = "CXXMethodDecl"; static const std::string CXXNullPtrLiteralExpr = "CXXNullPtrLiteralExpr"; @@ -571,6 +572,28 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) createTokensFunctionDecl(tokenList); return nullptr; } + if (nodeType == CXXForRangeStmt) { + Token *forToken = addtoken(tokenList, "for"); + Token *par1 = addtoken(tokenList, "("); + children[5]->children[0]->mExtTokens.pop_back(); + children[5]->children[0]->children.clear(); + Token *expr1 = children[5]->children[0]->createTokens(tokenList); + Token *colon = addtoken(tokenList, ":"); + Token *expr2 = children[0]->children[0]->children[0]->createTokens(tokenList); + Token *par2 = addtoken(tokenList, ")"); + + par1->link(par2); + par2->link(par1); + + colon->astOperand1(expr1); + colon->astOperand2(expr2); + par1->astOperand1(forToken); + par1->astOperand2(colon); + + Scope *scope = createScope(tokenList, Scope::ScopeType::eFor, children[6]); + scope->classDef = forToken; + return nullptr; + } if (nodeType == CXXMethodDecl) { createTokensFunctionDecl(tokenList); return nullptr; diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index a3e981188..3bb470fad 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -43,6 +43,7 @@ private: TEST_CASE(cxxConstructExpr1); TEST_CASE(cxxConstructExpr2); TEST_CASE(cxxConstructExpr3); + TEST_CASE(cxxForRangeStmt); TEST_CASE(cxxMemberCall); TEST_CASE(cxxMethodDecl); TEST_CASE(cxxNullPtrLiteralExpr); @@ -261,6 +262,42 @@ private: ASSERT_EQUALS("void f ( ) { char * p@1 ; std::string s@2 ( p@1 ) ; }", parse(clang)); } + void cxxForRangeStmt() { + const char clang[] = "`-FunctionDecl 0x4280820 line:4:6 foo 'void ()'\n" + " `-CompoundStmt 0x42810f0 \n" + " `-CXXForRangeStmt 0x4281090 \n" + " |-DeclStmt 0x4280c30 \n" + " | `-VarDecl 0x42809c8 col:17 implicit referenced __range1 'char const (&)[6]' cinit\n" + " | `-DeclRefExpr 0x42808c0 'const char [6]' lvalue Var 0x4280678 'hello' 'const char [6]'\n" + " |-DeclStmt 0x4280ef8 \n" + " | `-VarDecl 0x4280ca8 col:15 implicit used __begin1 'const char *':'const char *' cinit\n" + " | `-ImplicitCastExpr 0x4280e10 'const char *' \n" + " | `-DeclRefExpr 0x4280c48 'char const[6]' lvalue Var 0x42809c8 '__range1' 'char const (&)[6]'\n" + " |-DeclStmt 0x4280f10 \n" + " | `-VarDecl 0x4280d18 col:15 implicit used __end1 'const char *':'const char *' cinit\n" + " | `-BinaryOperator 0x4280e60 'const char *' '+'\n" + " | |-ImplicitCastExpr 0x4280e48 'const char *' \n" + " | | `-DeclRefExpr 0x4280c70 'char const[6]' lvalue Var 0x42809c8 '__range1' 'char const (&)[6]'\n" + " | `-IntegerLiteral 0x4280e28 'long' 6\n" + " |-BinaryOperator 0x4280fa8 'bool' '!='\n" + " | |-ImplicitCastExpr 0x4280f78 'const char *':'const char *' \n" + " | | `-DeclRefExpr 0x4280f28 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n" + " | `-ImplicitCastExpr 0x4280f90 'const char *':'const char *' \n" + " | `-DeclRefExpr 0x4280f50 'const char *':'const char *' lvalue Var 0x4280d18 '__end1' 'const char *':'const char *'\n" + " |-UnaryOperator 0x4280ff8 'const char *':'const char *' lvalue prefix '++'\n" + " | `-DeclRefExpr 0x4280fd0 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n" + " |-DeclStmt 0x4280958 \n" + " | `-VarDecl 0x42808f8 col:13 c1 'char' cinit\n" + " | `-ImplicitCastExpr 0x4281078 'char' \n" + " | `-UnaryOperator 0x4281058 'const char' lvalue prefix '*' cannot overflow\n" + " | `-ImplicitCastExpr 0x4281040 'const char *':'const char *' \n" + " | `-DeclRefExpr 0x4281018 'const char *':'const char *' lvalue Var 0x4280ca8 '__begin1' 'const char *':'const char *'\n" + " `-CompoundStmt 0x42810e0 "; + ASSERT_EQUALS("void foo ( ) {\n" + "for ( char c1@1 : hello ) { } }", + parse(clang)); + } + void cxxMemberCall() { const char clang[] = "`-FunctionDecl 0x320dc80 col:6 bar 'void ()'\n" " `-CompoundStmt 0x323bb08 \n"