Clang import; CXXConstructorDecl, CXXThisExpr
This commit is contained in:
parent
1589ac5352
commit
060c695f80
|
@ -34,9 +34,11 @@ 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 CXXConstructorDecl = "CXXConstructorDecl";
|
||||||
static const std::string CXXMemberCallExpr = "CXXMemberCallExpr";
|
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 CXXThisExpr = "CXXThisExpr";
|
||||||
static const std::string DeclRefExpr = "DeclRefExpr";
|
static const std::string DeclRefExpr = "DeclRefExpr";
|
||||||
static const std::string DeclStmt = "DeclStmt";
|
static const std::string DeclStmt = "DeclStmt";
|
||||||
static const std::string FieldDecl = "FieldDecl";
|
static const std::string FieldDecl = "FieldDecl";
|
||||||
|
@ -374,6 +376,18 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
||||||
}
|
}
|
||||||
if (nodeType == ContinueStmt)
|
if (nodeType == ContinueStmt)
|
||||||
return addtoken(tokenList, "continue");
|
return addtoken(tokenList, "continue");
|
||||||
|
if (nodeType == CXXConstructorDecl) {
|
||||||
|
bool hasBody = false;
|
||||||
|
for (AstNodePtr child: children) {
|
||||||
|
if (child->nodeType == CompoundStmt && !child->children.empty()) {
|
||||||
|
hasBody = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasBody)
|
||||||
|
createTokensFunctionDecl(tokenList);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
if (nodeType == CXXMethodDecl) {
|
if (nodeType == CXXMethodDecl) {
|
||||||
createTokensFunctionDecl(tokenList);
|
createTokensFunctionDecl(tokenList);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -384,6 +398,8 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
||||||
createTokensForCXXRecord(tokenList);
|
createTokensForCXXRecord(tokenList);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
if (nodeType == CXXThisExpr)
|
||||||
|
return addtoken(tokenList, "this");
|
||||||
if (nodeType == DeclStmt)
|
if (nodeType == DeclStmt)
|
||||||
return children[0]->createTokens(tokenList);
|
return children[0]->createTokens(tokenList);
|
||||||
if (nodeType == DeclRefExpr) {
|
if (nodeType == DeclRefExpr) {
|
||||||
|
@ -468,7 +484,14 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList)
|
||||||
if (nodeType == MemberExpr) {
|
if (nodeType == MemberExpr) {
|
||||||
Token *s = children[0]->createTokens(tokenList);
|
Token *s = children[0]->createTokens(tokenList);
|
||||||
Token *dot = addtoken(tokenList, ".");
|
Token *dot = addtoken(tokenList, ".");
|
||||||
Token *member = addtoken(tokenList, getSpelling().substr(1));
|
std::string memberName = getSpelling();
|
||||||
|
if (memberName.compare(0,2,"->") == 0) {
|
||||||
|
dot->originalName("->");
|
||||||
|
memberName = memberName.substr(2);
|
||||||
|
} else {
|
||||||
|
memberName = memberName.substr(1);
|
||||||
|
}
|
||||||
|
Token *member = addtoken(tokenList, memberName);
|
||||||
mData->ref(mExtTokens.back(), member);
|
mData->ref(mExtTokens.back(), member);
|
||||||
dot->astOperand1(s);
|
dot->astOperand1(s);
|
||||||
dot->astOperand2(member);
|
dot->astOperand2(member);
|
||||||
|
@ -613,10 +636,10 @@ void clangastdump::AstNode::createTokensForCXXRecord(TokenList *tokenList)
|
||||||
const std::string className = mExtTokens[mExtTokens.size() - 2] + getTemplateParameters();
|
const std::string className = mExtTokens[mExtTokens.size() - 2] + getTemplateParameters();
|
||||||
/*Token *nameToken =*/ addtoken(tokenList, className);
|
/*Token *nameToken =*/ addtoken(tokenList, className);
|
||||||
std::vector<AstNodePtr> children2;
|
std::vector<AstNodePtr> children2;
|
||||||
for (auto child: children) {
|
for (AstNodePtr child: children) {
|
||||||
if (child->nodeType == CXXMethodDecl)
|
if (child->nodeType == CXXConstructorDecl ||
|
||||||
children2.push_back(child);
|
child->nodeType == CXXMethodDecl ||
|
||||||
else if (child->nodeType == FieldDecl)
|
child->nodeType == FieldDecl)
|
||||||
children2.push_back(child);
|
children2.push_back(child);
|
||||||
}
|
}
|
||||||
if (children2.empty()) {
|
if (children2.empty()) {
|
||||||
|
|
|
@ -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(cxxConstructorDecl);
|
||||||
TEST_CASE(cxxMemberCall);
|
TEST_CASE(cxxMemberCall);
|
||||||
TEST_CASE(forStmt);
|
TEST_CASE(forStmt);
|
||||||
TEST_CASE(funcdecl1);
|
TEST_CASE(funcdecl1);
|
||||||
|
@ -161,6 +162,17 @@ private:
|
||||||
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { continue ; } }", parse(clang));
|
ASSERT_EQUALS("void foo ( ) { while ( 0 ) { continue ; } }", parse(clang));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cxxConstructorDecl() {
|
||||||
|
const char clang[] = "|-CXXConstructorDecl 0x428e890 <col:11, col:24> col:11 C 'void ()'\n"
|
||||||
|
"| `-CompoundStmt 0x428ea58 <col:15, col:24>\n"
|
||||||
|
"| `-BinaryOperator 0x428ea30 <col:17, col:21> 'int' lvalue '='\n"
|
||||||
|
"| |-MemberExpr 0x428e9d8 <col:17> 'int' lvalue ->x 0x428e958\n"
|
||||||
|
"| | `-CXXThisExpr 0x428e9c0 <col:17> 'C *' this\n"
|
||||||
|
"| `-IntegerLiteral 0x428ea10 <col:21> 'int' 0\n"
|
||||||
|
"`-FieldDecl 0x428e958 <col:26, col:30> col:30 referenced x 'int'";
|
||||||
|
ASSERT_EQUALS("void C ( ) { this . x = 0 ; } int x@1", parse(clang));
|
||||||
|
}
|
||||||
|
|
||||||
void cxxMemberCall() {
|
void cxxMemberCall() {
|
||||||
const char clang[] = "`-FunctionDecl 0x320dc80 <line:2:1, col:33> col:6 bar 'void ()'\n"
|
const char clang[] = "`-FunctionDecl 0x320dc80 <line:2:1, col:33> col:6 bar 'void ()'\n"
|
||||||
" `-CompoundStmt 0x323bb08 <col:12, col:33>\n"
|
" `-CompoundStmt 0x323bb08 <col:12, col:33>\n"
|
||||||
|
|
Loading…
Reference in New Issue