diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-10-20 22:00:55 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-10-20 22:00:55 +0000 |
| commit | 796d76a663795d66ed5aa97a1f585514dd68b043 (patch) | |
| tree | 98f71284a72e7f7714726b6ac5058e61dc56d97d /clang/lib/Lex/PreprocessingRecord.cpp | |
| parent | 2edaa2fb24eb17fbb6b3752ddb7d06a8d6b0799e (diff) | |
| download | bcm5719-llvm-796d76a663795d66ed5aa97a1f585514dd68b043.tar.gz bcm5719-llvm-796d76a663795d66ed5aa97a1f585514dd68b043.zip | |
Extend the preprocessing record and libclang with support for
inclusion directives, keeping track of every #include, #import,
etc. in the translation unit. We keep track of the source location and
kind of the inclusion, how the file name was spelled, and the
underlying file to which the inclusion resolved.
llvm-svn: 116952
Diffstat (limited to 'clang/lib/Lex/PreprocessingRecord.cpp')
| -rw-r--r-- | clang/lib/Lex/PreprocessingRecord.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index c446d96b452..34421779c93 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -14,6 +14,8 @@ #include "clang/Lex/PreprocessingRecord.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Token.h" +#include "clang/Basic/IdentifierTable.h" +#include "llvm/Support/ErrorHandling.h" using namespace clang; @@ -127,3 +129,38 @@ void PreprocessingRecord::MacroUndefined(SourceLocation Loc, MacroDefinitions.erase(Pos); } +void PreprocessingRecord::InclusionDirective(SourceLocation HashLoc, + const clang::Token &IncludeTok, + llvm::StringRef FileName, + bool IsAngled, + const FileEntry *File, + clang::SourceLocation EndLoc) { + InclusionDirective::InclusionKind Kind = InclusionDirective::Include; + + switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { + case tok::pp_include: + Kind = InclusionDirective::Include; + break; + + case tok::pp_import: + Kind = InclusionDirective::Import; + break; + + case tok::pp_include_next: + Kind = InclusionDirective::IncludeNext; + break; + + case tok::pp___include_macros: + Kind = InclusionDirective::IncludeMacros; + break; + + default: + llvm_unreachable("Unknown include directive kind"); + return; + } + + clang::InclusionDirective *ID + = new (*this) clang::InclusionDirective(Kind, FileName, !IsAngled, File, + SourceRange(HashLoc, EndLoc)); + PreprocessedEntities.push_back(ID); +} |

