diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index cca0d902c..4f6295806 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -48,6 +48,7 @@ static const std::string CXXStaticCastExpr = "CXXStaticCastExpr"; static const std::string CXXThisExpr = "CXXThisExpr"; static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclStmt = "DeclStmt"; +static const std::string ExprWithCleanups = "ExprWithCleanups"; static const std::string FieldDecl = "FieldDecl"; static const std::string ForStmt = "ForStmt"; static const std::string FunctionDecl = "FunctionDecl"; @@ -557,8 +558,6 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) } if (nodeType == CXXThisExpr) return addtoken(tokenList, "this"); - if (nodeType == DeclStmt) - return children[0]->createTokens(tokenList); if (nodeType == DeclRefExpr) { const std::string addr = mExtTokens[mExtTokens.size() - 3]; std::string name = unquote(getSpelling()); @@ -566,6 +565,10 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) mData->ref(addr, reftok); return reftok; } + if (nodeType == DeclStmt) + return children[0]->createTokens(tokenList); + if (nodeType == ExprWithCleanups) + return children[0]->createTokens(tokenList); if (nodeType == FieldDecl) return createTokensVarDecl(tokenList); if (nodeType == ForStmt) { @@ -857,6 +860,14 @@ Token * clangimport::AstNode::createTokensVarDecl(TokenList *tokenList) eq->astOperand1(vartok1); eq->astOperand2(children.back()->createTokens(tokenList)); return eq; + } else if (mExtTokens.back() == "callinit") { + Token *par1 = addtoken(tokenList, "("); + par1->astOperand1(vartok1); + par1->astOperand2(children[0]->createTokens(tokenList)); + Token *par2 = addtoken(tokenList, ")"); + par1->link(par2); + par2->link(par1); + return par1; } return vartok1; } diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 18031ca23..d8a94e443 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -40,6 +40,7 @@ private: TEST_CASE(cxxConstructorDecl); TEST_CASE(cxxConstructExpr1); TEST_CASE(cxxConstructExpr2); + TEST_CASE(cxxConstructExpr3); TEST_CASE(cxxMemberCall); TEST_CASE(cxxMethodDecl); TEST_CASE(cxxNullPtrLiteralExpr); @@ -224,6 +225,22 @@ private: ASSERT_EQUALS("std::string f ( ) { return std::string ( ) ; }", parse(clang)); } + void cxxConstructExpr3() { + const char clang[] = "`-FunctionDecl 0x2c585b8 <1.cpp:4:1, col:39> col:6 f 'void ()'\n" + " `-CompoundStmt 0x2c589d0 \n" + " |-DeclStmt 0x2c586d0 \n" + " | `-VarDecl 0x2c58670 col:18 used p 'char *'\n" + " `-DeclStmt 0x2c589b8 \n" + " `-VarDecl 0x2c58798 col:33 s 'std::string':'std::__cxx11::basic_string' callinit\n" + " `-ExprWithCleanups 0x2c589a0 'std::string':'std::__cxx11::basic_string'\n" + " `-CXXConstructExpr 0x2c58960 'std::string':'std::__cxx11::basic_string' 'void (const char *, const std::allocator &)'\n" + " |-ImplicitCastExpr 0x2c58870 'const char *' \n" + " | `-ImplicitCastExpr 0x2c58858 'char *' \n" + " | `-DeclRefExpr 0x2c58750 'char *' lvalue Var 0x2c58670 'p' 'char *'\n" + " `-CXXDefaultArgExpr 0x2c58940 <> 'const std::allocator':'const std::allocator' lvalue\n"; + ASSERT_EQUALS("void f ( ) { char * p@1 ; std::string s@2 ( p@1 ) ; }", parse(clang)); + } + void cxxMemberCall() { const char clang[] = "`-FunctionDecl 0x320dc80 col:6 bar 'void ()'\n" " `-CompoundStmt 0x323bb08 \n" @@ -233,7 +250,7 @@ private: " `-CXXMemberCallExpr 0x323bab8 'int':'int'\n" " `-MemberExpr 0x323ba80 '' .foo 0x320e160\n" " `-DeclRefExpr 0x323ba58 'C':'C' lvalue Var 0x320df28 'c' 'C':'C'"; - ASSERT_EQUALS("void bar ( ) { C c@1 ; c@1 . foo ( ) ; }", parse(clang)); + ASSERT_EQUALS("void bar ( ) { C c@1 ( C ( ) ) ; c@1 . foo ( ) ; }", parse(clang)); } void cxxMethodDecl() { @@ -266,7 +283,7 @@ private: " | `-DeclRefExpr 0x3c37250 'void (int)' lvalue CXXMethod 0x3c098c0 'operator=' 'void (int)'\n" " |-DeclRefExpr 0x3c0a078 'C' lvalue Var 0x3c09ae0 'c' 'C'\n" " `-IntegerLiteral 0x3c0a0a0 'int' 4"; - ASSERT_EQUALS("void foo ( ) { C c@1 ; c@1 . operator= ( 4 ) ; }", parse(clang)); + ASSERT_EQUALS("void foo ( ) { C c@1 ( C ( ) ) ; c@1 . operator= ( 4 ) ; }", parse(clang)); } void cxxRecordDecl1() {