From ecdcb883cbc6bb4a2445dc6f02d58d9bdb54a0ed Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Wed, 20 Oct 2010 22:00:55 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116952 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/PreprocessingRecord.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/Lex/PreprocessingRecord.cpp') diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp index c446d96b45..34421779c9 100644 --- a/lib/Lex/PreprocessingRecord.cpp +++ b/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); +} -- cgit v1.2.3-70-g09d2