2015-08-23 16:03:24 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-01-28 10:16:34 +01:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2015-08-23 16:03:24 +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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-08-30 13:41:57 +02:00
|
|
|
#include "cppchecklibrarydata.h"
|
2015-08-23 16:03:24 +02:00
|
|
|
|
2023-09-11 11:34:22 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
2020-05-24 09:16:02 +02:00
|
|
|
#include <stdexcept>
|
2022-09-16 07:15:49 +02:00
|
|
|
#include <string>
|
2020-05-24 09:16:02 +02:00
|
|
|
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QObject>
|
2021-02-09 13:53:32 +01:00
|
|
|
#include <QVariant>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QXmlStreamAttributes>
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include <QtGlobal>
|
|
|
|
|
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
|
|
|
#include <QStringRef>
|
|
|
|
#endif
|
2015-08-23 16:03:24 +02:00
|
|
|
|
2015-08-30 13:41:57 +02:00
|
|
|
const unsigned int CppcheckLibraryData::Function::Arg::ANY = ~0U;
|
2017-11-12 15:07:11 +01:00
|
|
|
const unsigned int CppcheckLibraryData::Function::Arg::VARIADIC = ~1U;
|
2015-08-23 16:03:24 +02:00
|
|
|
|
2017-11-12 21:03:22 +01:00
|
|
|
static std::string unhandledElement(const QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
throw std::runtime_error(QObject::tr("line %1: Unhandled element %2").arg(xmlReader.lineNumber()).arg(xmlReader.name().toString()).toStdString());
|
|
|
|
}
|
|
|
|
|
2022-05-08 20:42:06 +02:00
|
|
|
static std::string mandatoryAttibuteMissing(const QXmlStreamReader &xmlReader, const QString& attributeName)
|
2021-01-11 18:48:56 +01:00
|
|
|
{
|
|
|
|
throw std::runtime_error(QObject::tr("line %1: Mandatory attribute '%2' missing in '%3'")
|
|
|
|
.arg(xmlReader.lineNumber())
|
|
|
|
.arg(attributeName)
|
|
|
|
.arg(xmlReader.name().toString()).toStdString());
|
|
|
|
}
|
|
|
|
|
2015-09-05 20:13:26 +02:00
|
|
|
static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
CppcheckLibraryData::Container container;
|
2017-11-12 15:07:11 +01:00
|
|
|
container.id = xmlReader.attributes().value("id").toString();
|
|
|
|
container.inherits = xmlReader.attributes().value("inherits").toString();
|
|
|
|
container.startPattern = xmlReader.attributes().value("startPattern").toString();
|
|
|
|
container.endPattern = xmlReader.attributes().value("endPattern").toString();
|
|
|
|
container.opLessAllowed = xmlReader.attributes().value("opLessAllowed").toString();
|
|
|
|
container.itEndPattern = xmlReader.attributes().value("itEndPattern").toString();
|
2015-09-05 20:13:26 +02:00
|
|
|
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "container") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "type") {
|
|
|
|
container.type.templateParameter = xmlReader.attributes().value("templateParameter").toString();
|
|
|
|
container.type.string = xmlReader.attributes().value("string").toString();
|
2022-07-04 22:23:20 +02:00
|
|
|
} else if (elementName == "size" || elementName == "access" || elementName == "other" || elementName == "rangeItemRecordType") {
|
2015-09-05 20:13:26 +02:00
|
|
|
const QString indexOperator = xmlReader.attributes().value("indexOperator").toString();
|
|
|
|
if (elementName == "access" && indexOperator == "array-like")
|
|
|
|
container.access_arrayLike = true;
|
|
|
|
const QString templateParameter = xmlReader.attributes().value("templateParameter").toString();
|
|
|
|
if (elementName == "size" && !templateParameter.isEmpty())
|
|
|
|
container.size_templateParameter = templateParameter.toInt();
|
|
|
|
for (;;) {
|
|
|
|
type = xmlReader.readNext();
|
|
|
|
if (xmlReader.name().toString() == elementName)
|
|
|
|
break;
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
2023-10-08 09:10:17 +02:00
|
|
|
CppcheckLibraryData::Container::Function function;
|
2015-09-05 20:13:26 +02:00
|
|
|
function.name = xmlReader.attributes().value("name").toString();
|
|
|
|
function.action = xmlReader.attributes().value("action").toString();
|
|
|
|
function.yields = xmlReader.attributes().value("yields").toString();
|
|
|
|
if (elementName == "size")
|
|
|
|
container.sizeFunctions.append(function);
|
|
|
|
else if (elementName == "access")
|
|
|
|
container.accessFunctions.append(function);
|
2022-07-04 22:23:20 +02:00
|
|
|
else if (elementName == "rangeItemRecordType") {
|
2023-10-08 09:10:17 +02:00
|
|
|
CppcheckLibraryData::Container::RangeItemRecordType rangeItemRecordType;
|
2022-07-04 22:23:20 +02:00
|
|
|
rangeItemRecordType.name = xmlReader.attributes().value("name").toString();
|
|
|
|
rangeItemRecordType.templateParameter = xmlReader.attributes().value("templateParameter").toString();
|
|
|
|
container.rangeItemRecordTypeList.append(rangeItemRecordType);
|
|
|
|
} else
|
2015-09-05 20:13:26 +02:00
|
|
|
container.otherFunctions.append(function);
|
2017-11-12 15:07:11 +01:00
|
|
|
}
|
|
|
|
} else {
|
2017-11-12 21:03:22 +01:00
|
|
|
unhandledElement(xmlReader);
|
2015-09-05 20:13:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return container;
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
static CppcheckLibraryData::Define loadDefine(const QXmlStreamReader &xmlReader)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::Define define;
|
2015-09-05 11:37:55 +02:00
|
|
|
define.name = xmlReader.attributes().value("name").toString();
|
|
|
|
define.value = xmlReader.attributes().value("value").toString();
|
2015-08-23 16:03:24 +02:00
|
|
|
return define;
|
|
|
|
}
|
|
|
|
|
2018-10-09 15:05:05 +02:00
|
|
|
static QString loadUndefine(const QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
return xmlReader.attributes().value("name").toString();
|
|
|
|
}
|
|
|
|
|
2022-07-04 22:23:20 +02:00
|
|
|
static CppcheckLibraryData::SmartPointer loadSmartPointer(QXmlStreamReader &xmlReader)
|
2021-01-18 19:10:53 +01:00
|
|
|
{
|
2022-07-04 22:23:20 +02:00
|
|
|
CppcheckLibraryData::SmartPointer smartPointer;
|
|
|
|
smartPointer.name = xmlReader.attributes().value("class-name").toString();
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "smart-pointer") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "unique") {
|
|
|
|
smartPointer.unique = true;
|
|
|
|
} else {
|
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return smartPointer;
|
2021-01-18 19:10:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static CppcheckLibraryData::TypeChecks loadTypeChecks(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
CppcheckLibraryData::TypeChecks typeChecks;
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "type-checks") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "suppress" || elementName == "check") {
|
|
|
|
QPair<QString, QString> entry(elementName, xmlReader.readElementText());
|
|
|
|
typeChecks.append(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return typeChecks;
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
static CppcheckLibraryData::Function::Arg loadFunctionArg(QXmlStreamReader &xmlReader)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::Function::Arg arg;
|
2015-09-05 11:37:55 +02:00
|
|
|
QString argnr = xmlReader.attributes().value("nr").toString();
|
|
|
|
if (argnr == "any")
|
2015-08-30 13:41:57 +02:00
|
|
|
arg.nr = CppcheckLibraryData::Function::Arg::ANY;
|
2017-11-12 15:07:11 +01:00
|
|
|
else if (argnr == "variadic")
|
|
|
|
arg.nr = CppcheckLibraryData::Function::Arg::VARIADIC;
|
2015-08-23 16:03:24 +02:00
|
|
|
else
|
2015-09-05 11:37:55 +02:00
|
|
|
arg.nr = argnr.toUInt();
|
2017-11-12 15:07:11 +01:00
|
|
|
arg.defaultValue = xmlReader.attributes().value("default").toString();
|
2015-09-05 11:37:55 +02:00
|
|
|
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "arg") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "not-bool")
|
2015-08-23 16:03:24 +02:00
|
|
|
arg.notbool = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "not-null")
|
2015-08-23 16:03:24 +02:00
|
|
|
arg.notnull = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "not-uninit")
|
2015-08-23 16:03:24 +02:00
|
|
|
arg.notuninit = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "strz")
|
2015-08-23 16:03:24 +02:00
|
|
|
arg.strz = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "formatstr")
|
2015-08-23 16:03:24 +02:00
|
|
|
arg.formatstr = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "valid")
|
|
|
|
arg.valid = xmlReader.readElementText();
|
|
|
|
else if (elementName == "minsize") {
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::Function::Arg::MinSize minsize;
|
2015-09-05 11:37:55 +02:00
|
|
|
minsize.type = xmlReader.attributes().value("type").toString();
|
|
|
|
minsize.arg = xmlReader.attributes().value("arg").toString();
|
|
|
|
minsize.arg2 = xmlReader.attributes().value("arg2").toString();
|
2015-08-30 13:33:43 +02:00
|
|
|
arg.minsizes.append(minsize);
|
2017-11-12 15:07:11 +01:00
|
|
|
} else if (elementName == "iterator") {
|
|
|
|
arg.iterator.container = xmlReader.attributes().value("container").toInt();
|
|
|
|
arg.iterator.type = xmlReader.attributes().value("type").toString();
|
|
|
|
} else {
|
2017-11-12 21:03:22 +01:00
|
|
|
unhandledElement(xmlReader);
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
2018-06-23 23:04:54 +02:00
|
|
|
static CppcheckLibraryData::Function loadFunction(QXmlStreamReader &xmlReader, const QString &comments)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::Function function;
|
2015-08-29 18:07:59 +02:00
|
|
|
function.comments = comments;
|
2015-09-05 11:37:55 +02:00
|
|
|
function.name = xmlReader.attributes().value("name").toString();
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "function") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "noreturn")
|
|
|
|
function.noreturn = (xmlReader.readElementText() == "true") ? CppcheckLibraryData::Function::True : CppcheckLibraryData::Function::False;
|
|
|
|
else if (elementName == "pure")
|
2015-08-23 16:03:24 +02:00
|
|
|
function.gccPure = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "const")
|
2015-08-23 16:03:24 +02:00
|
|
|
function.gccConst = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "leak-ignore")
|
2015-08-23 16:03:24 +02:00
|
|
|
function.leakignore = true;
|
2015-09-05 11:37:55 +02:00
|
|
|
else if (elementName == "use-retval")
|
2015-08-23 16:03:24 +02:00
|
|
|
function.useretval = true;
|
2017-11-12 15:07:11 +01:00
|
|
|
else if (elementName == "returnValue") {
|
|
|
|
const QString container = xmlReader.attributes().value("container").toString();
|
|
|
|
function.returnValue.container = container.isNull() ? -1 : container.toInt();
|
|
|
|
function.returnValue.type = xmlReader.attributes().value("type").toString();
|
|
|
|
function.returnValue.value = xmlReader.readElementText();
|
|
|
|
} else if (elementName == "formatstr") {
|
2015-09-05 11:37:55 +02:00
|
|
|
function.formatstr.scan = xmlReader.attributes().value("scan").toString();
|
|
|
|
function.formatstr.secure = xmlReader.attributes().value("secure").toString();
|
|
|
|
} else if (elementName == "arg")
|
|
|
|
function.args.append(loadFunctionArg(xmlReader));
|
2015-11-22 11:45:29 +01:00
|
|
|
else if (elementName == "warn") {
|
|
|
|
function.warn.severity = xmlReader.attributes().value("severity").toString();
|
2017-11-12 15:07:11 +01:00
|
|
|
function.warn.cstd = xmlReader.attributes().value("cstd").toString();
|
2015-11-22 11:45:29 +01:00
|
|
|
function.warn.reason = xmlReader.attributes().value("reason").toString();
|
|
|
|
function.warn.alternatives = xmlReader.attributes().value("alternatives").toString();
|
|
|
|
function.warn.msg = xmlReader.readElementText();
|
2022-07-04 22:23:20 +02:00
|
|
|
} else if (elementName == "not-overlapping-data") {
|
|
|
|
const QStringList attributeList {"ptr1-arg", "ptr2-arg", "size-arg", "strlen-arg"};
|
|
|
|
for (const QString &attr : attributeList) {
|
|
|
|
if (xmlReader.attributes().hasAttribute(attr)) {
|
|
|
|
function.notOverlappingDataArgs[attr] = xmlReader.attributes().value(attr).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (elementName == "container") {
|
|
|
|
const QStringList attributeList {"action", "yields"};
|
|
|
|
for (const QString &attr : attributeList) {
|
|
|
|
if (xmlReader.attributes().hasAttribute(attr)) {
|
|
|
|
function.containerAttributes[attr] = xmlReader.attributes().value(attr).toString();
|
|
|
|
}
|
|
|
|
}
|
2017-11-12 15:07:11 +01:00
|
|
|
} else {
|
2017-11-12 21:03:22 +01:00
|
|
|
unhandledElement(xmlReader);
|
2015-11-22 11:45:29 +01:00
|
|
|
}
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
return function;
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
static CppcheckLibraryData::MemoryResource loadMemoryResource(QXmlStreamReader &xmlReader)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::MemoryResource memoryresource;
|
2015-09-05 11:37:55 +02:00
|
|
|
memoryresource.type = xmlReader.name().toString();
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != memoryresource.type) {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
2020-12-25 20:08:33 +01:00
|
|
|
if (elementName == "alloc" || elementName == "realloc") {
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::MemoryResource::Alloc alloc;
|
2020-12-25 20:08:33 +01:00
|
|
|
alloc.isRealloc = (elementName == "realloc");
|
2015-09-05 11:37:55 +02:00
|
|
|
alloc.init = (xmlReader.attributes().value("init").toString() == "true");
|
2020-12-25 20:08:33 +01:00
|
|
|
if (xmlReader.attributes().hasAttribute("arg")) {
|
|
|
|
alloc.arg = xmlReader.attributes().value("arg").toInt();
|
|
|
|
}
|
|
|
|
if (alloc.isRealloc && xmlReader.attributes().hasAttribute("realloc-arg")) {
|
|
|
|
alloc.reallocArg = xmlReader.attributes().value("realloc-arg").toInt();
|
|
|
|
}
|
|
|
|
if (memoryresource.type == "memory") {
|
|
|
|
alloc.bufferSize = xmlReader.attributes().value("buffer-size").toString();
|
|
|
|
}
|
2015-09-05 11:37:55 +02:00
|
|
|
alloc.name = xmlReader.readElementText();
|
2015-08-23 16:03:24 +02:00
|
|
|
memoryresource.alloc.append(alloc);
|
2020-12-25 20:08:33 +01:00
|
|
|
} else if (elementName == "dealloc") {
|
|
|
|
CppcheckLibraryData::MemoryResource::Dealloc dealloc;
|
|
|
|
if (xmlReader.attributes().hasAttribute("arg")) {
|
|
|
|
dealloc.arg = xmlReader.attributes().value("arg").toInt();
|
|
|
|
}
|
|
|
|
dealloc.name = xmlReader.readElementText();
|
|
|
|
memoryresource.dealloc.append(dealloc);
|
2020-12-25 20:13:29 +01:00
|
|
|
} else if (elementName == "use")
|
2015-09-05 11:37:55 +02:00
|
|
|
memoryresource.use.append(xmlReader.readElementText());
|
2017-11-12 15:07:11 +01:00
|
|
|
else
|
2017-11-12 21:03:22 +01:00
|
|
|
unhandledElement(xmlReader);
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
return memoryresource;
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
static CppcheckLibraryData::PodType loadPodType(const QXmlStreamReader &xmlReader)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-08-30 13:41:57 +02:00
|
|
|
CppcheckLibraryData::PodType podtype;
|
2015-09-05 11:37:55 +02:00
|
|
|
podtype.name = xmlReader.attributes().value("name").toString();
|
2021-01-11 18:48:56 +01:00
|
|
|
if (podtype.name.isEmpty()) {
|
|
|
|
mandatoryAttibuteMissing(xmlReader, "name");
|
|
|
|
}
|
2021-01-09 21:30:29 +01:00
|
|
|
podtype.stdtype = xmlReader.attributes().value("stdtype").toString();
|
2015-09-05 11:37:55 +02:00
|
|
|
podtype.size = xmlReader.attributes().value("size").toString();
|
|
|
|
podtype.sign = xmlReader.attributes().value("sign").toString();
|
2015-08-23 16:03:24 +02:00
|
|
|
return podtype;
|
|
|
|
}
|
|
|
|
|
2021-01-29 14:54:19 +01:00
|
|
|
static CppcheckLibraryData::PlatformType loadPlatformType(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
CppcheckLibraryData::PlatformType platformType;
|
|
|
|
platformType.name = xmlReader.attributes().value("name").toString();
|
|
|
|
platformType.value = xmlReader.attributes().value("value").toString();
|
|
|
|
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "platformtype") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (QStringList({"unsigned", "long", "pointer", "const_ptr", "ptr_ptr"}).contains(elementName)) {
|
|
|
|
platformType.types.append(elementName);
|
|
|
|
} else if (elementName == "platform") {
|
|
|
|
platformType.platforms.append(xmlReader.attributes().value("type").toString());
|
|
|
|
} else {
|
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return platformType;
|
|
|
|
}
|
|
|
|
|
2021-02-03 12:52:52 +01:00
|
|
|
static CppcheckLibraryData::Reflection loadReflection(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
CppcheckLibraryData::Reflection reflection;
|
|
|
|
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "reflection") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "call") {
|
|
|
|
CppcheckLibraryData::Reflection::Call call;
|
|
|
|
if (xmlReader.attributes().hasAttribute("arg")) {
|
|
|
|
call.arg = xmlReader.attributes().value("arg").toInt();
|
|
|
|
} else {
|
|
|
|
mandatoryAttibuteMissing(xmlReader, "arg");
|
|
|
|
}
|
|
|
|
call.name = xmlReader.readElementText();
|
|
|
|
reflection.calls.append(call);
|
|
|
|
} else {
|
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reflection;
|
|
|
|
}
|
|
|
|
|
2021-02-09 13:53:32 +01:00
|
|
|
static CppcheckLibraryData::Markup loadMarkup(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
CppcheckLibraryData::Markup markup;
|
|
|
|
|
|
|
|
QXmlStreamReader::TokenType type;
|
|
|
|
if (xmlReader.attributes().hasAttribute("ext")) {
|
|
|
|
markup.ext = xmlReader.attributes().value("ext").toString();
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
mandatoryAttibuteMissing(xmlReader, "ext");
|
|
|
|
}
|
|
|
|
if (xmlReader.attributes().hasAttribute("aftercode")) {
|
2023-03-17 13:51:55 +01:00
|
|
|
markup.afterCode = (xmlReader.attributes().value("aftercode") == QString("true"));
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
mandatoryAttibuteMissing(xmlReader, "aftercode");
|
|
|
|
}
|
|
|
|
if (xmlReader.attributes().hasAttribute("reporterrors")) {
|
2023-03-17 13:51:55 +01:00
|
|
|
markup.reportErrors = (xmlReader.attributes().value("reporterrors") == QString("true"));
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
mandatoryAttibuteMissing(xmlReader, "reporterrors");
|
|
|
|
}
|
|
|
|
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "markup") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
const QString elementName = xmlReader.name().toString();
|
|
|
|
if (elementName == "keywords") {
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "keywords") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
if (xmlReader.name().toString() == "keyword") {
|
|
|
|
markup.keywords.append(xmlReader.attributes().value("name").toString());
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (elementName == "codeblocks") {
|
|
|
|
CppcheckLibraryData::Markup::CodeBlocks codeBlock;
|
|
|
|
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "codeblocks") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
if (xmlReader.name().toString() == "block") {
|
|
|
|
codeBlock.blocks.append(xmlReader.attributes().value("name").toString());
|
2021-02-10 11:42:00 +01:00
|
|
|
} else if (xmlReader.name().toString() == "structure") {
|
2021-02-09 13:53:32 +01:00
|
|
|
codeBlock.offset = xmlReader.attributes().value("offset").toInt();
|
|
|
|
codeBlock.start = xmlReader.attributes().value("start").toString();
|
|
|
|
codeBlock.end = xmlReader.attributes().value("end").toString();
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
markup.codeBlocks.append(codeBlock);
|
|
|
|
} else if (elementName == "exported") {
|
|
|
|
CppcheckLibraryData::Markup::Exporter exporter;
|
|
|
|
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "exported") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
if (xmlReader.name().toString() == "exporter") {
|
|
|
|
exporter.prefix = xmlReader.attributes().value("prefix").toString();
|
2021-02-10 11:42:00 +01:00
|
|
|
} else if (xmlReader.name().toString() == "prefix") {
|
2021-02-09 13:53:32 +01:00
|
|
|
exporter.prefixList.append(xmlReader.readElementText());
|
2021-02-10 11:42:00 +01:00
|
|
|
} else if (xmlReader.name().toString() == "suffix") {
|
2021-02-09 13:53:32 +01:00
|
|
|
exporter.suffixList.append(xmlReader.readElementText());
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
markup.exporter.append(exporter);
|
|
|
|
} else if (elementName == "imported") {
|
|
|
|
while ((type = xmlReader.readNext()) != QXmlStreamReader::EndElement ||
|
|
|
|
xmlReader.name().toString() != "imported") {
|
|
|
|
if (type != QXmlStreamReader::StartElement)
|
|
|
|
continue;
|
|
|
|
if (xmlReader.name().toString() == "importer") {
|
|
|
|
markup.importer.append(xmlReader.readElementText());
|
2021-02-10 11:42:00 +01:00
|
|
|
} else {
|
2021-02-09 13:53:32 +01:00
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unhandledElement(xmlReader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return markup;
|
|
|
|
}
|
|
|
|
|
2023-01-27 19:43:08 +01:00
|
|
|
static CppcheckLibraryData::Entrypoint loadEntrypoint(QXmlStreamReader &xmlReader)
|
|
|
|
{
|
|
|
|
CppcheckLibraryData::Entrypoint entrypoint;
|
|
|
|
entrypoint.name = xmlReader.attributes().value("name").toString();
|
|
|
|
return entrypoint;
|
|
|
|
}
|
|
|
|
|
2017-11-12 21:03:22 +01:00
|
|
|
QString CppcheckLibraryData::open(QIODevice &file)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-08-29 18:50:08 +02:00
|
|
|
clear();
|
2015-09-10 20:11:05 +02:00
|
|
|
QString comments;
|
2015-09-05 11:37:55 +02:00
|
|
|
QXmlStreamReader xmlReader(&file);
|
|
|
|
while (!xmlReader.atEnd()) {
|
|
|
|
const QXmlStreamReader::TokenType t = xmlReader.readNext();
|
|
|
|
switch (t) {
|
|
|
|
case QXmlStreamReader::Comment:
|
2015-09-10 20:11:05 +02:00
|
|
|
if (!comments.isEmpty())
|
|
|
|
comments += "\n";
|
|
|
|
comments += xmlReader.text().toString();
|
2015-09-05 11:37:55 +02:00
|
|
|
break;
|
|
|
|
case QXmlStreamReader::StartElement:
|
2017-11-12 15:07:11 +01:00
|
|
|
try {
|
|
|
|
const QString elementName(xmlReader.name().toString());
|
|
|
|
if (elementName == "def")
|
|
|
|
;
|
|
|
|
else if (elementName == "container")
|
|
|
|
containers.append(loadContainer(xmlReader));
|
|
|
|
else if (elementName == "define")
|
|
|
|
defines.append(loadDefine(xmlReader));
|
2018-10-09 15:05:05 +02:00
|
|
|
else if (elementName == "undefine")
|
|
|
|
undefines.append(loadUndefine(xmlReader));
|
2017-11-12 15:07:11 +01:00
|
|
|
else if (elementName == "function")
|
|
|
|
functions.append(loadFunction(xmlReader, comments));
|
|
|
|
else if (elementName == "memory" || elementName == "resource")
|
|
|
|
memoryresource.append(loadMemoryResource(xmlReader));
|
|
|
|
else if (elementName == "podtype")
|
|
|
|
podtypes.append(loadPodType(xmlReader));
|
2021-01-18 19:10:53 +01:00
|
|
|
else if (elementName == "smart-pointer")
|
|
|
|
smartPointers.append(loadSmartPointer(xmlReader));
|
|
|
|
else if (elementName == "type-checks")
|
|
|
|
typeChecks.append(loadTypeChecks(xmlReader));
|
2021-01-29 14:54:19 +01:00
|
|
|
else if (elementName == "platformtype")
|
|
|
|
platformTypes.append(loadPlatformType(xmlReader));
|
2021-02-03 12:52:52 +01:00
|
|
|
else if (elementName == "reflection")
|
|
|
|
reflections.append(loadReflection(xmlReader));
|
2021-02-09 13:53:32 +01:00
|
|
|
else if (elementName == "markup")
|
|
|
|
markups.append(loadMarkup(xmlReader));
|
2023-01-27 19:43:08 +01:00
|
|
|
else if (elementName == "entrypoint")
|
|
|
|
entrypoints.append(loadEntrypoint(xmlReader));
|
2017-11-12 15:07:11 +01:00
|
|
|
else
|
2017-11-12 21:03:22 +01:00
|
|
|
unhandledElement(xmlReader);
|
2017-11-12 15:07:11 +01:00
|
|
|
} catch (std::runtime_error &e) {
|
2017-11-12 21:03:22 +01:00
|
|
|
return e.what();
|
2017-11-12 15:07:11 +01:00
|
|
|
}
|
2015-08-29 18:07:59 +02:00
|
|
|
comments.clear();
|
2015-09-05 11:37:55 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2015-08-29 18:07:59 +02:00
|
|
|
}
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
2023-06-20 18:43:21 +02:00
|
|
|
if (xmlReader.hasError())
|
2021-01-10 12:10:30 +01:00
|
|
|
return xmlReader.errorString();
|
2023-06-20 18:43:21 +02:00
|
|
|
return QString();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2023-10-08 09:10:17 +02:00
|
|
|
static void writeContainerFunctions(QXmlStreamWriter &xmlWriter, const QString &name, int extra, const QList<CppcheckLibraryData::Container::Function> &functions)
|
2015-09-05 20:13:26 +02:00
|
|
|
{
|
2017-11-12 15:07:11 +01:00
|
|
|
if (functions.isEmpty() && extra < 0)
|
2015-09-05 20:13:26 +02:00
|
|
|
return;
|
|
|
|
xmlWriter.writeStartElement(name);
|
2017-11-12 15:07:11 +01:00
|
|
|
if (extra >= 0) {
|
2015-09-05 20:13:26 +02:00
|
|
|
if (name == "access")
|
|
|
|
xmlWriter.writeAttribute("indexOperator", "array-like");
|
|
|
|
else if (name == "size")
|
|
|
|
xmlWriter.writeAttribute("templateParameter", QString::number(extra));
|
|
|
|
}
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::Container::Function &function : functions) {
|
2015-09-05 20:13:26 +02:00
|
|
|
xmlWriter.writeStartElement("function");
|
|
|
|
xmlWriter.writeAttribute("name", function.name);
|
|
|
|
if (!function.action.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("action", function.action);
|
|
|
|
if (!function.yields.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("yields", function.yields);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2023-10-08 09:10:17 +02:00
|
|
|
static void writeContainerRangeItemRecords(QXmlStreamWriter &xmlWriter, const QList<CppcheckLibraryData::Container::RangeItemRecordType> &rangeItemRecords)
|
2022-07-04 22:23:20 +02:00
|
|
|
{
|
|
|
|
if (rangeItemRecords.isEmpty())
|
|
|
|
return;
|
|
|
|
xmlWriter.writeStartElement("rangeItemRecordType");
|
|
|
|
for (const CppcheckLibraryData::Container::RangeItemRecordType &item : rangeItemRecords) {
|
|
|
|
xmlWriter.writeStartElement("member");
|
|
|
|
xmlWriter.writeAttribute("name", item.name);
|
|
|
|
xmlWriter.writeAttribute("templateParameter", item.templateParameter);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2015-09-05 20:13:26 +02:00
|
|
|
static void writeContainer(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Container &container)
|
|
|
|
{
|
|
|
|
xmlWriter.writeStartElement("container");
|
|
|
|
xmlWriter.writeAttribute("id", container.id);
|
|
|
|
if (!container.startPattern.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("startPattern", container.startPattern);
|
2015-09-06 08:48:13 +02:00
|
|
|
if (!container.endPattern.isNull())
|
2015-09-05 20:13:26 +02:00
|
|
|
xmlWriter.writeAttribute("endPattern", container.endPattern);
|
|
|
|
if (!container.inherits.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("inherits", container.inherits);
|
2017-11-12 15:07:11 +01:00
|
|
|
if (!container.opLessAllowed.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("opLessAllowed", container.opLessAllowed);
|
|
|
|
if (!container.itEndPattern.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("itEndPattern", container.itEndPattern);
|
|
|
|
|
2015-09-05 20:13:26 +02:00
|
|
|
if (!container.type.templateParameter.isEmpty() || !container.type.string.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("type");
|
|
|
|
if (!container.type.templateParameter.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("templateParameter", container.type.templateParameter);
|
|
|
|
if (!container.type.string.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("string", container.type.string);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
writeContainerFunctions(xmlWriter, "size", container.size_templateParameter, container.sizeFunctions);
|
2017-11-12 15:07:11 +01:00
|
|
|
writeContainerFunctions(xmlWriter, "access", container.access_arrayLike?1:-1, container.accessFunctions);
|
|
|
|
writeContainerFunctions(xmlWriter, "other", -1, container.otherFunctions);
|
2022-07-04 22:23:20 +02:00
|
|
|
writeContainerRangeItemRecords(xmlWriter, container.rangeItemRecordTypeList);
|
2015-09-05 20:13:26 +02:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
static void writeFunction(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Function &function)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-09-10 20:11:05 +02:00
|
|
|
QString comments = function.comments;
|
|
|
|
while (comments.startsWith("\n"))
|
|
|
|
comments = comments.mid(1);
|
|
|
|
while (comments.endsWith("\n"))
|
|
|
|
comments.chop(1);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &comment : comments.split('\n')) {
|
2015-11-21 16:10:14 +01:00
|
|
|
if (comment.length() >= 1)
|
|
|
|
xmlWriter.writeComment(comment);
|
2015-09-05 11:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xmlWriter.writeStartElement("function");
|
|
|
|
xmlWriter.writeAttribute("name", function.name);
|
|
|
|
|
2015-08-23 16:03:24 +02:00
|
|
|
if (function.useretval)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("use-retval");
|
2015-08-29 18:07:59 +02:00
|
|
|
if (function.gccConst)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("const");
|
2015-08-29 18:07:59 +02:00
|
|
|
if (function.gccPure)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("pure");
|
2017-11-12 15:07:11 +01:00
|
|
|
if (!function.returnValue.empty()) {
|
|
|
|
xmlWriter.writeStartElement("returnValue");
|
|
|
|
if (!function.returnValue.type.isNull())
|
|
|
|
xmlWriter.writeAttribute("type", function.returnValue.type);
|
|
|
|
if (function.returnValue.container >= 0)
|
|
|
|
xmlWriter.writeAttribute("container", QString::number(function.returnValue.container));
|
|
|
|
if (!function.returnValue.value.isNull())
|
|
|
|
xmlWriter.writeCharacters(function.returnValue.value);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2017-11-12 15:15:54 +01:00
|
|
|
if (function.noreturn != CppcheckLibraryData::Function::Unknown)
|
2023-09-11 11:34:22 +02:00
|
|
|
xmlWriter.writeTextElement("noreturn", bool_to_string(function.noreturn == CppcheckLibraryData::Function::True));
|
2015-09-03 07:00:43 +02:00
|
|
|
if (function.leakignore)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("leak-ignore");
|
2015-08-23 16:03:24 +02:00
|
|
|
// Argument info..
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::Function::Arg &arg : function.args) {
|
2015-09-03 07:00:43 +02:00
|
|
|
if (arg.formatstr) {
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartElement("formatstr");
|
2015-09-03 07:00:43 +02:00
|
|
|
if (!function.formatstr.scan.isNull())
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeAttribute("scan", function.formatstr.scan);
|
2015-09-03 07:00:43 +02:00
|
|
|
if (!function.formatstr.secure.isNull())
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeAttribute("secure", function.formatstr.secure);
|
|
|
|
xmlWriter.writeEndElement();
|
2015-09-03 07:00:43 +02:00
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartElement("arg");
|
2015-08-30 13:41:57 +02:00
|
|
|
if (arg.nr == CppcheckLibraryData::Function::Arg::ANY)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeAttribute("nr", "any");
|
2017-11-12 15:07:11 +01:00
|
|
|
else if (arg.nr == CppcheckLibraryData::Function::Arg::VARIADIC)
|
|
|
|
xmlWriter.writeAttribute("nr", "variadic");
|
2015-08-23 16:03:24 +02:00
|
|
|
else
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeAttribute("nr", QString::number(arg.nr));
|
2017-11-12 15:07:11 +01:00
|
|
|
if (!arg.defaultValue.isNull())
|
|
|
|
xmlWriter.writeAttribute("default", arg.defaultValue);
|
2015-09-03 07:00:43 +02:00
|
|
|
if (arg.formatstr)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("formatstr");
|
2015-08-23 16:03:24 +02:00
|
|
|
if (arg.notnull)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("not-null");
|
2015-08-23 16:03:24 +02:00
|
|
|
if (arg.notuninit)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("not-uninit");
|
2015-09-03 07:00:43 +02:00
|
|
|
if (arg.notbool)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("not-bool");
|
2015-08-23 16:03:24 +02:00
|
|
|
if (arg.strz)
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEmptyElement("strz");
|
|
|
|
|
|
|
|
if (!arg.valid.isEmpty())
|
|
|
|
xmlWriter.writeTextElement("valid",arg.valid);
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::Function::Arg::MinSize &minsize : arg.minsizes) {
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartElement("minsize");
|
|
|
|
xmlWriter.writeAttribute("type", minsize.type);
|
|
|
|
xmlWriter.writeAttribute("arg", minsize.arg);
|
|
|
|
if (!minsize.arg2.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("arg2", minsize.arg2);
|
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2017-11-12 15:07:11 +01:00
|
|
|
if (arg.iterator.container >= 0 || !arg.iterator.type.isNull()) {
|
|
|
|
xmlWriter.writeStartElement("iterator");
|
|
|
|
if (arg.iterator.container >= 0)
|
|
|
|
xmlWriter.writeAttribute("container", QString::number(arg.iterator.container));
|
|
|
|
if (!arg.iterator.type.isNull())
|
|
|
|
xmlWriter.writeAttribute("type", arg.iterator.type);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
2015-11-22 11:45:29 +01:00
|
|
|
|
|
|
|
if (!function.warn.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("warn");
|
|
|
|
|
|
|
|
if (!function.warn.severity.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("severity", function.warn.severity);
|
|
|
|
|
2017-11-12 15:07:11 +01:00
|
|
|
if (!function.warn.cstd.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("cstd", function.warn.cstd);
|
2015-11-22 11:45:29 +01:00
|
|
|
|
|
|
|
if (!function.warn.alternatives.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("alternatives", function.warn.alternatives);
|
|
|
|
|
2017-11-12 15:07:11 +01:00
|
|
|
if (!function.warn.reason.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("reason", function.warn.reason);
|
|
|
|
|
2015-11-22 11:45:29 +01:00
|
|
|
if (!function.warn.msg.isEmpty())
|
|
|
|
xmlWriter.writeCharacters(function.warn.msg);
|
|
|
|
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2022-07-04 22:23:20 +02:00
|
|
|
if (!function.notOverlappingDataArgs.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("not-overlapping-data");
|
|
|
|
foreach (const QString value, function.notOverlappingDataArgs) {
|
|
|
|
xmlWriter.writeAttribute(function.notOverlappingDataArgs.key(value), value);
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (!function.containerAttributes.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("container");
|
|
|
|
foreach (const QString value, function.containerAttributes) {
|
|
|
|
xmlWriter.writeAttribute(function.containerAttributes.key(value), value);
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
static void writeMemoryResource(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::MemoryResource &mr)
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartElement(mr.type);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::MemoryResource::Alloc &alloc : mr.alloc) {
|
2020-12-25 20:08:33 +01:00
|
|
|
if (alloc.isRealloc) {
|
|
|
|
xmlWriter.writeStartElement("realloc");
|
|
|
|
} else {
|
2020-12-25 20:13:29 +01:00
|
|
|
xmlWriter.writeStartElement("alloc");
|
2020-12-25 20:08:33 +01:00
|
|
|
}
|
2023-09-11 11:34:22 +02:00
|
|
|
xmlWriter.writeAttribute("init", bool_to_string(alloc.init));
|
2020-12-25 20:08:33 +01:00
|
|
|
if (alloc.arg != -1) {
|
|
|
|
xmlWriter.writeAttribute("arg", QString("%1").arg(alloc.arg));
|
|
|
|
}
|
|
|
|
if (alloc.isRealloc && alloc.reallocArg != -1) {
|
|
|
|
xmlWriter.writeAttribute("realloc-arg", QString("%1").arg(alloc.reallocArg));
|
|
|
|
}
|
|
|
|
if (mr.type == "memory" && !alloc.bufferSize.isEmpty()) {
|
|
|
|
xmlWriter.writeAttribute("buffer-size", alloc.bufferSize);
|
|
|
|
}
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeCharacters(alloc.name);
|
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
2020-12-25 20:08:33 +01:00
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::MemoryResource::Dealloc &dealloc : mr.dealloc) {
|
2020-12-25 20:08:33 +01:00
|
|
|
xmlWriter.writeStartElement("dealloc");
|
|
|
|
if (dealloc.arg != -1) {
|
|
|
|
xmlWriter.writeAttribute("arg", QString("%1").arg(dealloc.arg));
|
2020-12-25 20:13:29 +01:00
|
|
|
}
|
2020-12-25 20:08:33 +01:00
|
|
|
xmlWriter.writeCharacters(dealloc.name);
|
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
2020-12-25 20:08:33 +01:00
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &use : mr.use) {
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeTextElement("use", use);
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2021-01-18 19:10:53 +01:00
|
|
|
static void writeTypeChecks(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::TypeChecks &typeChecks)
|
|
|
|
{
|
|
|
|
xmlWriter.writeStartElement("type-checks");
|
|
|
|
if (!typeChecks.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("unusedvar");
|
|
|
|
}
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QPair<QString, QString> &check : typeChecks) {
|
2021-01-18 19:10:53 +01:00
|
|
|
xmlWriter.writeStartElement(check.first);
|
|
|
|
xmlWriter.writeCharacters(check.second);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (!typeChecks.isEmpty()) {
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2021-01-30 17:52:41 +01:00
|
|
|
static void writePlatformType(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::PlatformType &pt)
|
2021-01-29 14:54:19 +01:00
|
|
|
{
|
|
|
|
xmlWriter.writeStartElement("platformtype");
|
|
|
|
xmlWriter.writeAttribute("name", pt.name);
|
|
|
|
xmlWriter.writeAttribute("value", pt.value);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &type : pt.types) {
|
2021-01-29 14:54:19 +01:00
|
|
|
xmlWriter.writeStartElement(type);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &platform : pt.platforms) {
|
2021-01-29 14:54:19 +01:00
|
|
|
xmlWriter.writeStartElement("platform");
|
|
|
|
if (!platform.isEmpty()) {
|
|
|
|
xmlWriter.writeAttribute("type", platform);
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2021-02-03 19:14:46 +01:00
|
|
|
static void writeReflection(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Reflection &refl)
|
2021-02-03 12:52:52 +01:00
|
|
|
{
|
|
|
|
xmlWriter.writeStartElement("reflection");
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::Reflection::Call &call : refl.calls) {
|
2021-02-03 12:52:52 +01:00
|
|
|
xmlWriter.writeStartElement("call");
|
|
|
|
xmlWriter.writeAttribute("arg", QString("%1").arg(call.arg));
|
|
|
|
xmlWriter.writeCharacters(call.name);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2021-02-09 13:53:32 +01:00
|
|
|
static void writeMarkup(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Markup &mup)
|
|
|
|
{
|
|
|
|
xmlWriter.writeStartElement("markup");
|
|
|
|
xmlWriter.writeAttribute("ext", mup.ext);
|
|
|
|
xmlWriter.writeAttribute("aftercode", QVariant(mup.afterCode).toString());
|
|
|
|
xmlWriter.writeAttribute("reporterrors", QVariant(mup.reportErrors).toString());
|
|
|
|
if (!mup.keywords.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("keywords");
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &keyword : mup.keywords) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("keyword");
|
|
|
|
xmlWriter.writeAttribute("name", keyword);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (!mup.importer.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("imported");
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &import : mup.importer) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("importer");
|
|
|
|
xmlWriter.writeCharacters(import);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
if (!mup.exporter.isEmpty()) {
|
|
|
|
xmlWriter.writeStartElement("exported");
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::Markup::Exporter &exporter : mup.exporter) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("exporter");
|
|
|
|
xmlWriter.writeAttribute("prefix", exporter.prefix);
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &prefix : exporter.prefixList) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("prefix");
|
|
|
|
xmlWriter.writeCharacters(prefix);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &suffix : exporter.suffixList) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("suffix");
|
|
|
|
xmlWriter.writeCharacters(suffix);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
2021-02-10 11:42:00 +01:00
|
|
|
if (!mup.codeBlocks.isEmpty()) {
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const CppcheckLibraryData::Markup::CodeBlocks &codeblock : mup.codeBlocks) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("codeblocks");
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &block : codeblock.blocks) {
|
2021-02-09 13:53:32 +01:00
|
|
|
xmlWriter.writeStartElement("block");
|
|
|
|
xmlWriter.writeAttribute("name", block);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
xmlWriter.writeStartElement("structure");
|
|
|
|
xmlWriter.writeAttribute("offset", QString("%1").arg(codeblock.offset));
|
|
|
|
xmlWriter.writeAttribute("start", codeblock.start);
|
|
|
|
xmlWriter.writeAttribute("end", codeblock.end);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2015-08-30 13:41:57 +02:00
|
|
|
QString CppcheckLibraryData::toString() const
|
2015-08-23 16:03:24 +02:00
|
|
|
{
|
2015-09-05 11:37:55 +02:00
|
|
|
QString outputString;
|
|
|
|
QXmlStreamWriter xmlWriter(&outputString);
|
|
|
|
xmlWriter.setAutoFormatting(true);
|
2015-09-06 09:10:45 +02:00
|
|
|
xmlWriter.setAutoFormattingIndent(2);
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartDocument("1.0");
|
|
|
|
xmlWriter.writeStartElement("def");
|
|
|
|
xmlWriter.writeAttribute("format","2");
|
2015-08-23 16:03:24 +02:00
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const Define &define : defines) {
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartElement("define");
|
|
|
|
xmlWriter.writeAttribute("name", define.name);
|
|
|
|
xmlWriter.writeAttribute("value", define.value);
|
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const QString &undef : undefines) {
|
2018-10-09 15:05:05 +02:00
|
|
|
xmlWriter.writeStartElement("undefine");
|
|
|
|
xmlWriter.writeAttribute("name", undef);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const Function &function : functions) {
|
2015-09-05 11:37:55 +02:00
|
|
|
writeFunction(xmlWriter, function);
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const MemoryResource &mr : memoryresource) {
|
2015-09-05 11:37:55 +02:00
|
|
|
writeMemoryResource(xmlWriter, mr);
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const Container &container : containers) {
|
2015-09-05 20:13:26 +02:00
|
|
|
writeContainer(xmlWriter, container);
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const PodType &podtype : podtypes) {
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeStartElement("podtype");
|
|
|
|
xmlWriter.writeAttribute("name", podtype.name);
|
2021-01-09 21:30:29 +01:00
|
|
|
if (!podtype.stdtype.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("stdtype", podtype.stdtype);
|
2015-09-03 07:00:43 +02:00
|
|
|
if (!podtype.sign.isEmpty())
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeAttribute("sign", podtype.sign);
|
2015-09-05 20:13:26 +02:00
|
|
|
if (!podtype.size.isEmpty())
|
|
|
|
xmlWriter.writeAttribute("size", podtype.size);
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const TypeChecks &check : typeChecks) {
|
2021-01-18 19:10:53 +01:00
|
|
|
writeTypeChecks(xmlWriter, check);
|
|
|
|
}
|
|
|
|
|
2022-07-04 22:23:20 +02:00
|
|
|
for (const SmartPointer &smartPtr : smartPointers) {
|
2021-01-18 19:10:53 +01:00
|
|
|
xmlWriter.writeStartElement("smart-pointer");
|
2022-07-04 22:23:20 +02:00
|
|
|
xmlWriter.writeAttribute("class-name", smartPtr.name);
|
|
|
|
if (smartPtr.unique) {
|
|
|
|
xmlWriter.writeEmptyElement("unique");
|
|
|
|
}
|
2021-01-18 19:10:53 +01:00
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const PlatformType &pt : platformTypes) {
|
2021-01-29 14:54:19 +01:00
|
|
|
writePlatformType(xmlWriter, pt);
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const Reflection &refl : reflections) {
|
2021-02-03 12:52:52 +01:00
|
|
|
writeReflection(xmlWriter, refl);
|
|
|
|
}
|
|
|
|
|
2022-03-21 17:14:26 +01:00
|
|
|
for (const Markup &mup : markups) {
|
2021-02-09 13:53:32 +01:00
|
|
|
writeMarkup(xmlWriter, mup);
|
|
|
|
}
|
|
|
|
|
2023-01-27 19:43:08 +01:00
|
|
|
for (const Entrypoint &ent : entrypoints) {
|
|
|
|
xmlWriter.writeStartElement("entrypoint");
|
|
|
|
xmlWriter.writeAttribute("name", ent.name);
|
|
|
|
xmlWriter.writeEndElement();
|
|
|
|
}
|
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
xmlWriter.writeEndElement();
|
2015-08-23 16:03:24 +02:00
|
|
|
|
2015-09-05 11:37:55 +02:00
|
|
|
return outputString;
|
|
|
|
}
|