This revision was automatically updated to reflect the committed changes. Closed by commit rGcf593d224c9c: SourceManager: getFileEntryRefForID => getNonBuiltinFilenameForID, NFC (authored by dexonsmith). Herald added a project: clang.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89508/new/ https://reviews.llvm.org/D89508 Files: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/SourceManager.cpp clang/lib/Frontend/DependencyFile.cpp clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -77,15 +77,10 @@ // Dependency generation really does want to go all the way to the // file entry for a source location to find out what is depended on. // We do not want #line markers to affect dependency generation! - Optional<FileEntryRef> File = - SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc))); - if (!File) - return; - - StringRef FileName = - llvm::sys::path::remove_leading_dotslash(File->getName()); - - MDC.MainDeps.push_back(std::string(FileName)); + if (Optional<StringRef> Filename = + SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc)))) + MDC.MainDeps.push_back( + std::string(llvm::sys::path::remove_leading_dotslash(*Filename))); } void ModuleDepCollectorPP::InclusionDirective( Index: clang/lib/Frontend/DependencyFile.cpp =================================================================== --- clang/lib/Frontend/DependencyFile.cpp +++ clang/lib/Frontend/DependencyFile.cpp @@ -46,17 +46,12 @@ // Dependency generation really does want to go all the way to the // file entry for a source location to find out what is depended on. // We do not want #line markers to affect dependency generation! - Optional<FileEntryRef> File = - SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc))); - if (!File) - return; - - StringRef Filename = - llvm::sys::path::remove_leading_dotslash(File->getName()); - - DepCollector.maybeAddDependency(Filename, /*FromModule*/false, - isSystem(FileType), - /*IsModuleFile*/false, /*IsMissing*/false); + if (Optional<StringRef> Filename = SM.getNonBuiltinFilenameForID( + SM.getFileID(SM.getExpansionLoc(Loc)))) + DepCollector.maybeAddDependency( + llvm::sys::path::remove_leading_dotslash(*Filename), + /*FromModule*/ false, isSystem(FileType), /*IsModuleFile*/ false, + /*IsMissing*/ false); } void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -725,11 +725,12 @@ const_cast<SrcMgr::ContentCache *>(CC)->IsTransient = true; } -Optional<FileEntryRef> SourceManager::getFileEntryRefForID(FileID FID) const { +Optional<StringRef> +SourceManager::getNonBuiltinFilenameForID(FileID FID) const { if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID)) if (auto *Content = Entry->getFile().getContentCache()) if (Content && Content->OrigEntry) - return FileEntryRef(Entry->getFile().getName(), *Content->OrigEntry); + return Entry->getFile().getName(); return None; } Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -997,8 +997,11 @@ return nullptr; } - /// Returns the FileEntryRef for the provided FileID. - Optional<FileEntryRef> getFileEntryRefForID(FileID FID) const; + /// Returns the filename for the provided FileID, unless it's a built-in + /// buffer that's not represented by a filename. + /// + /// Returns None for non-files and built-in files. + Optional<StringRef> getNonBuiltinFilenameForID(FileID FID) const; /// Returns the FileEntry record for the provided SLocEntry. const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -77,15 +77,10 @@ // Dependency generation really does want to go all the way to the // file entry for a source location to find out what is depended on. // We do not want #line markers to affect dependency generation! - Optional<FileEntryRef> File = - SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc))); - if (!File) - return; - - StringRef FileName = - llvm::sys::path::remove_leading_dotslash(File->getName()); - - MDC.MainDeps.push_back(std::string(FileName)); + if (Optional<StringRef> Filename = + SM.getNonBuiltinFilenameForID(SM.getFileID(SM.getExpansionLoc(Loc)))) + MDC.MainDeps.push_back( + std::string(llvm::sys::path::remove_leading_dotslash(*Filename))); } void ModuleDepCollectorPP::InclusionDirective( Index: clang/lib/Frontend/DependencyFile.cpp =================================================================== --- clang/lib/Frontend/DependencyFile.cpp +++ clang/lib/Frontend/DependencyFile.cpp @@ -46,17 +46,12 @@ // Dependency generation really does want to go all the way to the // file entry for a source location to find out what is depended on. // We do not want #line markers to affect dependency generation! - Optional<FileEntryRef> File = - SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(Loc))); - if (!File) - return; - - StringRef Filename = - llvm::sys::path::remove_leading_dotslash(File->getName()); - - DepCollector.maybeAddDependency(Filename, /*FromModule*/false, - isSystem(FileType), - /*IsModuleFile*/false, /*IsMissing*/false); + if (Optional<StringRef> Filename = SM.getNonBuiltinFilenameForID( + SM.getFileID(SM.getExpansionLoc(Loc)))) + DepCollector.maybeAddDependency( + llvm::sys::path::remove_leading_dotslash(*Filename), + /*FromModule*/ false, isSystem(FileType), /*IsModuleFile*/ false, + /*IsMissing*/ false); } void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok, Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -725,11 +725,12 @@ const_cast<SrcMgr::ContentCache *>(CC)->IsTransient = true; } -Optional<FileEntryRef> SourceManager::getFileEntryRefForID(FileID FID) const { +Optional<StringRef> +SourceManager::getNonBuiltinFilenameForID(FileID FID) const { if (const SrcMgr::SLocEntry *Entry = getSLocEntryForFile(FID)) if (auto *Content = Entry->getFile().getContentCache()) if (Content && Content->OrigEntry) - return FileEntryRef(Entry->getFile().getName(), *Content->OrigEntry); + return Entry->getFile().getName(); return None; } Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -997,8 +997,11 @@ return nullptr; } - /// Returns the FileEntryRef for the provided FileID. - Optional<FileEntryRef> getFileEntryRefForID(FileID FID) const; + /// Returns the filename for the provided FileID, unless it's a built-in + /// buffer that's not represented by a filename. + /// + /// Returns None for non-files and built-in files. + Optional<StringRef> getNonBuiltinFilenameForID(FileID FID) const; /// Returns the FileEntry record for the provided SLocEntry. const FileEntry *getFileEntryForSLocEntry(const SrcMgr::SLocEntry &sloc) const
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits