aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp49
1 files changed, 27 insertions, 22 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp b/contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp
index 2ab480940264..9c1bf490fcd6 100644
--- a/contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/contrib/llvm-project/clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,12 +43,27 @@ public:
delete OutputFile;
}
+ HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+ HeaderIncludesCallback &operator=(const HeaderIncludesCallback &) = delete;
+
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
SrcMgr::CharacteristicKind FileType) override;
+
+private:
+ bool ShouldShowHeader(SrcMgr::CharacteristicKind HeaderType) {
+ if (!DepOpts.IncludeSystemHeaders && isSystem(HeaderType))
+ return false;
+
+ // Show the current header if we are (a) past the predefines, or (b) showing
+ // all headers and in the predefines at a depth past the initial file and
+ // command line buffers.
+ return (HasProcessedPredefines ||
+ (ShowAllHeaders && CurrentIncludeDepth > 2));
+ }
};
/// A callback for emitting header usage information to a file in JSON. Each
@@ -78,6 +93,10 @@ public:
delete OutputFile;
}
+ HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+ HeaderIncludesJSONCallback &
+ operator=(const HeaderIncludesJSONCallback &) = delete;
+
void EndOfMainFile() override;
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
@@ -202,38 +221,24 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
// We track when we are done with the predefines by watching for the first
// place where we drop back to a nesting depth of 1.
- if (CurrentIncludeDepth == 1 && !HasProcessedPredefines) {
- if (!DepOpts.ShowIncludesPretendHeader.empty()) {
- PrintHeaderInfo(OutputFile, DepOpts.ShowIncludesPretendHeader,
- ShowDepth, 2, MSStyle);
- }
+ if (CurrentIncludeDepth == 1 && !HasProcessedPredefines)
HasProcessedPredefines = true;
- }
return;
- } else
+ } else {
+ return;
+ }
+
+ if (!ShouldShowHeader(NewFileType))
return;
- // Show the header if we are (a) past the predefines, or (b) showing all
- // headers and in the predefines at a depth past the initial file and command
- // line buffers.
- bool ShowHeader = (HasProcessedPredefines ||
- (ShowAllHeaders && CurrentIncludeDepth > 2));
unsigned IncludeDepth = CurrentIncludeDepth;
if (!HasProcessedPredefines)
--IncludeDepth; // Ignore indent from <built-in>.
- else if (!DepOpts.ShowIncludesPretendHeader.empty())
- ++IncludeDepth; // Pretend inclusion by ShowIncludesPretendHeader.
-
- if (!DepOpts.IncludeSystemHeaders && isSystem(NewFileType))
- ShowHeader = false;
- // Dump the header include information we are past the predefines buffer or
- // are showing all headers and this isn't the magic implicit <command line>
- // header.
// FIXME: Identify headers in a more robust way than comparing their name to
// "<command line>" and "<built-in>" in a bunch of places.
- if (ShowHeader && Reason == PPCallbacks::EnterFile &&
+ if (Reason == PPCallbacks::EnterFile &&
UserLoc.getFilename() != StringRef("<command line>")) {
PrintHeaderInfo(OutputFile, UserLoc.getFilename(), ShowDepth, IncludeDepth,
MSStyle);
@@ -246,7 +251,7 @@ void HeaderIncludesCallback::FileSkipped(const FileEntryRef &SkippedFile, const
if (!DepOpts.ShowSkippedHeaderIncludes)
return;
- if (!DepOpts.IncludeSystemHeaders && isSystem(FileType))
+ if (!ShouldShowHeader(FileType))
return;
PrintHeaderInfo(OutputFile, SkippedFile.getName(), ShowDepth,