diff options
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Lex/PPCallbacks.h | 29 | ||||
-rw-r--r-- | include/clang/Lex/PreprocessingRecord.h | 75 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 12 | ||||
-rw-r--r-- | include/clang/Serialization/ASTBitCodes.h | 6 | ||||
-rw-r--r-- | include/clang/Serialization/ASTReader.h | 3 |
5 files changed, 118 insertions, 7 deletions
diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 782f2d57a5..1bcc364e67 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -54,6 +54,35 @@ public: SrcMgr::CharacteristicKind FileType) { } + /// \brief This callback is invoked whenever an inclusion directive of + /// any kind (\c #include, \c #import, etc.) has been processed, regardless + /// of whether the inclusion will actually result in an inclusion. + /// + /// \param HashLoc The location of the '#' that starts the inclusion + /// directive. + /// + /// \param IncludeTok The token that indicates the kind of inclusion + /// directive, e.g., 'include' or 'import'. + /// + /// \param FileName The name of the file being included, as written in the + /// source code. + /// + /// \param IsAngled Whether the file name was enclosed in angle brackets; + /// otherwise, it was enclosed in quotes. + /// + /// \param File The actual file that may be included by this inclusion + /// directive. + /// + /// \param EndLoc The location of the last token within the inclusion + /// directive. + virtual void InclusionDirective(SourceLocation HashLoc, + const Token &IncludeTok, + llvm::StringRef FileName, + bool IsAngled, + const FileEntry *File, + SourceLocation EndLoc) { + } + /// EndOfMainFile - This callback is invoked when the end of the main file is /// reach, no subsequent callbacks will be made. virtual void EndOfMainFile() { diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h index 576b571a4e..0c5b7bc37f 100644 --- a/include/clang/Lex/PreprocessingRecord.h +++ b/include/clang/Lex/PreprocessingRecord.h @@ -35,6 +35,7 @@ void operator delete(void* ptr, clang::PreprocessingRecord& PR, namespace clang { class MacroDefinition; + class FileEntry; /// \brief Base class that describes a preprocessed entity, which may be a /// preprocessor directive or macro instantiation. @@ -54,8 +55,12 @@ namespace clang { /// \brief A macro definition. MacroDefinitionKind, + /// \brief An inclusion directive, such as \c #include, \c + /// #import, or \c #include_next. + InclusionDirectiveKind, + FirstPreprocessingDirective = PreprocessingDirectiveKind, - LastPreprocessingDirective = MacroDefinitionKind + LastPreprocessingDirective = InclusionDirectiveKind }; private: @@ -173,6 +178,68 @@ namespace clang { } static bool classof(const MacroDefinition *) { return true; } }; + + /// \brief Record the location of an inclusion directive, such as an + /// \c #include or \c #import statement. + class InclusionDirective : public PreprocessingDirective { + public: + /// \brief The kind of inclusion directives known to the + /// preprocessor. + enum InclusionKind { + /// \brief An \c #include directive. + Include, + /// \brief An Objective-C \c #import directive. + Import, + /// \brief A GNU \c #include_next directive. + IncludeNext, + /// \brief A Clang \c #__include_macros directive. + IncludeMacros + }; + + private: + /// \brief The name of the file that was included, as written in + /// the source. + std::string FileName; + + /// \brief Whether the file name was in quotation marks; otherwise, it was + /// in angle brackets. + unsigned InQuotes : 1; + + /// \brief The kind of inclusion directive we have. + /// + /// This is a value of type InclusionKind. + unsigned Kind : 2; + + /// \brief The file that was included. + const FileEntry *File; + + public: + explicit InclusionDirective(InclusionKind Kind, + const std::string &FileName, bool InQuotes, + const FileEntry *File, SourceRange Range) + : PreprocessingDirective(InclusionDirectiveKind, Range), + FileName(FileName), InQuotes(InQuotes), Kind(Kind), File(File) { } + + /// \brief Determine what kind of inclusion directive this is. + InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); } + + /// \brief Retrieve the included file name as it was written in the source. + llvm::StringRef getFileName() const { return FileName; } + + /// \brief Determine whether the included file name was written in quotes; + /// otherwise, it was written in angle brackets. + bool wasInQuotes() const { return InQuotes; } + + /// \brief Retrieve the file entry for the actual file that was included + /// by this directive. + const FileEntry *getFile() const { return File; } + + // Implement isa/cast/dyncast/etc. + static bool classof(const PreprocessedEntity *PE) { + return PE->getKind() == InclusionDirectiveKind; + } + static bool classof(const InclusionDirective *) { return true; } + }; /// \brief An abstract class that should be subclassed by any external source /// of preprocessing record entries. @@ -263,6 +330,12 @@ namespace clang { virtual void MacroDefined(const IdentifierInfo *II, const MacroInfo *MI); virtual void MacroUndefined(SourceLocation Loc, const IdentifierInfo *II, const MacroInfo *MI); + virtual void InclusionDirective(SourceLocation HashLoc, + const Token &IncludeTok, + llvm::StringRef FileName, + bool IsAngled, + const FileEntry *File, + SourceLocation EndLoc); }; } // end namespace clang diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 1ee0fec1c5..87b62d0a9a 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -823,7 +823,8 @@ public: /// This code concatenates and consumes tokens up to the '>' token. It /// returns false if the > was found, otherwise it returns true if it finds /// and consumes the EOM marker. - bool ConcatenateIncludeName(llvm::SmallString<128> &FilenameBuffer); + bool ConcatenateIncludeName(llvm::SmallString<128> &FilenameBuffer, + SourceLocation &End); private: @@ -972,12 +973,13 @@ private: void HandleIdentSCCSDirective(Token &Tok); // File inclusion. - void HandleIncludeDirective(Token &Tok, + void HandleIncludeDirective(SourceLocation HashLoc, + Token &Tok, const DirectoryLookup *LookupFrom = 0, bool isImport = false); - void HandleIncludeNextDirective(Token &Tok); - void HandleIncludeMacrosDirective(Token &Tok); - void HandleImportDirective(Token &Tok); + void HandleIncludeNextDirective(SourceLocation HashLoc, Token &Tok); + void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok); + void HandleImportDirective(SourceLocation HashLoc, Token &Tok); // Macro handling. void HandleDefineDirective(Token &Tok); diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index edb61917d4..da27cde29f 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -372,7 +372,11 @@ namespace clang { PP_MACRO_INSTANTIATION = 4, /// \brief Describes a macro definition within the preprocessing record. - PP_MACRO_DEFINITION = 5 + PP_MACRO_DEFINITION = 5, + + /// \brief Describes am inclusion directive within the preprocessing + /// record. + PP_INCLUSION_DIRECTIVE = 6 }; /// \defgroup ASTAST AST file AST constants diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 979b953d1f..b049e6eb4e 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -277,6 +277,9 @@ private: /// all of the macro definitions. llvm::BitstreamCursor MacroCursor; + /// \brief The offset of the start of the set of defined macros. + uint64_t MacroStartOffset; + /// \brief The number of macro definitions in this file. unsigned LocalNumMacroDefinitions; |