diff options
| -rw-r--r-- | sources/shiboken6/ApiExtractor/classdocumentation.cpp | 31 | ||||
| -rw-r--r-- | sources/shiboken6/ApiExtractor/classdocumentation.h | 14 | ||||
| -rw-r--r-- | sources/shiboken6/ApiExtractor/qtdocparser.cpp | 5 |
3 files changed, 30 insertions, 20 deletions
diff --git a/sources/shiboken6/ApiExtractor/classdocumentation.cpp b/sources/shiboken6/ApiExtractor/classdocumentation.cpp index 2008d83d2..8c1297593 100644 --- a/sources/shiboken6/ApiExtractor/classdocumentation.cpp +++ b/sources/shiboken6/ApiExtractor/classdocumentation.cpp @@ -85,7 +85,7 @@ qsizetype ClassDocumentation::indexOfProperty(const QString &name) const enum class WebXmlTag { - Class, Description, Enum, Function, Parameter, Property, Typedef, Other + Class, Description, Enum, Function, Header, Parameter, Property, Typedef, Other }; static WebXmlTag tag(QStringView name) @@ -98,6 +98,8 @@ static WebXmlTag tag(QStringView name) return WebXmlTag::Function; if (name == u"description") return WebXmlTag::Description; + if (name == u"header") + return WebXmlTag::Header; if (name == u"parameter") return WebXmlTag::Parameter; if (name == u"property") @@ -113,6 +115,11 @@ static void parseWebXmlElement(WebXmlTag tag, const QXmlStreamAttributes &attrib switch (tag) { case WebXmlTag::Class: cd->name = attributes.value(u"name"_s).toString(); + cd->type = ClassDocumentation::Class; + break; + case WebXmlTag::Header: + cd->name = attributes.value(u"name"_s).toString(); + cd->type = ClassDocumentation::Header; break; case WebXmlTag::Enum: { EnumDocumentation ed; @@ -185,14 +192,14 @@ static QString msgXmlError(const QString &fileName, const QXmlStreamReader &read return result; } -ClassDocumentation parseWebXml(const QString &fileName, QString *errorMessage) +std::optional<ClassDocumentation> parseWebXml(const QString &fileName, QString *errorMessage) { ClassDocumentation result; QFile file(fileName); if (!file.open(QIODevice::Text | QIODevice::ReadOnly)) { *errorMessage = msgCannotOpenForReading(file); - return result; + return std::nullopt; } WebXmlTag lastTag = WebXmlTag::Other; @@ -206,6 +213,7 @@ ClassDocumentation parseWebXml(const QString &fileName, QString *errorMessage) case WebXmlTag::Class: case WebXmlTag::Function: case WebXmlTag::Enum: + case WebXmlTag::Header: case WebXmlTag::Property: case WebXmlTag::Typedef: lastTag = currentTag; @@ -242,7 +250,7 @@ ClassDocumentation parseWebXml(const QString &fileName, QString *errorMessage) if (reader.error() != QXmlStreamReader::NoError) { *errorMessage= msgXmlError(fileName, reader); - return {}; + return std::nullopt; } sortDocumentation(&result); @@ -363,16 +371,11 @@ QDebug operator<<(QDebug debug, const ClassDocumentation &c) QDebugStateSaver saver(debug); debug.noquote(); debug.nospace(); - debug << "Class("; - if (c) { - debug << c.name << ", "; - formatDescription(debug, c.description); - formatList(debug, ", enums", c.enums); - formatList(debug, ", properties", c.properties); - formatList(debug, ", functions", c.functions); - } else { - debug << "invalid"; - } + debug << "Class(" << c.name << ", "; + formatDescription(debug, c.description); + formatList(debug, ", enums", c.enums); + formatList(debug, ", properties", c.properties); + formatList(debug, ", functions", c.functions); debug << ')'; return debug; } diff --git a/sources/shiboken6/ApiExtractor/classdocumentation.h b/sources/shiboken6/ApiExtractor/classdocumentation.h index ef66912f8..d47101389 100644 --- a/sources/shiboken6/ApiExtractor/classdocumentation.h +++ b/sources/shiboken6/ApiExtractor/classdocumentation.h @@ -6,6 +6,8 @@ #include <QtCore/QStringList> +#include <optional> + QT_FORWARD_DECLARE_CLASS(QDebug) /// An enumeration in a WebXML/doxygen document @@ -41,9 +43,14 @@ struct FunctionDocumentation : public FunctionDocumentationQuery using FunctionDocumentationList = QList<FunctionDocumentation>; -/// A class/namespace in a WebXML/doxygen document +/// A WebXML/doxygen document struct ClassDocumentation { + enum Type { + Class, // <class>, class/namespace + Header // <header>, grouped global functions/enums + }; + qsizetype indexOfEnum(const QString &name) const; FunctionDocumentationList findFunctionCandidates(const QString &name, bool constant) const; @@ -51,18 +58,17 @@ struct ClassDocumentation const FunctionDocumentationQuery &q); qsizetype indexOfProperty(const QString &name) const; + Type type = Type::Class; QString name; QString description; QList<EnumDocumentation> enums; QList<PropertyDocumentation> properties; FunctionDocumentationList functions; - - operator bool() const { return !name.isEmpty(); } }; /// Parse a WebXML class/namespace document -ClassDocumentation parseWebXml(const QString &fileName, QString *errorMessage); +std::optional<ClassDocumentation> parseWebXml(const QString &fileName, QString *errorMessage); /// Extract the module description from a WebXML module document QString webXmlModuleDescription(const QString &fileName, QString *errorMessage); diff --git a/sources/shiboken6/ApiExtractor/qtdocparser.cpp b/sources/shiboken6/ApiExtractor/qtdocparser.cpp index 5aa6ebdca..93fcb440d 100644 --- a/sources/shiboken6/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken6/ApiExtractor/qtdocparser.cpp @@ -231,12 +231,13 @@ void QtDocParser::fillDocumentation(const AbstractMetaClassPtr &metaClass) const QString sourceFileName = sourceFile.absoluteFilePath(); QString errorMessage; - const ClassDocumentation classDocumentation = parseWebXml(sourceFileName, &errorMessage); - if (!classDocumentation) { + const auto classDocumentationO = parseWebXml(sourceFileName, &errorMessage); + if (!classDocumentationO.has_value()) { qCWarning(lcShibokenDoc, "%s", qPrintable(errorMessage)); return; } + const auto &classDocumentation = classDocumentationO.value(); for (const auto &p : classDocumentation.properties) { Documentation doc(p.description, p.brief); metaClass->setPropertyDocumentation(p.name, doc); |
