parent
39c5274742
commit
fbf63b932e
|
@ -329,20 +329,17 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
|
||||||
QXmlStreamReader::TokenType type;
|
QXmlStreamReader::TokenType type;
|
||||||
if (xmlReader.attributes().hasAttribute("ext")) {
|
if (xmlReader.attributes().hasAttribute("ext")) {
|
||||||
markup.ext = xmlReader.attributes().value("ext").toString();
|
markup.ext = xmlReader.attributes().value("ext").toString();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mandatoryAttibuteMissing(xmlReader, "ext");
|
mandatoryAttibuteMissing(xmlReader, "ext");
|
||||||
}
|
}
|
||||||
if (xmlReader.attributes().hasAttribute("aftercode")) {
|
if (xmlReader.attributes().hasAttribute("aftercode")) {
|
||||||
markup.afterCode = (xmlReader.attributes().value("aftercode") == "true") ? true : false;
|
markup.afterCode = (xmlReader.attributes().value("aftercode") == "true") ? true : false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mandatoryAttibuteMissing(xmlReader, "aftercode");
|
mandatoryAttibuteMissing(xmlReader, "aftercode");
|
||||||
}
|
}
|
||||||
if (xmlReader.attributes().hasAttribute("reporterrors")) {
|
if (xmlReader.attributes().hasAttribute("reporterrors")) {
|
||||||
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == "true") ? true : false;
|
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == "true") ? true : false;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
mandatoryAttibuteMissing(xmlReader, "reporterrors");
|
mandatoryAttibuteMissing(xmlReader, "reporterrors");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,8 +355,7 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
|
||||||
continue;
|
continue;
|
||||||
if (xmlReader.name().toString() == "keyword") {
|
if (xmlReader.name().toString() == "keyword") {
|
||||||
markup.keywords.append(xmlReader.attributes().value("name").toString());
|
markup.keywords.append(xmlReader.attributes().value("name").toString());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unhandledElement(xmlReader);
|
unhandledElement(xmlReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -372,13 +368,11 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
|
||||||
continue;
|
continue;
|
||||||
if (xmlReader.name().toString() == "block") {
|
if (xmlReader.name().toString() == "block") {
|
||||||
codeBlock.blocks.append(xmlReader.attributes().value("name").toString());
|
codeBlock.blocks.append(xmlReader.attributes().value("name").toString());
|
||||||
}
|
} else if (xmlReader.name().toString() == "structure") {
|
||||||
else if (xmlReader.name().toString() == "structure") {
|
|
||||||
codeBlock.offset = xmlReader.attributes().value("offset").toInt();
|
codeBlock.offset = xmlReader.attributes().value("offset").toInt();
|
||||||
codeBlock.start = xmlReader.attributes().value("start").toString();
|
codeBlock.start = xmlReader.attributes().value("start").toString();
|
||||||
codeBlock.end = xmlReader.attributes().value("end").toString();
|
codeBlock.end = xmlReader.attributes().value("end").toString();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unhandledElement(xmlReader);
|
unhandledElement(xmlReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,14 +386,11 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
|
||||||
continue;
|
continue;
|
||||||
if (xmlReader.name().toString() == "exporter") {
|
if (xmlReader.name().toString() == "exporter") {
|
||||||
exporter.prefix = xmlReader.attributes().value("prefix").toString();
|
exporter.prefix = xmlReader.attributes().value("prefix").toString();
|
||||||
}
|
} else if (xmlReader.name().toString() == "prefix") {
|
||||||
else if (xmlReader.name().toString() == "prefix") {
|
|
||||||
exporter.prefixList.append(xmlReader.readElementText());
|
exporter.prefixList.append(xmlReader.readElementText());
|
||||||
}
|
} else if (xmlReader.name().toString() == "suffix") {
|
||||||
else if (xmlReader.name().toString() == "suffix") {
|
|
||||||
exporter.suffixList.append(xmlReader.readElementText());
|
exporter.suffixList.append(xmlReader.readElementText());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unhandledElement(xmlReader);
|
unhandledElement(xmlReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -411,8 +402,7 @@ static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
|
||||||
continue;
|
continue;
|
||||||
if (xmlReader.name().toString() == "importer") {
|
if (xmlReader.name().toString() == "importer") {
|
||||||
markup.importer.append(xmlReader.readElementText());
|
markup.importer.append(xmlReader.readElementText());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
unhandledElement(xmlReader);
|
unhandledElement(xmlReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -481,7 +481,7 @@ void TestCppcheckLibraryData::markupValid()
|
||||||
QCOMPARE(libraryData.markups[0].afterCode, true);
|
QCOMPARE(libraryData.markups[0].afterCode, true);
|
||||||
|
|
||||||
QCOMPARE(libraryData.markups[0].keywords.size(), 4);
|
QCOMPARE(libraryData.markups[0].keywords.size(), 4);
|
||||||
QCOMPARE(libraryData.markups[0].keywords, QStringList( {"if", "while", "typeof", "for"} ));
|
QCOMPARE(libraryData.markups[0].keywords, QStringList({"if", "while", "typeof", "for"}));
|
||||||
|
|
||||||
QCOMPARE(libraryData.markups[0].importer.size(), 1);
|
QCOMPARE(libraryData.markups[0].importer.size(), 1);
|
||||||
QCOMPARE(libraryData.markups[0].importer, QStringList("connect"));
|
QCOMPARE(libraryData.markups[0].importer, QStringList("connect"));
|
||||||
|
@ -491,11 +491,11 @@ void TestCppcheckLibraryData::markupValid()
|
||||||
QCOMPARE(libraryData.markups[0].exporter[0].suffixList.size(), 1);
|
QCOMPARE(libraryData.markups[0].exporter[0].suffixList.size(), 1);
|
||||||
QCOMPARE(libraryData.markups[0].exporter[0].suffixList, QStringList("READ"));
|
QCOMPARE(libraryData.markups[0].exporter[0].suffixList, QStringList("READ"));
|
||||||
QCOMPARE(libraryData.markups[0].exporter[0].prefixList.size(), 3);
|
QCOMPARE(libraryData.markups[0].exporter[0].prefixList.size(), 3);
|
||||||
QCOMPARE(libraryData.markups[0].exporter[0].prefixList, QStringList( {"READ", "WRITE", "NOTIFY"} ));
|
QCOMPARE(libraryData.markups[0].exporter[0].prefixList, QStringList({"READ", "WRITE", "NOTIFY"}));
|
||||||
|
|
||||||
QCOMPARE(libraryData.markups[0].codeBlocks.size(), 2);
|
QCOMPARE(libraryData.markups[0].codeBlocks.size(), 2);
|
||||||
QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks.size(), 5);
|
QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks.size(), 5);
|
||||||
QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks, QStringList( {"onClicked", "onFinished", "onTriggered", "onPressed", "onTouch"} ));
|
QCOMPARE(libraryData.markups[0].codeBlocks[0].blocks, QStringList({"onClicked", "onFinished", "onTriggered", "onPressed", "onTouch"}));
|
||||||
QCOMPARE(libraryData.markups[0].codeBlocks[0].offset, 3);
|
QCOMPARE(libraryData.markups[0].codeBlocks[0].offset, 3);
|
||||||
QCOMPARE(libraryData.markups[0].codeBlocks[0].start, "{");
|
QCOMPARE(libraryData.markups[0].codeBlocks[0].start, "{");
|
||||||
QCOMPARE(libraryData.markups[0].codeBlocks[0].end, "}");
|
QCOMPARE(libraryData.markups[0].codeBlocks[0].end, "}");
|
||||||
|
|
|
@ -755,13 +755,12 @@ static void followVariableExpressionError(const Token *tok1, const Token *tok2,
|
||||||
std::vector<ReferenceToken> followAllReferences(const Token* tok, bool inconclusive, ErrorPath errors, int depth)
|
std::vector<ReferenceToken> followAllReferences(const Token* tok, bool inconclusive, ErrorPath errors, int depth)
|
||||||
{
|
{
|
||||||
struct ReferenceTokenLess {
|
struct ReferenceTokenLess {
|
||||||
bool operator()(const ReferenceToken& x, const ReferenceToken& y) const
|
bool operator()(const ReferenceToken& x, const ReferenceToken& y) const {
|
||||||
{
|
|
||||||
return x.token < y.token;
|
return x.token < y.token;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (!tok)
|
if (!tok)
|
||||||
return std::vector<ReferenceToken>{};
|
return std::vector<ReferenceToken> {};
|
||||||
if (depth < 0)
|
if (depth < 0)
|
||||||
return {{tok, std::move(errors)}};
|
return {{tok, std::move(errors)}};
|
||||||
const Variable *var = tok->variable();
|
const Variable *var = tok->variable();
|
||||||
|
@ -811,7 +810,7 @@ std::vector<ReferenceToken> followAllReferences(const Token* tok, bool inconclus
|
||||||
if (returnTok == tok)
|
if (returnTok == tok)
|
||||||
continue;
|
continue;
|
||||||
std::vector<ReferenceToken> argvarRt = followAllReferences(returnTok, inconclusive, errors, depth - 1);
|
std::vector<ReferenceToken> argvarRt = followAllReferences(returnTok, inconclusive, errors, depth - 1);
|
||||||
for(const ReferenceToken& rt:followAllReferences(returnTok, inconclusive, errors, depth - 1)) {
|
for (const ReferenceToken& rt:followAllReferences(returnTok, inconclusive, errors, depth - 1)) {
|
||||||
const Variable* argvar = rt.token->variable();
|
const Variable* argvar = rt.token->variable();
|
||||||
if (!argvar)
|
if (!argvar)
|
||||||
return {{tok, std::move(errors)}};
|
return {{tok, std::move(errors)}};
|
||||||
|
|
|
@ -2845,7 +2845,9 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
|
||||||
// the full definition must be compared
|
// the full definition must be compared
|
||||||
bool fullDefinition = std::all_of(classScope->functionList.begin(),
|
bool fullDefinition = std::all_of(classScope->functionList.begin(),
|
||||||
classScope->functionList.end(),
|
classScope->functionList.end(),
|
||||||
[](const Function& f) { return f.hasBody(); });
|
[](const Function& f) {
|
||||||
|
return f.hasBody();
|
||||||
|
});
|
||||||
if (!fullDefinition)
|
if (!fullDefinition)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -584,7 +584,6 @@ void execute(const Token *expr,
|
||||||
*result = 0;
|
*result = 0;
|
||||||
else
|
else
|
||||||
*error = true;
|
*error = true;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
*error = true;
|
*error = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2001,8 +2001,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
||||||
return isModified(tok);
|
return isModified(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
Action analyzeToken(const Token* ref, const Token* tok, Direction d, bool inconclusiveRef) const
|
Action analyzeToken(const Token* ref, const Token* tok, Direction d, bool inconclusiveRef) const {
|
||||||
{
|
|
||||||
if (!ref)
|
if (!ref)
|
||||||
return Action::None;
|
return Action::None;
|
||||||
// If its an inconclusiveRef then ref != tok
|
// If its an inconclusiveRef then ref != tok
|
||||||
|
@ -2054,7 +2053,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
||||||
// Follow references
|
// Follow references
|
||||||
std::vector<ReferenceToken> refs = followAllReferences(tok);
|
std::vector<ReferenceToken> refs = followAllReferences(tok);
|
||||||
const bool inconclusiveRefs = refs.size() != 1;
|
const bool inconclusiveRefs = refs.size() != 1;
|
||||||
for(const ReferenceToken& ref:refs) {
|
for (const ReferenceToken& ref:refs) {
|
||||||
Action a = analyzeToken(ref.token, tok, d, inconclusiveRefs);
|
Action a = analyzeToken(ref.token, tok, d, inconclusiveRefs);
|
||||||
if (a != Action::None)
|
if (a != Action::None)
|
||||||
return a;
|
return a;
|
||||||
|
|
|
@ -5038,18 +5038,18 @@ private:
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0));
|
ASSERT_EQUALS(true, testValueOfXKnown(code, 4U, 0));
|
||||||
|
|
||||||
code = "bool f(std::string s) {\n"
|
code = "bool f(std::string s) {\n"
|
||||||
" if (!s.empty()) {\n"
|
" if (!s.empty()) {\n"
|
||||||
" bool x = s == \"0\";\n"
|
" bool x = s == \"0\";\n"
|
||||||
" return x;\n"
|
" return x;\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" return false;\n"
|
" return false;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 0));
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 0));
|
||||||
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
|
ASSERT_EQUALS(false, testValueOfXKnown(code, 4U, 1));
|
||||||
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
|
ASSERT_EQUALS(false, testValueOfXImpossible(code, 4U, 0));
|
||||||
|
|
||||||
code = "bool f() {\n"
|
code = "bool f() {\n"
|
||||||
" std::list<int> x1;\n"
|
" std::list<int> x1;\n"
|
||||||
" std::list<int> x2;\n"
|
" std::list<int> x2;\n"
|
||||||
" for (int i = 0; i < 10; ++i) {\n"
|
" for (int i = 0; i < 10; ++i) {\n"
|
||||||
|
|
Loading…
Reference in New Issue