diff options
author | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-09-08 16:18:31 +0300 |
---|---|---|
committer | Anton Kudryavtsev <a.kudryavtsev@netris.ru> | 2016-09-09 13:47:05 +0000 |
commit | 1e8294ecc431c4d554315c89ad050a03aefbb507 (patch) | |
tree | fe9d44d5e810cb615be509038798e9a6859923cc /src | |
parent | 798b6ba239f59f7b3ed36b3c2cf10955a7bdffcb (diff) |
Qml compiler: replace 'foreach' with 'range for'
... and with 'index-based for' in one place.
Change-Id: I4df75bd5921f9ee8b5744067adbaafbc46452f87
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 19 | ||||
-rw-r--r-- | src/qml/compiler/qqmltypecompiler.cpp | 10 | ||||
-rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 4 | ||||
-rw-r--r-- | src/qml/compiler/qv4isel_moth.cpp | 2 | ||||
-rw-r--r-- | src/qml/compiler/qv4ssa.cpp | 84 | ||||
-rw-r--r-- | src/qml/compiler/qv4ssa_p.h | 6 |
6 files changed, 64 insertions, 61 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index 1cc0dcc189..89fa86c857 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -362,10 +362,11 @@ bool IRBuilder::generateFromQml(const QString &code, const QString &url, Documen QQmlJS::Parser parser(&output->jsParserEngine); - if (! parser.parse() || !parser.diagnosticMessages().isEmpty()) { - + const bool parseResult = parser.parse(); + const auto diagnosticMessages = parser.diagnosticMessages(); + if (!parseResult || !diagnosticMessages.isEmpty()) { // Extract errors from the parser - foreach (const QQmlJS::DiagnosticMessage &m, parser.diagnosticMessages()) { + for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) { if (m.isWarning()) { qWarning("%s:%d : %s", qPrintable(url), m.loc.startLine, qPrintable(m.message)); @@ -1247,7 +1248,7 @@ bool IRBuilder::resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, O // If it's a namespace, prepend the qualifier and we'll resolve it later to the correct type. QString currentName = qualifiedIdElement->name.toString(); if (qualifiedIdElement->next) { - foreach (const QV4::CompiledData::Import* import, _imports) + for (const QV4::CompiledData::Import* import : qAsConst(_imports)) if (import->qualifierIndex != emptyStringIndex && stringAt(import->qualifierIndex) == currentName) { qualifiedIdElement = qualifiedIdElement->next; @@ -1372,7 +1373,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, QQmlEngine QHash<const Object*, quint32> objectOffsets; int objectsSize = 0; - foreach (Object *o, output.objects) { + for (Object *o : qAsConst(output.objects)) { objectOffsets.insert(o, unitSize + importSize + objectOffsetTableSize + objectsSize); objectsSize += QV4::CompiledData::Object::calculateSizeExcludingSignals(o->functionCount(), o->propertyCount(), o->aliasCount(), o->signalCount(), o->bindingCount(), o->namedObjectsInComponent.count); @@ -1418,7 +1419,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, QQmlEngine // write imports char *importPtr = data + qmlUnit->offsetToImports; - foreach (const QV4::CompiledData::Import *imp, output.imports) { + for (const QV4::CompiledData::Import *imp : qAsConst(output.imports)) { QV4::CompiledData::Import *importToWrite = reinterpret_cast<QV4::CompiledData::Import*>(importPtr); *importToWrite = *imp; importPtr += sizeof(QV4::CompiledData::Import); @@ -1523,7 +1524,7 @@ QV4::CompiledData::Unit *QmlUnitGenerator::generate(Document &output, QQmlEngine } // enable flag if we encountered pragma Singleton - foreach (Pragma *p, output.pragmas) { + for (Pragma *p : qAsConst(output.pragmas)) { if (p->type == Pragma::PragmaSingleton) { qmlUnit->flags |= QV4::CompiledData::Unit::IsSingleton; break; @@ -1587,7 +1588,7 @@ QVector<int> JSCodeGen::generateJSCodeForFunctionsAndBindings(const QList<Compil ScanFunctions scan(this, sourceCode, GlobalCode); scan.enterEnvironment(0, QmlBinding); scan.enterQmlScope(qmlRoot, QStringLiteral("context scope")); - foreach (const CompiledFunctionOrExpression &f, functions) { + for (const CompiledFunctionOrExpression &f : functions) { Q_ASSERT(f.node != qmlRoot); QQmlJS::AST::FunctionDeclaration *function = QQmlJS::AST::cast<QQmlJS::AST::FunctionDeclaration*>(f.node); @@ -1922,7 +1923,7 @@ QV4::IR::Expr *JSCodeGen::fallbackNameLookup(const QString &name, int line, int // with the correct QML context. // Look for IDs first. - foreach (const IdMapping &mapping, _idObjects) + for (const IdMapping &mapping : qAsConst(_idObjects)) if (name == mapping.name) { if (_function->isQmlBinding) _function->idObjectDependencies.insert(mapping.idIndex); diff --git a/src/qml/compiler/qqmltypecompiler.cpp b/src/qml/compiler/qqmltypecompiler.cpp index 2308e66609..5e05485b93 100644 --- a/src/qml/compiler/qqmltypecompiler.cpp +++ b/src/qml/compiler/qqmltypecompiler.cpp @@ -471,7 +471,7 @@ bool SignalHandlerConverter::convertSignalHandlerExpressionsToFunctionDeclaratio QQmlJS::MemoryPool *pool = compiler->memoryPool(); QQmlJS::AST::FormalParameterList *paramList = 0; - foreach (const QString ¶m, parameters) { + for (const QString ¶m : qAsConst(parameters)) { QStringRef paramNameRef = compiler->newStringRef(param); if (paramList) @@ -1348,9 +1348,9 @@ bool QQmlJSCodeGenerator::compileJavaScriptCodeInObjectsRecursively(int objectIn functionsToCompile << *foe; } const QVector<int> runtimeFunctionIndices = v4CodeGen->generateJSCodeForFunctionsAndBindings(functionsToCompile); - QList<QQmlError> jsErrors = v4CodeGen->qmlErrors(); + const QList<QQmlError> jsErrors = v4CodeGen->qmlErrors(); if (!jsErrors.isEmpty()) { - foreach (const QQmlError &e, jsErrors) + for (const QQmlError &e : jsErrors) compiler->recordError(e); return false; } @@ -1733,7 +1733,7 @@ void QQmlIRFunctionCleanser::clean() module->functions = newFunctions; - foreach (QV4::IR::Function *function, module->functions) { + for (QV4::IR::Function *function : qAsConst(module->functions)) { for (QV4::IR::BasicBlock *block : function->basicBlocks()) { for (QV4::IR::Stmt *s : block->statements()) { visit(s); @@ -1741,7 +1741,7 @@ void QQmlIRFunctionCleanser::clean() } } - foreach (QmlIR::Object *obj, *compiler->qmlObjects()) { + for (QmlIR::Object *obj : qAsConst(*compiler->qmlObjects())) { for (int i = 0; i < obj->runtimeFunctionIndices.count; ++i) obj->runtimeFunctionIndices[i] = newFunctionIndices[obj->runtimeFunctionIndices.at(i)]; } diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index c6a872cc34..0f39506c28 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -211,7 +211,7 @@ int QV4::Compiler::JSUnitGenerator::registerJSClass(int count, IR::ExprList *arg QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorOption option) { registerString(irModule->fileName); - foreach (QV4::IR::Function *f, irModule->functions) { + for (QV4::IR::Function *f : qAsConst(irModule->functions)) { registerString(*f->name); for (int i = 0; i < f->formals.size(); ++i) registerString(*f->formals.at(i)); @@ -242,7 +242,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorO } CompiledData::Lookup *lookupsToWrite = reinterpret_cast<CompiledData::Lookup*>(dataPtr + unit->offsetToLookupTable); - foreach (const CompiledData::Lookup &l, lookups) + for (const CompiledData::Lookup &l : qAsConst(lookups)) *lookupsToWrite++ = l; CompiledData::RegExp *regexpTable = reinterpret_cast<CompiledData::RegExp *>(dataPtr + unit->offsetToRegexpTable); diff --git a/src/qml/compiler/qv4isel_moth.cpp b/src/qml/compiler/qv4isel_moth.cpp index d54d939e93..91386b1133 100644 --- a/src/qml/compiler/qv4isel_moth.cpp +++ b/src/qml/compiler/qv4isel_moth.cpp @@ -292,7 +292,7 @@ QQmlRefPointer<QV4::CompiledData::CompilationUnit> InstructionSelection::backend { compilationUnit->codeRefs.resize(irModule->functions.size()); int i = 0; - foreach (IR::Function *irFunction, irModule->functions) + for (IR::Function *irFunction : qAsConst(irModule->functions)) compilationUnit->codeRefs[i++] = codeRefs[irFunction]; QQmlRefPointer<QV4::CompiledData::CompilationUnit> result; result.adopt(compilationUnit.take()); diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp index a37d8ef7a5..a98cf6d338 100644 --- a/src/qml/compiler/qv4ssa.cpp +++ b/src/qml/compiler/qv4ssa.cpp @@ -1123,7 +1123,7 @@ public: { QVector<UntypedTemp> res; res.reserve(tempCount()); - foreach (const DefUse &du, _defUses) + for (const DefUse &du : _defUses) if (du.isValid()) res.append(UntypedTemp(du.temp)); return res; @@ -1150,7 +1150,7 @@ public: { Q_ASSERT(static_cast<unsigned>(variable.index) < _defUses.size()); QVector<Stmt *> &uses = _defUses[variable.index].uses; - foreach (Stmt *stmt, newUses) + for (Stmt *stmt : newUses) if (std::find(uses.begin(), uses.end(), stmt) == uses.end()) uses.push_back(stmt); } @@ -1226,7 +1226,7 @@ public: QVector<Stmt*> removeDefUses(Stmt *s) { QVector<Stmt*> defStmts; - foreach (const Temp &usedVar, usedVars(s)) { + for (const Temp &usedVar : usedVars(s)) { if (Stmt *ds = defStmt(usedVar)) defStmts += ds; removeUse(s, usedVar); @@ -1247,7 +1247,7 @@ public: buf.open(QIODevice::WriteOnly); QTextStream qout(&buf); qout << "Defines and uses:" << endl; - foreach (const DefUse &du, _defUses) { + for (const DefUse &du : _defUses) { if (!du.isValid()) continue; qout << '%' << du.temp.index; @@ -1255,14 +1255,14 @@ public: << ", statement: " << du.defStmt->id() << endl; qout << " uses:"; - foreach (Stmt *s, du.uses) + for (Stmt *s : du.uses) qout << ' ' << s->id(); qout << endl; } qout << "Uses per statement:" << endl; for (size_t i = 0, ei = _usesPerStatement.size(); i != ei; ++i) { qout << " " << i << ":"; - foreach (const Temp &t, _usesPerStatement[i]) + for (const Temp &t : _usesPerStatement[i]) qout << ' ' << t.index; qout << endl; } @@ -1633,7 +1633,7 @@ bool hasPhiOnlyUses(Phi *phi, const DefUses &defUses, QBitArray &collectedPhis) { collectedPhis.setBit(phi->id()); - foreach (Stmt *use, defUses.uses(*phi->targetTemp)) { + for (Stmt *use : defUses.uses(*phi->targetTemp)) { Phi *dependentPhi = use->asPhi(); if (!dependentPhi) return false; // there is a use by a non-phi node @@ -1679,7 +1679,7 @@ void cleanupPhis(DefUses &defUses) const Temp &targetVar = *phi->targetTemp; defUses.defStmtBlock(targetVar)->removeStatement(phi); - foreach (const Temp &usedVar, defUses.usedVars(phi)) + for (const Temp &usedVar : defUses.usedVars(phi)) defUses.removeUse(phi, usedVar); defUses.removeDef(targetVar); } @@ -1729,7 +1729,7 @@ public: worklist.assign(worklist.size(), false); worklistSize = 0; - foreach (Stmt *s, stmts) { + for (Stmt *s : stmts) { if (!s) continue; @@ -1802,7 +1802,7 @@ public: StatementWorklist &operator+=(const QVector<Stmt *> &stmts) { - foreach (Stmt *s, stmts) + for (Stmt *s : stmts) this->operator+=(s); return *this; @@ -2092,7 +2092,7 @@ public: theTemp = temp; if (Stmt *defStmt = defUses.defStmt(temp.temp)) visit(defStmt); - foreach (Stmt *use, defUses.uses(temp.temp)) + for (Stmt *use : defUses.uses(temp.temp)) visit(use); } @@ -2246,7 +2246,7 @@ private: it = ty; if (DebugTypeInference) { - foreach (Stmt *s, _defUses.uses(*t)) { + for (Stmt *s : _defUses.uses(*t)) { QBuffer buf; buf.open(QIODevice::WriteOnly); QTextStream qout(&buf); @@ -2606,7 +2606,7 @@ public: } PropagateTempTypes propagator(_defUses); - foreach (const UntypedTemp &t, knownOk) { + for (const UntypedTemp &t : qAsConst(knownOk)) { propagator.run(t, SInt32Type); if (Stmt *defStmt = _defUses.defStmt(t.temp)) { if (Move *m = defStmt->asMove()) { @@ -2630,7 +2630,7 @@ private: if (uses.isEmpty()) return false; - foreach (Stmt *use, uses) { + for (Stmt *use : uses) { if (Move *m = use->asMove()) { Temp *targetTemp = m->target->asTemp(); @@ -3165,7 +3165,8 @@ public: std::vector<BasicBlock *> backedges; backedges.reserve(4); - foreach (BasicBlock *bb, dt.calculateDFNodeIterOrder()) { + const auto order = dt.calculateDFNodeIterOrder(); + for (BasicBlock *bb : order) { Q_ASSERT(!bb->isRemoved()); backedges.clear(); @@ -3188,12 +3189,12 @@ public: if (!DebugLoopDetection) return; - foreach (LoopInfo *info, loopInfos) { + for (const LoopInfo *info : loopInfos) { qDebug() << "Loop header:" << info->loopHeader->index() << "for loop" << quint64(info); - foreach (BasicBlock *bb, info->loopBody) + for (BasicBlock *bb : info->loopBody) qDebug() << " " << bb->index(); - foreach (LoopInfo *nested, info->nestedLoops) + for (LoopInfo *nested : info->nestedLoops) qDebug() << " sub loop:" << quint64(nested); qDebug() << " parent loop:" << quint64(info->parentLoop); } @@ -3277,15 +3278,15 @@ private: findLoop(loopHeader)->loopBody.append(bb); } - foreach (LoopInfo *info, loopInfos) { - if (BasicBlock *containingLoopHeader = info->loopHeader->containingGroup()) - findLoop(containingLoopHeader)->addNestedLoop(info); + for (int i = 0, size = loopInfos.size(); i < size; ++i) { + if (BasicBlock *containingLoopHeader = loopInfos.at(i)->loopHeader->containingGroup()) + findLoop(containingLoopHeader)->addNestedLoop(loopInfos.at(i)); } } LoopInfo *findLoop(BasicBlock *loopHeader) { - foreach (LoopInfo *info, loopInfos) { + for (LoopInfo *info : qAsConst(loopInfos)) { if (info->loopHeader == loopHeader) return info; } @@ -3459,8 +3460,8 @@ public: }; #ifndef QT_NO_DEBUG -void checkCriticalEdges(QVector<BasicBlock *> basicBlocks) { - foreach (BasicBlock *bb, basicBlocks) { +void checkCriticalEdges(const QVector<BasicBlock *> &basicBlocks) { + for (BasicBlock *bb : basicBlocks) { if (bb && bb->out.size() > 1) { for (BasicBlock *bb2 : bb->out) { if (bb2 && bb2->in.size() > 1) { @@ -3594,7 +3595,7 @@ public: newUses->reserve(uses.size()); // qout << " " << uses.size() << " uses:"<<endl; - foreach (Stmt *use, uses) { + for (Stmt *use : uses) { // qout<<" ";use->dump(qout);qout<<"\n"; visit(use); // qout<<" -> ";use->dump(qout);qout<<"\n"; @@ -3752,7 +3753,7 @@ void unlink(BasicBlock *from, BasicBlock *to, IR::Function *func, DefUses &defUs return; to->in.remove(idx); - foreach (Stmt *outStmt, to->statements()) { + for (Stmt *outStmt : to->statements()) { if (!outStmt) continue; if (Phi *phi = outStmt->asPhi()) { @@ -3770,7 +3771,7 @@ void unlink(BasicBlock *from, BasicBlock *to, IR::Function *func, DefUses &defUs static bool isReachable(BasicBlock *bb, const DominatorTree &dt) { - foreach (BasicBlock *in, bb->in) { + for (BasicBlock *in : bb->in) { if (in->isRemoved()) continue; if (dt.dominates(bb, in)) // a back-edge, not interesting @@ -3940,13 +3941,13 @@ void cfg2dot(IR::Function *f, const QVector<LoopDetection::LoopInfo *> &loops = struct Util { QTextStream &qout; Util(QTextStream &qout): qout(qout) {} - void genLoop(LoopDetection::LoopInfo *loop) + void genLoop(const LoopDetection::LoopInfo *loop) { qout << " subgraph \"cluster" << quint64(loop) << "\" {\n"; qout << " L" << loop->loopHeader->index() << ";\n"; - foreach (BasicBlock *bb, loop->loopBody) + for (BasicBlock *bb : loop->loopBody) qout << " L" << bb->index() << ";\n"; - foreach (LoopDetection::LoopInfo *nested, loop->nestedLoops) + for (LoopDetection::LoopInfo *nested : loop->nestedLoops) genLoop(nested); qout << " }\n"; } @@ -3957,7 +3958,7 @@ void cfg2dot(IR::Function *f, const QVector<LoopDetection::LoopInfo *> &loops = else name = QStringLiteral("%1").arg((unsigned long long)f); qout << "digraph \"" << name << "\" { ordering=out;\n"; - foreach (LoopDetection::LoopInfo *l, loops) { + for (LoopDetection::LoopInfo *l : loops) { if (l->parentLoop == 0) Util(qout).genLoop(l); } @@ -4463,7 +4464,8 @@ public: qout << "Life ranges:" << endl; qout << "Intervals:" << endl; - foreach (const LifeTimeInterval *range, _sortedIntervals->intervals()) { + const auto intervals = _sortedIntervals->intervals(); + for (const LifeTimeInterval *range : intervals) { range->dump(qout); qout << endl; } @@ -4723,7 +4725,7 @@ private: clonedStmt = phi; phi->targetTemp = clone(p->targetTemp); - foreach (Expr *in, p->incoming) + for (Expr *in : p->incoming) phi->incoming.append(clone(in)); block->appendStatement(phi); } else { @@ -4753,7 +4755,7 @@ public: void run(const QVector<LoopDetection::LoopInfo *> &loops) { - foreach (LoopDetection::LoopInfo *loopInfo, loops) + for (LoopDetection::LoopInfo *loopInfo : loops) peelLoop(loopInfo); } @@ -4857,7 +4859,7 @@ private: // The original loop is now peeled off, and won't jump back to the loop header. Meaning, it // is not a loop anymore, so unmark it. loop->loopHeader->markAsGroupStart(false); - foreach (BasicBlock *bb, loop->loopBody) + for (BasicBlock *bb : qAsConst(loop->loopBody)) bb->setContainingGroup(loop->loopHeader->containingGroup()); // calculate the idoms in a separate loop, because addBasicBlock in the previous loop will @@ -4875,7 +4877,7 @@ private: } BasicBlockSet siblings(f); - foreach (BasicBlock *bb, loopExits) + for (BasicBlock *bb : qAsConst(loopExits)) dt.collectSiblings(bb, siblings); dt.recalculateIDoms(siblings, loop->loopHeader); @@ -5658,7 +5660,7 @@ QList<IR::Move *> MoveMapping::insertMoves(BasicBlock *bb, IR::Function *functio newMoves.reserve(_moves.size()); int insertionPoint = atEnd ? bb->statements().size() - 1 : 0; - foreach (const Move &m, _moves) { + for (const Move &m : _moves) { IR::Move *move = function->NewStmt<IR::Move>(); move->init(clone(m.to, function), clone(m.from, function)); move->swap = m.needsSwap; @@ -5677,7 +5679,7 @@ void MoveMapping::dump() const QTextStream os(&buf); IRPrinter printer(&os); os << "Move mapping has " << _moves.size() << " moves..." << endl; - foreach (const Move &m, _moves) { + for (const Move &m : _moves) { os << "\t"; printer.print(m.to); if (m.needsSwap) @@ -5694,8 +5696,8 @@ void MoveMapping::dump() const MoveMapping::Action MoveMapping::schedule(const Move &m, QList<Move> &todo, QList<Move> &delayed, QList<Move> &output, QList<Move> &swaps) const { - Moves usages = sourceUsages(m.to, todo) + sourceUsages(m.to, delayed); - foreach (const Move &dependency, usages) { + const Moves usages = sourceUsages(m.to, todo) + sourceUsages(m.to, delayed); + for (const Move &dependency : usages) { if (!output.contains(dependency)) { if (delayed.contains(dependency)) { // We have a cycle! Break it by swapping instead of assigning. @@ -5706,7 +5708,7 @@ MoveMapping::Action MoveMapping::schedule(const Move &m, QList<Move> &todo, QLis QTextStream out(&buf); IRPrinter printer(&out); out<<"we have a cycle! temps:" << endl; - foreach (const Move &m, delayed) { + for (const Move &m : qAsConst(delayed)) { out<<"\t"; printer.print(m.to); out<<" <- "; diff --git a/src/qml/compiler/qv4ssa_p.h b/src/qml/compiler/qv4ssa_p.h index f64fb9c3d9..f1e191de4b 100644 --- a/src/qml/compiler/qv4ssa_p.h +++ b/src/qml/compiler/qv4ssa_p.h @@ -412,8 +412,8 @@ protected: } } moves.order(); - QList<IR::Move *> newMoves = moves.insertMoves(_currentBasicBlock, _function, true); - foreach (IR::Move *move, newMoves) + const QList<IR::Move *> newMoves = moves.insertMoves(_currentBasicBlock, _function, true); + for (IR::Move *move : newMoves) visit(move); } } @@ -444,7 +444,7 @@ protected: #if !defined(QT_NO_DEBUG) Q_ASSERT(_stackSlotForTemp.contains(phi->targetTemp->index)); Q_ASSERT(_slotIsInUse[_stackSlotForTemp[phi->targetTemp->index]]); - foreach (IR::Expr *e, phi->incoming) { + for (IR::Expr *e : phi->incoming) { if (IR::Temp *t = e->asTemp()) Q_ASSERT(_stackSlotForTemp.contains(t->index)); } |