qdbusxml2cpp: Finish migration to qsizetype

Inspect and change int types to qsizetypes where necessary.

As a drive-by, port from in-the-process-of-being-deprecated count()
to size().

Fixes: QTBUG-103549
Change-Id: Id51d7065eb681d61be517689f89ae488f72edb88
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Mate Barany 2022-07-08 17:18:44 +02:00 committed by Marc Mutz
parent 4262e3b6ef
commit dbb3fdafac

View File

@ -179,7 +179,7 @@ static QString classNameForInterface(const QString &interface, ClassType classTy
// They are only here because before signal arguments where previously searched as "In" so to maintain compatibility // 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" // we first search for "Out" and if not found we search for "In"
static QByteArray qtTypeName(const QString &where, const QString &signature, static QByteArray qtTypeName(const QString &where, const QString &signature,
const QDBusIntrospection::Annotations &annotations, int paramId = -1, const QDBusIntrospection::Annotations &annotations, qsizetype paramId = -1,
const char *direction = "Out", bool isSignal = false) const char *direction = "Out", bool isSignal = false)
{ {
int type = QDBusMetaType::signatureToMetaType(signature.toLatin1()).id(); int type = QDBusMetaType::signatureToMetaType(signature.toLatin1()).id();
@ -248,10 +248,10 @@ static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs,
QDBusIntrospection::Arguments()) QDBusIntrospection::Arguments())
{ {
QStringList retval; QStringList retval;
const int numInputArgs = inputArgs.count(); const qsizetype numInputArgs = inputArgs.size();
const int numOutputArgs = outputArgs.count(); const qsizetype numOutputArgs = outputArgs.size();
retval.reserve(numInputArgs + numOutputArgs); retval.reserve(numInputArgs + numOutputArgs);
for (int i = 0; i < numInputArgs; ++i) { for (qsizetype i = 0; i < numInputArgs; ++i) {
const QDBusIntrospection::Argument &arg = inputArgs.at(i); const QDBusIntrospection::Argument &arg = inputArgs.at(i);
QString name = arg.name; QString name = arg.name;
if (name.isEmpty()) if (name.isEmpty())
@ -262,7 +262,7 @@ static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs,
name += "_"_L1; name += "_"_L1;
retval << name; retval << name;
} }
for (int i = 0; i < numOutputArgs; ++i) { for (qsizetype i = 0; i < numOutputArgs; ++i) {
const QDBusIntrospection::Argument &arg = outputArgs.at(i); const QDBusIntrospection::Argument &arg = outputArgs.at(i);
QString name = arg.name; QString name = arg.name;
if (name.isEmpty()) if (name.isEmpty())
@ -283,8 +283,8 @@ static void writeArgList(QTextStream &ts, const QStringList &argNames,
{ {
// input args: // input args:
bool first = true; bool first = true;
int argPos = 0; qsizetype argPos = 0;
for (int i = 0; i < inputArgs.count(); ++i) { for (qsizetype i = 0; i < inputArgs.size(); ++i) {
const QDBusIntrospection::Argument &arg = inputArgs.at(i); const QDBusIntrospection::Argument &arg = inputArgs.at(i);
QString type = constRefArg(qtTypeName(arg.name, arg.type, annotations, i, "In")); QString type = constRefArg(qtTypeName(arg.name, arg.type, annotations, i, "In"));
@ -298,7 +298,7 @@ static void writeArgList(QTextStream &ts, const QStringList &argNames,
// output args // output args
// yes, starting from 1 // yes, starting from 1
for (int i = 1; i < outputArgs.count(); ++i) { for (qsizetype i = 1; i < outputArgs.size(); ++i) {
const QDBusIntrospection::Argument &arg = outputArgs.at(i); const QDBusIntrospection::Argument &arg = outputArgs.at(i);
if (!first) if (!first)
@ -314,8 +314,8 @@ static void writeSignalArgList(QTextStream &ts, const QStringList &argNames,
const QDBusIntrospection::Arguments &outputArgs) const QDBusIntrospection::Arguments &outputArgs)
{ {
bool first = true; bool first = true;
int argPos = 0; qsizetype argPos = 0;
for (int i = 0; i < outputArgs.count(); ++i) { for (qsizetype i = 0; i < outputArgs.size(); ++i) {
const QDBusIntrospection::Argument &arg = outputArgs.at(i); const QDBusIntrospection::Argument &arg = outputArgs.at(i);
QString type = constRefArg( QString type = constRefArg(
qtTypeName(arg.name, arg.type, annotations, i, "Out", true /* isSignal */)); qtTypeName(arg.name, arg.type, annotations, i, "Out", true /* isSignal */));
@ -379,7 +379,7 @@ static QString methodName(const QDBusIntrospection::Method &method)
static QString stringify(const QString &data) static QString stringify(const QString &data)
{ {
QString retval; QString retval;
int i; qsizetype i;
for (i = 0; i < data.length(); ++i) { for (i = 0; i < data.length(); ++i) {
retval += u'\"'; retval += u'\"';
for ( ; i < data.length() && data[i] != u'\n' && data[i] != u'\r'; ++i) for ( ; i < data.length() && data[i] != u'\n' && data[i] != u'\r'; ++i)
@ -569,7 +569,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
hs << "Q_NOREPLY void "; hs << "Q_NOREPLY void ";
} else { } else {
hs << "QDBusPendingReply<"; hs << "QDBusPendingReply<";
for (int i = 0; i < method.outputArgs.count(); ++i) for (qsizetype i = 0; i < method.outputArgs.size(); ++i)
hs << (i > 0 ? ", " : "") hs << (i > 0 ? ", " : "")
<< templateArg(qtTypeName(method.name, method.outputArgs.at(i).type, << templateArg(qtTypeName(method.name, method.outputArgs.at(i).type,
method.annotations, i, "Out")); method.annotations, i, "Out"));
@ -587,7 +587,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
if (!method.inputArgs.isEmpty()) { if (!method.inputArgs.isEmpty()) {
hs << " argumentList"; hs << " argumentList";
for (int argPos = 0; argPos < method.inputArgs.count(); ++argPos) for (qsizetype argPos = 0; argPos < method.inputArgs.size(); ++argPos)
hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')'; hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')';
hs << ";" << Qt::endl; hs << ";" << Qt::endl;
} }
@ -602,7 +602,7 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
// close the function: // close the function:
hs << " }" << Qt::endl; hs << " }" << Qt::endl;
if (method.outputArgs.count() > 1) { if (method.outputArgs.size() > 1) {
// generate the old-form QDBusReply methods with multiple incoming parameters // generate the old-form QDBusReply methods with multiple incoming parameters
hs << " inline " << (isDeprecated ? "Q_DECL_DEPRECATED " : "") << "QDBusReply<" hs << " inline " << (isDeprecated ? "Q_DECL_DEPRECATED " : "") << "QDBusReply<"
<< templateArg(qtTypeName(method.name, method.outputArgs.first().type, << templateArg(qtTypeName(method.name, method.outputArgs.first().type,
@ -617,10 +617,10 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
<< " {" << Qt::endl << " {" << Qt::endl
<< " QList<QVariant> argumentList;" << Qt::endl; << " QList<QVariant> argumentList;" << Qt::endl;
int argPos = 0; qsizetype argPos = 0;
if (!method.inputArgs.isEmpty()) { if (!method.inputArgs.isEmpty()) {
hs << " argumentList"; hs << " argumentList";
for (argPos = 0; argPos < method.inputArgs.count(); ++argPos) for (argPos = 0; argPos < method.inputArgs.size(); ++argPos)
hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')'; hs << " << QVariant::fromValue(" << argNames.at(argPos) << ')';
hs << ";" << Qt::endl; hs << ";" << Qt::endl;
} }
@ -629,11 +629,11 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
<< "QStringLiteral(\"" << method.name << "\"), argumentList);" << Qt::endl; << "QStringLiteral(\"" << method.name << "\"), argumentList);" << Qt::endl;
argPos++; argPos++;
hs << " if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() == " hs << " if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().size() == "
<< method.outputArgs.count() << ") {" << Qt::endl; << method.outputArgs.size() << ") {" << Qt::endl;
// yes, starting from 1 // yes, starting from 1
for (int i = 1; i < method.outputArgs.count(); ++i) for (qsizetype i = 1; i < method.outputArgs.size(); ++i)
hs << " " << argNames.at(argPos++) << " = qdbus_cast<" hs << " " << argNames.at(argPos++) << " = qdbus_cast<"
<< templateArg(qtTypeName(method.name, method.outputArgs.at(i).type, << templateArg(qtTypeName(method.name, method.outputArgs.at(i).type,
method.annotations, i, "Out")) method.annotations, i, "Out"))
@ -677,22 +677,22 @@ static void writeProxy(const QString &filename, const QDBusIntrospection::Interf
name = current.takeLast(); name = current.takeLast();
} }
int i = 0; qsizetype i = 0;
while (i < current.count() && i < last.count() && current.at(i) == last.at(i)) while (i < current.size() && i < last.size() && current.at(i) == last.at(i))
++i; ++i;
// i parts matched // i parts matched
// close last.arguments().count() - i namespaces: // close last.arguments().size() - i namespaces:
for (int j = i; j < last.count(); ++j) for (qsizetype j = i; j < last.size(); ++j)
hs << QString((last.count() - j - 1 + i) * 2, u' ') << "}" << Qt::endl; hs << QString((last.size() - j - 1 + i) * 2, u' ') << "}" << Qt::endl;
// open current.arguments().count() - i namespaces // open current.arguments().size() - i namespaces
for (int j = i; j < current.count(); ++j) for (qsizetype j = i; j < current.size(); ++j)
hs << QString(j * 2, u' ') << "namespace " << current.at(j) << " {" << Qt::endl; hs << QString(j * 2, u' ') << "namespace " << current.at(j) << " {" << Qt::endl;
// add this class: // add this class:
if (!name.isEmpty()) { if (!name.isEmpty()) {
hs << QString(current.count() * 2, u' ') hs << QString(current.size() * 2, u' ')
<< "using " << name << " = ::" << classNameForInterface(it->constData()->name, Proxy) << "using " << name << " = ::" << classNameForInterface(it->constData()->name, Proxy)
<< ";" << Qt::endl; << ";" << Qt::endl;
} }
@ -933,14 +933,14 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
// make the call // make the call
bool usingInvokeMethod = false; bool usingInvokeMethod = false;
if (parentClassName.isEmpty() && method.inputArgs.count() <= 10 if (parentClassName.isEmpty() && method.inputArgs.size() <= 10
&& method.outputArgs.count() <= 1) && method.outputArgs.size() <= 1)
usingInvokeMethod = true; usingInvokeMethod = true;
if (usingInvokeMethod) { if (usingInvokeMethod) {
// we are using QMetaObject::invokeMethod // we are using QMetaObject::invokeMethod
if (!returnType.isEmpty()) if (!returnType.isEmpty())
cs << " " << returnType << " " << argNames.at(method.inputArgs.count()) cs << " " << returnType << " " << argNames.at(method.inputArgs.size())
<< ";" << Qt::endl; << ";" << Qt::endl;
static const char invoke[] = " QMetaObject::invokeMethod(parent(), \""; static const char invoke[] = " QMetaObject::invokeMethod(parent(), \"";
@ -950,9 +950,9 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
cs << ", Q_RETURN_ARG(" cs << ", Q_RETURN_ARG("
<< qtTypeName(method.name, method.outputArgs.at(0).type, method.annotations, << qtTypeName(method.name, method.outputArgs.at(0).type, method.annotations,
0, "Out") 0, "Out")
<< ", " << argNames.at(method.inputArgs.count()) << ")"; << ", " << argNames.at(method.inputArgs.size()) << ")";
for (int i = 0; i < method.inputArgs.count(); ++i) for (qsizetype i = 0; i < method.inputArgs.size(); ++i)
cs << ", Q_ARG(" cs << ", Q_ARG("
<< qtTypeName(method.name, method.inputArgs.at(i).type, method.annotations, << qtTypeName(method.name, method.inputArgs.at(i).type, method.annotations,
i, "In") i, "In")
@ -961,7 +961,7 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
cs << ");" << Qt::endl; cs << ");" << Qt::endl;
if (!returnType.isEmpty()) if (!returnType.isEmpty())
cs << " return " << argNames.at(method.inputArgs.count()) << ";" << Qt::endl; cs << " return " << argNames.at(method.inputArgs.size()) << ";" << Qt::endl;
} else { } else {
if (parentClassName.isEmpty()) if (parentClassName.isEmpty())
cs << " //"; cs << " //";
@ -977,14 +977,14 @@ static void writeAdaptor(const QString &filename, const QDBusIntrospection::Inte
cs << "parent()->"; cs << "parent()->";
cs << name << "("; cs << name << "(";
int argPos = 0; qsizetype argPos = 0;
bool first = true; bool first = true;
for (int i = 0; i < method.inputArgs.count(); ++i) { for (qsizetype i = 0; i < method.inputArgs.size(); ++i) {
cs << (first ? "" : ", ") << argNames.at(argPos++); cs << (first ? "" : ", ") << argNames.at(argPos++);
first = false; first = false;
} }
++argPos; // skip retval, if any ++argPos; // skip retval, if any
for (int i = 1; i < method.outputArgs.count(); ++i) { for (qsizetype i = 1; i < method.outputArgs.size(); ++i) {
cs << (first ? "" : ", ") << argNames.at(argPos++); cs << (first ? "" : ", ") << argNames.at(argPos++);
first = false; first = false;
} }