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.maxTemplateRecursion = mProjectFile->getMaxTemplateRecursion();
result.checkHeaders = mProjectFile->getCheckHeaders();
result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates();
result.safeChecks.classes = mProjectFile->safeChecks.classes;

View File

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

View File

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

View File

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

View File

@ -520,7 +520,11 @@
</widget>
</item>
<item>
<widget class="QSpinBox" name="mMaxCtuDepth"/>
<widget class="QSpinBox" name="mMaxCtuDepth">
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
@ -537,6 +541,40 @@
</item>
</layout>
</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>
</widget>
</item>

View File

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