diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-10-08 19:56:03 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-10-10 21:02:08 +0200 |
commit | 675a7f59025d40d4813bce70d72ce087024fb008 (patch) | |
tree | 48b9d173109ac94c69b2d2c3e302c404e10563ee | |
parent | 63541a15e21d3ced40e516705c904a4939cb70f1 (diff) | |
download | qttools-675a7f59025d40d4813bce70d72ce087024fb008.tar.gz |
Port from container::count() and length() to size() - V4
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:
const std::string o = "object";
auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };
auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
auto exprOfDeclaredType = [&](auto decl) {
return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
};
return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
};
auto renameMethod = [&] (ArrayRef<StringRef> classes,
StringRef from, StringRef to) {
return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
changeTo(cat(access(o, cat(to)), "()")),
cat("use '", to, "' instead of '", from, "'"));
};
renameMethod(<classes>, "count", "size");
renameMethod(<classes>, "length", "size");
a.k.a qt-port-to-std-compatible-api V4 with config Scope: 'Container'.
Change-Id: I58e1b41b91c34d2e860dbb5847b3752edbfc6fc9
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
-rw-r--r-- | src/assistant/assistant/bookmarkfiltermodel.cpp | 6 | ||||
-rw-r--r-- | src/assistant/assistant/openpagesmanager.cpp | 2 | ||||
-rw-r--r-- | src/linguist/linguist/batchtranslationdialog.cpp | 4 | ||||
-rw-r--r-- | src/linguist/linguist/phraseview.cpp | 4 | ||||
-rw-r--r-- | src/linguist/lupdate/cpp.cpp | 36 | ||||
-rw-r--r-- | src/linguist/lupdate/python.cpp | 2 | ||||
-rw-r--r-- | src/linguist/shared/translator.cpp | 10 | ||||
-rw-r--r-- | src/qdbus/qdbus/qdbus.cpp | 2 | ||||
-rw-r--r-- | src/qdoc/config.cpp | 6 | ||||
-rw-r--r-- | src/qdoc/cppcodeparser.cpp | 4 | ||||
-rw-r--r-- | src/qdoc/docbookgenerator.cpp | 8 | ||||
-rw-r--r-- | src/qdoc/htmlgenerator.cpp | 18 |
12 files changed, 51 insertions, 51 deletions
diff --git a/src/assistant/assistant/bookmarkfiltermodel.cpp b/src/assistant/assistant/bookmarkfiltermodel.cpp index 61954d8f9..89fe5cad7 100644 --- a/src/assistant/assistant/bookmarkfiltermodel.cpp +++ b/src/assistant/assistant/bookmarkfiltermodel.cpp @@ -62,7 +62,7 @@ void BookmarkFilterModel::setSourceModel(QAbstractItemModel *_sourceModel) int BookmarkFilterModel::rowCount(const QModelIndex &index) const { Q_UNUSED(index); - return cache.count(); + return cache.size(); } int BookmarkFilterModel::columnCount(const QModelIndex &index) const @@ -76,7 +76,7 @@ int BookmarkFilterModel::columnCount(const QModelIndex &index) const QModelIndex BookmarkFilterModel::mapToSource(const QModelIndex &proxyIndex) const { const int row = proxyIndex.row(); - if (proxyIndex.isValid() && row >= 0 && row < cache.count()) + if (proxyIndex.isValid() && row >= 0 && row < cache.size()) return cache[row]; return QModelIndex(); } @@ -96,7 +96,7 @@ QModelIndex BookmarkFilterModel::index(int row, int column, const QModelIndex &index) const { Q_UNUSED(index); - if (row < 0 || column < 0 || cache.count() <= row + if (row < 0 || column < 0 || cache.size() <= row || !sourceModel || sourceModel->columnCount() <= column) { return QModelIndex(); } diff --git a/src/assistant/assistant/openpagesmanager.cpp b/src/assistant/assistant/openpagesmanager.cpp index 65f37b19c..ca66bdde3 100644 --- a/src/assistant/assistant/openpagesmanager.cpp +++ b/src/assistant/assistant/openpagesmanager.cpp @@ -146,7 +146,7 @@ void OpenPagesManager::closeCurrentPage() = m_openPagesWidget->selectionModel()->selectedRows(); if (selectedIndexes.isEmpty()) return; - Q_ASSERT(selectedIndexes.count() == 1); + Q_ASSERT(selectedIndexes.size() == 1); removePage(selectedIndexes.first().row()); } diff --git a/src/linguist/linguist/batchtranslationdialog.cpp b/src/linguist/linguist/batchtranslationdialog.cpp index c3c9ea8b2..cedd0d796 100644 --- a/src/linguist/linguist/batchtranslationdialog.cpp +++ b/src/linguist/linguist/batchtranslationdialog.cpp @@ -129,7 +129,7 @@ void BatchTranslationDialog::startTranslation() void BatchTranslationDialog::movePhraseBookUp() { QModelIndexList indexes = m_ui.phrasebookList->selectionModel()->selectedIndexes(); - if (indexes.count() <= 0) return; + if (indexes.size() <= 0) return; QModelIndex sel = indexes[0]; int row = sel.row(); @@ -145,7 +145,7 @@ void BatchTranslationDialog::movePhraseBookUp() void BatchTranslationDialog::movePhraseBookDown() { QModelIndexList indexes = m_ui.phrasebookList->selectionModel()->selectedIndexes(); - if (indexes.count() <= 0) return; + if (indexes.size() <= 0) return; QModelIndex sel = indexes[0]; int row = sel.row(); diff --git a/src/linguist/linguist/phraseview.cpp b/src/linguist/linguist/phraseview.cpp index 3cc4718a7..81e7d49de 100644 --- a/src/linguist/linguist/phraseview.cpp +++ b/src/linguist/linguist/phraseview.cpp @@ -194,9 +194,9 @@ static CandidateList similarTextHeuristicCandidates(MultiDataModel *model, int m int score = stringmatcher.getSimilarityScore(s); - if (candidates.count() == maxCandidates && score > scores[maxCandidates - 1]) + if (candidates.size() == maxCandidates && score > scores[maxCandidates - 1]) candidates.removeLast(); - if (candidates.count() < maxCandidates && score >= textSimilarityThreshold ) { + if (candidates.size() < maxCandidates && score >= textSimilarityThreshold ) { Candidate cand(mtm.context(), s, mtm.comment(), mtm.translation()); int i; diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index a851dc843..4510d4c2d 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -904,17 +904,17 @@ void CppParser::loadState(const CppParserState &state) Namespace *CppParser::modifyNamespace(NamespaceList *namespaces, bool haveLast) { Namespace *pns, *ns = &results->rootNamespace; - for (int i = 1; i < namespaces->count(); ++i) { + for (int i = 1; i < namespaces->size(); ++i) { pns = ns; if (!(ns = pns->children.value(namespaces->at(i)))) { do { ns = new Namespace; - if (haveLast || i < namespaces->count() - 1) + if (haveLast || i < namespaces->size() - 1) if (const Namespace *ons = findNamespace(*namespaces, i + 1)) ns->classDef = ons->classDef; pns->children.insert(namespaces->at(i), ns); pns = ns; - } while (++i < namespaces->count()); + } while (++i < namespaces->size()); break; } } @@ -925,10 +925,10 @@ QString CppParser::stringifyNamespace(int start, const NamespaceList &namespaces { QString ret; int l = 0; - for (int j = start; j < namespaces.count(); ++j) + for (int j = start; j < namespaces.size(); ++j) l += namespaces.at(j).value().size(); - ret.reserve(l + qMax(0, (namespaces.count() - start - 1)) * 2); - for (int i = start; i < namespaces.count(); ++i) { + ret.reserve(l + qMax(0, (namespaces.size() - start - 1)) * 2); + for (int i = start; i < namespaces.size(); ++i) { if (i > start) ret += QLatin1String("::"); ret += namespaces.at(i).value(); @@ -1047,7 +1047,7 @@ bool CppParser::fullyQualify(const NamespaceList &namespaces, int nsCnt, if (segments.first().value().isEmpty()) { // fully qualified - if (segments.count() == 1) { + if (segments.size() == 1) { resolved->clear(); *resolved << HashString(QString()); return true; @@ -1062,8 +1062,8 @@ bool CppParser::fullyQualify(const NamespaceList &namespaces, int nsCnt, do { if (qualifyOne(namespaces, nsIdx + 1, segments[initSegIdx], resolved)) { int segIdx = initSegIdx; - while (++segIdx < segments.count()) { - if (!qualifyOne(*resolved, resolved->count(), segments[segIdx], resolved)) { + while (++segIdx < segments.size()) { + if (!qualifyOne(*resolved, resolved->size(), segments[segIdx], resolved)) { if (unresolved) *unresolved = segments.mid(segIdx); return false; @@ -1083,7 +1083,7 @@ bool CppParser::fullyQualify(const NamespaceList &namespaces, const NamespaceList &segments, bool isDeclaration, NamespaceList *resolved, NamespaceList *unresolved) const { - return fullyQualify(namespaces, namespaces.count(), + return fullyQualify(namespaces, namespaces.size(), segments, isDeclaration, resolved, unresolved); } @@ -1109,7 +1109,7 @@ const Namespace *CppParser::findNamespace(const NamespaceList &namespaces, int n { const Namespace *ns = 0; if (nsCount == -1) - nsCount = namespaces.count(); + nsCount = namespaces.size(); visitNamespace(namespaces, nsCount, &CppParser::findNamespaceCallback, &ns); return ns; } @@ -1123,7 +1123,7 @@ void CppParser::enterNamespace(NamespaceList *namespaces, const HashString &name void CppParser::truncateNamespaces(NamespaceList *namespaces, int length) { - if (namespaces->count() > length) + if (namespaces->size() > length) namespaces->erase(namespaces->begin() + length, namespaces->end()); } @@ -1246,7 +1246,7 @@ void CppParser::processInclude(const QString &file, ConversionData &cd, const QS // it. Otherwise it is safe to process it stand-alone and re-use the parsed // namespace data for inclusion into other files. bool isIndirect = false; - if (namespaces.count() == 1 && functionContext.count() == 1 + if (namespaces.size() == 1 && functionContext.size() == 1 && functionContextUnresolved.isEmpty() && pendingContext.isEmpty() && !CppFiles::isBlacklisted(cleanFile) && isHeader(cleanFile)) { @@ -1454,7 +1454,7 @@ void CppParser::handleTr(QString &prefix, bool plural) } if (prefix.isEmpty()) { if (functionContextUnresolved.isEmpty()) { - int idx = functionContext.length(); + int idx = functionContext.size(); if (idx < 2) { yyMsg() << "tr() cannot be called without context\n"; return; @@ -1758,10 +1758,10 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac yyMsg() << "Ignoring definition of undeclared qualified class\n"; break; } - namespaceDepths.push(namespaces.count()); + namespaceDepths.push(namespaces.size()); namespaces = nsl; } else { - namespaceDepths.push(namespaces.count()); + namespaceDepths.push(namespaces.size()); } enterNamespace(&namespaces, fct); @@ -1794,7 +1794,7 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac ns = HashString(text); } if (yyTok == Tok_LeftBrace) { - namespaceDepths.push(namespaces.count()); + namespaceDepths.push(namespaces.size()); for (const auto &nns : nestedNamespaces) enterNamespace(&namespaces, nns); enterNamespace(&namespaces, ns); @@ -1827,7 +1827,7 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac } } else if (yyTok == Tok_LeftBrace) { // Anonymous namespace - namespaceDepths.push(namespaces.count()); + namespaceDepths.push(namespaces.size()); metaExpected = true; yyTok = getToken(); } diff --git a/src/linguist/lupdate/python.cpp b/src/linguist/lupdate/python.cpp index 79496b9be..560984e54 100644 --- a/src/linguist/lupdate/python.cpp +++ b/src/linguist/lupdate/python.cpp @@ -97,7 +97,7 @@ static int getCharFromFile() } else { if (yyIndentationSize == 1 && yyContinuousSpaceCount > yyIndentationSize) yyIndentationSize = yyContinuousSpaceCount; - if (yyCountingIndentation && yyContextStack.count() > 1) { + if (yyCountingIndentation && yyContextStack.size() > 1) { ContextPair& top = yyContextStack.top(); if (top.second == 0 && yyContinuousSpaceCount > 0) { top.second = yyContinuousSpaceCount; diff --git a/src/linguist/shared/translator.cpp b/src/linguist/shared/translator.cpp index 75772d9f6..dba9c84cc 100644 --- a/src/linguist/shared/translator.cpp +++ b/src/linguist/shared/translator.cpp @@ -80,7 +80,7 @@ void Translator::ensureIndexed() const m_ctxCmtIdx.clear(); m_idMsgIdx.clear(); m_msgIdx.clear(); - for (int i = 0; i < m_messages.count(); i++) + for (int i = 0; i < m_messages.size(); i++) addIndex(i, m_messages.at(i)); } } @@ -155,7 +155,7 @@ void Translator::extend(const TranslatorMessage &msg, ConversionData &cd) void Translator::insert(int idx, const TranslatorMessage &msg) { if (m_indexOk) { - if (idx == m_messages.count()) + if (idx == m_messages.size()) addIndex(idx, msg); else m_indexOk = false; @@ -165,7 +165,7 @@ void Translator::insert(int idx, const TranslatorMessage &msg) void Translator::append(const TranslatorMessage &msg) { - insert(m_messages.count(), msg); + insert(m_messages.size(), msg); } void Translator::appendSorted(const TranslatorMessage &msg) @@ -558,7 +558,7 @@ Translator::Duplicates Translator::resolveDuplicates() Duplicates dups; QSet<TranslatorMessageIdPtr> idRefs; QSet<TranslatorMessageContentPtr> contentRefs; - for (int i = 0; i < m_messages.count();) { + for (int i = 0; i < m_messages.size();) { const TranslatorMessage &msg = m_messages.at(i); TranslatorMessage *omsg; int oi; @@ -679,7 +679,7 @@ void Translator::normalizeTranslations(ConversionData &cd) if (getNumerusInfo(l, c, 0, &forms, 0)) numPlurals = forms.size(); // includes singular } - for (int i = 0; i < m_messages.count(); ++i) { + for (int i = 0; i < m_messages.size(); ++i) { const TranslatorMessage &msg = m_messages.at(i); QStringList tlns = msg.translations(); int ccnt = msg.isPlural() ? numPlurals : 1; diff --git a/src/qdbus/qdbus/qdbus.cpp b/src/qdbus/qdbus/qdbus.cpp index 89be6c101..f18fdca3a 100644 --- a/src/qdbus/qdbus/qdbus.cpp +++ b/src/qdbus/qdbus/qdbus.cpp @@ -338,7 +338,7 @@ static int placeCall(const QString &service, const QString &path, const QString } params += p; } - if (params.count() == types.size() && args.isEmpty()) + if (params.size() == types.size() && args.isEmpty()) matchFound = true; else if (knownIds.isEmpty()) { fprintf(stderr, "Invalid number of parameters\n"); diff --git a/src/qdoc/config.cpp b/src/qdoc/config.cpp index 2b2994a02..5a54d5edc 100644 --- a/src/qdoc/config.cpp +++ b/src/qdoc/config.cpp @@ -163,7 +163,7 @@ void MetaStack::process(QChar ch, const Location &location) push(MetaStackEntry()); top().open(); } else if (ch == QLatin1Char('}')) { - if (count() == 1) + if (size() == 1) location.fatal(QStringLiteral("Unexpected '}'")); top().close(); @@ -175,7 +175,7 @@ void MetaStack::process(QChar ch, const Location &location) for (const auto &suffix : suffixes) top().next << prefix + suffix; } - } else if (ch == QLatin1Char(',') && count() > 1) { + } else if (ch == QLatin1Char(',') && size() > 1) { top().close(); top().open(); } else { @@ -189,7 +189,7 @@ void MetaStack::process(QChar ch, const Location &location) */ QStringList MetaStack::getExpanded(const Location &location) { - if (count() > 1) + if (size() > 1) location.fatal(QStringLiteral("Missing '}'")); top().close(); diff --git a/src/qdoc/cppcodeparser.cpp b/src/qdoc/cppcodeparser.cpp index 5dbd7d59a..aa9c8864d 100644 --- a/src/qdoc/cppcodeparser.cpp +++ b/src/qdoc/cppcodeparser.cpp @@ -402,8 +402,8 @@ void CppCodeParser::processQmlProperties(const Doc &doc, NodeList &nodes, DocLis // valid nodes. Note that it's important to do this *after* constructing // the topic nodes - which need to be written to index before the related // scn. - if (sharedNodes.count() > 1) { - auto *scn = new SharedCommentNode(qmlType, sharedNodes.count(), group); + if (sharedNodes.size() > 1) { + auto *scn = new SharedCommentNode(qmlType, sharedNodes.size(), group); scn->setLocation(doc.startLocation()); nodes.append(scn); docs.append(doc); diff --git a/src/qdoc/docbookgenerator.cpp b/src/qdoc/docbookgenerator.cpp index 1145f7033..9b72680a9 100644 --- a/src/qdoc/docbookgenerator.cpp +++ b/src/qdoc/docbookgenerator.cpp @@ -1317,7 +1317,7 @@ void DocBookGenerator::generateCompactList(ListType listType, const Node *relati int paragraphOffset[NumParagraphs + 1]; // 37 + 1 paragraphOffset[0] = 0; for (int i = 0; i < NumParagraphs; i++) // i = 0..36 - paragraphOffset[i + 1] = paragraphOffset[i] + paragraph[i].count(); + paragraphOffset[i + 1] = paragraphOffset[i] + paragraph[i].size(); // No table of contents in DocBook. @@ -1327,8 +1327,8 @@ void DocBookGenerator::generateCompactList(ListType listType, const Node *relati QString previousName; bool multipleOccurrences = false; - for (int i = 0; i < nmm.count(); i++) { - while ((curParNr < NumParagraphs) && (curParOffset == paragraph[curParNr].count())) { + for (int i = 0; i < nmm.size(); i++) { + while ((curParNr < NumParagraphs) && (curParOffset == paragraph[curParNr].size())) { ++curParNr; curParOffset = 0; } @@ -1421,7 +1421,7 @@ void DocBookGenerator::generateCompactList(ListType listType, const Node *relati newLine(); curParOffset++; } - if (nmm.count() > 0) { + if (nmm.size() > 0) { m_writer->writeEndElement(); // variablelist } } diff --git a/src/qdoc/htmlgenerator.cpp b/src/qdoc/htmlgenerator.cpp index 4f859558b..3d1806240 100644 --- a/src/qdoc/htmlgenerator.cpp +++ b/src/qdoc/htmlgenerator.cpp @@ -2754,7 +2754,7 @@ void HtmlGenerator::generateCompactList(ListType listType, const Node *relative, qsizetype paragraphOffset[NumParagraphs + 1]; // 37 + 1 paragraphOffset[0] = 0; for (int i = 0; i < NumParagraphs; i++) // i = 0..36 - paragraphOffset[i + 1] = paragraphOffset[i] + paragraph[i].count(); + paragraphOffset[i + 1] = paragraphOffset[i] + paragraph[i].size(); /* Output the alphabet as a row of links. @@ -2780,8 +2780,8 @@ void HtmlGenerator::generateCompactList(ListType listType, const Node *relative, QString previousName; bool multipleOccurrences = false; - for (int i = 0; i < nmm.count(); i++) { - while ((curParNr < NumParagraphs) && (curParOffset == paragraph[curParNr].count())) { + for (int i = 0; i < nmm.size(); i++) { + while ((curParNr < NumParagraphs) && (curParOffset == paragraph[curParNr].size())) { ++curParNr; curParOffset = 0; } @@ -2856,7 +2856,7 @@ void HtmlGenerator::generateCompactList(ListType listType, const Node *relative, out() << "</dd>\n"; curParOffset++; } - if (nmm.count() > 0) + if (nmm.size() > 0) out() << "</dl>\n"; out() << "</div>\n"; @@ -3016,7 +3016,7 @@ void HtmlGenerator::generateSection(const NodeVector &nv, const Node *relative, if (!nv.isEmpty()) { bool twoColumn = false; if (nv.first()->isProperty()) { - twoColumn = (nv.count() >= 5); + twoColumn = (nv.size() >= 5); alignNames = false; } if (alignNames) { @@ -3036,7 +3036,7 @@ void HtmlGenerator::generateSection(const NodeVector &nv, const Node *relative, if (alignNames) { out() << "<tr><td class=\"memItemLeft rightAlign topAlign\"> "; } else { - if (twoColumn && i == (nv.count() + 1) / 2) + if (twoColumn && i == (nv.size() + 1) / 2) out() << "</ul></td><td class=\"topAlign\"><ul>\n"; out() << "<li class=\"fn\">"; } @@ -3070,9 +3070,9 @@ void HtmlGenerator::generateSectionList(const Section §ion, const Node *rela bool twoColumn = false; if (section.style() == Section::AllMembers) { alignNames = false; - twoColumn = (members.count() >= 16); + twoColumn = (members.size() >= 16); } else if (members.first()->isProperty()) { - twoColumn = (members.count() >= 5); + twoColumn = (members.size() >= 5); alignNames = false; } if (alignNames) { @@ -3092,7 +3092,7 @@ void HtmlGenerator::generateSectionList(const Section §ion, const Node *rela if (alignNames) { out() << "<tr><td class=\"memItemLeft topAlign rightAlign\"> "; } else { - if (twoColumn && i == (members.count() + 1) / 2) + if (twoColumn && i == (members.size() + 1) / 2) out() << "</ul></td><td class=\"topAlign\"><ul>\n"; out() << "<li class=\"fn\">"; } |