Skip to content

Commit

Permalink
qdbusxml2cpp: Improve error message
Browse files Browse the repository at this point in the history
Instead of saying:
You should add <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="<type>"/> to the XML description
It now says
You should add <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="<type>"/> to the XML description for 'Bind'

So you get an idea of which type it's asking to annotate.

Change-Id: Ia0842d3b54681825201813fe0875014cd35d8192
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
  • Loading branch information
aleixpol committed Mar 24, 2022
1 parent 897845c commit 3ec95f9
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/tools/qdbusxml2cpp/qdbusxml2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ static QString classNameForInterface(const QString &interface, ClassType classTy
// ### Qt6 Remove the two isSignal ifs
// They are only here because before signal arguments where previously searched as "In" so to maintain compatibility
// we first search for "Out" and if not found we search for "In"
static QByteArray qtTypeName(const QString &signature, const QDBusIntrospection::Annotations &annotations, int paramId = -1, const char *direction = "Out", bool isSignal = false)
static QByteArray qtTypeName(const QString &where, const QString &signature,
const QDBusIntrospection::Annotations &annotations, int paramId = -1,
const char *direction = "Out", bool isSignal = false)
{
int type = QDBusMetaType::signatureToMetaType(signature.toLatin1()).id();
if (type == QMetaType::UnknownType) {
Expand All @@ -223,12 +225,14 @@ static QByteArray qtTypeName(const QString &signature, const QDBusIntrospection:
if (!isSignal || qstrcmp(direction, "Out") == 0) {
fprintf(stderr, "%s: Got unknown type `%s' processing '%s'\n",
PROGRAMNAME, qPrintable(signature), qPrintable(inputFile));
fprintf(stderr, "You should add <annotation name=\"%s\" value=\"<type>\"/> to the XML description\n",
qPrintable(annotationName));
fprintf(stderr,
"You should add <annotation name=\"%s\" value=\"<type>\"/> to the XML "
"description for '%s'\n",
qPrintable(annotationName), qPrintable(where));
}

if (isSignal)
return qtTypeName(signature, annotations, paramId, "In", isSignal);
return qtTypeName(where, signature, annotations, paramId, "In", isSignal);

exit(1);
}
Expand Down Expand Up @@ -307,7 +311,7 @@ static void writeArgList(QTextStream &ts, const QStringList &argNames,
int argPos = 0;
for (int i = 0; i < inputArgs.count(); ++i) {
const QDBusIntrospection::Argument &arg = inputArgs.at(i);
QString type = constRefArg(qtTypeName(arg.type, annotations, i, "In"));
QString type = constRefArg(qtTypeName(arg.name, arg.type, annotations, i, "In"));

if (!first)
ts << ", ";
Expand All @@ -324,7 +328,7 @@ static void writeArgList(QTextStream &ts, const QStringList &argNames,

if (!first)
ts << ", ";
ts << nonConstRefArg(qtTypeName(arg.type, annotations, i, "Out"))
ts << nonConstRefArg(qtTypeName(arg.name, arg.type, annotations, i, "Out"))
<< argNames.at(argPos++);
first = false;
}
Expand All @@ -338,7 +342,8 @@ static void writeSignalArgList(QTextStream &ts, const QStringList &argNames,
int argPos = 0;
for (int i = 0; i < outputArgs.count(); ++i) {
const QDBusIntrospection::Argument &arg = outputArgs.at(i);
QString type = constRefArg(qtTypeName(arg.type, annotations, i, "Out", true /* isSignal */));
QString type = constRefArg(
qtTypeName(arg.name, arg.type, annotations, i, "Out", true /* isSignal */));

if (!first)
ts << ", ";
Expand Down Expand Up @@ -529,7 +534,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf

// properties:
for (const QDBusIntrospection::Property &property : interface->properties) {
QByteArray type = qtTypeName(property.type, property.annotations);
QByteArray type = qtTypeName(property.name, property.type, property.annotations);
QString getter = propertyGetter(property);
QString setter = propertySetter(property);

Expand Down Expand Up @@ -586,7 +591,8 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
hs << "QDBusPendingReply<";
for (int i = 0; i < method.outputArgs.count(); ++i)
hs << (i > 0 ? ", " : "")
<< templateArg(qtTypeName(method.outputArgs.at(i).type, method.annotations, i, "Out"));
<< templateArg(qtTypeName(method.name, method.outputArgs.at(i).type,
method.annotations, i, "Out"));
hs << "> ";
}

Expand Down Expand Up @@ -618,10 +624,10 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf

if (method.outputArgs.count() > 1) {
// generate the old-form QDBusReply methods with multiple incoming parameters
hs << " inline "
<< (isDeprecated ? "Q_DECL_DEPRECATED " : "")
<< "QDBusReply<"
<< templateArg(qtTypeName(method.outputArgs.first().type, method.annotations, 0, "Out")) << "> ";
hs << " inline " << (isDeprecated ? "Q_DECL_DEPRECATED " : "") << "QDBusReply<"
<< templateArg(qtTypeName(method.name, method.outputArgs.first().type,
method.annotations, 0, "Out"))
<< "> ";
hs << method.name << "(";

QStringList argNames = makeArgNames(method.inputArgs, method.outputArgs);
Expand Down Expand Up @@ -649,7 +655,8 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
// yes, starting from 1
for (int i = 1; i < method.outputArgs.count(); ++i)
hs << " " << argNames.at(argPos++) << " = qdbus_cast<"
<< templateArg(qtTypeName(method.outputArgs.at(i).type, method.annotations, i, "Out"))
<< templateArg(qtTypeName(method.name, method.outputArgs.at(i).type,
method.annotations, i, "Out"))
<< ">(reply.arguments().at(" << i << "));" << Qt::endl;
hs << " }" << Qt::endl
<< " return reply;" << Qt::endl
Expand Down Expand Up @@ -858,7 +865,7 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte

hs << "public: // PROPERTIES" << Qt::endl;
for (const QDBusIntrospection::Property &property : interface->properties) {
QByteArray type = qtTypeName(property.type, property.annotations);
QByteArray type = qtTypeName(property.name, property.type, property.annotations);
QString constRefType = constRefArg(type);
QString getter = propertyGetter(property);
QString setter = propertySetter(property);
Expand Down Expand Up @@ -922,7 +929,8 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
hs << "void ";
cs << "void ";
} else {
returnType = qtTypeName(method.outputArgs.first().type, method.annotations, 0, "Out");
returnType = qtTypeName(method.name, method.outputArgs.first().type,
method.annotations, 0, "Out");
hs << returnType << " ";
cs << returnType << " ";
}
Expand Down Expand Up @@ -957,19 +965,15 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte

if (!method.outputArgs.isEmpty())
cs << ", Q_RETURN_ARG("
<< qtTypeName(method.outputArgs.at(0).type, method.annotations,
<< qtTypeName(method.name, method.outputArgs.at(0).type, method.annotations,
0, "Out")
<< ", "
<< argNames.at(method.inputArgs.count())
<< ")";
<< ", " << argNames.at(method.inputArgs.count()) << ")";

for (int i = 0; i < method.inputArgs.count(); ++i)
cs << ", Q_ARG("
<< qtTypeName(method.inputArgs.at(i).type, method.annotations,
<< qtTypeName(method.name, method.inputArgs.at(i).type, method.annotations,
i, "In")
<< ", "
<< argNames.at(i)
<< ")";
<< ", " << argNames.at(i) << ")";

cs << ");" << Qt::endl;

Expand Down

0 comments on commit 3ec95f9

Please sign in to comment.