2009-06-22 10:57:17 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-02-05 11:45:17 +01:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2009-06-22 10:57:17 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-06-22 10:57:17 +02:00
|
|
|
*/
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include "projectfile.h"
|
|
|
|
|
2017-09-22 15:41:27 +02:00
|
|
|
#include "common.h"
|
2019-08-09 21:15:02 +02:00
|
|
|
#include "importproject.h"
|
2019-07-23 11:54:38 +02:00
|
|
|
#include "settings.h"
|
2019-04-19 15:09:55 +02:00
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
|
2020-07-15 13:03:07 +02:00
|
|
|
ProjectFile *ProjectFile::mActiveProject;
|
|
|
|
|
2009-06-22 10:57:17 +02:00
|
|
|
ProjectFile::ProjectFile(QObject *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QObject(parent)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
2017-08-10 00:18:04 +02:00
|
|
|
clear();
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ProjectFile::ProjectFile(const QString &filename, QObject *parent) :
|
2010-04-15 20:08:51 +02:00
|
|
|
QObject(parent),
|
|
|
|
mFilename(filename)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
2017-08-10 00:18:04 +02:00
|
|
|
clear();
|
2017-07-31 12:02:51 +02:00
|
|
|
read();
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
void ProjectFile::clear()
|
|
|
|
{
|
2020-06-26 17:12:02 +02:00
|
|
|
const Settings settings;
|
2021-04-30 16:47:02 +02:00
|
|
|
clangParser = false;
|
2017-08-10 00:18:04 +02:00
|
|
|
mRootPath.clear();
|
|
|
|
mBuildDir.clear();
|
|
|
|
mImportProject.clear();
|
|
|
|
mAnalyzeAllVsConfigs = true;
|
|
|
|
mIncludeDirs.clear();
|
|
|
|
mDefines.clear();
|
2018-10-09 15:05:05 +02:00
|
|
|
mUndefines.clear();
|
2017-08-10 00:18:04 +02:00
|
|
|
mPaths.clear();
|
|
|
|
mExcludedPaths.clear();
|
|
|
|
mLibraries.clear();
|
2018-03-13 13:07:10 +01:00
|
|
|
mPlatform.clear();
|
2017-08-10 00:18:04 +02:00
|
|
|
mSuppressions.clear();
|
|
|
|
mAddons.clear();
|
2021-04-30 16:47:02 +02:00
|
|
|
mClangAnalyzer = mClangTidy = false;
|
2019-04-10 16:49:24 +02:00
|
|
|
mAnalyzeAllVsConfigs = false;
|
|
|
|
mCheckHeaders = true;
|
2020-11-23 18:29:08 +01:00
|
|
|
mCheckUnusedTemplates = true;
|
2020-06-26 17:12:02 +02:00
|
|
|
mMaxCtuDepth = settings.maxCtuDepth;
|
|
|
|
mMaxTemplateRecursion = settings.maxTemplateRecursion;
|
2019-07-11 21:05:52 +02:00
|
|
|
mCheckUnknownFunctionReturn.clear();
|
2020-02-09 21:02:28 +01:00
|
|
|
safeChecks.clear();
|
2020-01-31 07:08:38 +01:00
|
|
|
mVsConfigurations.clear();
|
2020-07-16 23:03:54 +02:00
|
|
|
mTags.clear();
|
|
|
|
mWarningTags.clear();
|
2017-08-10 00:18:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
bool ProjectFile::read(const QString &filename)
|
2009-06-22 10:57:17 +02:00
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!filename.isEmpty())
|
2009-06-22 10:57:17 +02:00
|
|
|
mFilename = filename;
|
|
|
|
|
|
|
|
QFile file(mFilename);
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
2009-06-22 10:57:17 +02:00
|
|
|
return false;
|
|
|
|
|
2017-08-10 00:18:04 +02:00
|
|
|
clear();
|
|
|
|
|
2009-06-22 10:57:17 +02:00
|
|
|
QXmlStreamReader xmlReader(&file);
|
|
|
|
bool insideProject = false;
|
2010-07-08 18:49:04 +02:00
|
|
|
bool projectTagFound = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
while (!xmlReader.atEnd()) {
|
|
|
|
switch (xmlReader.readNext()) {
|
2009-06-22 10:57:17 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::ProjectElementName)) {
|
2009-06-22 10:57:17 +02:00
|
|
|
insideProject = true;
|
2010-07-08 18:49:04 +02:00
|
|
|
projectTagFound = true;
|
2019-07-23 11:54:38 +02:00
|
|
|
break;
|
2010-07-08 18:49:04 +02:00
|
|
|
}
|
2019-07-23 11:54:38 +02:00
|
|
|
if (!insideProject)
|
|
|
|
break;
|
|
|
|
|
2010-08-20 22:58:00 +02:00
|
|
|
// Read root path from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::RootPathName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readRootPath(xmlReader);
|
2010-08-20 22:58:00 +02:00
|
|
|
|
2016-11-19 20:38:50 +01:00
|
|
|
// Read root path from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::BuildDirElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readBuildDir(xmlReader);
|
2016-11-19 20:38:50 +01:00
|
|
|
|
2010-08-14 17:42:37 +02:00
|
|
|
// Find paths to check from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::PathsElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readCheckPaths(xmlReader);
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::ImportProjectElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readImportProject(xmlReader);
|
2016-08-18 21:58:50 +02:00
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::AnalyzeAllVsConfigsElementName))
|
2019-04-10 16:49:24 +02:00
|
|
|
mAnalyzeAllVsConfigs = readBool(xmlReader);
|
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::Parser))
|
2021-04-30 16:47:02 +02:00
|
|
|
clangParser = true;
|
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::CheckHeadersElementName))
|
2019-04-10 16:49:24 +02:00
|
|
|
mCheckHeaders = readBool(xmlReader);
|
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::CheckUnusedTemplatesElementName))
|
2019-04-10 16:49:24 +02:00
|
|
|
mCheckUnusedTemplates = readBool(xmlReader);
|
2017-08-10 00:18:04 +02:00
|
|
|
|
2010-07-03 23:15:19 +02:00
|
|
|
// Find include directory from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::IncludeDirElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readIncludeDirs(xmlReader);
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2010-07-03 23:15:19 +02:00
|
|
|
// Find preprocessor define from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::DefinesElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readDefines(xmlReader);
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2018-10-09 15:05:05 +02:00
|
|
|
// Find preprocessor define from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::UndefinesElementName))
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(mUndefines, xmlReader, CppcheckXml::UndefineName);
|
2018-10-09 15:05:05 +02:00
|
|
|
|
2011-08-23 18:54:53 +02:00
|
|
|
// Find exclude list from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::ExcludeElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readExcludes(xmlReader);
|
2011-08-23 18:54:53 +02:00
|
|
|
|
2011-02-27 17:32:53 +01:00
|
|
|
// Find ignore list from inside project element
|
2011-08-23 18:54:53 +02:00
|
|
|
// These are read for compatibility
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::IgnoreElementName))
|
2017-07-28 05:08:59 +02:00
|
|
|
readExcludes(xmlReader);
|
2011-02-27 17:32:53 +01:00
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
// Find libraries list from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::LibrariesElementName))
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(mLibraries, xmlReader, CppcheckXml::LibraryElementName);
|
2013-12-30 22:32:50 +01:00
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::PlatformElementName))
|
2018-03-13 13:07:10 +01:00
|
|
|
readPlatform(xmlReader);
|
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
// Find suppressions list from inside project element
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::SuppressionsElementName))
|
2018-04-09 06:43:48 +02:00
|
|
|
readSuppressions(xmlReader);
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2019-07-11 21:05:52 +02:00
|
|
|
// Unknown function return values
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::CheckUnknownFunctionReturn))
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(mCheckUnknownFunctionReturn, xmlReader, CppcheckXml::Name);
|
2019-07-11 21:05:52 +02:00
|
|
|
|
|
|
|
// check all function parameter values
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(Settings::SafeChecks::XmlRootName))
|
2020-02-09 21:02:28 +01:00
|
|
|
safeChecks.loadFromXml(xmlReader);
|
2019-07-11 21:05:52 +02:00
|
|
|
|
2017-08-03 12:30:28 +02:00
|
|
|
// Addons
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::AddonsElementName))
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(mAddons, xmlReader, CppcheckXml::AddonElementName);
|
2017-08-03 12:30:28 +02:00
|
|
|
|
2017-09-22 15:41:27 +02:00
|
|
|
// Tools
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::ToolsElementName)) {
|
2017-09-22 15:41:27 +02:00
|
|
|
QStringList tools;
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(tools, xmlReader, CppcheckXml::ToolElementName);
|
2021-04-30 16:47:02 +02:00
|
|
|
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
|
2017-09-22 15:41:27 +02:00
|
|
|
mClangTidy = tools.contains(CLANG_TIDY);
|
|
|
|
}
|
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::TagsElementName))
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(mTags, xmlReader, CppcheckXml::TagElementName);
|
2017-08-18 17:25:08 +02:00
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::TagWarningsElementName))
|
2020-07-16 23:03:54 +02:00
|
|
|
readTagWarnings(xmlReader, xmlReader.attributes().value(QString(), CppcheckXml::TagAttributeName).toString());
|
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::MaxCtuDepthElementName))
|
2019-04-10 16:49:24 +02:00
|
|
|
mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth);
|
|
|
|
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::MaxTemplateRecursionElementName))
|
2020-06-26 17:12:02 +02:00
|
|
|
mMaxTemplateRecursion = readInt(xmlReader, mMaxTemplateRecursion);
|
|
|
|
|
2020-01-31 07:08:38 +01:00
|
|
|
// VSConfiguration
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::VSConfigurationElementName))
|
2020-01-31 07:08:38 +01:00
|
|
|
readVsConfigurations(xmlReader);
|
2009-06-22 10:57:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(CppcheckXml::ProjectElementName))
|
2009-06-22 10:57:17 +02:00
|
|
|
insideProject = false;
|
|
|
|
break;
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2009-06-23 08:15:00 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
2017-07-28 05:08:59 +02:00
|
|
|
return projectTagFound;
|
2009-06-22 10:57:17 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readRootPath(QXmlStreamReader &reader)
|
2010-08-20 22:58:00 +02:00
|
|
|
{
|
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2019-08-09 21:15:02 +02:00
|
|
|
QString name = attribs.value(QString(), CppcheckXml::RootPathNameAttrib).toString();
|
2010-08-20 22:58:00 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mRootPath = name;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readBuildDir(QXmlStreamReader &reader)
|
2016-11-19 20:38:50 +01:00
|
|
|
{
|
|
|
|
mBuildDir.clear();
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mBuildDir = reader.text().toString();
|
2021-01-21 18:13:32 +01:00
|
|
|
FALLTHROUGH;
|
2016-11-19 20:38:50 +01:00
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-07 11:33:08 +01:00
|
|
|
} while (true);
|
2016-11-19 20:38:50 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readImportProject(QXmlStreamReader &reader)
|
2016-08-18 21:58:50 +02:00
|
|
|
{
|
|
|
|
mImportProject.clear();
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mImportProject = reader.text().toString();
|
2021-01-21 18:13:32 +01:00
|
|
|
FALLTHROUGH;
|
2016-08-18 21:58:50 +02:00
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-07 11:33:08 +01:00
|
|
|
} while (true);
|
2016-08-18 21:58:50 +02:00
|
|
|
}
|
|
|
|
|
2019-04-10 16:49:24 +02:00
|
|
|
bool ProjectFile::readBool(QXmlStreamReader &reader)
|
2017-08-10 00:18:04 +02:00
|
|
|
{
|
2019-04-10 16:49:24 +02:00
|
|
|
bool ret = false;
|
2017-08-10 00:18:04 +02:00
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
2019-04-10 16:49:24 +02:00
|
|
|
ret = (reader.text().toString() == "true");
|
2021-01-21 18:13:32 +01:00
|
|
|
FALLTHROUGH;
|
2017-08-10 00:18:04 +02:00
|
|
|
case QXmlStreamReader::EndElement:
|
2019-04-10 16:49:24 +02:00
|
|
|
return ret;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-07 11:33:08 +01:00
|
|
|
} while (true);
|
2019-04-10 16:49:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ProjectFile::readInt(QXmlStreamReader &reader, int defaultValue)
|
|
|
|
{
|
|
|
|
int ret = defaultValue;
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
ret = reader.text().toString().toInt();
|
2021-01-21 18:13:32 +01:00
|
|
|
FALLTHROUGH;
|
2019-04-10 16:49:24 +02:00
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return ret;
|
2017-08-10 00:18:04 +02:00
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-07 11:33:08 +01:00
|
|
|
} while (true);
|
2017-08-10 00:18:04 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readIncludeDirs(QXmlStreamReader &reader)
|
2009-07-04 00:38:47 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2009-07-04 00:38:47 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2009-07-04 00:38:47 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
|
|
|
// Read dir-elements
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::DirElementName) {
|
2009-07-04 00:38:47 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2019-08-09 21:15:02 +02:00
|
|
|
QString name = attribs.value(QString(), CppcheckXml::DirNameAttrib).toString();
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!name.isEmpty())
|
2009-07-04 00:38:47 +02:00
|
|
|
mIncludeDirs << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::IncludeDirElementName)
|
2009-07-04 00:38:47 +02:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2009-07-04 00:38:47 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2009-07-04 00:38:47 +02:00
|
|
|
}
|
2010-05-20 07:22:19 +02:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readDefines(QXmlStreamReader &reader)
|
2010-05-20 07:22:19 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2010-05-20 07:22:19 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2010-05-20 07:22:19 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read define-elements
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::DefineName) {
|
2010-05-20 07:22:19 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2019-08-09 21:15:02 +02:00
|
|
|
QString name = attribs.value(QString(), CppcheckXml::DefineNameAttrib).toString();
|
2010-05-20 07:22:19 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mDefines << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::DefinesElementName)
|
2010-05-20 07:22:19 +02:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2010-05-20 07:22:19 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2010-05-20 07:22:19 +02:00
|
|
|
}
|
2010-07-07 23:59:02 +02:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readCheckPaths(QXmlStreamReader &reader)
|
2010-08-14 17:42:37 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2010-08-14 17:42:37 +02:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2010-08-14 17:42:37 +02:00
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
|
|
|
// Read dir-elements
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::PathName) {
|
2010-08-14 17:42:37 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2019-08-09 21:15:02 +02:00
|
|
|
QString name = attribs.value(QString(), CppcheckXml::PathNameAttrib).toString();
|
2010-08-14 17:42:37 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mPaths << name;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::PathsElementName)
|
2010-08-14 17:42:37 +02:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2010-08-14 17:42:37 +02:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2010-08-14 17:42:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readExcludes(QXmlStreamReader &reader)
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
2011-10-13 20:53:06 +02:00
|
|
|
do {
|
2011-02-27 17:32:53 +01:00
|
|
|
type = reader.readNext();
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (type) {
|
2011-02-27 17:32:53 +01:00
|
|
|
case QXmlStreamReader::StartElement:
|
2011-08-23 18:54:53 +02:00
|
|
|
// Read exclude-elements
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::ExcludePathName) {
|
2011-08-23 18:54:53 +02:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2019-08-09 21:15:02 +02:00
|
|
|
QString name = attribs.value(QString(), CppcheckXml::ExcludePathNameAttrib).toString();
|
2011-08-23 18:54:53 +02:00
|
|
|
if (!name.isEmpty())
|
|
|
|
mExcludedPaths << name;
|
|
|
|
}
|
|
|
|
// Read ignore-elements - deprecated but support reading them
|
2019-08-09 21:15:02 +02:00
|
|
|
else if (reader.name().toString() == CppcheckXml::IgnorePathName) {
|
2011-02-27 17:32:53 +01:00
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
2019-08-09 21:15:02 +02:00
|
|
|
QString name = attribs.value(QString(), CppcheckXml::IgnorePathNameAttrib).toString();
|
2011-02-27 17:32:53 +01:00
|
|
|
if (!name.isEmpty())
|
2011-08-23 18:54:53 +02:00
|
|
|
mExcludedPaths << name;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::IgnoreElementName)
|
2011-02-27 17:32:53 +01:00
|
|
|
allRead = true;
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::ExcludeElementName)
|
2011-08-23 18:54:53 +02:00
|
|
|
allRead = true;
|
2011-02-27 17:32:53 +01:00
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2011-02-27 17:32:53 +01:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2011-10-13 20:53:06 +02:00
|
|
|
} while (!allRead);
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2020-01-31 07:08:38 +01:00
|
|
|
void ProjectFile::readVsConfigurations(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read library-elements
|
|
|
|
if (reader.name().toString() == CppcheckXml::VSConfigurationName) {
|
|
|
|
QString config;
|
|
|
|
type = reader.readNext();
|
|
|
|
if (type == QXmlStreamReader::Characters) {
|
|
|
|
config = reader.text().toString();
|
|
|
|
}
|
|
|
|
mVsConfigurations << config;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() != CppcheckXml::VSConfigurationName)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
void ProjectFile::readPlatform(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
mPlatform = reader.text().toString();
|
2021-01-21 18:13:32 +01:00
|
|
|
FALLTHROUGH;
|
2018-03-13 13:07:10 +01:00
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
return;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-07 11:33:08 +01:00
|
|
|
} while (true);
|
2018-03-13 13:07:10 +01:00
|
|
|
}
|
|
|
|
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2018-04-09 06:43:48 +02:00
|
|
|
void ProjectFile::readSuppressions(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read library-elements
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() == CppcheckXml::SuppressionElementName) {
|
2018-04-09 06:43:48 +02:00
|
|
|
Suppressions::Suppression suppression;
|
|
|
|
if (reader.attributes().hasAttribute(QString(),"fileName"))
|
|
|
|
suppression.fileName = reader.attributes().value(QString(),"fileName").toString().toStdString();
|
|
|
|
if (reader.attributes().hasAttribute(QString(),"lineNumber"))
|
|
|
|
suppression.lineNumber = reader.attributes().value(QString(),"lineNumber").toInt();
|
|
|
|
if (reader.attributes().hasAttribute(QString(),"symbolName"))
|
|
|
|
suppression.symbolName = reader.attributes().value(QString(),"symbolName").toString().toStdString();
|
2020-07-21 11:27:03 +02:00
|
|
|
if (reader.attributes().hasAttribute(QString(),"hash"))
|
|
|
|
suppression.hash = reader.attributes().value(QString(),"hash").toULongLong();
|
2018-04-09 06:43:48 +02:00
|
|
|
type = reader.readNext();
|
|
|
|
if (type == QXmlStreamReader::Characters) {
|
|
|
|
suppression.errorId = reader.text().toString().toStdString();
|
|
|
|
}
|
|
|
|
mSuppressions << suppression;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (reader.name().toString() != CppcheckXml::SuppressionElementName)
|
2018-04-09 06:43:48 +02:00
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-17 12:25:06 +02:00
|
|
|
void ProjectFile::readTagWarnings(QXmlStreamReader &reader, const QString &tag)
|
2020-07-16 23:03:54 +02:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read library-elements
|
|
|
|
if (reader.name().toString() == CppcheckXml::WarningElementName) {
|
2020-07-21 11:27:03 +02:00
|
|
|
std::size_t hash = reader.attributes().value(QString(), CppcheckXml::HashAttributeName).toULongLong();
|
|
|
|
mWarningTags[hash] = tag;
|
2020-07-16 23:03:54 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() != CppcheckXml::WarningElementName)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::readStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[])
|
2013-12-29 18:06:31 +01:00
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
// Read library-elements
|
2013-12-30 22:32:50 +01:00
|
|
|
if (reader.name().toString() == elementname) {
|
2013-12-29 18:06:31 +01:00
|
|
|
type = reader.readNext();
|
|
|
|
if (type == QXmlStreamReader::Characters) {
|
2013-12-30 22:32:50 +01:00
|
|
|
QString text = reader.text().toString();
|
|
|
|
stringlist << text;
|
2013-12-29 18:06:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2013-12-30 22:32:50 +01:00
|
|
|
if (reader.name().toString() != elementname)
|
2013-12-29 18:06:31 +01:00
|
|
|
allRead = true;
|
|
|
|
break;
|
|
|
|
|
2015-12-17 15:40:54 +01:00
|
|
|
// Not handled
|
2013-12-29 18:06:31 +01:00
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!allRead);
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setIncludes(const QStringList &includes)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
|
|
|
mIncludeDirs = includes;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setDefines(const QStringList &defines)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
|
|
|
mDefines = defines;
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:05:05 +02:00
|
|
|
void ProjectFile::setUndefines(const QStringList &undefines)
|
|
|
|
{
|
|
|
|
mUndefines = undefines;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setCheckPaths(const QStringList &paths)
|
2010-08-14 17:42:37 +02:00
|
|
|
{
|
|
|
|
mPaths = paths;
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setExcludedPaths(const QStringList &paths)
|
2011-02-27 17:32:53 +01:00
|
|
|
{
|
2011-08-23 18:54:53 +02:00
|
|
|
mExcludedPaths = paths;
|
2011-02-27 17:32:53 +01:00
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::setLibraries(const QStringList &libraries)
|
2013-12-29 18:06:31 +01:00
|
|
|
{
|
|
|
|
mLibraries = libraries;
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
void ProjectFile::setPlatform(const QString &platform)
|
|
|
|
{
|
|
|
|
mPlatform = platform;
|
|
|
|
}
|
|
|
|
|
2018-04-09 06:43:48 +02:00
|
|
|
void ProjectFile::setSuppressions(const QList<Suppressions::Suppression> &suppressions)
|
2013-12-30 22:32:50 +01:00
|
|
|
{
|
|
|
|
mSuppressions = suppressions;
|
|
|
|
}
|
|
|
|
|
2020-07-16 16:36:55 +02:00
|
|
|
void ProjectFile::addSuppression(const Suppressions::Suppression &suppression)
|
|
|
|
{
|
|
|
|
mSuppressions.append(suppression);
|
|
|
|
}
|
|
|
|
|
2017-08-03 12:30:28 +02:00
|
|
|
void ProjectFile::setAddons(const QStringList &addons)
|
|
|
|
{
|
|
|
|
mAddons = addons;
|
|
|
|
}
|
|
|
|
|
2020-01-31 07:08:38 +01:00
|
|
|
void ProjectFile::setVSConfigurations(const QStringList &vsConfigs)
|
|
|
|
{
|
|
|
|
mVsConfigurations = vsConfigs;
|
|
|
|
}
|
|
|
|
|
2022-01-18 20:17:05 +01:00
|
|
|
void ProjectFile::setWarningTags(std::size_t hash, const QString& tags)
|
2020-07-16 23:03:54 +02:00
|
|
|
{
|
2020-12-04 18:53:17 +01:00
|
|
|
if (tags.isEmpty())
|
2020-07-21 11:27:03 +02:00
|
|
|
mWarningTags.erase(hash);
|
|
|
|
else if (hash > 0)
|
2020-12-04 18:53:17 +01:00
|
|
|
mWarningTags[hash] = tags;
|
2020-07-16 23:03:54 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 11:27:03 +02:00
|
|
|
QString ProjectFile::getWarningTags(std::size_t hash) const
|
2020-07-16 23:03:54 +02:00
|
|
|
{
|
2020-07-21 11:27:03 +02:00
|
|
|
auto it = mWarningTags.find(hash);
|
2020-07-16 23:03:54 +02:00
|
|
|
return (it != mWarningTags.end()) ? it->second : QString();
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
bool ProjectFile::write(const QString &filename)
|
2010-07-07 23:59:02 +02:00
|
|
|
{
|
2010-07-08 15:16:25 +02:00
|
|
|
if (!filename.isEmpty())
|
|
|
|
mFilename = filename;
|
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
QFile file(mFilename);
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QXmlStreamWriter xmlWriter(&file);
|
|
|
|
xmlWriter.setAutoFormatting(true);
|
|
|
|
xmlWriter.writeStartDocument("1.0");
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::ProjectElementName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::ProjectVersionAttrib, CppcheckXml::ProjectFileVersion);
|
2010-07-07 23:59:02 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mRootPath.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::RootPathName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::RootPathNameAttrib, mRootPath);
|
2010-08-20 22:58:00 +02:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2016-11-19 20:38:50 +01:00
|
|
|
if (!mBuildDir.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::BuildDirElementName);
|
2016-11-19 20:38:50 +01:00
|
|
|
xmlWriter.writeCharacters(mBuildDir);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2018-03-13 13:07:10 +01:00
|
|
|
if (!mPlatform.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::PlatformElementName);
|
2018-03-13 13:07:10 +01:00
|
|
|
xmlWriter.writeCharacters(mPlatform);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2016-08-18 21:58:50 +02:00
|
|
|
if (!mImportProject.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::ImportProjectElementName);
|
2016-08-18 21:58:50 +02:00
|
|
|
xmlWriter.writeCharacters(mImportProject);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::AnalyzeAllVsConfigsElementName);
|
2017-08-10 00:18:04 +02:00
|
|
|
xmlWriter.writeCharacters(mAnalyzeAllVsConfigs ? "true" : "false");
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
|
2021-04-30 16:47:02 +02:00
|
|
|
if (clangParser) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::Parser);
|
|
|
|
xmlWriter.writeCharacters("clang");
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::CheckHeadersElementName);
|
2019-04-10 16:49:24 +02:00
|
|
|
xmlWriter.writeCharacters(mCheckHeaders ? "true" : "false");
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::CheckUnusedTemplatesElementName);
|
2019-04-10 16:49:24 +02:00
|
|
|
xmlWriter.writeCharacters(mCheckUnusedTemplates ? "true" : "false");
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::MaxCtuDepthElementName);
|
2019-04-10 16:49:24 +02:00
|
|
|
xmlWriter.writeCharacters(QString::number(mMaxCtuDepth));
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
|
2020-06-26 17:12:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::MaxTemplateRecursionElementName);
|
|
|
|
xmlWriter.writeCharacters(QString::number(mMaxTemplateRecursion));
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mIncludeDirs.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::IncludeDirElementName);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& incdir : mIncludeDirs) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::DirElementName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::DirNameAttrib, incdir);
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mDefines.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::DefinesElementName);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& define : mDefines) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::DefineName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::DefineNameAttrib, define);
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2010-08-14 17:42:37 +02:00
|
|
|
|
2020-01-31 07:08:38 +01:00
|
|
|
if (!mVsConfigurations.isEmpty()) {
|
|
|
|
writeStringList(xmlWriter,
|
|
|
|
mVsConfigurations,
|
|
|
|
CppcheckXml::VSConfigurationElementName,
|
|
|
|
CppcheckXml::VSConfigurationName);
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:05:05 +02:00
|
|
|
writeStringList(xmlWriter,
|
|
|
|
mUndefines,
|
2019-08-09 21:15:02 +02:00
|
|
|
CppcheckXml::UndefinesElementName,
|
|
|
|
CppcheckXml::UndefineName);
|
2018-10-09 15:05:05 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mPaths.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::PathsElementName);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& path : mPaths) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::PathName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::PathNameAttrib, path);
|
2010-08-14 17:42:37 +02:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!mExcludedPaths.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::ExcludeElementName);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& path : mExcludedPaths) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::ExcludePathName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::ExcludePathNameAttrib, path);
|
2011-02-28 15:08:14 +01:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
writeStringList(xmlWriter,
|
2013-12-30 22:32:50 +01:00
|
|
|
mLibraries,
|
2019-08-09 21:15:02 +02:00
|
|
|
CppcheckXml::LibrariesElementName,
|
|
|
|
CppcheckXml::LibraryElementName);
|
2013-12-30 22:32:50 +01:00
|
|
|
|
2018-04-09 06:43:48 +02:00
|
|
|
if (!mSuppressions.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::SuppressionsElementName);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const Suppressions::Suppression &suppression : mSuppressions) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::SuppressionElementName);
|
2018-04-09 06:43:48 +02:00
|
|
|
if (!suppression.fileName.empty())
|
|
|
|
xmlWriter.writeAttribute("fileName", QString::fromStdString(suppression.fileName));
|
|
|
|
if (suppression.lineNumber > 0)
|
|
|
|
xmlWriter.writeAttribute("lineNumber", QString::number(suppression.lineNumber));
|
|
|
|
if (!suppression.symbolName.empty())
|
|
|
|
xmlWriter.writeAttribute("symbolName", QString::fromStdString(suppression.symbolName));
|
2020-07-21 11:27:03 +02:00
|
|
|
if (suppression.hash > 0)
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::HashAttributeName, QString::number(suppression.hash));
|
2018-04-09 06:43:48 +02:00
|
|
|
if (!suppression.errorId.empty())
|
|
|
|
xmlWriter.writeCharacters(QString::fromStdString(suppression.errorId));
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2013-12-29 18:06:31 +01:00
|
|
|
|
2019-07-11 21:05:52 +02:00
|
|
|
writeStringList(xmlWriter,
|
|
|
|
mCheckUnknownFunctionReturn,
|
2019-08-09 21:15:02 +02:00
|
|
|
CppcheckXml::CheckUnknownFunctionReturn,
|
|
|
|
CppcheckXml::Name);
|
2019-07-11 21:05:52 +02:00
|
|
|
|
2020-02-09 21:02:28 +01:00
|
|
|
safeChecks.saveToXml(xmlWriter);
|
2019-07-11 21:05:52 +02:00
|
|
|
|
2017-08-03 12:30:28 +02:00
|
|
|
writeStringList(xmlWriter,
|
|
|
|
mAddons,
|
2019-08-09 21:15:02 +02:00
|
|
|
CppcheckXml::AddonsElementName,
|
|
|
|
CppcheckXml::AddonElementName);
|
2017-08-03 12:30:28 +02:00
|
|
|
|
2017-09-22 15:41:27 +02:00
|
|
|
QStringList tools;
|
2021-04-30 16:47:02 +02:00
|
|
|
if (mClangAnalyzer)
|
|
|
|
tools << CLANG_ANALYZER;
|
2017-09-22 15:41:27 +02:00
|
|
|
if (mClangTidy)
|
|
|
|
tools << CLANG_TIDY;
|
|
|
|
writeStringList(xmlWriter,
|
|
|
|
tools,
|
2019-08-09 21:15:02 +02:00
|
|
|
CppcheckXml::ToolsElementName,
|
|
|
|
CppcheckXml::ToolElementName);
|
2017-09-22 15:41:27 +02:00
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
writeStringList(xmlWriter, mTags, CppcheckXml::TagsElementName, CppcheckXml::TagElementName);
|
2020-07-16 23:03:54 +02:00
|
|
|
if (!mWarningTags.empty()) {
|
|
|
|
QStringList tags;
|
2020-09-21 19:41:28 +02:00
|
|
|
for (const auto& wt: mWarningTags) {
|
2020-07-16 23:03:54 +02:00
|
|
|
if (!tags.contains(wt.second))
|
|
|
|
tags.append(wt.second);
|
|
|
|
}
|
|
|
|
for (const QString &tag: tags) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::TagWarningsElementName);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::TagAttributeName, tag);
|
2020-09-21 19:41:28 +02:00
|
|
|
for (const auto& wt: mWarningTags) {
|
2020-07-16 23:03:54 +02:00
|
|
|
if (wt.second == tag) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::WarningElementName);
|
2020-07-21 11:27:03 +02:00
|
|
|
xmlWriter.writeAttribute(CppcheckXml::HashAttributeName, QString::number(wt.first));
|
2020-07-16 23:03:54 +02:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 17:25:08 +02:00
|
|
|
|
2010-07-07 23:59:02 +02:00
|
|
|
xmlWriter.writeEndDocument();
|
|
|
|
file.close();
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-30 22:32:50 +01:00
|
|
|
|
2017-07-28 05:08:59 +02:00
|
|
|
void ProjectFile::writeStringList(QXmlStreamWriter &xmlWriter, const QStringList &stringlist, const char startelementname[], const char stringelementname[])
|
2013-12-30 22:32:50 +01:00
|
|
|
{
|
|
|
|
if (stringlist.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
xmlWriter.writeStartElement(startelementname);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& str : stringlist) {
|
2013-12-30 22:32:50 +01:00
|
|
|
xmlWriter.writeStartElement(stringelementname);
|
|
|
|
xmlWriter.writeCharacters(str);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2016-10-02 18:03:21 +02:00
|
|
|
|
|
|
|
QStringList ProjectFile::fromNativeSeparators(const QStringList &paths)
|
|
|
|
{
|
|
|
|
QStringList ret;
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &path : paths)
|
|
|
|
ret << QDir::fromNativeSeparators(path);
|
2016-10-02 18:03:21 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2017-09-22 15:41:27 +02:00
|
|
|
|
2017-09-22 18:57:53 +02:00
|
|
|
QStringList ProjectFile::getAddonsAndTools() const
|
|
|
|
{
|
|
|
|
QStringList ret(mAddons);
|
2021-04-30 16:47:02 +02:00
|
|
|
if (mClangAnalyzer)
|
|
|
|
ret << CLANG_ANALYZER;
|
2017-09-22 18:57:53 +02:00
|
|
|
if (mClangTidy)
|
|
|
|
ret << CLANG_TIDY;
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-23 11:54:38 +02:00
|
|
|
|
|
|
|
void ProjectFile::SafeChecks::loadFromXml(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
classes = externalFunctions = internalFunctions = externalVariables = false;
|
|
|
|
|
|
|
|
int level = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
const QXmlStreamReader::TokenType type = xmlReader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
++level;
|
2022-02-07 17:35:25 +01:00
|
|
|
if (xmlReader.name() == QString(Settings::SafeChecks::XmlClasses))
|
2019-07-23 11:54:38 +02:00
|
|
|
classes = true;
|
2022-02-07 17:35:25 +01:00
|
|
|
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlExternalFunctions))
|
2019-07-23 11:54:38 +02:00
|
|
|
externalFunctions = true;
|
2022-02-07 17:35:25 +01:00
|
|
|
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlInternalFunctions))
|
2019-07-23 11:54:38 +02:00
|
|
|
internalFunctions = true;
|
2022-02-07 17:35:25 +01:00
|
|
|
else if (xmlReader.name() == QString(Settings::SafeChecks::XmlExternalVariables))
|
2019-07-23 11:54:38 +02:00
|
|
|
externalVariables = true;
|
|
|
|
break;
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (level <= 0)
|
|
|
|
return;
|
|
|
|
level--;
|
|
|
|
break;
|
|
|
|
// Not handled
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-07 11:33:08 +01:00
|
|
|
} while (true);
|
2019-07-23 11:54:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProjectFile::SafeChecks::saveToXml(QXmlStreamWriter &xmlWriter) const
|
|
|
|
{
|
|
|
|
if (!classes && !externalFunctions && !internalFunctions && !externalVariables)
|
|
|
|
return;
|
|
|
|
xmlWriter.writeStartElement(Settings::SafeChecks::XmlRootName);
|
|
|
|
if (classes) {
|
|
|
|
xmlWriter.writeStartElement(Settings::SafeChecks::XmlClasses);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (externalFunctions) {
|
|
|
|
xmlWriter.writeStartElement(Settings::SafeChecks::XmlExternalFunctions);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (internalFunctions) {
|
|
|
|
xmlWriter.writeStartElement(Settings::SafeChecks::XmlInternalFunctions);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (externalVariables) {
|
|
|
|
xmlWriter.writeStartElement(Settings::SafeChecks::XmlExternalVariables);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2020-05-17 16:50:02 +02:00
|
|
|
|
2020-05-17 23:14:40 +02:00
|
|
|
QString ProjectFile::getAddonFilePath(QString filesDir, const QString &addon)
|
2020-05-17 16:50:02 +02:00
|
|
|
{
|
|
|
|
if (!filesDir.endsWith("/"))
|
|
|
|
filesDir += "/";
|
|
|
|
|
|
|
|
QStringList searchPaths;
|
2020-11-01 15:11:28 +01:00
|
|
|
searchPaths << filesDir << (filesDir + "addons/") << (filesDir + "../addons/")
|
|
|
|
#ifdef FILESDIR
|
2021-08-07 20:51:18 +02:00
|
|
|
<< (QLatin1String(FILESDIR) + "/addons/")
|
2020-11-01 15:11:28 +01:00
|
|
|
#endif
|
2021-08-07 20:51:18 +02:00
|
|
|
;
|
2020-05-17 16:50:02 +02:00
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString& path : searchPaths) {
|
2020-05-17 16:50:02 +02:00
|
|
|
QString f = path + addon + ".py";
|
|
|
|
if (QFile(f).exists())
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|