summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2023-06-30 12:54:52 +0200
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2023-07-06 21:51:05 +0200
commit1572c420f397a8e2828b254c66c599fc694aca1f (patch)
tree357e00f4e9ee4d7f374bc70c886cb055aefe9efd
parent058d993611b697e7cb25536535ba679d1fc347d6 (diff)
QDBusIntrospection: Add source location fields
Add source location to the introspection structs so that errors and warning produced by qdbusxml2cpp can be related to the source location. Task-number: QTBUG-2597 Change-Id: I9a6ada45f9c0357dbfb846f13789c5f261e59d55 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/dbus/qdbusintrospection_p.h13
-rw-r--r--src/dbus/qdbusxmlparser.cpp45
-rw-r--r--src/dbus/qdbusxmlparser_p.h3
3 files changed, 54 insertions, 7 deletions
diff --git a/src/dbus/qdbusintrospection_p.h b/src/dbus/qdbusintrospection_p.h
index 0dd7f70579..b16fc4924a 100644
--- a/src/dbus/qdbusintrospection_p.h
+++ b/src/dbus/qdbusintrospection_p.h
@@ -51,8 +51,16 @@ public:
public:
// the structs
+ // Line and column numbers have the same meaning as in QXmlStreamReader.
+ struct SourceLocation
+ {
+ qint64 lineNumber = 1;
+ qint64 columnNumber = 0;
+ };
+
struct Argument
{
+ SourceLocation location;
QString type;
QString name;
@@ -62,6 +70,7 @@ public:
struct Method
{
+ SourceLocation location;
QString name;
Arguments inputArgs;
Arguments outputArgs;
@@ -74,6 +83,7 @@ public:
struct Signal
{
+ SourceLocation location;
QString name;
Arguments outputArgs;
Annotations annotations;
@@ -86,6 +96,7 @@ public:
struct Property
{
enum Access { Read, Write, ReadWrite };
+ SourceLocation location;
QString name;
QString type;
Access access;
@@ -98,6 +109,7 @@ public:
struct Interface: public QSharedData
{
+ SourceLocation location;
QString name;
QString introspection;
@@ -112,6 +124,7 @@ public:
struct Object: public QSharedData
{
+ SourceLocation location;
QString service;
QString path;
diff --git a/src/dbus/qdbusxmlparser.cpp b/src/dbus/qdbusxmlparser.cpp
index 4685fe4ac4..277eda1852 100644
--- a/src/dbus/qdbusxmlparser.cpp
+++ b/src/dbus/qdbusxmlparser.cpp
@@ -111,7 +111,7 @@ bool QDBusXmlParser::parseProperty(QDBusIntrospection::Property &propertyData)
m_currentInterface->introspection += " <property access=\""_L1 + access + "\" type=\""_L1 + propertyData.type + "\" name=\""_L1 + propertyName + u'"';
- if (!m_xml.readNextStartElement()) {
+ if (!readNextStartElement()) {
m_currentInterface->introspection += "/>\n"_L1;
} else {
m_currentInterface->introspection += ">\n"_L1;
@@ -123,7 +123,7 @@ bool QDBusXmlParser::parseProperty(QDBusIntrospection::Property &propertyData)
qDBusParserError() << "Unknown element" << m_xml.name() << "while checking for annotations";
}
m_xml.skipCurrentElement();
- } while (m_xml.readNextStartElement());
+ } while (readNextStartElement());
m_currentInterface->introspection += " </property>\n"_L1;
}
@@ -156,7 +156,7 @@ bool QDBusXmlParser::parseMethod(QDBusIntrospection::Method &methodData)
QDBusIntrospection::Arguments inArguments;
QDBusIntrospection::Annotations annotations;
- if (!m_xml.readNextStartElement()) {
+ if (!readNextStartElement()) {
m_currentInterface->introspection += "/>\n"_L1;
} else {
m_currentInterface->introspection += ">\n"_L1;
@@ -168,6 +168,7 @@ bool QDBusXmlParser::parseMethod(QDBusIntrospection::Method &methodData)
const QXmlStreamAttributes attributes = m_xml.attributes();
const QString direction = attributes.value("direction"_L1).toString();
QDBusIntrospection::Argument argument;
+ argument.location = m_currentLocation;
if (!attributes.hasAttribute("direction"_L1) || direction == "in"_L1) {
parseArg(attributes, argument);
inArguments << argument;
@@ -179,7 +180,7 @@ bool QDBusXmlParser::parseMethod(QDBusIntrospection::Method &methodData)
qDBusParserError() << "Unknown element" << m_xml.name() << "while checking for method arguments";
}
m_xml.skipCurrentElement();
- } while (m_xml.readNextStartElement());
+ } while (readNextStartElement());
m_currentInterface->introspection += " </method>\n"_L1;
}
@@ -211,7 +212,7 @@ bool QDBusXmlParser::parseSignal(QDBusIntrospection::Signal &signalData)
QDBusIntrospection::Arguments arguments;
QDBusIntrospection::Annotations annotations;
- if (!m_xml.readNextStartElement()) {
+ if (!readNextStartElement()) {
m_currentInterface->introspection += "/>\n"_L1;
} else {
m_currentInterface->introspection += ">\n"_L1;
@@ -222,6 +223,7 @@ bool QDBusXmlParser::parseSignal(QDBusIntrospection::Signal &signalData)
} else if (m_xml.name() == "arg"_L1) {
const QXmlStreamAttributes attributes = m_xml.attributes();
QDBusIntrospection::Argument argument;
+ argument.location = m_currentLocation;
if (!attributes.hasAttribute("direction"_L1) ||
attributes.value("direction"_L1) == "out"_L1) {
parseArg(attributes, argument);
@@ -231,7 +233,7 @@ bool QDBusXmlParser::parseSignal(QDBusIntrospection::Signal &signalData)
qDBusParserError() << "Unknown element" << m_xml.name() << "while checking for signal arguments";
}
m_xml.skipCurrentElement();
- } while (m_xml.readNextStartElement());
+ } while (readNextStartElement());
m_currentInterface->introspection += " </signal>\n"_L1;
}
@@ -256,20 +258,24 @@ void QDBusXmlParser::readInterface()
m_object->interfaces.append(ifaceName);
m_currentInterface = std::make_unique<QDBusIntrospection::Interface>();
+ m_currentInterface->location = m_currentLocation;
m_currentInterface->name = ifaceName;
m_currentInterface->introspection += " <interface name=\""_L1 + ifaceName + "\">\n"_L1;
- while (m_xml.readNextStartElement()) {
+ while (readNextStartElement()) {
if (m_xml.name() == "method"_L1) {
QDBusIntrospection::Method methodData;
+ methodData.location = m_currentLocation;
if (parseMethod(methodData))
m_currentInterface->methods.insert(methodData.name, methodData);
} else if (m_xml.name() == "signal"_L1) {
QDBusIntrospection::Signal signalData;
+ signalData.location = m_currentLocation;
if (parseSignal(signalData))
m_currentInterface->signals_.insert(signalData.name, signalData);
} else if (m_xml.name() == "property"_L1) {
QDBusIntrospection::Property propertyData;
+ propertyData.location = m_currentLocation;
if (parseProperty(propertyData))
m_currentInterface->properties.insert(propertyData.name, propertyData);
} else if (m_xml.name() == "annotation"_L1) {
@@ -308,6 +314,30 @@ void QDBusXmlParser::readNode(int nodeLevel)
if (nodeLevel > 0)
m_object->childObjects.append(objName);
+ else
+ m_object->location = m_currentLocation;
+}
+
+void QDBusXmlParser::updateCurrentLocation()
+{
+ m_currentLocation =
+ QDBusIntrospection::SourceLocation{ m_xml.lineNumber(), m_xml.columnNumber() };
+}
+
+// Similar to m_xml.readNextElement() but sets current location to point
+// to the start element.
+bool QDBusXmlParser::readNextStartElement()
+{
+ updateCurrentLocation();
+
+ while (m_xml.readNext() != QXmlStreamReader::Invalid) {
+ if (m_xml.isEndElement())
+ return false;
+ else if (m_xml.isStartElement())
+ return true;
+ updateCurrentLocation();
+ }
+ return false;
}
QDBusXmlParser::QDBusXmlParser(const QString &service, const QString &path, const QString &xmlData)
@@ -319,6 +349,7 @@ QDBusXmlParser::QDBusXmlParser(const QString &service, const QString &path, cons
int nodeLevel = -1;
while (!m_xml.atEnd()) {
+ updateCurrentLocation();
m_xml.readNext();
switch (m_xml.tokenType()) {
diff --git a/src/dbus/qdbusxmlparser_p.h b/src/dbus/qdbusxmlparser_p.h
index d91223a70c..5ca20805a7 100644
--- a/src/dbus/qdbusxmlparser_p.h
+++ b/src/dbus/qdbusxmlparser_p.h
@@ -38,6 +38,7 @@ class QDBusXmlParser
std::unique_ptr<QDBusIntrospection::Interface> m_currentInterface;
QDBusIntrospection::Interfaces m_interfaces;
QXmlStreamReader m_xml;
+ QDBusIntrospection::SourceLocation m_currentLocation;
public:
QDBusXmlParser(const QString& service, const QString& path,
@@ -55,6 +56,8 @@ private:
bool parseAnnotation(QDBusIntrospection::Annotations &annotations,
bool interfaceAnnotation = false);
bool parseArg(const QXmlStreamAttributes &attributes, QDBusIntrospection::Argument &argData);
+ bool readNextStartElement();
+ void updateCurrentLocation();
};
QT_END_NAMESPACE