From ff0f4cef16f3eb8904db12f99816e623b8e1abe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 5 Sep 2015 20:13:26 +0200 Subject: [PATCH] GUI: Add handling of containers to CppcheckLibraryData --- cfg/std.cfg | 90 +++++++++++++++---------------- gui/cppchecklibrarydata.cpp | 103 +++++++++++++++++++++++++++++++++++- gui/cppchecklibrarydata.h | 27 ++++++++++ 3 files changed, 172 insertions(+), 48 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index b16f7d960..ca3418cfc 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -2321,9 +2321,9 @@ + 0: - @@ -2340,9 +2340,9 @@ + 0: - @@ -2359,9 +2359,9 @@ + 0: - @@ -2378,9 +2378,9 @@ + 0: - @@ -2395,9 +2395,9 @@ + 0: - @@ -2412,9 +2412,9 @@ + 0: - @@ -2754,24 +2754,24 @@ - + false - - - - + + + + @@ -2779,15 +2779,15 @@ false - - - - + + + + @@ -2797,9 +2797,9 @@ - + @@ -2850,16 +2850,6 @@ - - free - malloc - calloc - - - fclose - fopen - tmpfile - false @@ -3392,9 +3382,8 @@ - - false + false @@ -3591,13 +3580,13 @@ false - + - + @@ -3783,17 +3772,39 @@ + false - - + + + + false + + + + + + + + + + + malloc + calloc + free + + + fopen + tmpfile + fclose + @@ -3867,8 +3878,7 @@ - - + @@ -3919,16 +3929,4 @@ - - - false - - - - - - - - - diff --git a/gui/cppchecklibrarydata.cpp b/gui/cppchecklibrarydata.cpp index fd6052970..68c8f327e 100644 --- a/gui/cppchecklibrarydata.cpp +++ b/gui/cppchecklibrarydata.cpp @@ -27,6 +27,52 @@ CppcheckLibraryData::CppcheckLibraryData() { } +static CppcheckLibraryData::Container loadContainer(QXmlStreamReader &xmlReader) +{ + CppcheckLibraryData::Container container; + 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(); + + 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(); + } else if (elementName == "size" || elementName == "access" || elementName == "other") { + 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; + struct CppcheckLibraryData::Container::Function function; + 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); + else + container.otherFunctions.append(function); + }; + } + } + return container; +} + static CppcheckLibraryData::Define loadDefine(const QXmlStreamReader &xmlReader) { CppcheckLibraryData::Define define; @@ -148,6 +194,8 @@ bool CppcheckLibraryData::open(QIODevice &file) comments.append(xmlReader.text().toString()); break; case QXmlStreamReader::StartElement: + if (xmlReader.name() == "container") + containers.append(loadContainer(xmlReader)); if (xmlReader.name() == "define") defines.append(loadDefine(xmlReader)); else if (xmlReader.name() == "function") @@ -166,6 +214,53 @@ bool CppcheckLibraryData::open(QIODevice &file) return true; } +static void writeContainerFunctions(QXmlStreamWriter &xmlWriter, const QString name, int extra, const QList &functions) +{ + if (functions.isEmpty() && extra <= 0) + return; + xmlWriter.writeStartElement(name); + if (extra > 0) { + if (name == "access") + xmlWriter.writeAttribute("indexOperator", "array-like"); + else if (name == "size") + xmlWriter.writeAttribute("templateParameter", QString::number(extra)); + } + foreach(const CppcheckLibraryData::Container::Function &function, functions) { + 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(); +} + +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); + if (!container.endPattern.isEmpty()) + xmlWriter.writeAttribute("endPattern", container.endPattern); + if (!container.inherits.isEmpty()) + xmlWriter.writeAttribute("inherits", container.inherits); + 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); + writeContainerFunctions(xmlWriter, "access", container.access_arrayLike, container.accessFunctions); + writeContainerFunctions(xmlWriter, "other", 0, container.otherFunctions); + xmlWriter.writeEndElement(); +} + static void writeFunction(QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Function &function) { foreach(const QString &comment, function.comments) { @@ -273,13 +368,17 @@ QString CppcheckLibraryData::toString() const writeMemoryResource(xmlWriter, mr); } + foreach(const Container &container, containers) { + writeContainer(xmlWriter, container); + } + foreach(const PodType &podtype, podtypes) { xmlWriter.writeStartElement("podtype"); xmlWriter.writeAttribute("name", podtype.name); - if (!podtype.size.isEmpty()) - xmlWriter.writeAttribute("size", podtype.size); if (!podtype.sign.isEmpty()) xmlWriter.writeAttribute("sign", podtype.sign); + if (!podtype.size.isEmpty()) + xmlWriter.writeAttribute("size", podtype.size); xmlWriter.writeEndElement(); } diff --git a/gui/cppchecklibrarydata.h b/gui/cppchecklibrarydata.h index e494a3f25..10462d909 100644 --- a/gui/cppchecklibrarydata.h +++ b/gui/cppchecklibrarydata.h @@ -28,6 +28,32 @@ class CppcheckLibraryData { public: CppcheckLibraryData(); + struct Container { + Container() : access_arrayLike(false), size_templateParameter(-1) {} + + QString id; + QString inherits; + QString startPattern; + QString endPattern; + + bool access_arrayLike; + int size_templateParameter; + + struct { + QString templateParameter; + QString string; + } type; + + struct Function { + QString name; + QString yields; + QString action; + }; + QList accessFunctions; + QList otherFunctions; + QList sizeFunctions; + }; + struct Define { QString name; QString value; @@ -101,6 +127,7 @@ public: bool open(QIODevice &file); QString toString() const; + QList containers; QList defines; QList functions; QList memoryresource;