diff --git a/lib/clangastdump.cpp b/lib/clangastdump.cpp index 7fa5804ab..ebe88bf1c 100644 --- a/lib/clangastdump.cpp +++ b/lib/clangastdump.cpp @@ -37,6 +37,7 @@ static const std::string ContinueStmt = "ContinueStmt"; static const std::string CXXConstructorDecl = "CXXConstructorDecl"; static const std::string CXXMemberCallExpr = "CXXMemberCallExpr"; static const std::string CXXMethodDecl = "CXXMethodDecl"; +static const std::string CXXOperatorCallExpr = "CXXOperatorCallExpr"; static const std::string CXXRecordDecl = "CXXRecordDecl"; static const std::string CXXThisExpr = "CXXThisExpr"; static const std::string DeclRefExpr = "DeclRefExpr"; @@ -394,6 +395,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList) } if (nodeType == CXXMemberCallExpr) return createTokensCall(tokenList); + if (nodeType == CXXOperatorCallExpr) + return createTokensCall(tokenList); if (nodeType == CXXRecordDecl) { createTokensForCXXRecord(tokenList); return nullptr; @@ -560,11 +563,24 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList) Token * clangastdump::AstNode::createTokensCall(TokenList *tokenList) { - Token *f = children[0]->createTokens(tokenList); + int firstParam; + Token *f; + if (nodeType == CXXOperatorCallExpr) { + firstParam = 2; + Token *obj = children[1]->createTokens(tokenList); + Token *dot = addtoken(tokenList, "."); + Token *op = children[0]->createTokens(tokenList); + dot->astOperand1(obj); + dot->astOperand2(op); + f = dot; + } else { + firstParam = 1; + f = children[0]->createTokens(tokenList); + } Token *par1 = addtoken(tokenList, "("); par1->astOperand1(f); Token *parent = par1; - for (int c = 1; c < children.size(); ++c) { + for (int c = firstParam; c < children.size(); ++c) { if (c + 1 < children.size()) { Token *child = children[c]->createTokens(tokenList); Token *comma = addtoken(tokenList, ","); diff --git a/test/testclangastdump.cpp b/test/testclangastdump.cpp index 873ce1e07..fdd0dbc02 100644 --- a/test/testclangastdump.cpp +++ b/test/testclangastdump.cpp @@ -36,6 +36,7 @@ private: TEST_CASE(continueStmt); TEST_CASE(cxxConstructorDecl); TEST_CASE(cxxMemberCall); + TEST_CASE(cxxOperatorCallExpr); TEST_CASE(forStmt); TEST_CASE(funcdecl1); TEST_CASE(funcdecl2); @@ -185,6 +186,20 @@ private: ASSERT_EQUALS("void bar ( ) { C c@1 ; c@1 . foo ( ) ; }", parse(clang)); } + void cxxOperatorCallExpr() { + const char clang[] = "`-FunctionDecl 0x3c099f0 col:6 foo 'void ()'\n" + " `-CompoundStmt 0x3c37308 \n" + " |-DeclStmt 0x3c0a060 \n" + " | `-VarDecl 0x3c09ae0 col:16 used c 'C' callinit\n" + " | `-CXXConstructExpr 0x3c0a030 'C' 'void () noexcept'\n" + " `-CXXOperatorCallExpr 0x3c372c0 'void'\n" + " |-ImplicitCastExpr 0x3c372a8 'void (*)(int)' \n" + " | `-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)); + } + void forStmt() { const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n" " `-CompoundStmt 0x2f93dc0 \n"