Commit 8cb82487 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

clang: port foreach -> range-based for

parent fdd06e1d
......@@ -195,7 +195,8 @@ ClangParseJob::ClangParseJob(const IndexedString& url, ILanguageSupport* languag
m_unsavedFiles = ClangUtils::unsavedFiles();
foreach(auto document, ICore::self()->documentController()->openDocuments()) {
const auto documents = ICore::self()->documentController()->openDocuments();
for (auto* document : documents) {
auto textDocument = document->textDocument();
if ( !textDocument ) {
continue;
......@@ -346,7 +347,7 @@ void ClangParseJob::run(ThreadWeaver::JobPointer /*self*/, ThreadWeaver::Thread*
#endif
}
foreach(const auto& context, includedFiles) {
for (const auto& context : qAsConst(includedFiles)) {
if (!context) {
continue;
}
......
......@@ -118,7 +118,8 @@ QPair<TopDUContextPointer, KTextEditor::Range> importedContextForPosition(const
}
// It's an #include, find out which file was included at the given line
foreach(const DUContext::Import &imported, topContext->importedParentContexts()) {
const auto importedParentContexts = topContext->importedParentContexts();
for (const DUContext::Import& imported : importedParentContexts) {
auto context = imported.context(nullptr);
if (context) {
if(topContext->transformFromLocalRevision(topContext->importPosition(context)).line() == wordRange.start().line()) {
......
......@@ -123,7 +123,7 @@ void AdaptSignatureAction::execute()
}
emit executed(this);
foreach(RenameAction * renAct, m_renameActions) {
for (RenameAction* renAct : m_renameActions) {
renAct->execute();
}
}
......
......@@ -62,7 +62,7 @@ private:
Signature m_oldSignature;
Signature m_newSignature;
bool m_editingDefinition;
QList<KDevelop::RenameAction*> m_renameActions;
const QList<KDevelop::RenameAction*> m_renameActions;
};
#endif // ADAPTSIGNATUREACTION_H
......@@ -427,8 +427,7 @@ QString makeSignatureString(const KDevelop::Declaration* functionDecl, const Sig
QStringList parameters;
parameters.reserve(signature.parameters.size());
foreach(const ParameterItem &item, signature.parameters)
{
for (const ParameterItem& item : signature.parameters) {
QString parameter;
AbstractType::Ptr type = item.first.abstractType();
......
......@@ -95,7 +95,7 @@ QString zeroIndentation(const QString& str, int fromLine = 0)
QRegExp nonWhiteSpace(QStringLiteral("\\S"));
int minLineStart = 10000;
foreach (const auto& line, lines) {
for (const auto& line : qAsConst(lines)) {
int lineStart = line.indexOf(nonWhiteSpace);
if (lineStart < minLineStart) {
minLineStart = lineStart;
......@@ -103,7 +103,7 @@ QString zeroIndentation(const QString& str, int fromLine = 0)
}
ret.reserve(ret.size() + lines.size());
foreach (const auto& line, lines) {
for (const auto& line : qAsConst(lines)) {
ret << line.mid(minLineStart);
}
......@@ -130,7 +130,8 @@ void SourceCodeInsertion::setSubScope(const QualifiedIdentifier& scope)
while (!needNamespace.isEmpty() && foundChild) {
foundChild = false;
foreach (DUContext* child, m_context->childContexts()) {
const auto childContexts = m_context->childContexts();
for (DUContext* child : childContexts) {
clangDebug() << "checking child" << child->localScopeIdentifier().toString() << "against"
<< needNamespace.first();
if (child->localScopeIdentifier().toString() == needNamespace.first() && child->type() == DUContext::Namespace) {
......@@ -161,7 +162,8 @@ QString SourceCodeInsertion::applySubScope(const QString& decl) const
}
QString ret;
foreach (const QString& scope, m_scope.toStringList()) {
const auto scopes = m_scope.toStringList();
for (const QString& scope : scopes) {
ret += scopeType + QLatin1Char(' ') + scope + QStringLiteral(" {\n");
}
......@@ -266,7 +268,8 @@ int SourceCodeInsertion::findInsertionPoint() const
{
int line = end().line();
foreach (auto decl, m_context->localDeclarations()) {
const auto localDeclarations = m_context->localDeclarations();
for (auto* decl : localDeclarations) {
if (m_context->type() == DUContext::Class) {
continue;
}
......
......@@ -293,7 +293,7 @@ struct CurrentContext
~CurrentContext()
{
DUChainWriteLocker lock;
foreach (auto childContext, previousChildContexts) {
for (auto* childContext : qAsConst(previousChildContexts)) {
if (!keepAliveContexts.contains(childContext)) {
delete childContext;
}
......@@ -1428,7 +1428,8 @@ Visitor::Visitor(CXTranslationUnit tu, CXFile file,
QSet<DUContext*> keepAliveContexts;
{
DUChainReadLocker lock;
foreach (const auto& problem, top->problems()) {
const auto problems = top->problems();
for (const auto& problem : problems) {
const auto& desc = problem->description();
if (desc.startsWith(QLatin1String("Return type of out-of-line definition of '"))
&& desc.endsWith(QLatin1String("' differs from that in the declaration"))) {
......
......@@ -69,7 +69,8 @@ CXChildVisitResult visitCursor(CXCursor cursor, CXCursor, CXClientData data)
uint line, column;
clang_getFileLocation(location, &parentFile, &line, &column, nullptr);
foreach (const auto& import, imports->values(parentFile)) {
const auto parentFileImports = imports->values(parentFile);
for (const auto& import : parentFileImports) {
// clang_getInclusions doesn't include the same import twice, so we shouldn't do it too.
if (import.file == file) {
return CXChildVisit_Continue;
......@@ -128,7 +129,7 @@ ReferencedTopDUContext ClangHelpers::buildDUChain(CXFile file, const Imports& im
QList<Import> sortedImports = imports.values(file);
std::sort(sortedImports.begin(), sortedImports.end(), importLocationLessThan);
foreach(const auto& import, sortedImports) {
for (const auto& import : qAsConst(sortedImports)) {
buildDUChain(import.file, imports, session, features, includedFiles, index, abortFunction);
}
......@@ -180,7 +181,7 @@ ReferencedTopDUContext ClangHelpers::buildDUChain(CXFile file, const Imports& im
}
context->setFeatures(features);
foreach(const auto& import, sortedImports) {
for (const auto& import : qAsConst(sortedImports)) {
auto ctx = includedFiles.value(import.file);
if (!ctx) {
// happens for cyclic imports
......
......@@ -126,7 +126,8 @@ IndexedString ClangIndex::translationUnitForUrl(const IndexedString& url)
// otherwise, fallback to a simple buddy search for headers
if (ClangHelpers::isHeader(url.str())) {
foreach(const QUrl& buddy, DocumentFinderHelpers::potentialBuddies(url.toUrl(), false)) {
const auto buddies = DocumentFinderHelpers::potentialBuddies(url.toUrl(), false);
for (const QUrl& buddy : buddies) {
const QString buddyPath = buddy.toLocalFile();
if (QFile::exists(buddyPath)) {
return IndexedString(buddyPath);
......
......@@ -299,7 +299,7 @@ ParseSessionData::ParseSessionData(const QVector<UnsavedFile>& unsavedFiles, Cla
if (qEnvironmentVariableIsSet("KDEV_CLANG_DISPLAY_ARGS")) {
QTextStream out(stdout);
out << "Invocation: clang";
foreach (const auto& arg, clangArguments) {
for (const auto& arg : qAsConst(clangArguments)) {
out << " " << arg;
}
out << " " << tuUrl.byteArray().constData() << "\n";
......
......@@ -95,7 +95,7 @@ private:
// make sure this case is sufficiently fast
// for each to-do marker, scan the comment text
foreach (const QString& todoMarker, m_todoMarkerWords) {
for (const QString& todoMarker : m_todoMarkerWords) {
int offset = m_str.indexOf(todoMarker, m_offset);
if (offset != -1) {
m_offset = offset;
......
......@@ -49,7 +49,7 @@ void UnsavedFile::convertToUtf8()
{
m_fileNameUtf8 = m_fileName.toUtf8();
m_contentsUtf8.clear();
foreach(const QString& line, m_contents) {
for (const QString& line : qAsConst(m_contents)) {
m_contentsUtf8 += line.toUtf8() + '\n';
}
}
......@@ -328,8 +328,7 @@ void TestAssistants::testRenameAssistant()
QFETCH(QString, oldDeclarationName);
QFETCH(QList<StateChange>, stateChanges);
foreach(StateChange stateChange, stateChanges)
{
for (const StateChange& stateChange : qAsConst(stateChanges)) {
testbed.changeDocument(Testbed::CppDoc, stateChange.range, stateChange.newText, true);
DUChainReadLocker lock;
......@@ -529,8 +528,7 @@ void TestAssistants::testSignatureAssistant()
QExplicitlySharedDataPointer<IAssistant> assistant;
QFETCH(QList<StateChange>, stateChanges);
foreach (StateChange stateChange, stateChanges)
{
for (const StateChange& stateChange : qAsConst(stateChanges)) {
testbed.changeDocument(stateChange.document, stateChange.range, stateChange.newText, true);
const auto document = testbed.document(stateChange.document);
......
......@@ -104,7 +104,8 @@ void TestFiles::testFiles()
DeclarationValidator validator;
top->visit(validator);
foreach(auto problem, top->problems()) {
const auto problems = top->problems();
for (auto& problem : problems) {
qDebug() << problem;
}
......
......@@ -61,7 +61,8 @@ CXCursor ClangUtils::getCXCursor(int line, int column, const CXTranslationUnit&
QVector<UnsavedFile> ClangUtils::unsavedFiles()
{
QVector<UnsavedFile> ret;
foreach(auto document, ICore::self()->documentController()->openDocuments()) {
const auto documents = ICore::self()->documentController()->openDocuments();
for (auto* document : documents) {
auto textDocument = document->textDocument();
// TODO: Introduce a cache so we don't have to re-read all the open documents
// which were not changed since the last run
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment