From 7a3bedb583b24cfeae720576d862d4af9d4a704e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 10 Jan 2020 18:54:28 +0100 Subject: [PATCH] Clang import; CXXConstructExpr --- lib/clangimport.cpp | 30 +++++++----------------------- test/testclangimport.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index 139c8bca4..cb5345839 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -38,6 +38,7 @@ static const std::string ContinueStmt = "ContinueStmt"; static const std::string CStyleCastExpr = "CStyleCastExpr"; static const std::string CXXBoolLiteralExpr = "CXXBoolLiteralExpr"; static const std::string CXXConstructorDecl = "CXXConstructorDecl"; +static const std::string CXXConstructExpr = "CXXConstructExpr"; static const std::string CXXMemberCallExpr = "CXXMemberCallExpr"; static const std::string CXXMethodDecl = "CXXMethodDecl"; static const std::string CXXOperatorCallExpr = "CXXOperatorCallExpr"; @@ -251,29 +252,10 @@ std::string clangimport::AstNode::getSpelling() const std::string clangimport::AstNode::getType() const { - if (nodeType == BinaryOperator) - return unquote(mExtTokens[mExtTokens.size() - 2]); - if (nodeType == CStyleCastExpr) - return unquote((mExtTokens.back() == "") ? - mExtTokens[mExtTokens.size() - 2] : - mExtTokens.back()); - if (nodeType == CXXStaticCastExpr) - return unquote(mExtTokens[mExtTokens.size() - 3]); - if (nodeType == DeclRefExpr) - return unquote(mExtTokens.back()); - if (nodeType == FunctionDecl) { - int retTypeIndex = mExtTokens.size() - 1; - while (mExtTokens[retTypeIndex][0] != '\'') - retTypeIndex--; - return unquote(mExtTokens[retTypeIndex]); - } - if (nodeType == IntegerLiteral) - return unquote(mExtTokens[mExtTokens.size() - 2]); - if (nodeType == TypedefDecl) - return unquote(mExtTokens.back()); - if (nodeType == UnaryExprOrTypeTraitExpr) - return unquote(mExtTokens[mExtTokens.size() - 3]); - return ""; + int typeIndex = mExtTokens.size() - 1; + while (typeIndex >= 0 && mExtTokens[typeIndex][0] != '\'') + typeIndex--; + return typeIndex == -1 ? "" : unquote(mExtTokens[typeIndex]); } std::string clangimport::AstNode::getTemplateParameters() const @@ -524,6 +506,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) tokenList->back()->setValueType(new ValueType(ValueType::Sign::UNKNOWN_SIGN, ValueType::Type::BOOL, 0)); return tokenList->back(); } + if (nodeType == CXXConstructExpr) + return children[0]->createTokens(tokenList); if (nodeType == CXXMethodDecl) { createTokensFunctionDecl(tokenList); return nullptr; diff --git a/test/testclangimport.cpp b/test/testclangimport.cpp index 9e4c242e7..7dec11180 100644 --- a/test/testclangimport.cpp +++ b/test/testclangimport.cpp @@ -38,6 +38,7 @@ private: TEST_CASE(cstyleCastExpr); TEST_CASE(cxxBoolLiteralExpr); TEST_CASE(cxxConstructorDecl); + TEST_CASE(cxxConstructExpr); TEST_CASE(cxxMemberCall); TEST_CASE(cxxOperatorCallExpr); TEST_CASE(cxxStaticCastExpr1); @@ -200,6 +201,17 @@ private: ASSERT_EQUALS("void C ( ) { this . x@1 = 0 ; } int x@1", parse(clang)); } + void cxxConstructExpr() { + const char clang[] = "`-FunctionDecl 0x2dd7940 col:5 f 'Foo (Foo)'\n" + " |-ParmVarDecl 0x2dd7880 col:11 used foo 'Foo'\n" + " `-CompoundStmt 0x2dd80c0 \n" + " `-ReturnStmt 0x2dd80a8 \n" + " `-CXXConstructExpr 0x2dd8070 'Foo' 'void (Foo &&) noexcept'\n" + " `-ImplicitCastExpr 0x2dd7f28 'Foo' xvalue \n" + " `-DeclRefExpr 0x2dd7a28 'Foo' lvalue ParmVar 0x2dd7880 'foo' 'Foo'"; + ASSERT_EQUALS("Foo f ( Foo foo@1 ) { return foo@1 ; }", parse(clang)); + } + void cxxMemberCall() { const char clang[] = "`-FunctionDecl 0x320dc80 col:6 bar 'void ()'\n" " `-CompoundStmt 0x323bb08 \n"