Clang import; CXXMemberCall

This commit is contained in:
Daniel Marjamäki 2020-01-08 21:49:23 +01:00
parent 3387ee3512
commit 4e8a922e18
2 changed files with 40 additions and 19 deletions

View File

@ -34,6 +34,7 @@ static const std::string ClassTemplateDecl = "ClassTemplateDecl";
static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl"; static const std::string ClassTemplateSpecializationDecl = "ClassTemplateSpecializationDecl";
static const std::string CompoundStmt = "CompoundStmt"; static const std::string CompoundStmt = "CompoundStmt";
static const std::string ContinueStmt = "ContinueStmt"; static const std::string ContinueStmt = "ContinueStmt";
static const std::string CXXMemberCallExpr = "CXXMemberCallExpr";
static const std::string CXXMethodDecl = "CXXMethodDecl"; static const std::string CXXMethodDecl = "CXXMethodDecl";
static const std::string CXXRecordDecl = "CXXRecordDecl"; static const std::string CXXRecordDecl = "CXXRecordDecl";
static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclRefExpr = "DeclRefExpr";
@ -164,6 +165,7 @@ namespace clangastdump {
void addTypeTokens(TokenList *tokenList, const std::string &str); void addTypeTokens(TokenList *tokenList, const std::string &str);
Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, AstNodePtr astNode); Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, AstNodePtr astNode);
Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, const std::vector<AstNodePtr> &children); Scope *createScope(TokenList *tokenList, Scope::ScopeType scopeType, const std::vector<AstNodePtr> &children);
Token *createTokensCall(TokenList *tokenList);
void createTokensFunctionDecl(TokenList *tokenList); void createTokensFunctionDecl(TokenList *tokenList);
void createTokensForCXXRecord(TokenList *tokenList); void createTokensForCXXRecord(TokenList *tokenList);
Token *createTokensVarDecl(TokenList *tokenList); Token *createTokensVarDecl(TokenList *tokenList);
@ -342,25 +344,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
} }
if (nodeType == BreakStmt) if (nodeType == BreakStmt)
return addtoken(tokenList, "break"); return addtoken(tokenList, "break");
if (nodeType == CallExpr) { if (nodeType == CallExpr)
Token *f = children[0]->createTokens(tokenList); return createTokensCall(tokenList);
Token *par1 = addtoken(tokenList, "(");
par1->astOperand1(f);
Token *parent = par1;
for (int c = 1; c < children.size(); ++c) {
if (c + 1 < children.size()) {
Token *child = children[c]->createTokens(tokenList);
Token *comma = addtoken(tokenList, ",");
comma->astOperand1(child);
parent->astOperand2(comma);
parent = comma;
} else {
parent->astOperand2(children[c]->createTokens(tokenList));
}
}
par1->link(addtoken(tokenList, ")"));
return par1;
}
if (nodeType == ClassTemplateDecl) { if (nodeType == ClassTemplateDecl) {
for (AstNodePtr child: children) { for (AstNodePtr child: children) {
if (child->nodeType == ClassTemplateSpecializationDecl) if (child->nodeType == ClassTemplateSpecializationDecl)
@ -385,6 +370,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
createTokensFunctionDecl(tokenList); createTokensFunctionDecl(tokenList);
return nullptr; return nullptr;
} }
if (nodeType == CXXMemberCallExpr)
return createTokensCall(tokenList);
if (nodeType == CXXRecordDecl) { if (nodeType == CXXRecordDecl) {
createTokensForCXXRecord(tokenList); createTokensForCXXRecord(tokenList);
return nullptr; return nullptr;
@ -526,6 +513,27 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
return addtoken(tokenList, "?" + nodeType + "?"); return addtoken(tokenList, "?" + nodeType + "?");
} }
Token * clangastdump::AstNode::createTokensCall(TokenList *tokenList)
{
Token *f = children[0]->createTokens(tokenList);
Token *par1 = addtoken(tokenList, "(");
par1->astOperand1(f);
Token *parent = par1;
for (int c = 1; c < children.size(); ++c) {
if (c + 1 < children.size()) {
Token *child = children[c]->createTokens(tokenList);
Token *comma = addtoken(tokenList, ",");
comma->astOperand1(child);
parent->astOperand2(comma);
parent = comma;
} else {
parent->astOperand2(children[c]->createTokens(tokenList));
}
}
par1->link(addtoken(tokenList, ")"));
return par1;
}
void clangastdump::AstNode::createTokensFunctionDecl(TokenList *tokenList) void clangastdump::AstNode::createTokensFunctionDecl(TokenList *tokenList)
{ {
SymbolDatabase *symbolDatabase = mData->mSymbolDatabase; SymbolDatabase *symbolDatabase = mData->mSymbolDatabase;

View File

@ -34,6 +34,7 @@ private:
TEST_CASE(classTemplateDecl1); TEST_CASE(classTemplateDecl1);
TEST_CASE(classTemplateDecl2); TEST_CASE(classTemplateDecl2);
TEST_CASE(continueStmt); TEST_CASE(continueStmt);
TEST_CASE(cxxMemberCall);
TEST_CASE(forStmt); TEST_CASE(forStmt);
TEST_CASE(funcdecl1); TEST_CASE(funcdecl1);
TEST_CASE(funcdecl2); TEST_CASE(funcdecl2);
@ -160,6 +161,18 @@ private:
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { continue ; } ; }", parse(clang)); ASSERT_EQUALS("void foo ( ) { while ( 0 ) { continue ; } ; }", parse(clang));
} }
void cxxMemberCall() {
const char clang[] = "`-FunctionDecl 0x320dc80 <line:2:1, col:33> col:6 bar 'void ()'\n"
" `-CompoundStmt 0x323bb08 <col:12, col:33>\n"
" |-DeclStmt 0x323ba40 <col:14, col:22>\n"
" | `-VarDecl 0x320df28 <col:14, col:21> col:21 used c 'C<int>':'C<int>' callinit\n"
" | `-CXXConstructExpr 0x323ba10 <col:21> 'C<int>':'C<int>' 'void () noexcept'\n"
" `-CXXMemberCallExpr 0x323bab8 <col:24, col:30> 'int':'int'\n"
" `-MemberExpr 0x323ba80 <col:24, col:26> '<bound member function type>' .foo 0x320e160\n"
" `-DeclRefExpr 0x323ba58 <col:24> 'C<int>':'C<int>' lvalue Var 0x320df28 'c' 'C<int>':'C<int>'";
ASSERT_EQUALS("void bar ( ) { C<int> c@1 ; c@1 . foo ( ) ; }", parse(clang));
}
void forStmt() { void forStmt() {
const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n" const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n"
" `-CompoundStmt 0x2f93dc0 <col:12, col:56>\n" " `-CompoundStmt 0x2f93dc0 <col:12, col:56>\n"