Clang import; CXXOperatorCallExpr

This commit is contained in:
Daniel Marjamäki 2020-01-09 15:59:09 +01:00
parent c83cbc9429
commit e6b873b7b9
2 changed files with 33 additions and 2 deletions

View File

@ -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, ",");

View File

@ -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<int> c@1 ; c@1 . foo ( ) ; }", parse(clang));
}
void cxxOperatorCallExpr() {
const char clang[] = "`-FunctionDecl 0x3c099f0 <line:2:1, col:24> col:6 foo 'void ()'\n"
" `-CompoundStmt 0x3c37308 <col:12, col:24>\n"
" |-DeclStmt 0x3c0a060 <col:14, col:17>\n"
" | `-VarDecl 0x3c09ae0 <col:14, col:16> col:16 used c 'C' callinit\n"
" | `-CXXConstructExpr 0x3c0a030 <col:16> 'C' 'void () noexcept'\n"
" `-CXXOperatorCallExpr 0x3c372c0 <col:19, col:21> 'void'\n"
" |-ImplicitCastExpr 0x3c372a8 <col:20> 'void (*)(int)' <FunctionToPointerDecay>\n"
" | `-DeclRefExpr 0x3c37250 <col:20> 'void (int)' lvalue CXXMethod 0x3c098c0 'operator=' 'void (int)'\n"
" |-DeclRefExpr 0x3c0a078 <col:19> 'C' lvalue Var 0x3c09ae0 'c' 'C'\n"
" `-IntegerLiteral 0x3c0a0a0 <col:21> '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 <col:12, col:56>\n"