2009-06-22 10:57:17 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2020-05-10 11:16:32 +02:00
|
|
|
* Copyright (C) 2007-2020 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QXmlStreamReader>
|
2010-07-07 23:59:02 +02:00
|
|
|
#include <QXmlStreamWriter>
|
2009-06-22 10:57:17 +02:00
|
|
|
#include <QFile>
|
2011-02-28 16:18:14 +01:00
|
|
|
#include <QDir>
|
2009-06-22 10:57:17 +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"
|
2009-06-22 10:57:17 +02:00
|
|
|
|
2019-07-23 11:54:38 +02:00
|
|
|
#include "settings.h"
|
2019-04-19 15:09:55 +02:00
|
|
|
|
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;
|
2020-02-02 10:45:42 +01:00
|
|
|
clangParser = false;
|
2020-02-04 21:20:43 +01:00
|
|
|
bugHunting = 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();
|
2020-04-27 09:08:50 +02:00
|
|
|
mFunctionContracts.clear();
|
2017-08-10 00:18:04 +02:00
|
|
|
mLibraries.clear();
|
2018-03-13 13:07:10 +01:00
|
|
|
mPlatform.clear();
|
2017-08-10 00:18:04 +02:00
|
|
|
mSuppressions.clear();
|
|
|
|
mAddons.clear();
|
2017-09-22 15:41:27 +02:00
|
|
|
mClangAnalyzer = mClangTidy = false;
|
2019-04-10 16:49:24 +02:00
|
|
|
mAnalyzeAllVsConfigs = false;
|
|
|
|
mCheckHeaders = true;
|
|
|
|
mCheckUnusedTemplates = false;
|
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();
|
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:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::PathsElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readCheckPaths(xmlReader);
|
2009-06-23 08:15:00 +02:00
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::ImportProjectElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readImportProject(xmlReader);
|
2016-08-18 21:58:50 +02:00
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::AnalyzeAllVsConfigsElementName)
|
2019-04-10 16:49:24 +02:00
|
|
|
mAnalyzeAllVsConfigs = readBool(xmlReader);
|
|
|
|
|
2020-02-02 10:45:42 +01:00
|
|
|
if (xmlReader.name() == CppcheckXml::Parser)
|
|
|
|
clangParser = true;
|
|
|
|
|
2020-02-04 21:20:43 +01:00
|
|
|
if (xmlReader.name() == CppcheckXml::BugHunting)
|
|
|
|
bugHunting = true;
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::CheckHeadersElementName)
|
2019-04-10 16:49:24 +02:00
|
|
|
mCheckHeaders = readBool(xmlReader);
|
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::UndefinesElementName)
|
|
|
|
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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::IgnoreElementName)
|
2017-07-28 05:08:59 +02:00
|
|
|
readExcludes(xmlReader);
|
2011-02-27 17:32:53 +01:00
|
|
|
|
2020-04-27 09:08:50 +02:00
|
|
|
// Function contracts
|
|
|
|
if (xmlReader.name() == CppcheckXml::FunctionContracts)
|
|
|
|
readFunctionContracts(xmlReader);
|
|
|
|
|
2013-12-30 22:32:50 +01:00
|
|
|
// Find libraries list from inside project element
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::LibrariesElementName)
|
|
|
|
readStringList(mLibraries, xmlReader, CppcheckXml::LibraryElementName);
|
2013-12-30 22:32:50 +01:00
|
|
|
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::CheckUnknownFunctionReturn)
|
|
|
|
readStringList(mCheckUnknownFunctionReturn, xmlReader, CppcheckXml::Name);
|
2019-07-11 21:05:52 +02:00
|
|
|
|
|
|
|
// check all function parameter values
|
2019-07-23 11:54:38 +02:00
|
|
|
if (xmlReader.name() == 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
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::AddonsElementName)
|
|
|
|
readStringList(mAddons, xmlReader, CppcheckXml::AddonElementName);
|
2017-08-03 12:30:28 +02:00
|
|
|
|
2017-09-22 15:41:27 +02:00
|
|
|
// Tools
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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);
|
2017-09-22 15:41:27 +02:00
|
|
|
mClangAnalyzer = tools.contains(CLANG_ANALYZER);
|
|
|
|
mClangTidy = tools.contains(CLANG_TIDY);
|
|
|
|
}
|
|
|
|
|
2019-09-20 15:06:37 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::TagsElementName)
|
2019-08-09 21:15:02 +02:00
|
|
|
readStringList(mTags, xmlReader, CppcheckXml::TagElementName);
|
2017-08-18 17:25:08 +02:00
|
|
|
|
2019-09-20 15:06:37 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::MaxCtuDepthElementName)
|
2019-04-10 16:49:24 +02:00
|
|
|
mMaxCtuDepth = readInt(xmlReader, mMaxCtuDepth);
|
|
|
|
|
2020-06-26 17:12:02 +02:00
|
|
|
if (xmlReader.name() == CppcheckXml::MaxTemplateRecursionElementName)
|
|
|
|
mMaxTemplateRecursion = readInt(xmlReader, mMaxTemplateRecursion);
|
|
|
|
|
2020-01-31 07:08:38 +01:00
|
|
|
// VSConfiguration
|
|
|
|
if (xmlReader.name() == CppcheckXml::VSConfigurationElementName)
|
|
|
|
readVsConfigurations(xmlReader);
|
2009-06-22 10:57:17 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
2019-08-09 21:15:02 +02:00
|
|
|
if (xmlReader.name() == 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();
|
|
|
|
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();
|
|
|
|
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");
|
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();
|
|
|
|
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-04-27 09:08:50 +02:00
|
|
|
void ProjectFile::readFunctionContracts(QXmlStreamReader &reader)
|
|
|
|
{
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
bool allRead = false;
|
|
|
|
do {
|
|
|
|
type = reader.readNext();
|
|
|
|
switch (type) {
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
if (reader.name().toString() == CppcheckXml::FunctionContract) {
|
|
|
|
QXmlStreamAttributes attribs = reader.attributes();
|
|
|
|
QString function = attribs.value(QString(), CppcheckXml::ContractFunction).toString();
|
|
|
|
QString expects = attribs.value(QString(), CppcheckXml::ContractExpects).toString();
|
|
|
|
if (!function.isEmpty() && !expects.isEmpty())
|
|
|
|
mFunctionContracts[function.toStdString()] = expects.toStdString();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
if (reader.name().toString() == CppcheckXml::FunctionContracts)
|
|
|
|
allRead = true;
|
|
|
|
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 (!allRead);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
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-15 13:03:07 +02:00
|
|
|
if (reader.attributes().hasAttribute(QString(),"cppcheck-id"))
|
|
|
|
suppression.cppcheckId = reader.attributes().value(QString(),"cppcheck-id").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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-27 09:08:50 +02:00
|
|
|
void ProjectFile::setFunctionContract(QString function, QString expects)
|
|
|
|
{
|
|
|
|
mFunctionContracts[function.toStdString()] = expects.toStdString();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2020-02-02 10:45:42 +01:00
|
|
|
if (clangParser) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::Parser);
|
|
|
|
xmlWriter.writeCharacters("clang");
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2020-02-04 21:20:43 +01:00
|
|
|
if (bugHunting) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::BugHunting);
|
|
|
|
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);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (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);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (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);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (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);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (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
|
|
|
|
2020-04-27 09:08:50 +02:00
|
|
|
if (!mFunctionContracts.empty()) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::FunctionContracts);
|
|
|
|
for (const auto contract: mFunctionContracts) {
|
|
|
|
xmlWriter.writeStartElement(CppcheckXml::FunctionContract);
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::ContractFunction, QString::fromStdString(contract.first));
|
|
|
|
xmlWriter.writeAttribute(CppcheckXml::ContractExpects, QString::fromStdString(contract.second));
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2018-04-09 06:43:48 +02:00
|
|
|
if (!mSuppressions.isEmpty()) {
|
2019-08-09 21:15:02 +02:00
|
|
|
xmlWriter.writeStartElement(CppcheckXml::SuppressionsElementName);
|
2018-04-09 06:43:48 +02:00
|
|
|
foreach (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-15 13:03:07 +02:00
|
|
|
if (suppression.cppcheckId > 0)
|
|
|
|
xmlWriter.writeAttribute("cppcheck-id", QString::number(suppression.cppcheckId));
|
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;
|
|
|
|
if (mClangAnalyzer)
|
|
|
|
tools << CLANG_ANALYZER;
|
|
|
|
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);
|
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);
|
2015-12-17 15:40:54 +01:00
|
|
|
foreach (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;
|
|
|
|
foreach (const QString &path, paths)
|
|
|
|
ret << QDir::fromNativeSeparators(path);
|
|
|
|
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);
|
|
|
|
if (mClangAnalyzer)
|
|
|
|
ret << CLANG_ANALYZER;
|
|
|
|
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;
|
|
|
|
if (xmlReader.name() == Settings::SafeChecks::XmlClasses)
|
|
|
|
classes = true;
|
|
|
|
else if (xmlReader.name() == Settings::SafeChecks::XmlExternalFunctions)
|
|
|
|
externalFunctions = true;
|
|
|
|
else if (xmlReader.name() == Settings::SafeChecks::XmlInternalFunctions)
|
|
|
|
internalFunctions = true;
|
|
|
|
else if (xmlReader.name() == Settings::SafeChecks::XmlExternalVariables)
|
|
|
|
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;
|
|
|
|
searchPaths << filesDir << (filesDir + "addons/") << (filesDir + "../addons/");
|
|
|
|
|
|
|
|
foreach (QString path, searchPaths) {
|
|
|
|
QString f = path + addon + ".py";
|
|
|
|
if (QFile(f).exists())
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2020-07-15 13:03:07 +02:00
|
|
|
void ProjectFile::suppressCppcheckId(std::size_t cppcheckId)
|
|
|
|
{
|
|
|
|
if (cppcheckId > 0) {
|
|
|
|
Suppressions::Suppression s;
|
|
|
|
s.cppcheckId = cppcheckId;
|
|
|
|
mSuppressions.append(s);
|
|
|
|
write();
|
|
|
|
}
|
|
|
|
}
|