Clang import; Fixed CXXConstructExpr without child
This commit is contained in:
parent
96ff57e275
commit
9c38a659a1
|
@ -253,10 +253,15 @@ std::string clangimport::AstNode::getSpelling() const
|
|||
|
||||
std::string clangimport::AstNode::getType() const
|
||||
{
|
||||
int typeIndex = mExtTokens.size() - 1;
|
||||
while (typeIndex >= 0 && mExtTokens[typeIndex][0] != '\'')
|
||||
typeIndex--;
|
||||
return typeIndex == -1 ? "" : unquote(mExtTokens[typeIndex]);
|
||||
int typeIndex = 1;
|
||||
typeIndex = 1;
|
||||
while (typeIndex < mExtTokens.size() && mExtTokens[typeIndex][0] != '\'')
|
||||
typeIndex++;
|
||||
if (typeIndex >= mExtTokens.size())
|
||||
return "";
|
||||
if (mExtTokens[typeIndex].find("\':\'") != std::string::npos)
|
||||
return mExtTokens[typeIndex].substr(1, mExtTokens[typeIndex].find("\':\'") - 1);
|
||||
return unquote(mExtTokens[typeIndex]);
|
||||
}
|
||||
|
||||
std::string clangimport::AstNode::getTemplateParameters() const
|
||||
|
@ -481,18 +486,6 @@ Token *clangimport::AstNode::createTokens(TokenList *tokenList)
|
|||
}
|
||||
if (nodeType == ContinueStmt)
|
||||
return addtoken(tokenList, "continue");
|
||||
if (nodeType == CXXConstructorDecl) {
|
||||
bool hasBody = false;
|
||||
for (AstNodePtr child: children) {
|
||||
if (child->nodeType == CompoundStmt && !child->children.empty()) {
|
||||
hasBody = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasBody)
|
||||
createTokensFunctionDecl(tokenList);
|
||||
return nullptr;
|
||||
}
|
||||
if (nodeType == CStyleCastExpr) {
|
||||
Token *par1 = addtoken(tokenList, "(");
|
||||
addTypeTokens(tokenList, '\'' + getType() + '\'');
|
||||
|
@ -507,8 +500,28 @@ 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 == CXXConstructExpr) {
|
||||
if (!children.empty())
|
||||
return children[0]->createTokens(tokenList);
|
||||
addTypeTokens(tokenList, '\'' + getType() + '\'');
|
||||
Token *par1 = addtoken(tokenList, "(");
|
||||
Token *par2 = addtoken(tokenList, ")");
|
||||
par1->link(par2);
|
||||
par2->link(par1);
|
||||
return par1;
|
||||
}
|
||||
if (nodeType == CXXConstructorDecl) {
|
||||
bool hasBody = false;
|
||||
for (AstNodePtr child: children) {
|
||||
if (child->nodeType == CompoundStmt && !child->children.empty()) {
|
||||
hasBody = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasBody)
|
||||
createTokensFunctionDecl(tokenList);
|
||||
return nullptr;
|
||||
}
|
||||
if (nodeType == CXXMethodDecl) {
|
||||
createTokensFunctionDecl(tokenList);
|
||||
return nullptr;
|
||||
|
|
|
@ -242,6 +242,8 @@ const char * CppCheck::extraVersion()
|
|||
unsigned int CppCheck::check(const std::string &path)
|
||||
{
|
||||
if (mSettings.clang) {
|
||||
mErrorLogger.reportOut(std::string("Checking ") + path + "...");
|
||||
|
||||
const std::string clang = Path::isCPP(path) ? "clang++" : "clang";
|
||||
|
||||
/* Experimental: import clang ast dump */
|
||||
|
@ -269,6 +271,8 @@ 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 + " ";
|
||||
|
||||
|
@ -286,7 +290,11 @@ unsigned int CppCheck::check(const std::string &path)
|
|||
//ValueFlow::setValues(&tokenizer.list, const_cast<SymbolDatabase *>(tokenizer.getSymbolDatabase()), this, &mSettings);
|
||||
if (mSettings.debugnormal)
|
||||
tokenizer.printDebugOutput(1);
|
||||
ExprEngine::runChecks(this, &tokenizer, &mSettings);
|
||||
|
||||
#ifdef USE_Z3
|
||||
if (mSettings.verification)
|
||||
ExprEngine::runChecks(this, &tokenizer, &mSettings);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ private:
|
|||
TEST_CASE(cstyleCastExpr);
|
||||
TEST_CASE(cxxBoolLiteralExpr);
|
||||
TEST_CASE(cxxConstructorDecl);
|
||||
TEST_CASE(cxxConstructExpr);
|
||||
TEST_CASE(cxxConstructExpr1);
|
||||
TEST_CASE(cxxConstructExpr2);
|
||||
TEST_CASE(cxxMemberCall);
|
||||
TEST_CASE(cxxNullPtrLiteralExpr);
|
||||
TEST_CASE(cxxOperatorCallExpr);
|
||||
|
@ -202,7 +203,7 @@ private:
|
|||
ASSERT_EQUALS("void C ( ) { this . x@1 = 0 ; } int x@1", parse(clang));
|
||||
}
|
||||
|
||||
void cxxConstructExpr() {
|
||||
void cxxConstructExpr1() {
|
||||
const char clang[] = "`-FunctionDecl 0x2dd7940 <line:2:1, col:30> col:5 f 'Foo (Foo)'\n"
|
||||
" |-ParmVarDecl 0x2dd7880 <col:7, col:11> col:11 used foo 'Foo'\n"
|
||||
" `-CompoundStmt 0x2dd80c0 <col:16, col:30>\n"
|
||||
|
@ -213,6 +214,14 @@ private:
|
|||
ASSERT_EQUALS("Foo f ( Foo foo@1 ) { return foo@1 ; }", parse(clang));
|
||||
}
|
||||
|
||||
void cxxConstructExpr2() {
|
||||
const char clang[] = "`-FunctionDecl 0x3e44180 <1.cpp:2:1, col:30> col:13 f 'std::string ()'\n"
|
||||
" `-CompoundStmt 0x3e4cb80 <col:17, col:30>\n"
|
||||
" `-ReturnStmt 0x3e4cb68 <col:19, col:27>\n"
|
||||
" `-CXXConstructExpr 0x3e4cb38 <col:26, col:27> 'std::string':'std::__cxx11::basic_string<char>' '....' list";
|
||||
ASSERT_EQUALS("std::string f ( ) { return std::string ( ) ; }", parse(clang));
|
||||
}
|
||||
|
||||
void cxxMemberCall() {
|
||||
const char clang[] = "`-FunctionDecl 0x320dc80 <line:2:1, col:33> col:6 bar 'void ()'\n"
|
||||
" `-CompoundStmt 0x323bb08 <col:12, col:33>\n"
|
||||
|
|
Loading…
Reference in New Issue