Index: clang/include/clang/Basic/Module.h =================================================================== --- clang/include/clang/Basic/Module.h +++ 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. Index: clang/lib/Basic/Module.cpp =================================================================== --- clang/lib/Basic/Module.cpp +++ 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); } } } @@ -550,14 +547,13 @@ OS << "export_as" << ExportAsModule << "\n"; } - for (submodule_const_iterator MI = submodule_begin(), MIEnd = submodule_end(); - MI != MIEnd; ++MI) + for (auto *Submodule : submodules()) // Print inferred subframework modules so that we don't need to re-infer // them (requires expensive directory iteration + stat calls) when we build // the module. Regular inferred submodules are OK, as we need to look at all // those header files anyway. - if (!(*MI)->IsInferred || (*MI)->IsFramework) - (*MI)->print(OS, Indent + 2, Dump); + if (!Submodule->IsInferred || Submodule->IsFramework) + Submodule->print(OS, Indent + 2, Dump); for (unsigned I = 0, N = Exports.size(); I != N; ++I) { OS.indent(Indent + 2); Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ 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; Index: clang/lib/Frontend/CompilerInstance.cpp =================================================================== --- clang/lib/Frontend/CompilerInstance.cpp +++ 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()); } } } Index: clang/lib/Frontend/FrontendAction.cpp =================================================================== --- clang/lib/Frontend/FrontendAction.cpp +++ 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(); Index: clang/lib/Sema/Sema.cpp =================================================================== --- clang/lib/Sema/Sema.cpp +++ clang/lib/Sema/Sema.cpp @@ -1240,7 +1240,8 @@ ModMap.resolveConflicts(Mod, /*Complain=*/false); // Queue the submodules, so their exports will also be resolved. - Stack.append(Mod->submodule_begin(), Mod->submodule_end()); + auto SubmodulesRange = Mod->submodules(); + Stack.append(SubmodulesRange.begin(), SubmodulesRange.end()); } } Index: clang/lib/Sema/SemaCodeComplete.cpp =================================================================== --- clang/lib/Sema/SemaCodeComplete.cpp +++ 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)); } } Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ 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; }