From b8aa71bc87c4eaf6b53d7d866df7debc2ef218f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 9 Jan 2020 20:53:06 +0100 Subject: [PATCH] Clang import; CXXStaticCast --- lib/clangastdump.cpp | 21 +++++++++++++++++++-- test/testclangastdump.cpp | 8 ++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/clangastdump.cpp b/lib/clangastdump.cpp index c188887d7..f8c642916 100644 --- a/lib/clangastdump.cpp +++ b/lib/clangastdump.cpp @@ -41,6 +41,7 @@ static const std::string CXXMemberCallExpr = "CXXMemberCallExpr"; static const std::string CXXMethodDecl = "CXXMethodDecl"; static const std::string CXXOperatorCallExpr = "CXXOperatorCallExpr"; static const std::string CXXRecordDecl = "CXXRecordDecl"; +static const std::string CXXStaticCastExpr = "CXXStaticCastExpr"; static const std::string CXXThisExpr = "CXXThisExpr"; static const std::string DeclRefExpr = "DeclRefExpr"; static const std::string DeclStmt = "DeclStmt"; @@ -322,7 +323,9 @@ const Scope *clangastdump::AstNode::getNestedInScope(TokenList *tokenList) void clangastdump::AstNode::setValueType(Token *tok) { int typeIndex = -1; - if (nodeType == UnaryExprOrTypeTraitExpr) + if (nodeType == CXXStaticCastExpr) + typeIndex = mExtTokens.size() - 3; + else if (nodeType == UnaryExprOrTypeTraitExpr) typeIndex = mExtTokens.size() - 3; else return; @@ -330,7 +333,9 @@ void clangastdump::AstNode::setValueType(Token *tok) TokenList decl(nullptr); addTypeTokens(&decl, mExtTokens[typeIndex]); - if (Token::simpleMatch(decl.front(), "unsigned long")) + if (Token::simpleMatch(decl.front(), "int")) + tok->setValueType(new ValueType(ValueType::Sign::SIGNED, ValueType::Type::INT, 0)); + else if (Token::simpleMatch(decl.front(), "unsigned long")) tok->setValueType(new ValueType(ValueType::Sign::UNSIGNED, ValueType::Type::LONG, 0)); } @@ -456,6 +461,18 @@ Token *clangastdump::AstNode::createTokens(TokenList *tokenList) createTokensForCXXRecord(tokenList); return nullptr; } + if (nodeType == CXXStaticCastExpr) { + Token *cast = addtoken(tokenList, getSpelling()); + Token *par1 = addtoken(tokenList, "("); + Token *expr = children[0]->createTokens(tokenList); + Token *par2 = addtoken(tokenList, ")"); + par1->link(par2); + par2->link(par1); + par1->astOperand1(cast); + par1->astOperand2(expr); + setValueType(par1); + return par1; + } if (nodeType == CXXThisExpr) return addtoken(tokenList, "this"); if (nodeType == DeclStmt) diff --git a/test/testclangastdump.cpp b/test/testclangastdump.cpp index c79f8d677..6ab7ab82b 100644 --- a/test/testclangastdump.cpp +++ b/test/testclangastdump.cpp @@ -39,6 +39,7 @@ private: TEST_CASE(cxxConstructorDecl); TEST_CASE(cxxMemberCall); TEST_CASE(cxxOperatorCallExpr); + TEST_CASE(cxxStaticCastExpr); TEST_CASE(forStmt); TEST_CASE(funcdecl1); TEST_CASE(funcdecl2); @@ -216,6 +217,13 @@ private: ASSERT_EQUALS("void foo ( ) { C c@1 ; c@1 . operator= ( 4 ) ; }", parse(clang)); } + void cxxStaticCastExpr() { + const char clang[] = "`-VarDecl 0x2e0e650 col:5 a 'int' cinit\n" + " `-CXXStaticCastExpr 0x2e0e728 'int' static_cast \n" + " `-IntegerLiteral 0x2e0e6f0 'int' 0"; + ASSERT_EQUALS("int a@1 = static_cast ( 0 ) ;", parse(clang)); + } + void forStmt() { const char clang[] = "`-FunctionDecl 0x2f93ae0 <1.c:1:1, col:56> col:5 main 'int ()'\n" " `-CompoundStmt 0x2f93dc0 \n"