qmljs: Remove foreach usage

Task-number: QTCREATORBUG-27464
Change-Id: Ifdb8cf514dfe328e0a64bde1beff3e63a4b7fbc3
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Artem Sokolovskii
2022-12-19 16:41:00 +01:00
parent 50ebf1f824
commit f0556b08b8
26 changed files with 138 additions and 125 deletions

View File

@@ -308,7 +308,7 @@ bool ArrayType::isLessThan(const Type *other) const
QList<Symbol *> Struct::members() const QList<Symbol *> Struct::members() const
{ {
QList<Symbol *> m; QList<Symbol *> m;
for (Symbol *s : std::as_const(_members)) { for (Symbol *s : _members) {
if (! s->name().isEmpty()) if (! s->name().isEmpty())
m.append(s); m.append(s);
} }
@@ -322,7 +322,7 @@ void Struct::add(Symbol *member)
Symbol *Struct::find(const QString &name) const Symbol *Struct::find(const QString &name) const
{ {
for (Symbol *s : std::as_const(_members)) { for (Symbol *s : _members) {
if (s->name() == name) if (s->name() == name)
return s; return s;
} }
@@ -411,7 +411,7 @@ bool Function::isLessThan(const Type *other) const
QList<Symbol *> Function::members() const QList<Symbol *> Function::members() const
{ {
QList<Symbol *> m; QList<Symbol *> m;
for (Argument *arg : std::as_const(_arguments)) { for (Argument *arg : _arguments) {
if (! arg->name().isEmpty()) if (! arg->name().isEmpty())
m.append(arg); m.append(arg);
} }
@@ -420,7 +420,7 @@ QList<Symbol *> Function::members() const
Symbol *Function::find(const QString &name) const Symbol *Function::find(const QString &name) const
{ {
for (Argument *arg : std::as_const(_arguments)) { for (Argument *arg : _arguments) {
if (arg->name() == name) if (arg->name() == name)
return arg; return arg;
} }

View File

@@ -283,11 +283,11 @@ void FakeMetaObject::setExportMetaObjectRevision(int exportIndex, int metaObject
m_exports[exportIndex].metaObjectRevision = metaObjectRevision; m_exports[exportIndex].metaObjectRevision = metaObjectRevision;
} }
QList<FakeMetaObject::Export> FakeMetaObject::exports() const const QList<FakeMetaObject::Export> FakeMetaObject::exports() const
{ return m_exports; } { return m_exports; }
FakeMetaObject::Export FakeMetaObject::exportInPackage(const QString &package) const FakeMetaObject::Export FakeMetaObject::exportInPackage(const QString &package) const
{ {
for (const Export &exp : std::as_const(m_exports)) { for (const Export &exp : m_exports) {
if (exp.package == package) if (exp.package == package)
return exp; return exp;
} }

View File

@@ -162,7 +162,7 @@ public:
void addExport(const QString &name, const QString &package, ComponentVersion version); void addExport(const QString &name, const QString &package, ComponentVersion version);
void setExportMetaObjectRevision(int exportIndex, int metaObjectRevision); void setExportMetaObjectRevision(int exportIndex, int metaObjectRevision);
QList<Export> exports() const; const QList<Export> exports() const;
Export exportInPackage(const QString &package) const; Export exportInPackage(const QString &package) const;
void setSuperclassName(const QString &superclass); void setSuperclassName(const QString &superclass);

View File

@@ -107,7 +107,7 @@ bool JsonCheck::visit(ObjectPattern *ast)
} }
QStringList missing; QStringList missing;
foreach (const QString &property, properties) { for (const QString &property : properties) {
if (!propertiesFound.contains(property)) { if (!propertiesFound.contains(property)) {
m_schema->enterNestedPropertySchema(property); m_schema->enterNestedPropertySchema(property);
if (m_schema->required()) if (m_schema->required())

View File

@@ -75,7 +75,7 @@ public:
_comments.append(QmlJS::SourceLocation(pos, len, line, col)); _comments.append(QmlJS::SourceLocation(pos, len, line, col));
} }
QList<SourceLocation> comments() const { return _comments; } const QList<SourceLocation> comments() const { return _comments; }
Lexer *lexer() const { return _lexer; } Lexer *lexer() const { return _lexer; }
void setLexer(Lexer *lexer) { _lexer = lexer; } void setLexer(Lexer *lexer) { _lexer = lexer; }

View File

@@ -96,7 +96,7 @@ void TrieNode::complete(QStringList &res, const TrieNode::Ptr &trie,
complete(res, trie->postfixes[0],QString(), base2, flags); complete(res, trie->postfixes[0],QString(), base2, flags);
return; return;
} }
foreach (TrieNode::Ptr t, trie->postfixes) { for (TrieNode::Ptr t : std::as_const(trie->postfixes)) {
if ((flags & Partial) != 0) if ((flags & Partial) != 0)
res.append(base2 + t->prefix); res.append(base2 + t->prefix);
else else
@@ -104,7 +104,7 @@ void TrieNode::complete(QStringList &res, const TrieNode::Ptr &trie,
} }
return; return;
} }
foreach (const TrieNode::Ptr v, trie->postfixes) { for (const TrieNode::Ptr &v : std::as_const(trie->postfixes)) {
QString::const_iterator vi = v->prefix.constBegin(), vEnd = v->prefix.constEnd(); QString::const_iterator vi = v->prefix.constBegin(), vEnd = v->prefix.constEnd();
if (vi != vEnd && (*vi == *j || ((flags & CaseInsensitive) != 0 if (vi != vEnd && (*vi == *j || ((flags & CaseInsensitive) != 0
&& vi->toLower() == j->toLower()) || ((flags & SkipChars) != 0))) && vi->toLower() == j->toLower()) || ((flags & SkipChars) != 0)))
@@ -199,7 +199,7 @@ bool TrieNode::contains(const TrieNode::Ptr &trie,
if ((flags & Partial) != 0) if ((flags & Partial) != 0)
return true; return true;
if (i == iEnd) { if (i == iEnd) {
foreach (const TrieNode::Ptr t, trie->postfixes) for (const TrieNode::Ptr &t : std::as_const(trie->postfixes))
if (t->prefix.isEmpty()) if (t->prefix.isEmpty())
return true; return true;
return trie->postfixes.isEmpty(); return trie->postfixes.isEmpty();
@@ -209,7 +209,7 @@ bool TrieNode::contains(const TrieNode::Ptr &trie,
if (i != iEnd) if (i != iEnd)
return false; return false;
bool res = false; bool res = false;
foreach (const TrieNode::Ptr v, trie->postfixes) { for (const TrieNode::Ptr &v : std::as_const(trie->postfixes)) {
QString::const_iterator vi = v->prefix.constBegin(), vEnd = v->prefix.constEnd(); QString::const_iterator vi = v->prefix.constBegin(), vEnd = v->prefix.constEnd();
if (vi != vEnd && (*vi == *j || ((flags & CaseInsensitive) != 0 if (vi != vEnd && (*vi == *j || ((flags & CaseInsensitive) != 0
&& vi->toLower() == j->toLower()))) && vi->toLower() == j->toLower())))
@@ -312,7 +312,7 @@ std::pair<TrieNode::Ptr,int> TrieNode::intersectF(
if (v1->postfixes.isEmpty() || v2->postfixes.isEmpty()) { if (v1->postfixes.isEmpty() || v2->postfixes.isEmpty()) {
if (v1->postfixes.isEmpty() && v2->postfixes.isEmpty()) if (v1->postfixes.isEmpty() && v2->postfixes.isEmpty())
return std::make_pair(v1, 3); return std::make_pair(v1, 3);
foreach (P t1, v1->postfixes) for (P t1 : std::as_const(v1->postfixes))
if (t1->prefix.isEmpty()) { if (t1->prefix.isEmpty()) {
if (index1 == 0) if (index1 == 0)
return std::make_pair(v2, 2); return std::make_pair(v2, 2);
@@ -320,7 +320,7 @@ std::pair<TrieNode::Ptr,int> TrieNode::intersectF(
return std::make_pair(TrieNode::create( return std::make_pair(TrieNode::create(
v1->prefix.left(index1).append(v2->prefix), v2->postfixes),0); v1->prefix.left(index1).append(v2->prefix), v2->postfixes),0);
} }
foreach (P t2, v2->postfixes) for (P t2 : std::as_const(v2->postfixes))
if (t2->prefix.isEmpty()) if (t2->prefix.isEmpty())
return std::make_pair(v1,1); return std::make_pair(v1,1);
return std::make_pair(P(nullptr), 0); return std::make_pair(P(nullptr), 0);
@@ -328,10 +328,10 @@ std::pair<TrieNode::Ptr,int> TrieNode::intersectF(
QMap<QString,int> p1, p2; QMap<QString,int> p1, p2;
QList<P> p3; QList<P> p3;
int ii = 0; int ii = 0;
foreach (P t1, v1->postfixes) for (P t1 : std::as_const(v1->postfixes))
p1[t1->prefix] = ii++; p1[t1->prefix] = ii++;
ii = 0; ii = 0;
foreach (P t2, v2->postfixes) for (P t2 : std::as_const(v2->postfixes))
p2[t2->prefix] = ii++; p2[t2->prefix] = ii++;
MapIterator p1Ptr = p1.constBegin(), p2Ptr = p2.constBegin(), MapIterator p1Ptr = p1.constBegin(), p2Ptr = p2.constBegin(),
p1End = p1.constEnd(), p2End = p2.constEnd(); p1End = p1.constEnd(), p2End = p2.constEnd();
@@ -419,7 +419,7 @@ std::pair<TrieNode::Ptr,int> TrieNode::intersectF(
} }
} }
// i == iEnd && j != jEnd // i == iEnd && j != jEnd
foreach (const P &t1, v1->postfixes) for (const P &t1 : std::as_const(v1->postfixes))
if ((!t1->prefix.isEmpty()) && t1->prefix.at(0) == *j) { if ((!t1->prefix.isEmpty()) && t1->prefix.at(0) == *j) {
std::pair<P,int> res = intersectF(v2,t1,j-v2->prefix.constBegin()); std::pair<P,int> res = intersectF(v2,t1,j-v2->prefix.constBegin());
if (index1 == 0) if (index1 == 0)
@@ -432,7 +432,7 @@ std::pair<TrieNode::Ptr,int> TrieNode::intersectF(
return std::make_pair(P(nullptr), 0); return std::make_pair(P(nullptr), 0);
} else { } else {
// i != iEnd && j == jEnd // i != iEnd && j == jEnd
foreach (P t2, v2->postfixes) for (P t2 : std::as_const(v2->postfixes))
if (!t2->prefix.isEmpty() && t2->prefix.at(0) == *i) { if (!t2->prefix.isEmpty() && t2->prefix.at(0) == *i) {
std::pair<P,int> res = intersectF(v1,t2,i-v1->prefix.constBegin()); std::pair<P,int> res = intersectF(v1,t2,i-v1->prefix.constBegin());
return std::make_pair(res.first, (res.second & 1)); return std::make_pair(res.first, (res.second & 1));
@@ -468,7 +468,8 @@ QDebug &TrieNode::printStrings(QDebug &dbg, const TrieNode::Ptr &trie)
return dbg << "Trie{*NULL*}"; return dbg << "Trie{*NULL*}";
dbg<<"Trie{ contents:["; dbg<<"Trie{ contents:[";
bool first = true; bool first = true;
foreach (const QString &s, stringList(trie)) { const QStringList list = stringList(trie);
for (const QString &s : list) {
if (!first) if (!first)
dbg << ","; dbg << ",";
else else
@@ -491,7 +492,7 @@ QDebug &TrieNode::describe(QDebug &dbg, const TrieNode::Ptr &trie,
dbg << trie->prefix; dbg << trie->prefix;
int newIndent = indent + trie->prefix.size() + 3; int newIndent = indent + trie->prefix.size() + 3;
bool newLine = false; bool newLine = false;
foreach (TrieNode::Ptr sub, trie->postfixes) { for (TrieNode::Ptr sub : std::as_const(trie->postfixes)) {
if (newLine) { if (newLine) {
dbg << "\n"; dbg << "\n";
for (int i=0; i < newIndent; ++i) for (int i=0; i < newIndent; ++i)

View File

@@ -88,7 +88,7 @@ template <typename T> void enumerateTrieNode(const TrieNode::Ptr &trie, T &t,
if (trie.isNull()) if (trie.isNull())
return; return;
base.append(trie->prefix); base.append(trie->prefix);
foreach (const TrieNode::Ptr subT, trie->postfixes) { for (const TrieNode::Ptr subT : std::as_const(trie->postfixes)) {
enumerateTrieNode(subT,t,base); enumerateTrieNode(subT,t,base);
} }
if (trie->postfixes.isEmpty()) if (trie->postfixes.isEmpty())

View File

@@ -54,7 +54,7 @@ bool Bind::isJsLibrary() const
return _isJsLibrary; return _isJsLibrary;
} }
QList<ImportInfo> Bind::imports() const const QList<ImportInfo> Bind::imports() const
{ {
return _imports; return _imports;
} }
@@ -86,7 +86,8 @@ bool Bind::usesQmlPrototype(ObjectValue *prototype,
if (componentName.isEmpty()) if (componentName.isEmpty())
return false; return false;
foreach (const ObjectValue *object, _qmlObjectsByPrototypeName.values(componentName)) { QList<const ObjectValue *> values = _qmlObjectsByPrototypeName.values(componentName);
for (const ObjectValue *object : values) {
// resolve and check the prototype // resolve and check the prototype
const ObjectValue *resolvedPrototype = object->prototype(context); const ObjectValue *resolvedPrototype = object->prototype(context);
if (resolvedPrototype == prototype) if (resolvedPrototype == prototype)

View File

@@ -25,7 +25,7 @@ public:
~Bind(); ~Bind();
bool isJsLibrary() const; bool isJsLibrary() const;
QList<ImportInfo> imports() const; const QList<ImportInfo> imports() const;
ObjectValue *idEnvironment() const; ObjectValue *idEnvironment() const;
ObjectValue *rootObjectValue() const; ObjectValue *rootObjectValue() const;

View File

@@ -142,7 +142,8 @@ void QmlBundle::printEscaped(QTextStream &s, const QString &str)
void QmlBundle::writeTrie(QTextStream &stream, const Trie &t, const QString &indent) { void QmlBundle::writeTrie(QTextStream &stream, const Trie &t, const QString &indent) {
stream << QLatin1Char('['); stream << QLatin1Char('[');
bool firstLine = true; bool firstLine = true;
foreach (const QString &i, t.stringList()) { const QStringList list = t.stringList();
for (const QString &i : list) {
if (firstLine) if (firstLine)
firstLine = false; firstLine = false;
else else
@@ -197,7 +198,8 @@ QStringList QmlBundle::maybeReadTrie(Trie &trie, Utils::JsonObjectValue *config,
Utils::JsonValue *imp0 = config->member(propertyName); Utils::JsonValue *imp0 = config->member(propertyName);
Utils::JsonArrayValue *imp = ((imp0 != nullptr) ? imp0->toArray() : nullptr); Utils::JsonArrayValue *imp = ((imp0 != nullptr) ? imp0->toArray() : nullptr);
if (imp != nullptr) { if (imp != nullptr) {
foreach (Utils::JsonValue *v, imp->elements()) { const QList<Utils::JsonValue *> elements = imp->elements();
for (Utils::JsonValue *v : elements) {
Utils::JsonStringValue *impStr = ((v != nullptr) ? v->toString() : nullptr); Utils::JsonStringValue *impStr = ((v != nullptr) ? v->toString() : nullptr);
if (impStr != nullptr) { if (impStr != nullptr) {
trie.insert(impStr->value()); trie.insert(impStr->value());
@@ -272,14 +274,14 @@ void QmlLanguageBundles::mergeBundleForLanguage(Dialect l, const QmlBundle &bund
m_bundles.insert(l,bundle); m_bundles.insert(l,bundle);
} }
QList<Dialect> QmlLanguageBundles::languages() const const QList<Dialect> QmlLanguageBundles::languages() const
{ {
return m_bundles.keys(); return m_bundles.keys();
} }
void QmlLanguageBundles::mergeLanguageBundles(const QmlLanguageBundles &o) void QmlLanguageBundles::mergeLanguageBundles(const QmlLanguageBundles &o)
{ {
foreach (Dialect l, o.languages()) for (Dialect l : o.languages())
mergeBundleForLanguage(l, o.bundleForLanguage(l)); mergeBundleForLanguage(l, o.bundleForLanguage(l));
} }

View File

@@ -74,7 +74,7 @@ class QMLJS_EXPORT QmlLanguageBundles
public: public:
QmlBundle bundleForLanguage(Dialect l) const; QmlBundle bundleForLanguage(Dialect l) const;
void mergeBundleForLanguage(Dialect l, const QmlBundle &bundle); void mergeBundleForLanguage(Dialect l, const QmlBundle &bundle);
QList<Dialect> languages() const; const QList<Dialect> languages() const;
void mergeLanguageBundles(const QmlLanguageBundles &); void mergeLanguageBundles(const QmlLanguageBundles &);
private: private:
QHash<Dialect,QmlBundle> m_bundles; QHash<Dialect,QmlBundle> m_bundles;

View File

@@ -433,7 +433,8 @@ protected:
} }
if (_possiblyUndeclaredUses.contains(name)) { if (_possiblyUndeclaredUses.contains(name)) {
foreach (const SourceLocation &loc, _possiblyUndeclaredUses.value(name)) { const QList<SourceLocation> values = _possiblyUndeclaredUses.value(name);
for (const SourceLocation &loc : values) {
addMessage(WarnVarUsedBeforeDeclaration, loc, name); addMessage(WarnVarUsedBeforeDeclaration, loc, name);
} }
_possiblyUndeclaredUses.remove(name); _possiblyUndeclaredUses.remove(name);
@@ -469,7 +470,8 @@ protected:
if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(ast)) { if (FunctionDeclaration *decl = cast<FunctionDeclaration *>(ast)) {
if (_possiblyUndeclaredUses.contains(name)) { if (_possiblyUndeclaredUses.contains(name)) {
foreach (const SourceLocation &loc, _possiblyUndeclaredUses.value(name)) { const QList<SourceLocation> values = _possiblyUndeclaredUses.value(name);
for (const SourceLocation &loc : values) {
addMessage(WarnFunctionUsedBeforeDeclaration, loc, name); addMessage(WarnFunctionUsedBeforeDeclaration, loc, name);
} }
_possiblyUndeclaredUses.remove(name); _possiblyUndeclaredUses.remove(name);
@@ -1642,7 +1644,7 @@ void Check::checkExtraParentheses(ExpressionNode *expression)
void Check::addMessages(const QList<Message> &messages) void Check::addMessages(const QList<Message> &messages)
{ {
foreach (const Message &msg, messages) for (const Message &msg : messages)
addMessage(msg); addMessage(msg);
} }
@@ -1682,7 +1684,8 @@ void Check::scanCommentsForAnnotations()
m_disabledMessageTypesByLine.clear(); m_disabledMessageTypesByLine.clear();
const QRegularExpression disableCommentPattern = Message::suppressionPattern(); const QRegularExpression disableCommentPattern = Message::suppressionPattern();
foreach (const SourceLocation &commentLoc, _doc->engine()->comments()) { const QList<SourceLocation> comments = _doc->engine()->comments();
for (const SourceLocation &commentLoc : comments) {
const QString &comment = _doc->source().mid(int(commentLoc.begin()), int(commentLoc.length)); const QString &comment = _doc->source().mid(int(commentLoc.begin()), int(commentLoc.length));
// enable all checks annotation // enable all checks annotation
@@ -1728,7 +1731,7 @@ void Check::warnAboutUnnecessarySuppressions()
{ {
for (auto it = m_disabledMessageTypesByLine.cbegin(), end = m_disabledMessageTypesByLine.cend(); for (auto it = m_disabledMessageTypesByLine.cbegin(), end = m_disabledMessageTypesByLine.cend();
it != end; ++it) { it != end; ++it) {
foreach (const MessageTypeAndSuppression &entry, it.value()) { for (const MessageTypeAndSuppression &entry : it.value()) {
if (!entry.wasSuppressed) if (!entry.wasSuppressed)
addMessage(WarnUnnecessaryMessageSuppression, entry.suppressionSource); addMessage(WarnUnnecessaryMessageSuppression, entry.suppressionSource);
} }
@@ -1738,7 +1741,7 @@ void Check::warnAboutUnnecessarySuppressions()
bool Check::isQtQuick2() const bool Check::isQtQuick2() const
{ {
if (_doc->language() == Dialect::Qml) { if (_doc->language() == Dialect::Qml) {
foreach (const Import &import, _imports->all()) { for (const Import &import : _imports->all()) {
if (import.info.name() == "QtQuick" if (import.info.name() == "QtQuick"
&& import.info.version().majorVersion() == 2) && import.info.version().majorVersion() == 2)
return true; return true;
@@ -2053,7 +2056,7 @@ void Check::checkCaseFallthrough(StatementList *statements, SourceLocation error
afterLastStatement = it->statement->lastSourceLocation().end(); afterLastStatement = it->statement->lastSourceLocation().end();
} }
foreach (const SourceLocation &comment, _doc->engine()->comments()) { for (const SourceLocation &comment : _doc->engine()->comments()) {
if (comment.begin() < afterLastStatement if (comment.begin() < afterLastStatement
|| comment.end() > nextLoc.begin()) || comment.end() > nextLoc.begin())
continue; continue;

View File

@@ -1023,7 +1023,7 @@ void CodeFormatter::dump() const
{ {
qCDebug(formatterLog) << "Current token index" << m_tokenIndex; qCDebug(formatterLog) << "Current token index" << m_tokenIndex;
qCDebug(formatterLog) << "Current state:"; qCDebug(formatterLog) << "Current state:";
foreach (const State &s, m_currentState) { for (const State &s : m_currentState) {
qCDebug(formatterLog) << stateToString(s.type) << s.savedIndentDepth; qCDebug(formatterLog) << stateToString(s.type) << s.savedIndentDepth;
} }
qCDebug(formatterLog) << "Current indent depth:" << m_indentDepth; qCDebug(formatterLog) << "Current indent depth:" << m_indentDepth;

View File

@@ -372,7 +372,7 @@ QByteArray LibraryInfo::calculateFingerprint() const
hash.addData(reinterpret_cast<const char *>(&_status), sizeof(_status)); hash.addData(reinterpret_cast<const char *>(&_status), sizeof(_status));
int len = _components.size(); int len = _components.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QmlDirParser::Component &component, _components) { for (const QmlDirParser::Component &component : _components) {
len = component.fileName.size(); len = component.fileName.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(component.fileName.constData()), hash.addData(reinterpret_cast<const char *>(component.fileName.constData()),
@@ -388,7 +388,7 @@ QByteArray LibraryInfo::calculateFingerprint() const
} }
len = _plugins.size(); len = _plugins.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QmlDirParser::Plugin &plugin, _plugins) { for (const QmlDirParser::Plugin &plugin : _plugins) {
len = plugin.path.size(); len = plugin.path.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(plugin.path.constData()), len * sizeofQChar); hash.addData(reinterpret_cast<const char *>(plugin.path.constData()), len * sizeofQChar);
@@ -398,7 +398,7 @@ QByteArray LibraryInfo::calculateFingerprint() const
} }
len = _typeinfos.size(); len = _typeinfos.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QString &typeinfo, _typeinfos) { for (const QString &typeinfo : _typeinfos) {
len = typeinfo.size(); len = typeinfo.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
hash.addData(reinterpret_cast<const char *>(typeinfo.constData()), hash.addData(reinterpret_cast<const char *>(typeinfo.constData()),
@@ -407,10 +407,10 @@ QByteArray LibraryInfo::calculateFingerprint() const
len = _metaObjects.size(); len = _metaObjects.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
QList<QByteArray> metaFingerprints; QList<QByteArray> metaFingerprints;
foreach (const LanguageUtils::FakeMetaObject::ConstPtr &metaObject, _metaObjects) for (const LanguageUtils::FakeMetaObject::ConstPtr &metaObject : _metaObjects)
metaFingerprints.append(metaObject->fingerprint()); metaFingerprints.append(metaObject->fingerprint());
std::sort(metaFingerprints.begin(), metaFingerprints.end()); std::sort(metaFingerprints.begin(), metaFingerprints.end());
foreach (const QByteArray &fp, metaFingerprints) for (const QByteArray &fp : std::as_const(metaFingerprints))
hash.addData(fp); hash.addData(fp);
hash.addData(reinterpret_cast<const char *>(&_dumpStatus), sizeof(_dumpStatus)); hash.addData(reinterpret_cast<const char *>(&_dumpStatus), sizeof(_dumpStatus));
len = _dumpError.size(); // localization dependent (avoid?) len = _dumpError.size(); // localization dependent (avoid?)
@@ -419,12 +419,12 @@ QByteArray LibraryInfo::calculateFingerprint() const
len = _moduleApis.size(); len = _moduleApis.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const ModuleApiInfo &moduleInfo, _moduleApis) for (const ModuleApiInfo &moduleInfo : _moduleApis)
moduleInfo.addToHash(hash); // make it order independent? moduleInfo.addToHash(hash); // make it order independent?
len = _imports.size(); len = _imports.size();
hash.addData(reinterpret_cast<const char *>(&len), sizeof(len)); hash.addData(reinterpret_cast<const char *>(&len), sizeof(len));
foreach (const QmlDirParser::Import &import, _imports) for (const QmlDirParser::Import &import : _imports)
hash.addData(import.module.toUtf8()); // import order matters, keep order-dependent hash.addData(import.module.toUtf8()); // import order matters, keep order-dependent
QByteArray res(hash.result()); QByteArray res(hash.result());
@@ -473,13 +473,14 @@ void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo
cImport.importId = path.toString(); cImport.importId = path.toString();
cImport.language = Dialect::AnyLanguage; cImport.language = Dialect::AnyLanguage;
QSet<ImportKey> packages; QSet<ImportKey> packages;
foreach (const ModuleApiInfo &moduleInfo, info.moduleApis()) { for (const ModuleApiInfo &moduleInfo : info.moduleApis()) {
ImportKey iKey(ImportType::Library, moduleInfo.uri, moduleInfo.version.majorVersion(), ImportKey iKey(ImportType::Library, moduleInfo.uri, moduleInfo.version.majorVersion(),
moduleInfo.version.minorVersion()); moduleInfo.version.minorVersion());
packages.insert(iKey); packages.insert(iKey);
} }
foreach (const LanguageUtils::FakeMetaObject::ConstPtr &metaO, info.metaObjects()) { const QList<LanguageUtils::FakeMetaObject::ConstPtr> metaObjects = info.metaObjects();
foreach (const LanguageUtils::FakeMetaObject::Export &e, metaO->exports()) { for (const LanguageUtils::FakeMetaObject::ConstPtr &metaO : metaObjects) {
for (const LanguageUtils::FakeMetaObject::Export &e : metaO->exports()) {
ImportKey iKey(ImportType::Library, e.package, e.version.majorVersion(), ImportKey iKey(ImportType::Library, e.package, e.version.majorVersion(),
e.version.minorVersion()); e.version.minorVersion());
packages.insert(iKey); packages.insert(iKey);
@@ -489,7 +490,7 @@ void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo
QStringList splitPath = path.path().split(QLatin1Char('/')); QStringList splitPath = path.path().split(QLatin1Char('/'));
const QRegularExpression vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$")); const QRegularExpression vNr(QLatin1String("^(.+)\\.([0-9]+)(?:\\.([0-9]+))?$"));
const QRegularExpression safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$")); const QRegularExpression safeName(QLatin1String("^[a-zA-Z_][[a-zA-Z0-9_]*$"));
foreach (const ImportKey &importKey, packages) { for (const ImportKey &importKey : std::as_const(packages)) {
if (importKey.splitPath.size() == 1 && importKey.splitPath.at(0).isEmpty() && splitPath.length() > 0) { if (importKey.splitPath.size() == 1 && importKey.splitPath.at(0).isEmpty() && splitPath.length() > 0) {
// relocatable // relocatable
QStringList myPath = splitPath; QStringList myPath = splitPath;
@@ -522,7 +523,7 @@ void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo
int majorVersion = LanguageUtils::ComponentVersion::NoVersion; int majorVersion = LanguageUtils::ComponentVersion::NoVersion;
int minorVersion = LanguageUtils::ComponentVersion::NoVersion; int minorVersion = LanguageUtils::ComponentVersion::NoVersion;
foreach (const QmlDirParser::Component &component, info.components()) { for (const QmlDirParser::Component &component : info.components()) {
if (component.majorVersion > majorVersion) if (component.majorVersion > majorVersion)
majorVersion = component.majorVersion; majorVersion = component.majorVersion;
if (component.minorVersion > minorVersion) if (component.minorVersion > minorVersion)
@@ -555,8 +556,8 @@ void Snapshot::insertLibraryInfo(const Utils::FilePath &path, const LibraryInfo
cImport.addPossibleExport(Export(iKey, newP, true)); cImport.addPossibleExport(Export(iKey, newP, true));
} }
} }
foreach (const QmlDirParser::Component &component, info.components()) { for (const QmlDirParser::Component &component : info.components()) {
foreach (const Export &e, cImport.possibleExports) for (const Export &e : std::as_const(cImport.possibleExports))
_dependencies.addExport(component.fileName, e.exportName, e.pathRequired, e.typeName); _dependencies.addExport(component.fileName, e.exportName, e.pathRequired, e.typeName);
} }

View File

@@ -154,13 +154,13 @@ public:
QByteArray fingerprint() const QByteArray fingerprint() const
{ return _fingerprint; } { return _fingerprint; }
QList<QmlDirParser::Component> components() const const QList<QmlDirParser::Component> components() const
{ return _components; } { return _components; }
QList<QmlDirParser::Plugin> plugins() const QList<QmlDirParser::Plugin> plugins() const
{ return _plugins; } { return _plugins; }
QStringList typeInfos() const const QStringList typeInfos() const
{ return _typeinfos; } { return _typeinfos; }
FakeMetaObjectList metaObjects() const FakeMetaObjectList metaObjects() const
@@ -169,7 +169,7 @@ public:
void setMetaObjects(const FakeMetaObjectList &objects) void setMetaObjects(const FakeMetaObjectList &objects)
{ _metaObjects = objects; } { _metaObjects = objects; }
QList<ModuleApiInfo> moduleApis() const const QList<ModuleApiInfo> moduleApis() const
{ return _moduleApis; } { return _moduleApis; }
void setModuleApis(const QList<ModuleApiInfo> &apis) void setModuleApis(const QList<ModuleApiInfo> &apis)

View File

@@ -637,9 +637,9 @@ static QString toQmlType(const FullySpecifiedType &type)
static Class *lookupClass(const QString &expression, Scope *scope, TypeOfExpression &typeOf) static Class *lookupClass(const QString &expression, Scope *scope, TypeOfExpression &typeOf)
{ {
QList<LookupItem> results = typeOf(expression.toUtf8(), scope); const QList<LookupItem> results = typeOf(expression.toUtf8(), scope);
Class *klass = nullptr; Class *klass = nullptr;
foreach (const LookupItem &item, results) { for (const LookupItem &item : results) {
if (item.declaration()) { if (item.declaration()) {
klass = item.declaration()->asClass(); klass = item.declaration()->asClass();
if (klass) if (klass)
@@ -707,8 +707,8 @@ static LanguageUtils::FakeMetaObject::Ptr buildFakeMetaObject(
if (QtEnum *qtEnum = member->asQtEnum()) { if (QtEnum *qtEnum = member->asQtEnum()) {
// find the matching enum // find the matching enum
Enum *e = nullptr; Enum *e = nullptr;
QList<LookupItem> result = typeOf(namePrinter.prettyName(qtEnum->name()).toUtf8(), klass); const QList<LookupItem> result = typeOf(namePrinter.prettyName(qtEnum->name()).toUtf8(), klass);
foreach (const LookupItem &item, result) { for (const LookupItem &item : result) {
if (item.declaration()) { if (item.declaration()) {
e = item.declaration()->asEnum(); e = item.declaration()->asEnum();
if (e) if (e)
@@ -757,7 +757,7 @@ static void buildExportedQmlObjects(
if (cppExports.isEmpty()) if (cppExports.isEmpty())
return; return;
foreach (const ExportedQmlType &exportedType, cppExports) { for (const ExportedQmlType &exportedType : cppExports) {
Class *klass = nullptr; Class *klass = nullptr;
if (!exportedType.typeExpression.isEmpty()) if (!exportedType.typeExpression.isEmpty())
klass = lookupClass(exportedType.typeExpression, exportedType.scope, typeOf); klass = lookupClass(exportedType.typeExpression, exportedType.scope, typeOf);
@@ -785,7 +785,7 @@ static void buildContextProperties(
{ {
using namespace LanguageUtils; using namespace LanguageUtils;
foreach (const ContextProperty &property, contextPropertyDescriptions) { for (const ContextProperty &property : contextPropertyDescriptions) {
Scope *scope = doc->scopeAt(property.line, property.column); Scope *scope = doc->scopeAt(property.line, property.column);
QList<LookupItem> results = typeOf(property.expression.toUtf8(), scope); QList<LookupItem> results = typeOf(property.expression.toUtf8(), scope);
QString typeName; QString typeName;
@@ -880,7 +880,7 @@ QStringList FindExportedCppTypes::operator()(const CPlusPlus::Document::Ptr &doc
m_exportedTypes += it.value(); m_exportedTypes += it.value();
fileNames += QLatin1String(it.key()->fileName()); fileNames += QLatin1String(it.key()->fileName());
} }
foreach (const LanguageUtils::FakeMetaObject::Ptr &fmo, extraFakeMetaObjects) { for (const LanguageUtils::FakeMetaObject::Ptr &fmo : std::as_const(extraFakeMetaObjects)) {
fmo->updateFingerprint(); fmo->updateFingerprint();
m_exportedTypes += fmo; m_exportedTypes += fmo;
} }

View File

@@ -61,12 +61,14 @@ void Icons::setIconFilesPath(const QString &iconPath)
if (debug) if (debug)
qCDebug(iconsLog) << "parsing" << iconPath; qCDebug(iconsLog) << "parsing" << iconPath;
QDir topDir(iconPath); QDir topDir(iconPath);
foreach (const QFileInfo &subDirInfo, topDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot)) { QList<QFileInfo> dirs = topDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (const QFileInfo &subDirInfo : dirs) {
if (debug) if (debug)
qCDebug(iconsLog) << "parsing" << subDirInfo.absoluteFilePath(); qCDebug(iconsLog) << "parsing" << subDirInfo.absoluteFilePath();
const QString packageName = subDirInfo.fileName(); const QString packageName = subDirInfo.fileName();
QDir subDir(subDirInfo.absoluteFilePath() + QLatin1String("/16x16")); QDir subDir(subDirInfo.absoluteFilePath() + QLatin1String("/16x16"));
foreach (const QFileInfo &iconFile, subDir.entryInfoList(QDir::Files)) { QList<QFileInfo> files = subDir.entryInfoList(QDir::Files);
for (const QFileInfo &iconFile : files) {
QIcon icon(iconFile.absoluteFilePath()); QIcon icon(iconFile.absoluteFilePath());
if (icon.isNull()) { if (icon.isNull()) {
if (debug) if (debug)

View File

@@ -188,7 +188,7 @@ void ImportKey::addToHash(QCryptographicHash &hash) const
hash.addData(reinterpret_cast<const char *>(&type), sizeof(type)); hash.addData(reinterpret_cast<const char *>(&type), sizeof(type));
hash.addData(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion)); hash.addData(reinterpret_cast<const char *>(&majorVersion), sizeof(majorVersion));
hash.addData(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion)); hash.addData(reinterpret_cast<const char *>(&minorVersion), sizeof(minorVersion));
foreach (const QString &s, splitPath) { for (const QString &s : splitPath) {
hash.addData("/", 1); hash.addData("/", 1);
hash.addData(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size()); hash.addData(reinterpret_cast<const char *>(s.constData()), sizeof(QChar) * s.size());
} }
@@ -484,7 +484,7 @@ size_t qHash(const ImportKey &info)
{ {
size_t res = ::qHash(info.type) ^ size_t res = ::qHash(info.type) ^
::qHash(info.majorVersion) ^ ::qHash(info.minorVersion); ::qHash(info.majorVersion) ^ ::qHash(info.minorVersion);
foreach (const QString &s, info.splitPath) for (const QString &s : std::as_const(info.splitPath))
res = res ^ ::qHash(s); res = res ^ ::qHash(s);
return res; return res;
} }
@@ -546,7 +546,7 @@ QByteArray DependencyInfo::calculateFingerprint(const ImportDependencies &deps)
rootImport.addToHash(hash); rootImport.addToHash(hash);
QStringList coreImports = Utils::toList(allCoreImports); QStringList coreImports = Utils::toList(allCoreImports);
coreImports.sort(); coreImports.sort();
foreach (const QString importId, coreImports) { for (const QString &importId : std::as_const(coreImports)) {
hash.addData(reinterpret_cast<const char*>(importId.constData()), importId.size() * sizeof(QChar)); hash.addData(reinterpret_cast<const char*>(importId.constData()), importId.size() * sizeof(QChar));
QByteArray coreImportFingerprint = deps.coreImport(importId).fingerprint; QByteArray coreImportFingerprint = deps.coreImport(importId).fingerprint;
hash.addData(coreImportFingerprint); hash.addData(coreImportFingerprint);
@@ -612,7 +612,7 @@ void ImportDependencies::filter(const ViewerContext &vContext)
const CoreImport &cImport = j.value(); const CoreImport &cImport = j.value();
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
QList<Export> newExports; QList<Export> newExports;
foreach (const Export &e, cImport.possibleExports) { for (const Export &e : std::as_const(cImport.possibleExports)) {
++benchMark.nPossibleExports; ++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
newExports.append(e); newExports.append(e);
@@ -660,10 +660,10 @@ void ImportDependencies::iterateOnCandidateImports(
default: default:
{ {
const QStringList imp = m_importCache.value(key.flatKey()); const QStringList imp = m_importCache.value(key.flatKey());
foreach (const QString &cImportName, imp) { for (const QString &cImportName : imp) {
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export e, cImport.possibleExports) { for (const Export e : std::as_const(cImport.possibleExports)) {
++benchMark.nPossibleExports; ++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
ImportMatchStrength m = e.exportName.matchImport(key, vContext); ImportMatchStrength m = e.exportName.matchImport(key, vContext);
@@ -683,10 +683,10 @@ void ImportDependencies::iterateOnCandidateImports(
while (lb != end) { while (lb != end) {
ImportKey::DirCompareInfo c = key.compareDir(lb.key()); ImportKey::DirCompareInfo c = key.compareDir(lb.key());
if (c == ImportKey::SameDir) { if (c == ImportKey::SameDir) {
foreach (const QString &cImportName, lb.value()) { for (const QString &cImportName : std::as_const(lb.value())) {
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export e, cImport.possibleExports) { for (const Export e : std::as_const(cImport.possibleExports)) {
++benchMark.nPossibleExports; ++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
ImportMatchStrength m = e.exportName.matchImport(key, vContext); ImportMatchStrength m = e.exportName.matchImport(key, vContext);
@@ -754,19 +754,19 @@ void ImportDependencies::addCoreImport(const CoreImport &import)
CoreImport newImport = import; CoreImport newImport = import;
if (m_coreImports.contains(import.importId)) { if (m_coreImports.contains(import.importId)) {
CoreImport oldVal = m_coreImports.value(import.importId); CoreImport oldVal = m_coreImports.value(import.importId);
foreach (const Export &e, oldVal.possibleExports) { for (const Export &e : std::as_const(oldVal.possibleExports)) {
if (e.intrinsic) if (e.intrinsic)
removeImportCacheEntry(e.exportName, import.importId); removeImportCacheEntry(e.exportName, import.importId);
else else
newImport.possibleExports.append(e); newImport.possibleExports.append(e);
} }
} }
foreach (const Export &e, import.possibleExports) for (const Export &e : std::as_const(import.possibleExports))
m_importCache[e.exportName].append(import.importId); m_importCache[e.exportName].append(import.importId);
m_coreImports.insert(newImport.importId, newImport); m_coreImports.insert(newImport.importId, newImport);
if (importsLog().isDebugEnabled()) { if (importsLog().isDebugEnabled()) {
QString msg = QString::fromLatin1("added import %1 for").arg(newImport.importId); QString msg = QString::fromLatin1("added import %1 for").arg(newImport.importId);
foreach (const Export &e, newImport.possibleExports) for (const Export &e : std::as_const(newImport.possibleExports))
msg += QString::fromLatin1("\n %1(%2)") msg += QString::fromLatin1("\n %1(%2)")
.arg(e.exportName.toString(), e.pathRequired.toUserOutput()); .arg(e.exportName.toString(), e.pathRequired.toUserOutput());
qCDebug(importsLog) << msg; qCDebug(importsLog) << msg;
@@ -781,7 +781,7 @@ void ImportDependencies::removeCoreImport(const QString &importId)
} }
CoreImport &cImport = m_coreImports[importId]; CoreImport &cImport = m_coreImports[importId];
QList<Export> newExports; QList<Export> newExports;
foreach (const Export &e, cImport.possibleExports) for (const Export &e : std::as_const(cImport.possibleExports))
if (e.intrinsic) if (e.intrinsic)
removeImportCacheEntry(e.exportName, importId); removeImportCacheEntry(e.exportName, importId);
else else
@@ -867,10 +867,10 @@ void ImportDependencies::iterateOnLibraryImports(
iter_t end = m_importCache.constEnd(); iter_t end = m_importCache.constEnd();
while (i != end && i.key().type == ImportType::Library) { while (i != end && i.key().type == ImportType::Library) {
qCDebug(importsLog) << "libloop:" << i.key().toString() << i.value(); qCDebug(importsLog) << "libloop:" << i.key().toString() << i.value();
foreach (const QString &cImportName, i.value()) { for (const QString &cImportName : i.value()) {
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export &e, cImport.possibleExports) { for (const Export &e : std::as_const(cImport.possibleExports)) {
++benchMark.nPossibleExports; ++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext) && e.exportName.type == ImportType::Library) { if (e.visibleInVContext(vContext) && e.exportName.type == ImportType::Library) {
ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext); ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext);
@@ -903,10 +903,10 @@ void ImportDependencies::iterateOnSubImports(
ImportKey::DirCompareInfo c = baseKey.compareDir(i.key()); ImportKey::DirCompareInfo c = baseKey.compareDir(i.key());
if (c != ImportKey::SameDir && c != ImportKey::SecondInFirst) if (c != ImportKey::SameDir && c != ImportKey::SecondInFirst)
break; break;
foreach (const QString &cImportName, i.value()) { for (const QString &cImportName : i.value()) {
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export &e, cImport.possibleExports) { for (const Export &e : std::as_const(cImport.possibleExports)) {
++benchMark.nPossibleExports; ++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext); ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext);
@@ -961,14 +961,15 @@ void ImportDependencies::checkConsistency() const
for (auto j = m_importCache.cbegin(), end = m_importCache.cend(); j != end; ++j) { for (auto j = m_importCache.cbegin(), end = m_importCache.cend(); j != end; ++j) {
for (const QString &s : j.value()) { for (const QString &s : j.value()) {
bool found = false; bool found = false;
foreach (const Export &e, m_coreImports.value(s).possibleExports) const QList<Export> exports = m_coreImports.value(s).possibleExports;
for (const Export &e : exports)
if (e.exportName == j.key()) if (e.exportName == j.key())
found = true; found = true;
Q_ASSERT(found); Q_UNUSED(found) Q_ASSERT(found); Q_UNUSED(found)
} }
} }
for (auto i = m_coreImports.cbegin(), end = m_coreImports.cend(); i != end; ++i) { for (auto i = m_coreImports.cbegin(), end = m_coreImports.cend(); i != end; ++i) {
foreach (const Export &e, i.value().possibleExports) { for (const Export &e : std::as_const(i.value().possibleExports)) {
if (!m_importCache.value(e.exportName).contains(i.key())) { if (!m_importCache.value(e.exportName).contains(i.key())) {
qCWarning(importsLog) << e.exportName.toString(); qCWarning(importsLog) << e.exportName.toString();
qCWarning(importsLog) << i.key(); qCWarning(importsLog) << i.key();

View File

@@ -427,7 +427,7 @@ const CppComponentValue *CppComponentValue::prototype() const
Use this function rather than calling prototype() in a loop, as it avoids Use this function rather than calling prototype() in a loop, as it avoids
cycles. cycles.
*/ */
QList<const CppComponentValue *> CppComponentValue::prototypes() const const QList<const CppComponentValue *> CppComponentValue::prototypes() const
{ {
QList<const CppComponentValue *> protos; QList<const CppComponentValue *> protos;
for (const CppComponentValue *it = this; it; it = it->prototype()) { for (const CppComponentValue *it = this; it; it = it->prototype()) {
@@ -457,7 +457,7 @@ QString CppComponentValue::defaultPropertyName() const
QString CppComponentValue::propertyType(const QString &propertyName) const QString CppComponentValue::propertyType(const QString &propertyName) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
int propIdx = iter->propertyIndex(propertyName); int propIdx = iter->propertyIndex(propertyName);
if (propIdx != -1) if (propIdx != -1)
@@ -468,7 +468,7 @@ QString CppComponentValue::propertyType(const QString &propertyName) const
bool CppComponentValue::isListProperty(const QString &propertyName) const bool CppComponentValue::isListProperty(const QString &propertyName) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
int propIdx = iter->propertyIndex(propertyName); int propIdx = iter->propertyIndex(propertyName);
if (propIdx != -1) if (propIdx != -1)
@@ -479,7 +479,7 @@ bool CppComponentValue::isListProperty(const QString &propertyName) const
FakeMetaEnum CppComponentValue::getEnum(const QString &typeName, const CppComponentValue **foundInScope) const FakeMetaEnum CppComponentValue::getEnum(const QString &typeName, const CppComponentValue **foundInScope) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
const int index = iter->enumeratorIndex(typeName); const int index = iter->enumeratorIndex(typeName);
if (index != -1) { if (index != -1) {
@@ -495,7 +495,7 @@ FakeMetaEnum CppComponentValue::getEnum(const QString &typeName, const CppCompon
const QmlEnumValue *CppComponentValue::getEnumValue(const QString &typeName, const CppComponentValue **foundInScope) const const QmlEnumValue *CppComponentValue::getEnumValue(const QString &typeName, const CppComponentValue **foundInScope) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
if (const QmlEnumValue *e = it->m_enums.value(typeName)) { if (const QmlEnumValue *e = it->m_enums.value(typeName)) {
if (foundInScope) if (foundInScope)
*foundInScope = it; *foundInScope = it;
@@ -544,7 +544,7 @@ const ObjectValue *CppComponentValue::signalScope(const QString &signalName) con
bool CppComponentValue::isWritable(const QString &propertyName) const bool CppComponentValue::isWritable(const QString &propertyName) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
int propIdx = iter->propertyIndex(propertyName); int propIdx = iter->propertyIndex(propertyName);
if (propIdx != -1) if (propIdx != -1)
@@ -555,7 +555,7 @@ bool CppComponentValue::isWritable(const QString &propertyName) const
bool CppComponentValue::isPointer(const QString &propertyName) const bool CppComponentValue::isPointer(const QString &propertyName) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
int propIdx = iter->propertyIndex(propertyName); int propIdx = iter->propertyIndex(propertyName);
if (propIdx != -1) if (propIdx != -1)
@@ -574,7 +574,7 @@ bool CppComponentValue::hasLocalProperty(const QString &typeName) const
bool CppComponentValue::hasProperty(const QString &propertyName) const bool CppComponentValue::hasProperty(const QString &propertyName) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
int propIdx = iter->propertyIndex(propertyName); int propIdx = iter->propertyIndex(propertyName);
if (propIdx != -1) if (propIdx != -1)
@@ -585,7 +585,7 @@ bool CppComponentValue::hasProperty(const QString &propertyName) const
bool CppComponentValue::isDerivedFrom(FakeMetaObject::ConstPtr base) const bool CppComponentValue::isDerivedFrom(FakeMetaObject::ConstPtr base) const
{ {
foreach (const CppComponentValue *it, prototypes()) { for (const CppComponentValue *it : prototypes()) {
FakeMetaObject::ConstPtr iter = it->m_metaObject; FakeMetaObject::ConstPtr iter = it->m_metaObject;
if (iter == base) if (iter == base)
return true; return true;
@@ -1326,7 +1326,7 @@ CppQmlTypesLoader::BuiltinObjects CppQmlTypesLoader::loadQmlTypes(const QFileInf
QHash<QString, FakeMetaObject::ConstPtr> newObjects; QHash<QString, FakeMetaObject::ConstPtr> newObjects;
QStringList newDependencies; QStringList newDependencies;
foreach (const QFileInfo &qmlTypeFile, qmlTypeFiles) { for (const QFileInfo &qmlTypeFile : qmlTypeFiles) {
QString error, warning; QString error, warning;
QFile file(qmlTypeFile.absoluteFilePath()); QFile file(qmlTypeFile.absoluteFilePath());
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
@@ -1400,8 +1400,8 @@ template <typename T>
void CppQmlTypes::load(const QString &originId, const T &fakeMetaObjects, const QString &overridePackage) void CppQmlTypes::load(const QString &originId, const T &fakeMetaObjects, const QString &overridePackage)
{ {
QList<CppComponentValue *> newCppTypes; QList<CppComponentValue *> newCppTypes;
foreach (const FakeMetaObject::ConstPtr &fmo, fakeMetaObjects) { for (const FakeMetaObject::ConstPtr &fmo : fakeMetaObjects) {
foreach (const FakeMetaObject::Export &exp, fmo->exports()) { for (const FakeMetaObject::Export &exp : fmo->exports()) {
QString package = exp.package; QString package = exp.package;
if (package.isEmpty()) if (package.isEmpty())
package = overridePackage; package = overridePackage;
@@ -1422,7 +1422,7 @@ void CppQmlTypes::load(const QString &originId, const T &fakeMetaObjects, const
} }
// set prototypes of cpp types // set prototypes of cpp types
foreach (CppComponentValue *object, newCppTypes) { for (CppComponentValue *object : std::as_const(newCppTypes)) {
const QString &protoCppName = object->metaObject()->superclassName(); const QString &protoCppName = object->metaObject()->superclassName();
const CppComponentValue *proto = objectByCppName(protoCppName); const CppComponentValue *proto = objectByCppName(protoCppName);
if (proto) if (proto)
@@ -1441,11 +1441,12 @@ QList<const CppComponentValue *> CppQmlTypes::createObjectsForImport(const QStri
QList<const CppComponentValue *> newObjects; QList<const CppComponentValue *> newObjects;
// make new exported objects // make new exported objects
foreach (const FakeMetaObjectWithOrigin &fmoo, m_fakeMetaObjectsByPackage.value(package)) { const QSet<FakeMetaObjectWithOrigin> fmoos = m_fakeMetaObjectsByPackage.value(package);
for (const FakeMetaObjectWithOrigin &fmoo : fmoos) {
const FakeMetaObject::ConstPtr &fmo = fmoo.fakeMetaObject; const FakeMetaObject::ConstPtr &fmo = fmoo.fakeMetaObject;
// find the highest-version export for each alias // find the highest-version export for each alias
QHash<QString, FakeMetaObject::Export> bestExports; QHash<QString, FakeMetaObject::Export> bestExports;
foreach (const FakeMetaObject::Export &exp, fmo->exports()) { for (const FakeMetaObject::Export &exp : fmo->exports()) {
if (exp.package != package || (version.isValid() && exp.version > version)) if (exp.package != package || (version.isValid() && exp.version > version))
continue; continue;
@@ -1465,7 +1466,7 @@ QList<const CppComponentValue *> CppQmlTypes::createObjectsForImport(const QStri
continue; continue;
ComponentVersion cppVersion; ComponentVersion cppVersion;
foreach (const FakeMetaObject::Export &bestExport, bestExports) { for (const FakeMetaObject::Export &bestExport : std::as_const(bestExports)) {
QString name = bestExport.type; QString name = bestExport.type;
bool exported = true; bool exported = true;
if (name.isEmpty()) { if (name.isEmpty()) {
@@ -1495,7 +1496,7 @@ QList<const CppComponentValue *> CppQmlTypes::createObjectsForImport(const QStri
// set their prototypes, creating them if necessary // set their prototypes, creating them if necessary
// this ensures that the prototypes of C++ objects are resolved correctly and with the correct // this ensures that the prototypes of C++ objects are resolved correctly and with the correct
// revision, and cannot be hidden by other objects. // revision, and cannot be hidden by other objects.
foreach (const CppComponentValue *cobject, newObjects) { for (const CppComponentValue *cobject : std::as_const(newObjects)) {
CppComponentValue *object = const_cast<CppComponentValue *>(cobject); CppComponentValue *object = const_cast<CppComponentValue *>(cobject);
while (!object->prototype()) { while (!object->prototype()) {
const QString &protoCppName = object->metaObject()->superclassName(); const QString &protoCppName = object->metaObject()->superclassName();
@@ -1860,7 +1861,7 @@ bool ASTObjectValue::getSourceLocation(Utils::FilePath *fileName, int *line, int
void ASTObjectValue::processMembers(MemberProcessor *processor) const void ASTObjectValue::processMembers(MemberProcessor *processor) const
{ {
foreach (ASTPropertyReference *ref, m_properties) { for (ASTPropertyReference *ref : m_properties) {
uint pFlags = PropertyInfo::Readable; uint pFlags = PropertyInfo::Readable;
if (!ref->ast()->isReadonly()) if (!ref->ast()->isReadonly())
pFlags |= PropertyInfo::Writeable; pFlags |= PropertyInfo::Writeable;
@@ -1868,7 +1869,7 @@ void ASTObjectValue::processMembers(MemberProcessor *processor) const
// ### Should get a different value? // ### Should get a different value?
processor->processGeneratedSlot(ref->onChangedSlotName(), ref); processor->processGeneratedSlot(ref->onChangedSlotName(), ref);
} }
foreach (ASTSignal *ref, m_signals) { for (ASTSignal *ref : m_signals) {
processor->processSignal(ref->ast()->name.toString(), ref); processor->processSignal(ref->ast()->name.toString(), ref);
// ### Should get a different value? // ### Should get a different value?
processor->processGeneratedSlot(ref->slotName(), ref); processor->processGeneratedSlot(ref->slotName(), ref);

View File

@@ -577,7 +577,7 @@ public:
using ObjectValue::prototype; using ObjectValue::prototype;
const CppComponentValue *prototype() const; const CppComponentValue *prototype() const;
QList<const CppComponentValue *> prototypes() const; const QList<const CppComponentValue *> prototypes() const;
LanguageUtils::FakeMetaObject::ConstPtr metaObject() const; LanguageUtils::FakeMetaObject::ConstPtr metaObject() const;

View File

@@ -105,7 +105,7 @@ QString LineInfo::trimmedCodeLine(const QString &t)
yyLinizerState.tokens = scanner(t, startState); yyLinizerState.tokens = scanner(t, startState);
QString trimmed; QString trimmed;
int previousTokenEnd = 0; int previousTokenEnd = 0;
foreach (const Token &token, yyLinizerState.tokens) { for (const Token &token : std::as_const(yyLinizerState.tokens)) {
trimmed.append(t.mid(previousTokenEnd, token.begin() - previousTokenEnd)); trimmed.append(t.mid(previousTokenEnd, token.begin() - previousTokenEnd));
if (token.is(Token::String)) { if (token.is(Token::String)) {
@@ -131,7 +131,7 @@ QString LineInfo::trimmedCodeLine(const QString &t)
} }
bool isBinding = false; bool isBinding = false;
foreach (const Token &token, yyLinizerState.tokens) { for (const Token &token : std::as_const(yyLinizerState.tokens)) {
if (token.is(Token::Colon)) { if (token.is(Token::Colon)) {
isBinding = true; isBinding = true;
break; break;

View File

@@ -133,14 +133,15 @@ void PluginDumper::onLoadPluginTypes(const Utils::FilePath &libraryPath,
} }
// add typeinfo files listed in qmldir // add typeinfo files listed in qmldir
foreach (const QString &typeInfo, libraryInfo.typeInfos()) { for (const QString &typeInfo : libraryInfo.typeInfos()) {
const FilePath pathNow = canonicalLibraryPath.resolvePath(typeInfo); const FilePath pathNow = canonicalLibraryPath.resolvePath(typeInfo);
if (!plugin.typeInfoPaths.contains(pathNow) && pathNow.exists()) if (!plugin.typeInfoPaths.contains(pathNow) && pathNow.exists())
plugin.typeInfoPaths += pathNow; plugin.typeInfoPaths += pathNow;
} }
// watch plugin libraries // watch plugin libraries
foreach (const QmlDirParser::Plugin &plugin, snapshot.libraryInfo(canonicalLibraryPath).plugins()) { const QList<QmlDirParser::Plugin> plugins = snapshot.libraryInfo(canonicalLibraryPath).plugins();
for (const QmlDirParser::Plugin &plugin : plugins) {
const QString pluginLibrary = resolvePlugin(canonicalLibraryPath.toString(), plugin.path, plugin.name); const QString pluginLibrary = resolvePlugin(canonicalLibraryPath.toString(), plugin.path, plugin.name);
if (!pluginLibrary.isEmpty()) { if (!pluginLibrary.isEmpty()) {
if (!pluginWatcher()->watchesFile(pluginLibrary)) if (!pluginWatcher()->watchesFile(pluginLibrary))
@@ -165,7 +166,7 @@ void PluginDumper::onLoadPluginTypes(const Utils::FilePath &libraryPath,
void PluginDumper::dumpAllPlugins() void PluginDumper::dumpAllPlugins()
{ {
foreach (const Plugin &plugin, m_plugins) { for (const Plugin &plugin : std::as_const(m_plugins)) {
dump(plugin); dump(plugin);
} }
} }
@@ -676,7 +677,7 @@ QString PluginDumper::resolvePlugin(const QDir &qmldirPath, const QString &qmldi
if (!qmldirPluginPathIsRelative) if (!qmldirPluginPathIsRelative)
searchPaths.prepend(qmldirPluginPath); searchPaths.prepend(qmldirPluginPath);
foreach (const QString &pluginPath, searchPaths) { for (const QString &pluginPath : std::as_const(searchPaths)) {
QString resolvedPath; QString resolvedPath;
@@ -690,7 +691,7 @@ QString PluginDumper::resolvePlugin(const QDir &qmldirPath, const QString &qmldi
} }
QDir dir(resolvedPath); QDir dir(resolvedPath);
foreach (const QString &suffix, suffixes) { for (const QString &suffix : suffixes) {
QString pluginFileName = prefix; QString pluginFileName = prefix;
pluginFileName += baseName; pluginFileName += baseName;

View File

@@ -273,7 +273,7 @@ protected:
const int minContentLength = 10; const int minContentLength = 10;
qreal result = badnessFromSplits; qreal result = badnessFromSplits;
foreach (const QString &line, lines) { for (const QString &line : std::as_const(lines)) {
// really long lines should be avoided at all cost // really long lines should be avoided at all cost
if (line.size() > strongMaxLineLength) { if (line.size() > strongMaxLineLength) {
result += 50 + (line.size() - strongMaxLineLength); result += 50 + (line.size() - strongMaxLineLength);

View File

@@ -48,7 +48,7 @@ void ScopeBuilder::push(AST::Node *node)
const ObjectValue *owner = nullptr; const ObjectValue *owner = nullptr;
const Value *value = nullptr; const Value *value = nullptr;
// try to find the name on the scope objects // try to find the name on the scope objects
foreach (const ObjectValue *scope, _scopeChain->qmlScopeObjects()) { for (const ObjectValue *scope : _scopeChain->qmlScopeObjects()) {
value = scope->lookupMember(name, _scopeChain->context(), &owner); value = scope->lookupMember(name, _scopeChain->context(), &owner);
if (value) if (value)
break; break;
@@ -84,7 +84,7 @@ void ScopeBuilder::push(AST::Node *node)
void ScopeBuilder::push(const QList<AST::Node *> &nodes) void ScopeBuilder::push(const QList<AST::Node *> &nodes)
{ {
foreach (Node *node, nodes) for (Node *node : nodes)
push(node); push(node);
} }
@@ -196,7 +196,7 @@ const Value *ScopeBuilder::scopeObjectLookup(AST::UiQualifiedId *id)
{ {
// do a name lookup on the scope objects // do a name lookup on the scope objects
const Value *result = nullptr; const Value *result = nullptr;
foreach (const ObjectValue *scopeObject, _scopeChain->qmlScopeObjects()) { for (const ObjectValue *scopeObject : _scopeChain->qmlScopeObjects()) {
const ObjectValue *object = scopeObject; const ObjectValue *object = scopeObject;
for (UiQualifiedId *it = id; it; it = it->next) { for (UiQualifiedId *it = id; it; it = it->next) {
if (it->name.isEmpty()) if (it->name.isEmpty())

View File

@@ -47,7 +47,7 @@ Document::Ptr QmlComponentChain::document() const
return m_document; return m_document;
} }
QList<const QmlComponentChain *> QmlComponentChain::instantiatingComponents() const const QList<const QmlComponentChain *> QmlComponentChain::instantiatingComponents() const
{ {
return m_instantiatingComponents; return m_instantiatingComponents;
} }
@@ -153,7 +153,7 @@ void ScopeChain::setQmlComponentChain(const QSharedPointer<const QmlComponentCha
m_qmlComponentScope = qmlComponentChain; m_qmlComponentScope = qmlComponentChain;
} }
QList<const ObjectValue *> ScopeChain::qmlScopeObjects() const const QList<const ObjectValue *> ScopeChain::qmlScopeObjects() const
{ {
return m_qmlScopeObjects; return m_qmlScopeObjects;
} }
@@ -212,7 +212,7 @@ QList<const ObjectValue *> ScopeChain::all() const
static void collectScopes(const QmlComponentChain *chain, QList<const ObjectValue *> *target) static void collectScopes(const QmlComponentChain *chain, QList<const ObjectValue *> *target)
{ {
foreach (const QmlComponentChain *parent, chain->instantiatingComponents()) for (const QmlComponentChain *parent : chain->instantiatingComponents())
collectScopes(parent, target); collectScopes(parent, target);
if (!chain->document()) if (!chain->document())
@@ -237,7 +237,7 @@ void ScopeChain::update() const
// the root scope in js files doesn't see instantiating components // the root scope in js files doesn't see instantiating components
if (m_document->language() != Dialect::JavaScript || m_jsScopes.count() != 1) { if (m_document->language() != Dialect::JavaScript || m_jsScopes.count() != 1) {
if (m_qmlComponentScope) { if (m_qmlComponentScope) {
foreach (const QmlComponentChain *parent, m_qmlComponentScope->instantiatingComponents()) for (const QmlComponentChain *parent : m_qmlComponentScope->instantiatingComponents())
collectScopes(parent, &m_all); collectScopes(parent, &m_all);
} }
} }
@@ -265,7 +265,7 @@ void ScopeChain::update() const
static void addInstantiatingComponents(ContextPtr context, QmlComponentChain *chain) static void addInstantiatingComponents(ContextPtr context, QmlComponentChain *chain)
{ {
const QRegularExpression importCommentPattern(QLatin1String("@scope\\s+(.*)")); const QRegularExpression importCommentPattern(QLatin1String("@scope\\s+(.*)"));
foreach (const SourceLocation &commentLoc, chain->document()->engine()->comments()) { for (const SourceLocation &commentLoc : chain->document()->engine()->comments()) {
const QString &comment = chain->document()->source().mid(commentLoc.begin(), commentLoc.length); const QString &comment = chain->document()->source().mid(commentLoc.begin(), commentLoc.length);
// find all @scope annotations // find all @scope annotations
@@ -283,10 +283,10 @@ static void addInstantiatingComponents(ContextPtr context, QmlComponentChain *ch
.absoluteFilePath(); .absoluteFilePath();
} }
foreach (const QmlComponentChain *c, chain->instantiatingComponents()) for (const QmlComponentChain *c : chain->instantiatingComponents())
additionalScopes.removeAll(c->document()->fileName()); additionalScopes.removeAll(c->document()->fileName());
foreach (const Utils::FilePath &scope, additionalScopes) { for (const Utils::FilePath &scope : std::as_const(additionalScopes)) {
Document::Ptr doc = context->snapshot().document(scope); Document::Ptr doc = context->snapshot().document(scope);
if (doc) { if (doc) {
QmlComponentChain *ch = new QmlComponentChain(doc); QmlComponentChain *ch = new QmlComponentChain(doc);
@@ -322,8 +322,8 @@ void ScopeChain::initializeRootScope()
// add scope chains for all components that import this file // add scope chains for all components that import this file
// unless there's .pragma library // unless there's .pragma library
if (!m_document->bind()->isJsLibrary()) { if (!m_document->bind()->isJsLibrary()) {
foreach (Document::Ptr otherDoc, snapshot) { for (Document::Ptr otherDoc : snapshot) {
foreach (const ImportInfo &import, otherDoc->bind()->imports()) { for (const ImportInfo &import : otherDoc->bind()->imports()) {
if ((import.type() == ImportType::File if ((import.type() == ImportType::File
&& m_document->fileName().toString() == import.path()) && m_document->fileName().toString() == import.path())
|| (import.type() == ImportType::QrcFile || (import.type() == ImportType::QrcFile
@@ -358,7 +358,7 @@ void ScopeChain::makeComponentChain(
const Bind *bind = doc->bind(); const Bind *bind = doc->bind();
// add scopes for all components instantiating this one // add scopes for all components instantiating this one
foreach (Document::Ptr otherDoc, snapshot) { for (Document::Ptr otherDoc : snapshot) {
if (otherDoc == doc) if (otherDoc == doc)
continue; continue;
if (otherDoc->bind()->usesQmlPrototype(bind->rootObjectValue(), m_context)) { if (otherDoc->bind()->usesQmlPrototype(bind->rootObjectValue(), m_context)) {

View File

@@ -26,7 +26,7 @@ public:
~QmlComponentChain(); ~QmlComponentChain();
Document::Ptr document() const; Document::Ptr document() const;
QList<const QmlComponentChain *> instantiatingComponents() const; const QList<const QmlComponentChain *> instantiatingComponents() const;
const ObjectValue *idScope() const; const ObjectValue *idScope() const;
const ObjectValue *rootObjectScope() const; const ObjectValue *rootObjectScope() const;
@@ -62,7 +62,7 @@ public:
QSharedPointer<const QmlComponentChain> qmlComponentChain() const; QSharedPointer<const QmlComponentChain> qmlComponentChain() const;
void setQmlComponentChain(const QSharedPointer<const QmlComponentChain> &qmlComponentChain); void setQmlComponentChain(const QSharedPointer<const QmlComponentChain> &qmlComponentChain);
QList<const ObjectValue *> qmlScopeObjects() const; const QList<const ObjectValue *> qmlScopeObjects() const;
void setQmlScopeObjects(const QList<const ObjectValue *> &qmlScopeObjects); void setQmlScopeObjects(const QList<const ObjectValue *> &qmlScopeObjects);
const TypeScope *qmlTypes() const; const TypeScope *qmlTypes() const;