Hahnfeld created this revision. Hahnfeld added reviewers: jansvoboda11, ahoppen. Herald added subscribers: shchenz, kbarton, nemanjai. Herald added a project: All. Hahnfeld requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This callback was removed with commit rG7a124f4859 <https://reviews.llvm.org/rG7a124f4859d5c4093467abc2e734f8ab15e78cc6>, but we use it downstream in ROOT/Cling to implement handling of a special include syntax. Add back a "safe" version of the callback that only takes the file name and return a bool to silently skip the file. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D142196 Files: clang/include/clang/Lex/PPCallbacks.h clang/lib/Lex/PPDirectives.cpp Index: clang/lib/Lex/PPDirectives.cpp =================================================================== --- clang/lib/Lex/PPDirectives.cpp +++ clang/lib/Lex/PPDirectives.cpp @@ -2019,6 +2019,10 @@ if (File) return File; + // Give the clients a chance to silently skip this include. + if (Callbacks && Callbacks->FileNotFound(Filename)) + return std::nullopt; + if (SuppressIncludeNotFoundError) return std::nullopt; Index: clang/include/clang/Lex/PPCallbacks.h =================================================================== --- clang/include/clang/Lex/PPCallbacks.h +++ clang/include/clang/Lex/PPCallbacks.h @@ -83,6 +83,16 @@ const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) {} + /// Callback invoked whenever an inclusion directive results in a + /// file-not-found error. + /// + /// \param FileName The name of the file being included, as written in the + /// source code. + /// + /// \returns true to indicate that the preprocessor should skip this file + /// and not issue any diagnostic. + virtual bool FileNotFound(StringRef FileName) { return false; } + /// Callback invoked whenever an inclusion directive of /// any kind (\c \#include, \c \#import, etc.) has been processed, regardless /// of whether the inclusion will actually result in an inclusion. @@ -451,6 +461,14 @@ Second->FileSkipped(SkippedFile, FilenameTok, FileType); } + bool FileNotFound(StringRef FileName) override { + bool Skip = First->FileNotFound(FileName); + // Make sure to invoke the second callback, no matter if the first already + // returned true to skip the file. + Skip |= Second->FileNotFound(FileName); + return Skip; + } + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange,
Index: clang/lib/Lex/PPDirectives.cpp =================================================================== --- clang/lib/Lex/PPDirectives.cpp +++ clang/lib/Lex/PPDirectives.cpp @@ -2019,6 +2019,10 @@ if (File) return File; + // Give the clients a chance to silently skip this include. + if (Callbacks && Callbacks->FileNotFound(Filename)) + return std::nullopt; + if (SuppressIncludeNotFoundError) return std::nullopt; Index: clang/include/clang/Lex/PPCallbacks.h =================================================================== --- clang/include/clang/Lex/PPCallbacks.h +++ clang/include/clang/Lex/PPCallbacks.h @@ -83,6 +83,16 @@ const Token &FilenameTok, SrcMgr::CharacteristicKind FileType) {} + /// Callback invoked whenever an inclusion directive results in a + /// file-not-found error. + /// + /// \param FileName The name of the file being included, as written in the + /// source code. + /// + /// \returns true to indicate that the preprocessor should skip this file + /// and not issue any diagnostic. + virtual bool FileNotFound(StringRef FileName) { return false; } + /// Callback invoked whenever an inclusion directive of /// any kind (\c \#include, \c \#import, etc.) has been processed, regardless /// of whether the inclusion will actually result in an inclusion. @@ -451,6 +461,14 @@ Second->FileSkipped(SkippedFile, FilenameTok, FileType); } + bool FileNotFound(StringRef FileName) override { + bool Skip = First->FileNotFound(FileName); + // Make sure to invoke the second callback, no matter if the first already + // returned true to skip the file. + Skip |= Second->FileNotFound(FileName); + return Skip; + } + void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits