diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -741,16 +741,11 @@ using submodule_iterator = std::vector::iterator; using submodule_const_iterator = std::vector::const_iterator; - submodule_iterator submodule_begin() { return SubModules.begin(); } - submodule_const_iterator submodule_begin() const {return SubModules.begin();} - submodule_iterator submodule_end() { return SubModules.end(); } - submodule_const_iterator submodule_end() const { return SubModules.end(); } - llvm::iterator_range submodules() { - return llvm::make_range(submodule_begin(), submodule_end()); + return llvm::make_range(SubModules.begin(), SubModules.end()); } llvm::iterator_range submodules() const { - return llvm::make_range(submodule_begin(), submodule_end()); + return llvm::make_range(SubModules.begin(), SubModules.end()); } /// Appends this module's list of exported modules to \p Exported. diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -59,9 +59,8 @@ } Module::~Module() { - for (submodule_iterator I = submodule_begin(), IEnd = submodule_end(); - I != IEnd; ++I) { - delete *I; + for (auto *Submodule: SubModules) { + delete Submodule; } } @@ -339,11 +338,9 @@ Current->IsAvailable = false; Current->IsUnimportable |= Unimportable; - for (submodule_iterator Sub = Current->submodule_begin(), - SubEnd = Current->submodule_end(); - Sub != SubEnd; ++Sub) { - if (needUpdate(*Sub)) - Stack.push_back(*Sub); + for(auto *Submodule: Current->submodules()){ + if (needUpdate(Submodule)) + Stack.push_back(Submodule); } } } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6536,16 +6536,14 @@ EmitTopLevelDecl(D); // Visit the submodules of this module. - for (clang::Module::submodule_iterator Sub = Mod->submodule_begin(), - SubEnd = Mod->submodule_end(); - Sub != SubEnd; ++Sub) { + for (auto *Submodule : Mod->submodules()) { // Skip explicit children; they need to be explicitly imported to emit // the initializers. - if ((*Sub)->IsExplicit) + if (Submodule->IsExplicit) continue; - if (Visited.insert(*Sub).second) - Stack.push_back(*Sub); + if (Visited.insert(Submodule).second) + Stack.push_back(Submodule); } } break; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -605,8 +605,9 @@ Module *Current = Stack.pop_back_val(); if (Current->IsUnimportable) continue; Current->IsAvailable = true; - Stack.insert(Stack.end(), - Current->submodule_begin(), Current->submodule_end()); + auto SubmodulesRange = Current->submodules(); + Stack.insert(Stack.end(), SubmodulesRange.begin(), + SubmodulesRange.end()); } } } diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -429,11 +429,9 @@ } // Recurse into submodules. - for (clang::Module::submodule_iterator Sub = Module->submodule_begin(), - SubEnd = Module->submodule_end(); - Sub != SubEnd; ++Sub) + for (auto *Submodule : Module->submodules()) if (std::error_code Err = collectModuleHeaderIncludes( - LangOpts, FileMgr, Diag, ModMap, *Sub, Includes)) + LangOpts, FileMgr, Diag, ModMap, Submodule, Includes)) return Err; return std::error_code(); diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -4309,15 +4309,12 @@ /*IsInclusionDirective=*/false); // Enumerate submodules. if (Mod) { - for (Module::submodule_iterator Sub = Mod->submodule_begin(), - SubEnd = Mod->submodule_end(); - Sub != SubEnd; ++Sub) { - + for (auto *Submodule : Mod->submodules()) { Builder.AddTypedTextChunk( - Builder.getAllocator().CopyString((*Sub)->Name)); + Builder.getAllocator().CopyString(Submodule->Name)); Results.AddResult(Result( Builder.TakeString(), CCP_Declaration, CXCursor_ModuleImportDecl, - (*Sub)->isAvailable() ? CXAvailability_Available + Submodule->isAvailable() ? CXAvailability_Available : CXAvailability_NotAvailable)); } } diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1903,18 +1903,16 @@ SavedStrings.push_back(FilenameDup.data()); HeaderFileInfoTrait::key_type Key = { - FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0 - }; + FilenameDup, *U.Size, IncludeTimestamps ? *U.ModTime : 0}; HeaderFileInfoTrait::data_type Data = { - Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)} - }; + Empty, {}, {M, ModuleMap::headerKindToRole(U.Kind)}}; // FIXME: Deal with cases where there are multiple unresolved header // directives in different submodules for the same header. Generator.insert(Key, Data, GeneratorTrait); ++NumHeaderSearchEntries; } - - Worklist.append(M->submodule_begin(), M->submodule_end()); + auto SubmodulesRange = M->submodules(); + Worklist.append(SubmodulesRange.begin(), SubmodulesRange.end()); } } @@ -2701,9 +2699,8 @@ /// given module). static unsigned getNumberOfModules(Module *Mod) { unsigned ChildModules = 0; - for (auto Sub = Mod->submodule_begin(), SubEnd = Mod->submodule_end(); - Sub != SubEnd; ++Sub) - ChildModules += getNumberOfModules(*Sub); + for (auto *Submodule : Mod->submodules()) + ChildModules += getNumberOfModules(Submodule); return ChildModules + 1; }