From 6b579293b6c86e1346ff15ec12e01402f38d27e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 12 Apr 2020 17:27:32 +0200 Subject: [PATCH] Clang import; Destructor --- lib/clangimport.cpp | 10 +++++++++- test/testclangimport.cpp | 12 ++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 943b6b995..bebd66279 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -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(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 children2; for (AstNodePtr child: children) { if (child->nodeType == CXXConstructorDecl || + child->nodeType == CXXDestructorDecl || child->nodeType == CXXMethodDecl || child->nodeType == FieldDecl) children2.push_back(child); diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index fdb6d47e0..91841d1f6 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -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 'const C &'\n" "| `-CXXConstructorDecl 0x247c828 col:25 implicit constexpr C 'void (C &&)' inline default trivial noexcept-unevaluated 0x247c828\n" "| `-ParmVarDecl 0x247c960 col:25 'C &&'\n"; - ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } }", parse(clang)); + ASSERT_EQUALS("class C { int foo ( ) { return 0 ; } default ( ) { } noexcept-unevaluated ( const C & ) ; noexcept-unevaluated ( C && ) ; }", parse(clang)); } void conditionalExpr() { @@ -304,7 +305,7 @@ private: "| | `-CXXThisExpr 0x428e9c0 'C *' this\n" "| `-IntegerLiteral 0x428ea10 'int' 0\n" "`-FieldDecl 0x428e958 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 col:3 ~S 'void () noexcept'\n" + " `-CompoundStmt 0x8ed1a8 "; + ASSERT_EQUALS("class S\n\n{ ~S ( ) { } }", parse(clang)); + } + void cxxForRangeStmt1() { const char clang[] = "`-FunctionDecl 0x4280820 line:4:6 foo 'void ()'\n" " `-CompoundStmt 0x42810f0 \n"