GUI: Add configuration for max recursion in template instantiation

This commit is contained in:
Daniel Marjamäki 2020-06-26 17:12:02 +02:00
parent f569bc79f5
commit c5f9e85ee7
6 changed files with 64 additions and 2 deletions

View File

@ -908,6 +908,7 @@ Settings MainWindow::getCppcheckSettings()
} }
result.maxCtuDepth = mProjectFile->getMaxCtuDepth(); result.maxCtuDepth = mProjectFile->getMaxCtuDepth();
result.maxTemplateRecursion = mProjectFile->getMaxTemplateRecursion();
result.checkHeaders = mProjectFile->getCheckHeaders(); result.checkHeaders = mProjectFile->getCheckHeaders();
result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates(); result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates();
result.safeChecks.classes = mProjectFile->safeChecks.classes; result.safeChecks.classes = mProjectFile->safeChecks.classes;

View File

@ -44,6 +44,7 @@ ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
void ProjectFile::clear() void ProjectFile::clear()
{ {
const Settings settings;
clangParser = false; clangParser = false;
bugHunting = false; bugHunting = false;
mRootPath.clear(); mRootPath.clear();
@ -64,7 +65,8 @@ void ProjectFile::clear()
mAnalyzeAllVsConfigs = false; mAnalyzeAllVsConfigs = false;
mCheckHeaders = true; mCheckHeaders = true;
mCheckUnusedTemplates = false; mCheckUnusedTemplates = false;
mMaxCtuDepth = 10; mMaxCtuDepth = settings.maxCtuDepth;
mMaxTemplateRecursion = settings.maxTemplateRecursion;
mCheckUnknownFunctionReturn.clear(); mCheckUnknownFunctionReturn.clear();
safeChecks.clear(); safeChecks.clear();
mVsConfigurations.clear(); mVsConfigurations.clear();
@ -187,6 +189,9 @@ bool ProjectFile::read(const QString &filename)
if (xmlReader.name() == CppcheckXml::MaxCtuDepthElementName) if (xmlReader.name() == CppcheckXml::MaxCtuDepthElementName)
mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth); mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth);
if (xmlReader.name() == CppcheckXml::MaxTemplateRecursionElementName)
mMaxTemplateRecursion = readInt(xmlReader, mMaxTemplateRecursion);
// VSConfiguration // VSConfiguration
if (xmlReader.name() == CppcheckXml::VSConfigurationElementName) if (xmlReader.name() == CppcheckXml::VSConfigurationElementName)
readVsConfigurations(xmlReader); readVsConfigurations(xmlReader);
@ -786,6 +791,10 @@ bool ProjectFile::write(const QString &filename)
xmlWriter.writeCharacters(QString::number(mMaxCtuDepth)); xmlWriter.writeCharacters(QString::number(mMaxCtuDepth));
xmlWriter.writeEndElement(); xmlWriter.writeEndElement();
xmlWriter.writeStartElement(CppcheckXml::MaxTemplateRecursionElementName);
xmlWriter.writeCharacters(QString::number(mMaxTemplateRecursion));
xmlWriter.writeEndElement();
if (!mIncludeDirs.isEmpty()) { if (!mIncludeDirs.isEmpty()) {
xmlWriter.writeStartElement(CppcheckXml::IncludeDirElementName); xmlWriter.writeStartElement(CppcheckXml::IncludeDirElementName);
foreach (QString incdir, mIncludeDirs) { foreach (QString incdir, mIncludeDirs) {

View File

@ -208,6 +208,14 @@ public:
mMaxCtuDepth = maxCtuDepth; mMaxCtuDepth = maxCtuDepth;
} }
int getMaxTemplateRecursion() const {
return mMaxTemplateRecursion;
}
void setMaxTemplateRecursion(int maxTemplateRecursion) {
mMaxTemplateRecursion = maxTemplateRecursion;
}
const std::map<std::string,std::string>& getFunctionContracts() const { const std::map<std::string,std::string>& getFunctionContracts() const {
return mFunctionContracts; return mFunctionContracts;
} }
@ -538,6 +546,9 @@ private:
/** Max CTU depth */ /** Max CTU depth */
int mMaxCtuDepth; int mMaxCtuDepth;
/** Max template instantiation recursion */
int mMaxTemplateRecursion;
QStringList mCheckUnknownFunctionReturn; QStringList mCheckUnknownFunctionReturn;
}; };

View File

@ -260,6 +260,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI.mCheckHeaders->setChecked(projectFile->getCheckHeaders()); mUI.mCheckHeaders->setChecked(projectFile->getCheckHeaders());
mUI.mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates()); mUI.mCheckUnusedTemplates->setChecked(projectFile->getCheckUnusedTemplates());
mUI.mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth()); mUI.mMaxCtuDepth->setValue(projectFile->getMaxCtuDepth());
mUI.mMaxTemplateRecursion->setValue(projectFile->getMaxTemplateRecursion());
if (projectFile->clangParser) if (projectFile->clangParser)
mUI.mBtnClangParser->setChecked(true); mUI.mBtnClangParser->setChecked(true);
else else
@ -361,6 +362,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
projectFile->setCheckHeaders(mUI.mCheckHeaders->isChecked()); projectFile->setCheckHeaders(mUI.mCheckHeaders->isChecked());
projectFile->setCheckUnusedTemplates(mUI.mCheckUnusedTemplates->isChecked()); projectFile->setCheckUnusedTemplates(mUI.mCheckUnusedTemplates->isChecked());
projectFile->setMaxCtuDepth(mUI.mMaxCtuDepth->value()); projectFile->setMaxCtuDepth(mUI.mMaxCtuDepth->value());
projectFile->setMaxTemplateRecursion(mUI.mMaxTemplateRecursion->value());
projectFile->setIncludes(getIncludePaths()); projectFile->setIncludes(getIncludePaths());
projectFile->setDefines(getDefines()); projectFile->setDefines(getDefines());
projectFile->setUndefines(getUndefines()); projectFile->setUndefines(getUndefines());

View File

@ -520,7 +520,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="mMaxCtuDepth"/> <widget class="QSpinBox" name="mMaxCtuDepth">
<property name="value">
<number>10</number>
</property>
</widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
@ -537,6 +541,40 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Max recursion in template instantiation</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mMaxTemplateRecursion">
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -164,6 +164,7 @@ namespace CppcheckXml {
const char CheckHeadersElementName[] = "check-headers"; const char CheckHeadersElementName[] = "check-headers";
const char CheckUnusedTemplatesElementName[] = "check-unused-templates"; const char CheckUnusedTemplatesElementName[] = "check-unused-templates";
const char MaxCtuDepthElementName[] = "max-ctu-depth"; const char MaxCtuDepthElementName[] = "max-ctu-depth";
const char MaxTemplateRecursionElementName[] = "max-template-recursion";
const char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values"; const char CheckUnknownFunctionReturn[] = "check-unknown-function-return-values";
const char ClangTidy[] = "clang-tidy"; const char ClangTidy[] = "clang-tidy";
const char Name[] = "name"; const char Name[] = "name";