aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-04-19 20:44:31 +0000
committerChris Lattner <sabre@nondot.org>2010-04-19 20:44:31 +0000
commit6fbe3ebeaef08665a37423f8425314c90b8b5bcf (patch)
tree028a1b89c4dae0e620a97791724c4866dcfdd65c
parented46442adea496dfb01dbbe53ace583d5614e79a (diff)
add a PPCallback handler for a skipped #include, patch by
Zhanyong Wan! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101813 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/PPCallbacks.h15
-rw-r--r--lib/Lex/PPDirectives.cpp15
2 files changed, 24 insertions, 6 deletions
diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h
index e891e94d4c..d74124e9c7 100644
--- a/include/clang/Lex/PPCallbacks.h
+++ b/include/clang/Lex/PPCallbacks.h
@@ -44,6 +44,14 @@ public:
SrcMgr::CharacteristicKind FileType) {
}
+ /// FileSkipped - This callback is invoked whenever a source file is
+ /// skipped as the result of header guard optimization. ParentFile
+ /// is the file that #includes the skipped file. FilenameTok is the
+ /// token in ParentFile that indicates the skipped file.
+ virtual void FileSkipped(const FileEntry &ParentFile,
+ const Token &FilenameTok,
+ SrcMgr::CharacteristicKind FileType) {
+ }
/// EndOfMainFile - This callback is invoked when the end of the main file is
/// reach, no subsequent callbacks will be made.
@@ -96,6 +104,13 @@ public:
Second->FileChanged(Loc, Reason, FileType);
}
+ virtual void FileSkipped(const FileEntry &ParentFile,
+ const Token &FilenameTok,
+ SrcMgr::CharacteristicKind FileType) {
+ First->FileSkipped(ParentFile, FilenameTok, FileType);
+ Second->FileSkipped(ParentFile, FilenameTok, FileType);
+ }
+
virtual void EndOfMainFile() {
First->EndOfMainFile();
Second->EndOfMainFile();
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 8033e475c8..eb8664585f 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1088,11 +1088,6 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok,
return;
}
- // Ask HeaderInfo if we should enter this #include file. If not, #including
- // this file will have no effect.
- if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport))
- return;
-
// The #included file will be considered to be a system header if either it is
// in a system include directory, or if the #includer is a system include
// header.
@@ -1100,6 +1095,15 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok,
std::max(HeaderInfo.getFileDirFlavor(File),
SourceMgr.getFileCharacteristic(FilenameTok.getLocation()));
+ // Ask HeaderInfo if we should enter this #include file. If not, #including
+ // this file will have no effect.
+ if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport)) {
+ if (Callbacks) {
+ Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
+ }
+ return;
+ }
+
// Look up the file, create a File ID for it.
FileID FID = SourceMgr.createFileID(File, FilenameTok.getLocation(),
FileCharacter);
@@ -1667,4 +1671,3 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) {
return SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true,
/*FoundElse*/CI.FoundElse);
}
-