Commit 3ff40c0e authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplastform/language/duchain: port foreach -> range-based for

parent a21a224b
......@@ -95,12 +95,13 @@ protected:
DUChainReadLocker lock(DUChain::lock());
QList<Declaration*> declarations = LanguageSpecificUseBuilderBase::currentContext()->findDeclarations(id,
newRange.start);
foreach (Declaration* declaration, declarations)
for (Declaration* declaration : qAsConst(declarations)) {
if (!declaration->isForwardDeclaration()) {
declarations.clear();
declarations.append(declaration);
break;
}
}
// If we don't break, there's no non-forward declaration
......
......@@ -683,8 +683,10 @@ QMap<IndexedString, QVector<RangeInRevision>> Declaration::uses() const
//First, search for uses within the own context
{
QMap<RangeInRevision, bool>& ranges(tempUses[topContext()->url()]);
foreach (const RangeInRevision range, allUses(topContext(), const_cast<Declaration*>(this)))
const auto useRanges = allUses(topContext(), const_cast<Declaration*>(this));
for (const RangeInRevision range : useRanges) {
ranges[range] = true;
}
}
DeclarationId _id = id();
......@@ -694,12 +696,14 @@ QMap<IndexedString, QVector<RangeInRevision>> Declaration::uses() const
useContexts.append(directUseContexts.data(), directUseContexts.size());
}
foreach (const IndexedTopDUContext indexedContext, useContexts) {
for (const IndexedTopDUContext indexedContext : qAsConst(useContexts)) {
TopDUContext* context = indexedContext.data();
if (context) {
QMap<RangeInRevision, bool>& ranges(tempUses[context->url()]);
foreach (const RangeInRevision range, allUses(context, const_cast<Declaration*>(this)))
const auto useRanges = allUses(context, const_cast<Declaration*>(this));
for (const RangeInRevision range : useRanges) {
ranges[range] = true;
}
}
}
......@@ -728,7 +732,8 @@ bool hasDeclarationUse(DUContext* context, int declIdx)
ret = uses[i].m_declarationIndex == declIdx;
}
foreach (DUContext* child, context->childContexts()) {
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
ret = ret || hasDeclarationUse(child, declIdx);
if (ret)
break;
......@@ -763,7 +768,8 @@ QMap<IndexedString, QVector<KTextEditor::Range>> Declaration::usesCurrentRevisio
//First, search for uses within the own context
{
QMap<KTextEditor::Range, bool>& ranges(tempUses[topContext()->url()]);
foreach (const RangeInRevision range, allUses(topContext(), const_cast<Declaration*>(this))) {
const auto useRanges = allUses(topContext(), const_cast<Declaration*>(this));
for (const RangeInRevision range : useRanges) {
ranges[topContext()->transformFromLocalRevision(range)] = true;
}
}
......@@ -775,12 +781,14 @@ QMap<IndexedString, QVector<KTextEditor::Range>> Declaration::usesCurrentRevisio
useContexts.append(directUseContexts.data(), directUseContexts.size());
}
foreach (const IndexedTopDUContext indexedContext, useContexts) {
for (const IndexedTopDUContext indexedContext : qAsConst(useContexts)) {
TopDUContext* context = indexedContext.data();
if (context) {
QMap<KTextEditor::Range, bool>& ranges(tempUses[context->url()]);
foreach (const RangeInRevision range, allUses(context, const_cast<Declaration*>(this)))
const auto useRanges = allUses(context, const_cast<Declaration*>(this));
for (const RangeInRevision range : useRanges) {
ranges[context->transformFromLocalRevision(range)] = true;
}
}
}
......
......@@ -140,7 +140,7 @@ KDevVarLengthArray<Declaration*> DeclarationId::declarations(const TopDUContext*
if (!ret.isEmpty() && m_specialization.index()) {
KDevVarLengthArray<Declaration*> newRet;
foreach (Declaration* decl, ret) {
for (Declaration* decl : qAsConst(ret)) {
Declaration* specialized = decl->specialize(m_specialization, top ? top : decl->topContext());
if (specialized)
newRet.append(specialized);
......
......@@ -403,8 +403,10 @@ public:
QMutexLocker l(&m_chainsMutex);
foreach (TopDUContext* top, m_chainsByUrl)
const auto currentChainsByUrl = m_chainsByUrl;
for (TopDUContext* top : currentChainsByUrl) {
removeDocumentChainFromMemory(top);
}
m_indexEnvironmentInformations.clear();
m_fileEnvironmentInformations.clear();
......@@ -558,7 +560,7 @@ public:
//Process the indices in a separate step after copying them from the array, so we don't need m_environmentListInfo.mutex locked,
//and can call loadInformation(..) safely, which else might lead to a deadlock.
foreach (uint topContextIndex, topContextIndices) {
for (uint topContextIndex : qAsConst(topContextIndices)) {
QExplicitlySharedDataPointer<ParsingEnvironmentFile> p =
ParsingEnvironmentFilePointer(loadInformation(topContextIndex));
if (p) {
......@@ -573,9 +575,11 @@ public:
QMutexLocker l(&m_chainsMutex);
//Add those information that have not been added to the stored lists yet
foreach (const ParsingEnvironmentFilePointer& file, m_fileEnvironmentInformations.values(url))
const auto files = m_fileEnvironmentInformations.values(url);
for (const ParsingEnvironmentFilePointer& file : files) {
if (!ret.contains(file))
ret << file;
}
return ret;
}
......@@ -626,7 +630,8 @@ public:
if (!chain->usingImportsCache()) {
//Eventually also load all the imported chains, so the import-structure is built
foreach (const DUContext::Import& import, chain->DUContext::importedParentContexts()) {
const auto importedParentContexts = chain->DUContext::importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
if (!loaded.contains(import.topContextIndex())) {
loadChain(import.topContextIndex(), loaded);
}
......@@ -656,14 +661,14 @@ public:
urls += m_fileEnvironmentInformations.keys();
}
foreach (const IndexedString& url, urls) {
for (const IndexedString& url : qAsConst(urls)) {
QList<ParsingEnvironmentFilePointer> check;
{
QMutexLocker lock(&m_chainsMutex);
check = m_fileEnvironmentInformations.values(url);
}
foreach (ParsingEnvironmentFilePointer file, check) {
for (const ParsingEnvironmentFilePointer& file : qAsConst(check)) {
EnvironmentInformationRequest req(file.data());
QMutexLocker lock(m_environmentInfo.mutex());
uint index = m_environmentInfo.findIndex(req);
......@@ -768,13 +773,13 @@ public:
writeLock.unlock();
//Here we wait for all parsing-threads to stop their processing
foreach (const auto language, languages) {
for (const auto language : qAsConst(languages)) {
if (lockFlag == TryLock) {
if (!language->parseLock()->tryLockForWrite()) {
qCDebug(LANGUAGE) << "Aborting cleanup because language plugin is still parsing:" <<
language->name();
// some language is still parsing, don't interfere with the cleanup
foreach (auto* lock, locked) {
for (auto* lock : qAsConst(locked)) {
lock->unlock();
}
......@@ -804,13 +809,13 @@ public:
QMutexLocker l(&m_chainsMutex);
workOnContexts.reserve(m_chainsByUrl.size());
foreach (TopDUContext* top, m_chainsByUrl) {
for (TopDUContext* top : qAsConst(m_chainsByUrl)) {
workOnContexts << top;
Q_ASSERT(hasChainForIndex(top->ownIndex()));
}
}
foreach (TopDUContext* context, workOnContexts) {
for (TopDUContext* context : qAsConst(workOnContexts)) {
context->m_dynamicData->store();
if (retries) {
......@@ -839,7 +844,8 @@ public:
unloadContexts:
foreach (TopDUContext * unload, workOnContexts) {
const auto currentWorkOnContexts = workOnContexts;
for (TopDUContext * unload : currentWorkOnContexts) {
bool hasReference = false;
{
......@@ -957,8 +963,9 @@ unloadContexts:
m_chainsByUrl.size() << "- retries" << retries;
}
foreach (QReadWriteLock* lock, locked)
for (QReadWriteLock* lock : qAsConst(locked)) {
lock->unlock();
}
#if HAVE_MALLOC_TRIM
// trim unused memory but keep a pad buffer of about 50 MB
......@@ -1063,7 +1070,7 @@ unloadContexts:
if (check.size() < checkContextsCount)
addContextsForRemoval(check, IndexedTopDUContext(visitor.checkContexts[a]));
foreach (uint topIndex, check) {
for (uint topIndex : qAsConst(check)) {
IndexedTopDUContext top(topIndex);
if (top.data()) {
qCDebug(LANGUAGE) << "removing top-context for" << top.data()->url().str() <<
......@@ -1525,7 +1532,7 @@ QList<QUrl> DUChain::documents() const
QList<QUrl> ret;
ret.reserve(sdDUChainPrivate->m_chainsByUrl.count());
foreach (TopDUContext* top, sdDUChainPrivate->m_chainsByUrl) {
for (TopDUContext* top : qAsConst(sdDUChainPrivate->m_chainsByUrl)) {
ret << top->url().toUrl();
}
......@@ -1538,7 +1545,7 @@ QList<IndexedString> DUChain::indexedDocuments() const
QList<IndexedString> ret;
ret.reserve(sdDUChainPrivate->m_chainsByUrl.count());
foreach (TopDUContext* top, sdDUChainPrivate->m_chainsByUrl) {
for (TopDUContext* top : qAsConst(sdDUChainPrivate->m_chainsByUrl)) {
ret << top->url();
}
......@@ -1580,9 +1587,11 @@ void DUChain::documentClosed(IDocument* document)
IndexedString url(document->url());
foreach (const ReferencedTopDUContext& top, sdDUChainPrivate->m_openDocumentContexts)
const auto currentDocumentContexts = sdDUChainPrivate->m_openDocumentContexts;
for (const ReferencedTopDUContext& top : currentDocumentContexts) {
if (top->url() == url)
sdDUChainPrivate->m_openDocumentContexts.remove(top);
}
}
void DUChain::documentLoadedPrepare(KDevelop::IDocument* doc)
......@@ -1614,9 +1623,11 @@ void DUChain::documentLoadedPrepare(KDevelop::IDocument* doc)
//This is not exactly right, as the direct imports don't necessarily equal the real imports used by uses
//but it approximates the correct behavior.
bool allImportsLoaded = true;
foreach (const DUContext::Import& import, standardContext->importedParentContexts())
const auto importedParentContexts = standardContext->importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
if (!import.indexedContext().indexedTopContext().isLoaded())
allImportsLoaded = false;
}
if (allImportsLoaded) {
l.unlock();
......
......@@ -117,7 +117,8 @@ void DUChainDumperPrivate::dumpProblems(TopDUContext* top, QTextStream& out)
if (!top->problems().isEmpty()) {
qout << top->problems().size() << "problems encountered:" << endl;
foreach (const ProblemPointer& p, top->problems()) {
const auto problems = top->problems();
for (const ProblemPointer& p : problems) {
qout << Indent(m_indent * 2) << p->description() << p->explanation() << p->finalLocation() << endl;
}
......@@ -147,7 +148,8 @@ void DUChainDumperPrivate::dump(DUContext* context, int allowedDepth, bool isFro
auto top = context->topContext();
if (allowedDepth >= 0) {
foreach (Declaration* dec, context->localDeclarations(top)) {
const auto localDeclarations = context->localDeclarations(top);
for (Declaration* dec : localDeclarations) {
//IdentifiedType* idType = dynamic_cast<IdentifiedType*>(dec->abstractType().data());
qout << Indent((m_indent + 2) * 2) << "Declaration:" << dec->toString() << "[" <<
......@@ -162,8 +164,9 @@ void DUChainDumperPrivate::dump(DUContext* context, int allowedDepth, bool isFro
const auto uses = dec->uses();
for (auto it = uses.constBegin(); it != uses.constEnd(); ++it) {
qout << Indent((m_indent + 3) * 2) << "File:" << it.key().str() << endl;
foreach (const RangeInRevision range, * it)
for (const RangeInRevision range : qAsConst(*it)) {
qout << Indent((m_indent + 4) * 2) << "Use:" << range.castToSimpleRange() << endl;
}
}
}
} else {
......@@ -174,7 +177,8 @@ void DUChainDumperPrivate::dump(DUContext* context, int allowedDepth, bool isFro
++m_indent;
{
/*
foreach (const DUContext::Import &parent, context->importedParentContexts()) {
const auto importedParentContexts = context->importedParentContexts();
for (const DUContext::Import& parent : importedParentContexts) {
DUContext* import = parent.context(top);
if(!import) {
qout << Indent((m_indent+2) * 2+1) << "Could not get parent, is it registered in the DUChain?" << endl;
......@@ -185,8 +189,10 @@ void DUChainDumperPrivate::dump(DUContext* context, int allowedDepth, bool isFro
}
*/
foreach (DUContext* child, context->childContexts())
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
dump(child, allowedDepth - 1, false, out);
}
}
--m_indent;
}
......
......@@ -301,7 +301,8 @@ struct ItemUnderCursorInternal
ItemUnderCursorInternal itemUnderCursorInternal(const CursorInRevision& c, DUContext* ctx, RangeInRevision::ContainsBehavior behavior)
{
//Search all collapsed sub-contexts. In C++, those can contain declarations that have ranges out of the context
foreach(DUContext* subCtx, ctx->childContexts()) {
const auto childContexts = ctx->childContexts();
for (DUContext* subCtx : childContexts) {
//This is a little hacky, but we need it in case of foreach macros and similar stuff
if(subCtx->range().contains(c, behavior) || subCtx->range().isEmpty() || subCtx->range().start.line == c.line || subCtx->range().end.line == c.line) {
ItemUnderCursorInternal sub = itemUnderCursorInternal(c, subCtx, behavior);
......@@ -311,7 +312,8 @@ ItemUnderCursorInternal itemUnderCursorInternal(const CursorInRevision& c, DUCon
}
}
foreach(Declaration* decl, ctx->localDeclarations()) {
const auto localDeclarations = ctx->localDeclarations();
for (Declaration* decl : localDeclarations) {
if(decl->range().contains(c, behavior)) {
return {decl, ctx, decl->range()};
}
......@@ -366,7 +368,8 @@ Declaration* DUChainUtils::declarationInLine(const KTextEditor::Cursor& _cursor,
CursorInRevision cursor = ctx->transformToLocalRevision(_cursor);
foreach(Declaration* decl, ctx->localDeclarations()) {
const auto localDeclarations = ctx->localDeclarations();
for (Declaration* decl : localDeclarations) {
if(decl->range().start.line == cursor.line)
return decl;
DUContext* funCtx = functionContext(decl);
......@@ -374,7 +377,8 @@ Declaration* DUChainUtils::declarationInLine(const KTextEditor::Cursor& _cursor,
return decl;
}
foreach(DUContext* child, ctx->childContexts()){
const auto childContexts = ctx->childContexts();
for (DUContext* child : childContexts){
Declaration* decl = declarationInLine(_cursor, child);
if(decl)
return decl;
......@@ -438,7 +442,8 @@ KDevelop::DUContext* DUChainUtils::argumentContext(KDevelop::Declaration* decl)
return nullptr;
if( internal->type() == DUContext::Function )
return internal;
foreach( const DUContext::Import &ctx, internal->importedParentContexts() ) {
const auto importedParentContexts = internal->importedParentContexts();
for (const DUContext::Import& ctx : importedParentContexts) {
if( ctx.context(decl->topContext()) )
if( ctx.context(decl->topContext())->type() == DUContext::Function )
return ctx.context(decl->topContext());
......@@ -474,7 +479,8 @@ static QList<Declaration*> inheritersInternal(const Declaration* decl, uint& max
return ret;
if(decl->internalContext() && decl->internalContext()->type() == DUContext::Class) {
foreach (const IndexedDUContext importer, decl->internalContext()->indexedImporters()) {
const auto indexedImporters = decl->internalContext()->indexedImporters();
for (const IndexedDUContext importer : indexedImporters) {
DUContext* imp = importer.data();
......@@ -530,8 +536,10 @@ QList<Declaration*> DUChainUtils::overriders(const Declaration* currentClass, co
if(currentClass != overriddenDeclaration->context()->owner() && currentClass->internalContext())
ret += currentClass->internalContext()->findLocalDeclarations(overriddenDeclaration->identifier(), CursorInRevision::invalid(), currentClass->topContext(), overriddenDeclaration->abstractType());
foreach(Declaration* inheriter, inheriters(currentClass, maxAllowedSteps))
const auto inheriters = DUChainUtils::inheriters(currentClass, maxAllowedSteps);
for (Declaration* inheriter : inheriters) {
ret += overriders(inheriter, overriddenDeclaration, maxAllowedSteps);
}
return ret;
}
......@@ -544,10 +552,10 @@ static bool hasUse(DUContext* context, int usedDeclarationIndex) {
if(context->uses()[a].m_declarationIndex == usedDeclarationIndex)
return true;
foreach(DUContext* child, context->childContexts())
if(hasUse(child, usedDeclarationIndex))
return true;
return false;
const auto childContexts = context->childContexts();
return std::any_of(childContexts.begin(), childContexts.end(), [&](DUContext* child) {
return hasUse(child, usedDeclarationIndex);
});
}
bool DUChainUtils::contextHasUse(DUContext* context, Declaration* declaration) {
......@@ -564,8 +572,10 @@ static uint countUses(DUContext* context, int usedDeclarationIndex) {
if(context->uses()[a].m_declarationIndex == usedDeclarationIndex)
++ret;
foreach(DUContext* child, context->childContexts())
const auto childContexts = context->childContexts();
for (DUContext* child : childContexts) {
ret += countUses(child, usedDeclarationIndex);
}
return ret;
}
......@@ -581,26 +591,27 @@ Declaration* DUChainUtils::overridden(const Declaration* decl) {
QList<Declaration*> decls;
foreach(const DUContext::Import &import, decl->context()->importedParentContexts()) {
const auto importedParentContexts = decl->context()->importedParentContexts();
for (const DUContext::Import &import : importedParentContexts) {
DUContext* ctx = import.context(decl->topContext());
if(ctx)
decls += ctx->findDeclarations(QualifiedIdentifier(decl->identifier()),
CursorInRevision::invalid(), decl->abstractType(), decl->topContext(), DUContext::DontSearchInParent);
}
foreach(Declaration* found, decls) {
auto it = std::find_if(decls.constBegin(), decls.constEnd(), [&](Declaration* found) {
const auto* foundClassFunDecl = dynamic_cast<const ClassFunctionDeclaration*>(found);
if(foundClassFunDecl && foundClassFunDecl->isVirtual())
return found;
}
return (foundClassFunDecl && foundClassFunDecl->isVirtual());
});
return nullptr;
return (it != decls.constEnd()) ? *it : nullptr;
}
DUContext* DUChainUtils::functionContext(Declaration* decl) {
DUContext* functionContext = decl->internalContext();
if(functionContext && functionContext->type() != DUContext::Function) {
foreach(const DUContext::Import& import, functionContext->importedParentContexts()) {
const auto importedParentContexts = functionContext->importedParentContexts();
for (const DUContext::Import& import : importedParentContexts) {
DUContext* ctx = import.context(decl->topContext());
if(ctx && ctx->type() == DUContext::Function)
functionContext = ctx;
......@@ -614,13 +625,19 @@ DUContext* DUChainUtils::functionContext(Declaration* decl) {
QVector<KDevelop::Problem::Ptr> KDevelop::DUChainUtils::allProblemsForContext(const KDevelop::ReferencedTopDUContext& top)
{
QVector<KDevelop::Problem::Ptr> ret;
Q_FOREACH ( const auto& p, top->problems() ) {
ret << p;
}
Q_FOREACH ( const auto& p, ICore::self()->languageController()->staticAssistantsManager()->problemsForContext(top) ) {
ret << p;
}
return ret;
QVector<KDevelop::Problem::Ptr> ret;
const auto problems = top->problems();
const auto contextProblems = ICore::self()->languageController()->staticAssistantsManager()->problemsForContext(top);
ret.reserve(problems.size() + contextProblems.size());
for (const auto& p : problems) {
ret << p;
}
for (const auto& p : contextProblems) {
ret << p;
}
return ret;
}
......@@ -707,7 +707,7 @@ bool DUContext::findDeclarationsInternal(const SearchItem::PtrList& baseIdentifi
if (d->m_importedContextsSize() != 0) {
///Step 2: Give identifiers that are not marked as explicitly-global to imported contexts(explicitly global ones are treatead in TopDUContext)
SearchItem::PtrList nonGlobalIdentifiers;
foreach (const SearchItem::Ptr& identifier, aliasedIdentifiers) {
for (const SearchItem::Ptr& identifier : qAsConst(aliasedIdentifiers)) {
if (!identifier->isExplicitlyGlobal) {
nonGlobalIdentifiers << identifier;
}
......@@ -775,8 +775,9 @@ QVector<QualifiedIdentifier> DUContext::fullyApplyAliases(const QualifiedIdentif
}
QVector<QualifiedIdentifier> ret;
foreach (const SearchItem::Ptr& item, identifiers)
for (const SearchItem::Ptr& item : qAsConst(identifiers)) {
ret += item->toList();
}
return ret;
}
......@@ -915,7 +916,7 @@ DUContext* DUContext::findContext(const CursorInRevision& position, DUContext* p
if (!parent)
parent = const_cast<DUContext*>(this);
foreach (DUContext* context, parent->m_dynamicData->m_childContexts) {
for (DUContext* context : qAsConst(parent->m_dynamicData->m_childContexts)) {
if (context->range().contains(position)) {
DUContext* ret = findContext(position, context);
if (!ret) {
......@@ -934,13 +935,10 @@ bool DUContext::parentContextOf(DUContext* context) const
if (this == context)
return true;
foreach (DUContext* child, m_dynamicData->m_childContexts) {
if (child->parentContextOf(context)) {
return true;
}
}
return false;
const auto& childContexts = m_dynamicData->m_childContexts;
return std::any_of(childContexts.begin(), childContexts.end(), [&](DUContext* child) {
return child->parentContextOf(context);
});
}
QVector<QPair<Declaration*, int>> DUContext::allDeclarations(const CursorInRevision& position,
......@@ -1045,7 +1043,8 @@ void DUContext::deleteLocalDeclarations()
if (d_func()->m_localDeclarations()) {
indexedLocal.append(d_func()->m_localDeclarations(), d_func()->m_localDeclarationsSize());
}
foreach (const LocalIndexedDeclaration& indexed, m_dynamicData->m_localDeclarations) {
const auto currentLocalDeclarations = m_dynamicData->m_localDeclarations;
for (const LocalIndexedDeclaration& indexed : currentLocalDeclarations) {
delete indexed.data(topContext());
}
......@@ -1056,11 +1055,9 @@ void DUContext::deleteChildContextsRecursively()
{
ENSURE_CAN_WRITE
// note: don't use qDeleteAll here because child ctx deletion changes m_dynamicData->m_childContexts
// also note: foreach iterates on a copy, so this is safe
foreach (DUContext * ctx, m_dynamicData->m_childContexts) {
delete ctx;
}
// note: operate on copy here because child ctx deletion changes m_dynamicData->m_childContexts
const auto currentChildContexts = m_dynamicData->m_childContexts;
qDeleteAll(currentChildContexts);
m_dynamicData->m_childContexts.clear();
}
......@@ -1068,7 +1065,7 @@ void DUContext::deleteChildContextsRecursively()
QVector<Declaration*> DUContext::clearLocalDeclarations()
{
auto copy = m_dynamicData->m_localDeclarations;
foreach (Declaration* dec, copy) {
for (Declaration* dec : qAsConst(copy)) {
dec->setContext(nullptr);
}
......@@ -1179,7 +1176,7 @@ void DUContext::deleteUsesRecursively()
{
deleteUses();
foreach (DUContext* childContext, m_dynamicData->m_childContexts) {
for (DUContext* childContext : qAsConst(m_dynamicData->m_childContexts)) {
childContext->deleteUsesRecursively();
}
}
......@@ -1241,7 +1238,7 @@ void DUContext::applyAliases(const SearchItem::PtrList& baseIdentifiers, SearchI
if (!identifier->isExplicitlyGlobal) {
if (!imports.isEmpty()) {
//We have namespace-imports.
foreach (Declaration* importDecl, imports) {
for (Declaration* importDecl : qAsConst(imports)) {
//Search for the identifier with the import-identifier prepended
if (dynamic_cast<NamespaceAliasDeclaration*>(importDecl)) {
auto* alias = static_cast<NamespaceAliasDeclaration*>(importDecl);
......@@ -1261,7 +1258,7 @@ void DUContext::applyAliases(const SearchItem::PtrList& baseIdentifiers, SearchI
if (!aliases.isEmpty()) {
//The first part of the identifier has been found as a namespace-alias.
//In c++, we only need the first alias. However, just to be correct, follow them all for now.
foreach (Declaration* aliasDecl, aliases) {
for (Declaration* aliasDecl : qAsConst(aliases)) {
if (!dynamic_cast<NamespaceAliasDeclaration*>(aliasDecl))
continue;
......@@ -1402,7 +1399,7 @@ Declaration* DUContext::findDeclarationAt(const CursorInRevision& position) cons
if (!range().contains(position))
return nullptr;
foreach (Declaration* child, m_dynamicData->m_localDeclarations) {
for (Declaration* child : qAsConst(m_dynamicData->m_localDeclarations)) {
if (child->range().contains(position)) {
return child;
}
......@@ -1418,7 +1415,7 @@ DUContext* DUContext::findContextIncluding(const RangeInRevision& range) const
if (!this->range().contains(range))
return nullptr;
foreach (DUContext* child, m_dynamicData->m_childContexts) {
for (DUContext* child : qAsConst(m_dynamicData->m_childContexts)) {
if (DUContext* specific = child->findContextIncluding(range)) {
return specific;
}
......@@ -1476,14 +1473,16 @@ void DUContext::cleanIfNotEncountered(const QSet<DUChainBase*>& encountered)
if (d_func()->m_localDeclarations()) {
indexedLocal.append(d_func()->m_localDeclarations(), d_func()->m_localDeclarationsSize());
}
foreach (const LocalIndexedDeclaration& indexed, m_dynamicData->m_localDeclarations) {