Better handling of CppcheckID suppressions
This commit is contained in:
parent
47ff29f1c8
commit
118e9eb3e2
|
@ -1033,7 +1033,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
|
|||
const std::string &path = mPath;
|
||||
|
||||
std::list<std::string> paths;
|
||||
std::list<std::string> suppressions;
|
||||
std::list<Suppressions::Suppression> suppressions;
|
||||
Settings temp;
|
||||
|
||||
guiProject.analyzeAllVsConfigs.clear();
|
||||
|
@ -1072,8 +1072,20 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
|
|||
guiProject.excludedPaths = readXmlStringList(node, "", CppcheckXml::IgnorePathName, CppcheckXml::IgnorePathNameAttrib);
|
||||
else if (strcmp(node->Name(), CppcheckXml::LibrariesElementName) == 0)
|
||||
guiProject.libraries = readXmlStringList(node, "", CppcheckXml::LibraryElementName, nullptr);
|
||||
else if (strcmp(node->Name(), CppcheckXml::SuppressionsElementName) == 0)
|
||||
suppressions = readXmlStringList(node, "", CppcheckXml::SuppressionElementName, nullptr);
|
||||
else if (strcmp(node->Name(), CppcheckXml::SuppressionsElementName) == 0) {
|
||||
for (const tinyxml2::XMLElement *child = node->FirstChildElement(); child; child = child->NextSiblingElement()) {
|
||||
if (strcmp(child->Name(), CppcheckXml::SuppressionsElementName) != 0)
|
||||
continue;
|
||||
auto read = [](const char *s, const char *def) { return s ? s : def; };
|
||||
Suppressions::Suppression s;
|
||||
s.errorId = read(child->GetText(), "");
|
||||
s.fileName = read(child->Attribute("fileName"), "");
|
||||
s.lineNumber = child->IntAttribute("lineNumber", Suppressions::Suppression::NO_LINE);
|
||||
s.symbolName = read(child->Attribute("symbolName"), "");
|
||||
std::istringstream(read(child->Attribute("cppcheck-id"), "0")) >> s.cppcheckId;
|
||||
suppressions.push_back(s);
|
||||
}
|
||||
}
|
||||
else if (strcmp(node->Name(), CppcheckXml::VSConfigurationElementName) == 0)
|
||||
guiProject.checkVsConfigs = readXmlStringList(node, "", CppcheckXml::VSConfigurationName, nullptr);
|
||||
else if (strcmp(node->Name(), CppcheckXml::PlatformElementName) == 0)
|
||||
|
@ -1130,8 +1142,8 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
|
|||
|
||||
for (const std::string &p : paths)
|
||||
guiProject.pathNames.push_back(p);
|
||||
for (const std::string &supp : suppressions)
|
||||
settings->nomsg.addSuppressionLine(supp);
|
||||
for (const Suppressions::Suppression &supp : suppressions)
|
||||
settings->nomsg.addSuppression(supp);
|
||||
settings->checkHeaders = temp.checkHeaders;
|
||||
settings->checkUnusedTemplates = temp.checkUnusedTemplates;
|
||||
settings->maxCtuDepth = temp.maxCtuDepth;
|
||||
|
|
|
@ -98,8 +98,10 @@ std::string Suppressions::parseXmlFile(const char *filename)
|
|||
s.lineNumber = std::atoi(text);
|
||||
else if (std::strcmp(e2->Name(), "symbolName") == 0)
|
||||
s.symbolName = text;
|
||||
else if (*text && std::strcmp(e2->Name(), "cppcheckId") == 0)
|
||||
std::istringstream(text) >> s.cppcheckId;
|
||||
else
|
||||
return "Unknown suppression element <" + std::string(e2->Name()) + ">, expected <id>/<fileName>/<lineNumber>/<symbolName>";
|
||||
return "Unknown suppression element <" + std::string(e2->Name()) + ">, expected <id>/<fileName>/<lineNumber>/<symbolName>/<cppcheckId>";
|
||||
}
|
||||
|
||||
const std::string err = addSuppression(s);
|
||||
|
@ -317,6 +319,8 @@ std::string Suppressions::Suppression::getText() const
|
|||
ret += " lineNumber=" + MathLib::toString(lineNumber);
|
||||
if (!symbolName.empty())
|
||||
ret += " symbolName=" + symbolName;
|
||||
if (cppcheckId > 0)
|
||||
ret += " cppcheckId=" + MathLib::toString(cppcheckId);
|
||||
if (ret.compare(0,1," ")==0)
|
||||
return ret.substr(1);
|
||||
return ret;
|
||||
|
@ -360,13 +364,13 @@ void Suppressions::dump(std::ostream & out) const
|
|||
out << " lineNumber=\"" << suppression.lineNumber << '"';
|
||||
if (!suppression.symbolName.empty())
|
||||
out << " symbolName=\"" << ErrorLogger::toxml(suppression.symbolName) << '\"';
|
||||
if (suppression.cppcheckId > 0)
|
||||
out << " cppcheckId=\"" << suppression.cppcheckId << '\"';
|
||||
out << " />" << std::endl;
|
||||
}
|
||||
out << " </suppressions>" << std::endl;
|
||||
}
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::list<Suppressions::Suppression> Suppressions::getUnmatchedLocalSuppressions(const std::string &file, const bool unusedFunctionChecking) const
|
||||
{
|
||||
std::list<Suppression> result;
|
||||
|
|
Loading…
Reference in New Issue