From df9d882d41b741fef7c5beeddb0abe9d904443d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2022 14:09:04 +0200 Subject: Port from container.count()/length() to size() This is semantic patch using ClangTidyTransformator: auto QtContainerClass = expr(hasType(namedDecl(hasAnyName()))).bind(o) makeRule(cxxMemberCallExpr(on(QtContainerClass), callee(cxxMethodDecl(hasAnyName({"count", "length"), parameterCountIs(0))))), changeTo(cat(access(o, cat("size"), "()"))), cat("use 'size()' instead of 'count()/length()'")) a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'. are: // sequential: "QByteArray", "QList", "QQueue", "QStack", "QString", "QVarLengthArray", "QVector", // associative: "QHash", "QMultiHash", "QMap", "QMultiMap", "QSet", // Qt has no QMultiSet Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af Reviewed-by: Qt CI Bot Reviewed-by: Volker Hilsheimer --- src/tools/moc/generator.cpp | 110 ++++++++++++++++++++--------------------- src/tools/moc/moc.cpp | 22 ++++----- src/tools/moc/moc.h | 4 +- src/tools/moc/preprocessor.cpp | 4 +- 4 files changed, 70 insertions(+), 70 deletions(-) (limited to 'src/tools/moc') diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index e9e5f167b7..13973645a1 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -72,23 +72,23 @@ QT_FOR_EACH_STATIC_TYPE(RETURN_METATYPENAME_STRING) static inline int lengthOfEscapeSequence(const QByteArray &s, int i) { - if (s.at(i) != '\\' || i >= s.length() - 1) + if (s.at(i) != '\\' || i >= s.size() - 1) return 1; const int startPos = i; ++i; char ch = s.at(i); if (ch == 'x') { ++i; - while (i < s.length() && is_hex_char(s.at(i))) + while (i < s.size() && is_hex_char(s.at(i))) ++i; } else if (is_octal_char(ch)) { while (i < startPos + 4 - && i < s.length() + && i < s.size() && is_octal_char(s.at(i))) { ++i; } } else { // single character escape sequence - i = qMin(i + 1, s.length()); + i = qMin(i + 1, s.size()); } return i - startPos; } @@ -96,14 +96,14 @@ static inline int lengthOfEscapeSequence(const QByteArray &s, int i) static inline uint lengthOfEscapedString(const QByteArray &str) { int extra = 0; - for (int j = 0; j < str.length(); ++j) { + for (int j = 0; j < str.size(); ++j) { if (str.at(j) == '\\') { int cnt = lengthOfEscapeSequence(str, j) - 1; extra += cnt; j += cnt; } } - return str.length() - extra; + return str.size() - extra; } // Prints \a s to \a out, breaking it into lines of at most ColumnWidth. The @@ -111,7 +111,7 @@ static inline uint lengthOfEscapedString(const QByteArray &str) static void printStringWithIndentation(FILE *out, const QByteArray &s) { static constexpr int ColumnWidth = 72; - int len = s.length(); + int len = s.size(); int idx = 0; do { @@ -146,8 +146,8 @@ int Generator::stridx(const QByteArray &s) static int aggregateParameterCount(const QList &list) { int sum = 0; - for (int i = 0; i < list.count(); ++i) - sum += list.at(i).arguments.count() + 1; // +1 for return type + for (int i = 0; i < list.size(); ++i) + sum += list.at(i).arguments.size() + 1; // +1 for return type return sum; } @@ -218,7 +218,7 @@ void Generator::generateCode() // filter out undeclared enumerators and sets { QList enumList; - for (int i = 0; i < cdef->enumList.count(); ++i) { + for (int i = 0; i < cdef->enumList.size(); ++i) { EnumDef def = cdef->enumList.at(i); if (cdef->enumDeclarations.contains(def.name)) { enumList += def; @@ -304,7 +304,7 @@ void Generator::generateCode() int idx = 0; for (int i = 0; i < strings.size(); ++i) { const QByteArray &str = strings.at(i); - const QByteArray comment = str.length() > 32 ? str.left(29) + "..." : str; + const QByteArray comment = str.size() > 32 ? str.left(29) + "..." : str; const char *comma = (i != strings.size() - 1 ? "," : " "); int len = lengthOfEscapedString(str); fprintf(out, "\n QT_MOC_LITERAL(%d, %d)%s // \"%s\"", idx, len, comma, @@ -340,10 +340,10 @@ void Generator::generateCode() fprintf(out, "\n // content:\n"); fprintf(out, " %4d, // revision\n", int(QMetaObjectPrivate::OutputRevision)); fprintf(out, " %4d, // classname\n", stridx(cdef->qualified)); - fprintf(out, " %4d, %4d, // classinfo\n", int(cdef->classInfoList.count()), int(cdef->classInfoList.count() ? index : 0)); - index += cdef->classInfoList.count() * 2; + fprintf(out, " %4d, %4d, // classinfo\n", int(cdef->classInfoList.size()), int(cdef->classInfoList.size() ? index : 0)); + index += cdef->classInfoList.size() * 2; - int methodCount = cdef->signalList.count() + cdef->slotList.count() + cdef->methodList.count(); + int methodCount = cdef->signalList.size() + cdef->slotList.size() + cdef->methodList.size(); fprintf(out, " %4d, %4d, // methods\n", methodCount, methodCount ? index : 0); index += methodCount * QMetaObjectPrivate::IntsPerMethod; if (cdef->revisionedMethods) @@ -355,16 +355,16 @@ void Generator::generateCode() + aggregateParameterCount(cdef->constructorList); index += totalParameterCount * 2 // types and parameter names - methodCount // return "parameters" don't have names - - cdef->constructorList.count(); // "this" parameters don't have names + - cdef->constructorList.size(); // "this" parameters don't have names - fprintf(out, " %4d, %4d, // properties\n", int(cdef->propertyList.count()), int(cdef->propertyList.count() ? index : 0)); - index += cdef->propertyList.count() * QMetaObjectPrivate::IntsPerProperty; - fprintf(out, " %4d, %4d, // enums/sets\n", int(cdef->enumList.count()), cdef->enumList.count() ? index : 0); + fprintf(out, " %4d, %4d, // properties\n", int(cdef->propertyList.size()), int(cdef->propertyList.size() ? index : 0)); + index += cdef->propertyList.size() * QMetaObjectPrivate::IntsPerProperty; + fprintf(out, " %4d, %4d, // enums/sets\n", int(cdef->enumList.size()), cdef->enumList.size() ? index : 0); int enumsIndex = index; - for (int i = 0; i < cdef->enumList.count(); ++i) - index += 5 + (cdef->enumList.at(i).values.count() * 2); - fprintf(out, " %4d, %4d, // constructors\n", isConstructible ? int(cdef->constructorList.count()) : 0, + for (int i = 0; i < cdef->enumList.size(); ++i) + index += 5 + (cdef->enumList.at(i).values.size() * 2); + fprintf(out, " %4d, %4d, // constructors\n", isConstructible ? int(cdef->constructorList.size()) : 0, isConstructible ? index : 0); int flags = 0; @@ -374,7 +374,7 @@ void Generator::generateCode() flags |= PropertyAccessInStaticMetaCall; } fprintf(out, " %4d, // flags\n", flags); - fprintf(out, " %4d, // signalCount\n", int(cdef->signalList.count())); + fprintf(out, " %4d, // signalCount\n", int(cdef->signalList.size())); // @@ -383,7 +383,7 @@ void Generator::generateCode() generateClassInfos(); // all property metatypes, + 1 for the type of the current class itself - int initialMetaTypeOffset = cdef->propertyList.count() + 1; + int initialMetaTypeOffset = cdef->propertyList.size() + 1; // // Build signals array first, otherwise the signal indices would be wrong @@ -446,7 +446,7 @@ void Generator::generateCode() QMultiHash knownExtraMetaObject(knownGadgets); knownExtraMetaObject.unite(knownQObjectClasses); - for (int i = 0; i < cdef->propertyList.count(); ++i) { + for (int i = 0; i < cdef->propertyList.size(); ++i) { const PropertyDef &p = cdef->propertyList.at(i); if (isBuiltinType(p.type)) continue; @@ -506,7 +506,7 @@ void Generator::generateCode() if (!extraList.isEmpty()) { fprintf(out, "Q_CONSTINIT static const QMetaObject::SuperData qt_meta_extradata_%s[] = {\n", qualifiedClassNameIdentifier.constData()); - for (int i = 0; i < extraList.count(); ++i) { + for (int i = 0; i < extraList.size(); ++i) { fprintf(out, " QMetaObject::SuperData::link<%s::staticMetaObject>(),\n", extraList.at(i).constData()); } fprintf(out, " nullptr\n};\n\n"); @@ -554,7 +554,7 @@ void Generator::generateCode() fprintf(out, " qt_metaTypeArray<"); } // metatypes for properties - for (int i = 0; i < cdef->propertyList.count(); ++i) { + for (int i = 0; i < cdef->propertyList.size(); ++i) { const PropertyDef &p = cdef->propertyList.at(i); fprintf(out, "%s\n // property '%s'\n %s", comma, p.name.constData(), stringForType(p.type, true).constData()); @@ -571,7 +571,7 @@ void Generator::generateCode() // because we definitely printed something above, this section doesn't need comma control for (const QList &methodContainer : { cdef->signalList, cdef->slotList, cdef->methodList }) { - for (int i = 0; i< methodContainer.count(); ++i) { + for (int i = 0; i< methodContainer.size(); ++i) { const FunctionDef& fdef = methodContainer.at(i); fprintf(out, ",\n // method '%s'\n %s", fdef.name.constData(), stringForType(fdef.type.name, false).constData()); @@ -581,7 +581,7 @@ void Generator::generateCode() } // but constructors have no return types, so this needs comma control again - for (int i = 0; i< cdef->constructorList.count(); ++i) { + for (int i = 0; i< cdef->constructorList.size(); ++i) { const FunctionDef& fdef = cdef->constructorList.at(i); if (fdef.arguments.isEmpty()) continue; @@ -698,7 +698,7 @@ void Generator::generateClassInfos() void Generator::registerFunctionStrings(const QList &list) { - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { const FunctionDef &f = list.at(i); strreg(f.name); @@ -706,7 +706,7 @@ void Generator::registerFunctionStrings(const QList &list) strreg(f.normalizedType); strreg(f.tag); - int argsCount = f.arguments.count(); + int argsCount = f.arguments.size(); for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (!isBuiltinType(a.normalizedType)) @@ -729,7 +729,7 @@ void Generator::generateFunctions(const QList &list, const char *fu return; fprintf(out, "\n // %ss: name, argc, parameters, tag, flags, initial metatype offsets\n", functype); - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { const FunctionDef &f = list.at(i); QByteArray comment; @@ -766,7 +766,7 @@ void Generator::generateFunctions(const QList &list, const char *fu comment.append(" | MethodIsConst "); } - int argc = f.arguments.count(); + int argc = f.arguments.size(); fprintf(out, " %4d, %4d, %4d, %4d, 0x%02x, %4d /* %s */,\n", stridx(f.name), argc, paramsIndex, stridx(f.tag), flags, initialMetatypeOffset, comment.constData()); @@ -778,9 +778,9 @@ void Generator::generateFunctions(const QList &list, const char *fu void Generator::generateFunctionRevisions(const QList &list, const char *functype) { - if (list.count()) + if (list.size()) fprintf(out, "\n // %ss: revision\n", functype); - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { const FunctionDef &f = list.at(i); fprintf(out, " %4d,\n", f.revision); } @@ -791,12 +791,12 @@ void Generator::generateFunctionParameters(const QList &list, const if (list.isEmpty()) return; fprintf(out, "\n // %ss: parameters\n", functype); - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { const FunctionDef &f = list.at(i); fprintf(out, " "); // Types - int argsCount = f.arguments.count(); + int argsCount = f.arguments.size(); for (int j = -1; j < argsCount; ++j) { if (j > -1) fputc(' ', out); @@ -842,7 +842,7 @@ void Generator::generateTypeInfo(const QByteArray &typeName, bool allowEmptyName void Generator::registerPropertyStrings() { - for (int i = 0; i < cdef->propertyList.count(); ++i) { + for (int i = 0; i < cdef->propertyList.size(); ++i) { const PropertyDef &p = cdef->propertyList.at(i); strreg(p.name); if (!isBuiltinType(p.type)) @@ -856,9 +856,9 @@ void Generator::generateProperties() // Create meta data // - if (cdef->propertyList.count()) + if (cdef->propertyList.size()) fprintf(out, "\n // properties: name, type, flags\n"); - for (int i = 0; i < cdef->propertyList.count(); ++i) { + for (int i = 0; i < cdef->propertyList.size(); ++i) { const PropertyDef &p = cdef->propertyList.at(i); uint flags = Invalid; if (!isBuiltinType(p.type)) @@ -912,12 +912,12 @@ void Generator::generateProperties() void Generator::registerEnumStrings() { - for (int i = 0; i < cdef->enumList.count(); ++i) { + for (int i = 0; i < cdef->enumList.size(); ++i) { const EnumDef &e = cdef->enumList.at(i); strreg(e.name); if (!e.enumName.isNull()) strreg(e.enumName); - for (int j = 0; j < e.values.count(); ++j) + for (int j = 0; j < e.values.size(); ++j) strreg(e.values.at(j)); } } @@ -928,9 +928,9 @@ void Generator::generateEnums(int index) return; fprintf(out, "\n // enums: name, alias, flags, count, data\n"); - index += 5 * cdef->enumList.count(); + index += 5 * cdef->enumList.size(); int i; - for (i = 0; i < cdef->enumList.count(); ++i) { + for (i = 0; i < cdef->enumList.size(); ++i) { const EnumDef &e = cdef->enumList.at(i); int flags = 0; if (cdef->enumDeclarations.value(e.name)) @@ -941,15 +941,15 @@ void Generator::generateEnums(int index) stridx(e.name), e.enumName.isNull() ? stridx(e.name) : stridx(e.enumName), flags, - int(e.values.count()), + int(e.values.size()), index); - index += e.values.count() * 2; + index += e.values.size() * 2; } fprintf(out, "\n // enum data: key, value\n"); - for (i = 0; i < cdef->enumList.count(); ++i) { + for (i = 0; i < cdef->enumList.size(); ++i) { const EnumDef &e = cdef->enumList.at(i); - for (int j = 0; j < e.values.count(); ++j) { + for (int j = 0; j < e.values.size(); ++j) { const QByteArray &val = e.values.at(j); QByteArray code = cdef->qualified.constData(); if (e.isEnumClass) @@ -1015,7 +1015,7 @@ void Generator::generateMetacall() " || _c == QMetaObject::ResetProperty || _c == QMetaObject::BindableProperty\n" " || _c == QMetaObject::RegisterPropertyMetaType) {\n" " qt_static_metacall(this, _c, _id, _a);\n" - " _id -= %d;\n }", int(cdef->propertyList.count())); + " _id -= %d;\n }", int(cdef->propertyList.size())); } if (methodList.size() || cdef->propertyList.size()) fprintf(out, "\n "); @@ -1041,7 +1041,7 @@ Generator::methodsWithAutomaticTypesHelper(const QList &methodList) QMap > methodsWithAutomaticTypes; for (int i = 0; i < methodList.size(); ++i) { const FunctionDef &f = methodList.at(i); - for (int j = 0; j < f.arguments.count(); ++j) { + for (int j = 0; j < f.arguments.size(); ++j) { const QByteArray argType = f.arguments.at(j).normalizedType; if (registerableMetaType(argType) && !isBuiltinType(argType)) methodsWithAutomaticTypes[i].insert(argType, j); @@ -1061,13 +1061,13 @@ void Generator::generateStaticMetacall() if (!cdef->constructorList.isEmpty()) { fprintf(out, " if (_c == QMetaObject::CreateInstance) {\n"); fprintf(out, " switch (_id) {\n"); - for (int ctorindex = 0; ctorindex < cdef->constructorList.count(); ++ctorindex) { + for (int ctorindex = 0; ctorindex < cdef->constructorList.size(); ++ctorindex) { fprintf(out, " case %d: { %s *_r = new %s(", ctorindex, cdef->classname.constData(), cdef->classname.constData()); const FunctionDef &f = cdef->constructorList.at(ctorindex); int offset = 1; - int argsCount = f.arguments.count(); + int argsCount = f.arguments.size(); for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (j) @@ -1126,7 +1126,7 @@ void Generator::generateStaticMetacall() if (f.isRawSlot) { fprintf(out, "QMethodRawArguments{ _a }"); } else { - int argsCount = f.arguments.count(); + int argsCount = f.arguments.size(); for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (j) @@ -1196,7 +1196,7 @@ void Generator::generateStaticMetacall() fprintf(out, " {\n"); fprintf(out, " using _t = %s (%s::*)(",f.type.rawName.constData() , cdef->classname.constData()); - int argsCount = f.arguments.count(); + int argsCount = f.arguments.size(); for (int j = 0; j < argsCount; ++j) { const ArgumentDef &a = f.arguments.at(j); if (j) @@ -1462,7 +1462,7 @@ void Generator::generateSignal(FunctionDef *def,int index) } int offset = 1; - for (int j = 0; j < def->arguments.count(); ++j) { + for (int j = 0; j < def->arguments.size(); ++j) { const ArgumentDef &a = def->arguments.at(j); if (j) fputs(", ", out); @@ -1495,7 +1495,7 @@ void Generator::generateSignal(FunctionDef *def,int index) } int i; for (i = 1; i < offset; ++i) - if (i <= def->arguments.count() && def->arguments.at(i - 1).type.isVolatile) + if (i <= def->arguments.size() && def->arguments.at(i - 1).type.isVolatile) fprintf(out, ", const_cast(reinterpret_cast(std::addressof(_t%d)))", i); else fprintf(out, ", const_cast(reinterpret_cast(std::addressof(_t%d)))", i); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 58e28687aa..a74dc246d7 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -368,7 +368,7 @@ QTypeRevision Moc::parseRevision() revisionString.remove(0, 1); revisionString.chop(1); const QList majorMinor = revisionString.split(','); - switch (majorMinor.length()) { + switch (majorMinor.size()) { case 1: { bool ok = false; const int revision = revisionString.toInt(&ok); @@ -1061,7 +1061,7 @@ static QByteArrayList requiredQtContainers(const QList &classes) void Moc::generate(FILE *out, FILE *jsonOutput) { QByteArray fn = filename; - int i = filename.length()-1; + int i = filename.size()-1; while (i > 0 && filename.at(i - 1) != '/' && filename.at(i - 1) != '\\') --i; // skip path if (i >= 0) @@ -1311,7 +1311,7 @@ void Moc::parsePropertyAttributes(PropertyDef &propDef) QByteArray v, v2; if (test(LPAREN)) { v = lexemUntil(RPAREN); - v = v.mid(1, v.length() - 2); // removes the '(' and ')' + v = v.mid(1, v.size() - 2); // removes the '(' and ')' } else if (test(INTEGER_LITERAL)) { v = lexem(); if (l != "REVISION") @@ -1608,7 +1608,7 @@ void Moc::parseInterfaces(ClassDef *def) } } // resolve from classnames to interface ids - for (int i = 0; i < iface.count(); ++i) { + for (int i = 0; i < iface.size(); ++i) { const QByteArray iid = interface2IdMap.value(iface.at(i).className); if (iid.isEmpty()) error("Undefined interface"); @@ -1800,7 +1800,7 @@ void Moc::checkSuperClasses(ClassDef *def) #endif return; } - for (int i = 1; i < def->superclassList.count(); ++i) { + for (int i = 1; i < def->superclassList.size(); ++i) { const QByteArray superClass = def->superclassList.at(i).first; if (knownQObjectClasses.contains(superClass)) { const QByteArray msg @@ -1816,7 +1816,7 @@ void Moc::checkSuperClasses(ClassDef *def) if (interface2IdMap.contains(superClass)) { bool registeredInterface = false; - for (int i = 0; i < def->interfaceList.count(); ++i) + for (int i = 0; i < def->interfaceList.size(); ++i) if (def->interfaceList.at(i).constFirst().className == superClass) { registeredInterface = true; break; @@ -1843,8 +1843,8 @@ void Moc::checkProperties(ClassDef *cdef) // specify get function, for compatibility we accept functions // returning pointers, or const char * for QByteArray. // - QDuplicateTracker definedProperties(cdef->propertyList.count()); - for (int i = 0; i < cdef->propertyList.count(); ++i) { + QDuplicateTracker definedProperties(cdef->propertyList.size()); + for (int i = 0; i < cdef->propertyList.size(); ++i) { PropertyDef &p = cdef->propertyList[i]; if (definedProperties.hasSeen(p.name)) { QByteArray msg = "The property '" + p.name + "' is defined multiple times in class " + cdef->classname + "."; @@ -1866,7 +1866,7 @@ void Moc::checkProperties(ClassDef *cdef) continue; } - for (int j = 0; j < cdef->publicList.count(); ++j) { + for (int j = 0; j < cdef->publicList.size(); ++j) { const FunctionDef &f = cdef->publicList.at(j); if (f.name != p.read) continue; @@ -1893,7 +1893,7 @@ void Moc::checkProperties(ClassDef *cdef) } if (!p.notify.isEmpty()) { int notifyId = -1; - for (int j = 0; j < cdef->signalList.count(); ++j) { + for (int j = 0; j < cdef->signalList.size(); ++j) { const FunctionDef &f = cdef->signalList.at(j); if (f.name != p.notify) { continue; @@ -1907,7 +1907,7 @@ void Moc::checkProperties(ClassDef *cdef) int index = cdef->nonClassSignalList.indexOf(p.notify); if (index == -1) { cdef->nonClassSignalList << p.notify; - p.notifyId = -1 - cdef->nonClassSignalList.count(); + p.notifyId = -1 - cdef->nonClassSignalList.size(); } else { p.notifyId = -2 - index; } diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index c27b2c633f..843a684bda 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -276,8 +276,8 @@ inline QByteArray noRef(const QByteArray &type) { if (type.endsWith('&')) { if (type.endsWith("&&")) - return type.left(type.length()-2); - return type.left(type.length()-1); + return type.left(type.size()-2); + return type.left(type.size()-1); } return type; } diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp index a0c0b7ffaa..0958e26be3 100644 --- a/src/tools/moc/preprocessor.cpp +++ b/src/tools/moc/preprocessor.cpp @@ -980,7 +980,7 @@ static void mergeStringLiterals(Symbols *_symbols) for (Symbols::iterator j = mergeSymbol + 1; j != i; ++j) mergeSymbolLexem.append(j->lex.constData() + j->from + 1, j->len - 2); // append j->unquotedLexem() mergeSymbolLexem.append('"'); - mergeSymbol->len = mergeSymbol->lex.length(); + mergeSymbol->len = mergeSymbol->lex.size(); mergeSymbol->from = 0; i = symbols.erase(mergeSymbol + 1, i); } @@ -1284,7 +1284,7 @@ void Preprocessor::parseDefineArguments(Macro *m) if (!test(PP_RPAREN)) error("missing ')' in macro argument list"); break; - } else if (!is_identifier(l.constData(), l.length())) { + } else if (!is_identifier(l.constData(), l.size())) { error("Unexpected character in macro argument list."); } } -- cgit v1.2.3