From bdc621b7a394bdd183946af4f7baba21973688d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 20 Jan 2020 21:27:49 +0100 Subject: [PATCH] Clang import; MaterializeTemporaryExpr --- lib/clangimport.cpp | 31 +++++++++++++++++-------------- lib/cppcheck.cpp | 7 +++++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/clangimport.cpp b/lib/clangimport.cpp index f4a23843f..27a352594 100644 --- a/lib/clangimport.cpp +++ b/lib/clangimport.cpp @@ -64,6 +64,7 @@ static const std::string ImplicitCastExpr = "ImplicitCastExpr"; static const std::string InitListExpr = "InitListExpr"; static const std::string IntegerLiteral = "IntegerLiteral"; static const std::string LabelStmt = "LabelStmt"; +static const std::string MaterializeTemporaryExpr = "MaterializeTemporaryExpr"; static const std::string MemberExpr = "MemberExpr"; static const std::string NamespaceDecl = "NamespaceDecl"; static const std::string NullStmt = "NullStmt"; @@ -756,20 +757,8 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) child->createTokens(tokenList); return nullptr; } - if (nodeType == NullStmt) - return addtoken(tokenList, ";"); - if (nodeType == NamespaceDecl) { - if (children.empty()) - return nullptr; - Token *defToken = addtoken(tokenList, "namespace"); - Token *nameToken = (mExtTokens[mExtTokens.size() - 2].compare(0,4,"col:") == 0) ? - addtoken(tokenList, mExtTokens.back()) : nullptr; - Scope *scope = createScope(tokenList, Scope::ScopeType::eNamespace, children); - scope->classDef = defToken; - if (nameToken) - scope->className = nameToken->str(); - return nullptr; - } + if (nodeType == MaterializeTemporaryExpr) + return children[0]->createTokens(tokenList); if (nodeType == MemberExpr) { Token *s = children[0]->createTokens(tokenList); Token *dot = addtoken(tokenList, "."); @@ -788,6 +777,20 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList) dot->astOperand2(member); return dot; } + if (nodeType == NamespaceDecl) { + if (children.empty()) + return nullptr; + Token *defToken = addtoken(tokenList, "namespace"); + Token *nameToken = (mExtTokens[mExtTokens.size() - 2].compare(0,4,"col:") == 0) ? + addtoken(tokenList, mExtTokens.back()) : nullptr; + Scope *scope = createScope(tokenList, Scope::ScopeType::eNamespace, children); + scope->classDef = defToken; + if (nameToken) + scope->className = nameToken->str(); + return nullptr; + } + if (nodeType == NullStmt) + return addtoken(tokenList, ";"); if (nodeType == ParenExpr) { Token *par1 = addtoken(tokenList, "("); Token *expr = children[0]->createTokens(tokenList); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a51d0c7a1..5123befa5 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -255,6 +255,7 @@ unsigned int CppCheck::check(const std::string &path) const std::string clang = Path::isCPP(path) ? "clang++" : "clang"; const std::string temp = mSettings.buildDir + "/__temp__.c"; + const std::string clangcmd = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-cmd"; const std::string clangStderr = AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, "") + ".clang-stderr"; /* Experimental: import clang ast dump */ @@ -279,12 +280,14 @@ unsigned int CppCheck::check(const std::string &path) } } - //std::cout << "Clang flags: " << flags << std::endl; - for (const std::string &i: mSettings.includePaths) flags += "-I" + i + " "; const std::string cmd = clang + " -cc1 -ast-dump " + flags + path + " 2> " + clangStderr; + std::ofstream fout(clangcmd); + fout << cmd << std::endl; + fout.close(); + std::pair res = executeCommand(cmd); if (!res.first) { std::cerr << "Failed to execute '" + cmd + "'" << std::endl;