Clang import; MaterializeTemporaryExpr

This commit is contained in:
Daniel Marjamäki 2020-01-20 21:27:49 +01:00
parent 78fcf93342
commit bdc621b7a3
2 changed files with 22 additions and 16 deletions

View File

@ -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);

View File

@ -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<bool, std::string> res = executeCommand(cmd);
if (!res.first) {
std::cerr << "Failed to execute '" + cmd + "'" << std::endl;