aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/HeaderIncludeGen.cpp
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2021-04-13 13:59:03 +0200
committerHans Wennborg <hans@chromium.org>2021-04-14 17:01:51 +0200
commitf29dcbdde10c86cfd89196fc2aa0e7f6ca3c9c4e (patch)
tree74c6ced9c741460e0a67ca0f6933be643f2febb2 /clang/lib/Frontend/HeaderIncludeGen.cpp
parentc4c9e4d6df3c492cf86728288b14a9bc718f6e2d (diff)
downloadllvm-f29dcbdde10c86cfd89196fc2aa0e7f6ca3c9c4e.zip
llvm-f29dcbdde10c86cfd89196fc2aa0e7f6ca3c9c4e.tar.gz
llvm-f29dcbdde10c86cfd89196fc2aa0e7f6ca3c9c4e.tar.bz2
Add flag for showing skipped headers in -H / --show-includes output
Consider the following set of files: a.cc: #include "a.h" a.h: #ifndef A_H #define A_H #include "b.h" #include "c.h" // This gets "skipped". #endif b.h: #ifndef B_H #define B_H #include "c.h" #endif c.h: #ifndef C_H #define C_H void c(); #endif And the output of the -H option: $ clang -c -H a.cc . ./a.h .. ./b.h ... ./c.h Note that the include of c.h in a.h is not shown in the output (GCC does the same). This is because of the include guard optimization: clang knows c.h is covered by an include guard which is already defined, so when it sees the include in a.h, it skips it. The same would have happened if #pragma once were used instead of include guards. However, a.h *does* include c.h, and it may be useful to show that in the -H output. This patch adds a flag for doing that. Differential revision: https://reviews.llvm.org/D100480
Diffstat (limited to 'clang/lib/Frontend/HeaderIncludeGen.cpp')
-rw-r--r--clang/lib/Frontend/HeaderIncludeGen.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/Frontend/HeaderIncludeGen.cpp b/clang/lib/Frontend/HeaderIncludeGen.cpp
index df3f534..1ee47d8 100644
--- a/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -45,6 +45,9 @@ public:
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
+
+ void FileSkipped(const FileEntryRef &SkippedFile, const Token &FilenameTok,
+ SrcMgr::CharacteristicKind FileType) override;
};
}
@@ -181,3 +184,16 @@ void HeaderIncludesCallback::FileChanged(SourceLocation Loc,
MSStyle);
}
}
+
+void HeaderIncludesCallback::FileSkipped(const FileEntryRef &SkippedFile, const
+ Token &FilenameTok,
+ SrcMgr::CharacteristicKind FileType) {
+ if (!DepOpts.ShowSkippedHeaderIncludes)
+ return;
+
+ if (!DepOpts.IncludeSystemHeaders && isSystem(FileType))
+ return;
+
+ PrintHeaderInfo(OutputFile, SkippedFile.getName(), ShowDepth,
+ CurrentIncludeDepth + 1, MSStyle);
+}