qdbusxml2cpp: Combine string literals

Use multi-line string literals instead of repeated applications
of << operator. This should improve code size and performance.

Change-Id: I661454c007877bf86a289174e98d4cd3fe145d6f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Ievgenii Meshcheriakov 2023-05-25 15:53:16 +02:00
parent 464bcc0b6a
commit f6be12f2f9

View File

@ -182,18 +182,18 @@ static QString moc(const QString &name)
static QTextStream &writeHeader(QTextStream &ts, bool changesWillBeLost) static QTextStream &writeHeader(QTextStream &ts, bool changesWillBeLost)
{ {
ts << "/*\n" ts << "/*\n"
<< " * This file was generated by " PROGRAMNAME " version " PROGRAMVERSION "\n" " * This file was generated by " PROGRAMNAME " version " PROGRAMVERSION "\n"
<< " * Command line was: " << commandLine << "\n" " * Command line was: " << commandLine << "\n"
<< " *\n" " *\n"
<< " * " PROGRAMNAME " is " PROGRAMCOPYRIGHT "\n" " * " PROGRAMNAME " is " PROGRAMCOPYRIGHT "\n"
<< " *\n" " *\n"
<< " * This is an auto-generated file.\n"; " * This is an auto-generated file.\n";
if (changesWillBeLost) if (changesWillBeLost)
ts << " * Do not edit! All changes made to it will be lost.\n"; ts << " * Do not edit! All changes made to it will be lost.\n";
else else
ts << " * This file may have been hand-edited. Look for HAND-EDIT comments\n" ts << " * This file may have been hand-edited. Look for HAND-EDIT comments\n"
<< " * before re-generating it.\n"; " * before re-generating it.\n";
ts << " */\n\n"; ts << " */\n\n";
@ -484,7 +484,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
} }
hs << "#ifndef " << includeGuard << "\n" hs << "#ifndef " << includeGuard << "\n"
<< "#define " << includeGuard << "\n\n"; "#define " << includeGuard << "\n\n";
// include our stuff: // include our stuff:
hs << "#include <QtCore/QObject>\n" hs << "#include <QtCore/QObject>\n"
@ -492,8 +492,8 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
hs << "#include <QtDBus/QtDBus>\n"; hs << "#include <QtDBus/QtDBus>\n";
#else #else
hs << "#include <QtDBus/QDBusAbstractInterface>\n"; hs << "#include <QtDBus/QDBusAbstractInterface>\n"
hs << "#include <QtDBus/QDBusPendingReply>\n"; "#include <QtDBus/QDBusPendingReply>\n";
#endif #endif
for (const QString &include : std::as_const(includes)) { for (const QString &include : std::as_const(includes)) {
@ -520,33 +520,33 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
// comment: // comment:
hs << "/*\n" hs << "/*\n"
<< " * Proxy class for interface " << interface->name << "\n" " * Proxy class for interface " << interface->name << "\n"
<< " */\n"; " */\n";
cs << "/*\n" cs << "/*\n"
<< " * Implementation of interface class " << className << "\n" " * Implementation of interface class " << className << "\n"
<< " */\n\n"; " */\n\n";
// class header: // class header:
hs << "class " << className << ": public QDBusAbstractInterface\n" hs << "class " << className << ": public QDBusAbstractInterface\n"
<< "{\n" "{\n"
<< " Q_OBJECT\n"; " Q_OBJECT\n";
// the interface name // the interface name
hs << "public:\n" hs << "public:\n"
<< " static inline const char *staticInterfaceName()\n" " static inline const char *staticInterfaceName()\n"
<< " { return \"" << interface->name << "\"; }\n\n"; " { return \"" << interface->name << "\"; }\n\n";
// constructors/destructors: // constructors/destructors:
hs << "public:\n" hs << "public:\n"
<< " " << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);\n\n" " " << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);\n\n"
<< " ~" << className << "();\n\n"; " ~" << className << "();\n\n";
cs << className << "::" << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)\n" cs << className << "::" << className << "(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)\n"
<< " : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)\n" " : QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)\n"
<< "{\n" "{\n"
<< "}\n\n" "}\n\n"
<< className << "::~" << className << "()\n" << className << "::~" << className << "()\n"
<< "{\n" "{\n"
<< "}\n\n"; "}\n\n";
// properties: // properties:
for (const QDBusIntrospection::Property &property : interface->properties) { for (const QDBusIntrospection::Property &property : interface->properties) {
@ -571,14 +571,14 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
// getter: // getter:
if (property.access != QDBusIntrospection::Property::Write) { if (property.access != QDBusIntrospection::Property::Write) {
hs << " inline " << type << " " << getter << "() const\n" hs << " inline " << type << " " << getter << "() const\n"
<< " { return qvariant_cast< " << type << " >(property(\"" " { return qvariant_cast< " << type << " >(property(\""
<< property.name << "\")); }\n"; << property.name << "\")); }\n";
} }
// setter: // setter:
if (property.access != QDBusIntrospection::Property::Read) { if (property.access != QDBusIntrospection::Property::Read) {
hs << " inline void " << setter << "(" << constRefArg(type) << "value)\n" hs << " inline void " << setter << "(" << constRefArg(type) << "value)\n"
<< " { setProperty(\"" << property.name " { setProperty(\"" << property.name
<< "\", QVariant::fromValue(value)); }\n"; << "\", QVariant::fromValue(value)); }\n";
} }
@ -620,8 +620,8 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
writeArgList(hs, argNames, method.annotations, method.inputArgs); writeArgList(hs, argNames, method.annotations, method.inputArgs);
hs << ")\n" hs << ")\n"
<< " {\n" " {\n"
<< " QList<QVariant> argumentList;\n"; " QList<QVariant> argumentList;\n";
if (!method.inputArgs.isEmpty()) { if (!method.inputArgs.isEmpty()) {
hs << " argumentList"; hs << " argumentList";
@ -632,7 +632,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
if (isNoReply) if (isNoReply)
hs << " callWithArgumentList(QDBus::NoBlock, " hs << " callWithArgumentList(QDBus::NoBlock, "
<< "QStringLiteral(\"" << method.name << "\"), argumentList);\n"; "QStringLiteral(\"" << method.name << "\"), argumentList);\n";
else else
hs << " return asyncCallWithArgumentList(QStringLiteral(\"" hs << " return asyncCallWithArgumentList(QStringLiteral(\""
<< method.name << "\"), argumentList);\n"; << method.name << "\"), argumentList);\n";
@ -652,8 +652,8 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
writeArgList(hs, argNames, method.annotations, method.inputArgs, method.outputArgs); writeArgList(hs, argNames, method.annotations, method.inputArgs, method.outputArgs);
hs << ")\n" hs << ")\n"
<< " {\n" " {\n"
<< " QList<QVariant> argumentList;\n"; " QList<QVariant> argumentList;\n";
qsizetype argPos = 0; qsizetype argPos = 0;
if (!method.inputArgs.isEmpty()) { if (!method.inputArgs.isEmpty()) {
@ -664,7 +664,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
} }
hs << " QDBusMessage reply = callWithArgumentList(QDBus::Block, " hs << " QDBusMessage reply = callWithArgumentList(QDBus::Block, "
<< "QStringLiteral(\"" << method.name << "\"), argumentList);\n"; "QStringLiteral(\"" << method.name << "\"), argumentList);\n";
argPos++; argPos++;
hs << " if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().size() == " hs << " if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().size() == "
@ -677,8 +677,8 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
method.annotations, i, "Out")) method.annotations, i, "Out"))
<< ">(reply.arguments().at(" << i << "));\n"; << ">(reply.arguments().at(" << i << "));\n";
hs << " }\n" hs << " }\n"
<< " return reply;\n" " return reply;\n"
<< " }\n"; " }\n";
} }
hs << "\n"; hs << "\n";
@ -747,7 +747,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
QString mocName = moc(filename); QString mocName = moc(filename);
if (includeMocs && !mocName.isEmpty()) if (includeMocs && !mocName.isEmpty())
cs << "\n" cs << "\n"
<< "#include \"" << mocName << "\"\n"; "#include \"" << mocName << "\"\n";
cs.flush(); cs.flush();
hs.flush(); hs.flush();
@ -795,18 +795,18 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
} }
hs << "#ifndef " << includeGuard << "\n" hs << "#ifndef " << includeGuard << "\n"
<< "#define " << includeGuard << "\n\n"; "#define " << includeGuard << "\n\n";
// include our stuff: // include our stuff:
hs << "#include <QtCore/QObject>\n"; hs << "#include <QtCore/QObject>\n";
if (cppName == headerName) if (cppName == headerName)
hs << "#include <QtCore/QMetaObject>\n" hs << "#include <QtCore/QMetaObject>\n"
<< "#include <QtCore/QVariant>\n"; "#include <QtCore/QVariant>\n";
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
hs << "#include <QtDBus/QtDBus>\n"; hs << "#include <QtDBus/QtDBus>\n";
#else #else
hs << "#include <QtDBus/QDBusAbstractAdaptor>\n"; hs << "#include <QtDBus/QDBusAbstractAdaptor>\n"
hs << "#include <QtDBus/QDBusObjectPath>\n"; "#include <QtDBus/QDBusObjectPath>\n";
#endif #endif
for (const QString &include : std::as_const(includes)) { for (const QString &include : std::as_const(includes)) {
@ -844,39 +844,39 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
// comment: // comment:
hs << "/*\n" hs << "/*\n"
<< " * Adaptor class for interface " << interface->name << "\n" " * Adaptor class for interface " << interface->name << "\n"
<< " */\n"; " */\n";
cs << "/*\n" cs << "/*\n"
<< " * Implementation of adaptor class " << className << "\n" " * Implementation of adaptor class " << className << "\n"
<< " */\n\n"; " */\n\n";
// class header: // class header:
hs << "class " << className << ": public QDBusAbstractAdaptor\n" hs << "class " << className << ": public QDBusAbstractAdaptor\n"
<< "{\n" "{\n"
<< " Q_OBJECT\n" " Q_OBJECT\n"
<< " Q_CLASSINFO(\"D-Bus Interface\", \"" << interface->name << "\")\n" " Q_CLASSINFO(\"D-Bus Interface\", \"" << interface->name << "\")\n"
<< " Q_CLASSINFO(\"D-Bus Introspection\", \"\"\n" " Q_CLASSINFO(\"D-Bus Introspection\", \"\"\n"
<< stringify(interface->introspection) << stringify(interface->introspection)
<< " \"\")\n" << " \"\")\n"
<< "public:\n" "public:\n"
<< " " << className << "(" << parent << " *parent);\n" " " << className << "(" << parent << " *parent);\n"
<< " virtual ~" << className << "();\n\n"; " virtual ~" << className << "();\n\n";
if (!parentClassName.isEmpty()) if (!parentClassName.isEmpty())
hs << " inline " << parent << " *parent() const\n" hs << " inline " << parent << " *parent() const\n"
<< " { return static_cast<" << parent << " *>(QObject::parent()); }\n\n"; " { return static_cast<" << parent << " *>(QObject::parent()); }\n\n";
// constructor/destructor // constructor/destructor
cs << className << "::" << className << "(" << parent << " *parent)\n" cs << className << "::" << className << "(" << parent << " *parent)\n"
<< " : QDBusAbstractAdaptor(parent)\n" " : QDBusAbstractAdaptor(parent)\n"
<< "{\n" "{\n"
<< " // constructor\n" " // constructor\n"
<< " setAutoRelaySignals(true);\n" " setAutoRelaySignals(true);\n"
<< "}\n\n" "}\n\n"
<< className << "::~" << className << "()\n" << className << "::~" << className << "()\n"
<< "{\n" "{\n"
<< " // destructor\n" " // destructor\n"
<< "}\n\n"; "}\n\n";
hs << "public: // PROPERTIES\n"; hs << "public: // PROPERTIES\n";
for (const QDBusIntrospection::Property &property : interface->properties) { for (const QDBusIntrospection::Property &property : interface->properties) {
@ -897,23 +897,23 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
hs << " " << type << " " << getter << "() const;\n"; hs << " " << type << " " << getter << "() const;\n";
cs << type << " " cs << type << " "
<< className << "::" << getter << "() const\n" << className << "::" << getter << "() const\n"
<< "{\n" "{\n"
<< " // get the value of property " << property.name << "\n" " // get the value of property " << property.name << "\n"
<< " return qvariant_cast< " << type <<" >(parent()->property(\"" << property.name << "\"));\n" " return qvariant_cast< " << type <<" >(parent()->property(\"" << property.name << "\"));\n"
<< "}\n\n"; "}\n\n";
} }
// setter // setter
if (property.access != QDBusIntrospection::Property::Read) { if (property.access != QDBusIntrospection::Property::Read) {
hs << " void " << setter << "(" << constRefType << "value);\n"; hs << " void " << setter << "(" << constRefType << "value);\n";
cs << "void " << className << "::" << setter << "(" << constRefType << "value)\n" cs << "void " << className << "::" << setter << "(" << constRefType << "value)\n"
<< "{\n" "{\n"
<< " // set the value of property " << property.name << "\n" " // set the value of property " << property.name << "\n"
<< " parent()->setProperty(\"" << property.name << "\", QVariant::fromValue(value"; " parent()->setProperty(\"" << property.name << "\", QVariant::fromValue(value";
if (constRefType.contains("QDBusVariant"_L1)) if (constRefType.contains("QDBusVariant"_L1))
cs << ".variant()"; cs << ".variant()";
cs << "));\n" cs << "));\n"
<< "}\n\n"; "}\n\n";
} }
hs << "\n"; hs << "\n";
@ -954,8 +954,8 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
hs << ");\n"; // finished for header hs << ");\n"; // finished for header
cs << ")\n" cs << ")\n"
<< "{\n" "{\n"
<< " // handle method call " << interface->name << "." << methodName(method) << "\n"; " // handle method call " << interface->name << "." << methodName(method) << "\n";
// make the call // make the call
bool usingInvokeMethod = false; bool usingInvokeMethod = false;
@ -1040,7 +1040,7 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
QString mocName = moc(filename); QString mocName = moc(filename);
if (includeMocs && !mocName.isEmpty()) if (includeMocs && !mocName.isEmpty())
cs << "\n" cs << "\n"
<< "#include \"" << mocName << "\"\n"; "#include \"" << mocName << "\"\n";
cs.flush(); cs.flush();
hs.flush(); hs.flush();