rmaz created this revision. Herald added a subscriber: arphaman. Herald added a project: All. rmaz requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Refactor a Module's TopHeaders to use FileEntryRef. This will keep the paths serialized in a module the same as the ones used to look up the header initially. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D142724 Files: clang/include/clang/Basic/Module.h clang/lib/Basic/Module.cpp clang/lib/Lex/ModuleMap.cpp clang/lib/Serialization/ASTWriter.cpp clang/tools/libclang/CIndex.cpp
Index: clang/tools/libclang/CIndex.cpp =================================================================== --- clang/tools/libclang/CIndex.cpp +++ clang/tools/libclang/CIndex.cpp @@ -8788,7 +8788,7 @@ return 0; Module *Mod = static_cast<Module *>(CXMod); FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager(); - ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr); + auto TopHeaders = Mod->getTopHeaders(FileMgr); return TopHeaders.size(); } @@ -8803,9 +8803,9 @@ Module *Mod = static_cast<Module *>(CXMod); FileManager &FileMgr = cxtu::getASTUnit(TU)->getFileManager(); - ArrayRef<const FileEntry *> TopHeaders = Mod->getTopHeaders(FileMgr); + auto TopHeaders = Mod->getTopHeaders(FileMgr); if (Index < TopHeaders.size()) - return const_cast<FileEntry *>(TopHeaders[Index]); + return const_cast<FileEntry *>(&TopHeaders[Index].getFileEntry()); return nullptr; } Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -2878,8 +2878,8 @@ { auto TopHeaders = Mod->getTopHeaders(PP->getFileManager()); RecordData::value_type Record[] = {SUBMODULE_TOPHEADER}; - for (auto *H : TopHeaders) { - SmallString<128> HeaderName(H->getName()); + for (auto H : TopHeaders) { + SmallString<128> HeaderName(H.getName()); PreparePathForOutput(HeaderName); Stream.EmitRecordWithBlob(TopHeaderAbbrev, Record, HeaderName); } Index: clang/lib/Lex/ModuleMap.cpp =================================================================== --- clang/lib/Lex/ModuleMap.cpp +++ clang/lib/Lex/ModuleMap.cpp @@ -660,7 +660,7 @@ Explicit).first; InferredModuleAllowedBy[Result] = UmbrellaModuleMap; Result->IsInferred = true; - Result->addTopHeader(File); + Result->addTopHeader(File->getLastRef()); // If inferred submodules export everything they import, add a // wildcard to the set of exports. Index: clang/lib/Basic/Module.cpp =================================================================== --- clang/lib/Basic/Module.cpp +++ clang/lib/Basic/Module.cpp @@ -269,16 +269,16 @@ Umbrella.dyn_cast<const DirectoryEntry *>()}; } -void Module::addTopHeader(const FileEntry *File) { +void Module::addTopHeader(OptionalFileEntryRef File) { assert(File); - TopHeaders.insert(File); + TopHeaders.insert(*File); } -ArrayRef<const FileEntry *> Module::getTopHeaders(FileManager &FileMgr) { +ArrayRef<FileEntryRef> Module::getTopHeaders(FileManager &FileMgr) { if (!TopHeaderNames.empty()) { for (std::vector<std::string>::iterator I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) { - if (auto FE = FileMgr.getFile(*I)) + if (auto FE = FileMgr.getFileRef(*I)) TopHeaders.insert(*FE); } TopHeaderNames.clear(); Index: clang/include/clang/Basic/Module.h =================================================================== --- clang/include/clang/Basic/Module.h +++ clang/include/clang/Basic/Module.h @@ -189,7 +189,7 @@ OptionalFileEntryRef ASTFile; /// The top-level headers associated with this module. - llvm::SmallSetVector<const FileEntry *, 2> TopHeaders; + llvm::SmallSetVector<FileEntryRef, 2> TopHeaders; /// top-level header filenames that aren't resolved to FileEntries yet. std::vector<std::string> TopHeaderNames; @@ -639,7 +639,7 @@ } /// Add a top-level header associated with this module. - void addTopHeader(const FileEntry *File); + void addTopHeader(OptionalFileEntryRef File); /// Add a top-level header filename associated with this module. void addTopHeaderFilename(StringRef Filename) { @@ -647,7 +647,7 @@ } /// The top-level headers associated with this module. - ArrayRef<const FileEntry *> getTopHeaders(FileManager &FileMgr); + ArrayRef<FileEntryRef> getTopHeaders(FileManager &FileMgr); /// Determine whether this module has declared its intention to /// directly use another module.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits