[PATCH] D142196: [clang][Lex] Add back PPCallbacks::FileNotFound
Jonas Hahnfeld via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 20 02:19:32 PST 2023
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142196.490758.patch
Type: text/x-patch
Size: 1962 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230120/0d03ba0c/attachment.bin>
More information about the cfe-commits
mailing list