Clang import; Destructor

This commit is contained in:
Daniel Marjamäki 2020-04-12 17:27:32 +02:00
parent 4dfb793cd2
commit 6b579293b6
2 changed files with 19 additions and 3 deletions

View File

@ -46,6 +46,7 @@ static const std::string CXXConstructorDecl = "CXXConstructorDecl";
static const std::string CXXConstructExpr = "CXXConstructExpr";
static const std::string CXXDefaultArgExpr = "CXXDefaultArgExpr";
static const std::string CXXDeleteExpr = "CXXDeleteExpr";
static const std::string CXXDestructorDecl = "CXXDestructorDecl";
static const std::string CXXForRangeStmt = "CXXForRangeStmt";
static const std::string CXXMemberCallExpr = "CXXMemberCallExpr";
static const std::string CXXMethodDecl = "CXXMethodDecl";
@ -640,6 +641,10 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
children[0]->createTokens(tokenList);
return nullptr;
}
if (nodeType == CXXDestructorDecl) {
createTokensFunctionDecl(tokenList);
return nullptr;
}
if (nodeType == CXXForRangeStmt) {
Token *forToken = addtoken(tokenList, "for");
Token *par1 = addtoken(tokenList, "(");
@ -1057,7 +1062,7 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
const bool hasBody = mFile == 0 && !children.empty() && children.back()->nodeType == CompoundStmt;
SymbolDatabase *symbolDatabase = mData->mSymbolDatabase;
if (nodeType != CXXConstructorDecl)
if (nodeType != CXXConstructorDecl && nodeType != CXXDestructorDecl)
addTypeTokens(tokenList, '\'' + getType() + '\'');
Token *nameToken = addtoken(tokenList, getSpelling() + getTemplateParameters());
Scope *nestedIn = const_cast<Scope *>(nameToken->scope());
@ -1067,6 +1072,8 @@ void clangimport::AstNode::createTokensFunctionDecl(TokenList *tokenList)
mData->funcDecl(mExtTokens.front(), nameToken, &nestedIn->functionList.back());
if (nodeType == CXXConstructorDecl)
nestedIn->functionList.back().type = Function::Type::eConstructor;
else if (nodeType == CXXDestructorDecl)
nestedIn->functionList.back().type = Function::Type::eDestructor;
} else {
const std::string addr = *(std::find(mExtTokens.begin(), mExtTokens.end(), "prev") + 1);
mData->ref(addr, nameToken);
@ -1136,6 +1143,7 @@ void clangimport::AstNode::createTokensForCXXRecord(TokenList *tokenList)
std::vector<AstNodePtr> children2;
for (AstNodePtr child: children) {
if (child->nodeType == CXXConstructorDecl ||
child->nodeType == CXXDestructorDecl ||
child->nodeType == CXXMethodDecl ||
child->nodeType == FieldDecl)
children2.push_back(child);

View File

@ -47,6 +47,7 @@ private:
TEST_CASE(cxxConstructExpr2);
TEST_CASE(cxxConstructExpr3);
TEST_CASE(cxxDeleteExpr);
TEST_CASE(cxxDestructorDecl);
TEST_CASE(cxxForRangeStmt1);
TEST_CASE(cxxForRangeStmt2);
TEST_CASE(cxxMemberCall);
@ -249,7 +250,7 @@ private:
"| | `-ParmVarDecl 0x247c790 <col:25> col:25 'const C<int> &'\n"
"| `-CXXConstructorDecl 0x247c828 <col:25> col:25 implicit constexpr C 'void (C<int> &&)' inline default trivial noexcept-unevaluated 0x247c828\n"
"| `-ParmVarDecl 0x247c960 <col:25> col:25 'C<int> &&'\n";
ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } }", parse(clang));
ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } default ( ) { } noexcept-unevaluated ( const C<int> & ) ; noexcept-unevaluated ( C<int> && ) ; }", parse(clang));
}
void conditionalExpr() {
@ -304,7 +305,7 @@ private:
"| | `-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@1 = 0 ; } int x@1", parse(clang));
ASSERT_EQUALS("C ( ) { this . x@1 = 0 ; } int x@1", parse(clang));
}
void cxxConstructExpr1() {
@ -352,6 +353,13 @@ private:
ASSERT_EQUALS("void f ( int * p@1 ) { delete p@1 ; }", parse(clang));
}
void cxxDestructorDecl() {
const char clang[] = "`-CXXRecordDecl 0x8ecd60 <1.cpp:1:1, line:4:1> line:1:8 struct S definition\n"
" `-CXXDestructorDecl 0x8ed088 <line:3:3, col:9> col:3 ~S 'void () noexcept'\n"
" `-CompoundStmt 0x8ed1a8 <col:8, col:9>";
ASSERT_EQUALS("class S\n\n{ ~S ( ) { } }", parse(clang));
}
void cxxForRangeStmt1() {
const char clang[] = "`-FunctionDecl 0x4280820 <line:4:1, line:8:1> line:4:6 foo 'void ()'\n"
" `-CompoundStmt 0x42810f0 <col:12, line:8:1>\n"