diff options
Diffstat (limited to 'include/clang/Lex/Preprocessor.h')
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 134 |
1 files changed, 82 insertions, 52 deletions
diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 055008f..02e3f1e 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -58,7 +58,7 @@ class ModuleLoader; /// Preprocessor - This object engages in a tight little dance with the lexer to /// efficiently preprocess tokens. Lexers know only about tokens within a /// single source file, and don't know anything about preprocessor-level issues -/// like the #include stack, token expansion, etc. +/// like the \#include stack, token expansion, etc. /// class Preprocessor : public RefCountedBase<Preprocessor> { DiagnosticsEngine *Diags; @@ -103,7 +103,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> { unsigned CounterValue; // Next __COUNTER__ value. enum { - /// MaxIncludeStackDepth - Maximum depth of #includes. + /// MaxIncludeStackDepth - Maximum depth of \#includes. MaxAllowedIncludeStackDepth = 200 }; @@ -121,9 +121,19 @@ class Preprocessor : public RefCountedBase<Preprocessor> { /// DisableMacroExpansion - True if macro expansion is disabled. bool DisableMacroExpansion : 1; + /// MacroExpansionInDirectivesOverride - Temporarily disables + /// DisableMacroExpansion (i.e. enables expansion) when parsing preprocessor + /// directives. + bool MacroExpansionInDirectivesOverride : 1; + + class ResetMacroExpansionHelper; + /// \brief Whether we have already loaded macros from the external source. mutable bool ReadMacrosFromExternalSource : 1; + /// \brief True if pragmas are enabled. + bool PragmasEnabled : 1; + /// \brief True if we are pre-expanding macro arguments. bool InMacroArgPreExpansion; @@ -165,11 +175,12 @@ class Preprocessor : public RefCountedBase<Preprocessor> { unsigned CodeCompletionOffset; /// \brief The location for the code-completion point. This gets instantiated - /// when the CodeCompletionFile gets #include'ed for preprocessing. + /// when the CodeCompletionFile gets \#include'ed for preprocessing. SourceLocation CodeCompletionLoc; /// \brief The start location for the file of the code-completion point. - /// This gets instantiated when the CodeCompletionFile gets #include'ed + /// + /// This gets instantiated when the CodeCompletionFile gets \#include'ed /// for preprocessing. SourceLocation CodeCompletionFileLoc; @@ -215,7 +226,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> { /// CurLookup - The DirectoryLookup structure used to find the current /// FileEntry, if CurLexer is non-null and if applicable. This allows us to - /// implement #include_next and find directory-specific properties. + /// implement \#include_next and find directory-specific properties. const DirectoryLookup *CurDirLookup; /// CurTokenLexer - This is the current macro we are expanding, if we are @@ -232,7 +243,7 @@ class Preprocessor : public RefCountedBase<Preprocessor> { } CurLexerKind; /// IncludeMacroStack - This keeps track of the stack of files currently - /// #included, and macros currently being expanded from, not counting + /// \#included, and macros currently being expanded from, not counting /// CurLexer/CurTokenLexer. struct IncludeStackInfo { enum CurLexerKind CurLexerKind; @@ -251,9 +262,18 @@ class Preprocessor : public RefCountedBase<Preprocessor> { std::vector<IncludeStackInfo> IncludeMacroStack; /// Callbacks - These are actions invoked when some preprocessor activity is - /// encountered (e.g. a file is #included, etc). + /// encountered (e.g. a file is \#included, etc). PPCallbacks *Callbacks; + struct MacroExpandsInfo { + Token Tok; + MacroInfo *MI; + SourceRange Range; + MacroExpandsInfo(Token Tok, MacroInfo *MI, SourceRange Range) + : Tok(Tok), MI(MI), Range(Range) { } + }; + SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks; + /// Macros - For each IdentifierInfo with 'HasMacro' set, we keep a mapping /// to the actual definition of the macro. llvm::DenseMap<IdentifierInfo*, MacroInfo*> Macros; @@ -400,6 +420,9 @@ public: bool getCommentRetentionState() const { return KeepComments; } + void setPragmasEnabled(bool Enabled) { PragmasEnabled = Enabled; } + bool getPragmasEnabled() const { return PragmasEnabled; } + void SetSuppressIncludeNotFoundError(bool Suppress) { SuppressIncludeNotFoundError = Suppress; } @@ -434,8 +457,8 @@ public: Callbacks = C; } - /// getMacroInfo - Given an identifier, return the MacroInfo it is #defined to - /// or null if it isn't #define'd. + /// \brief Given an identifier, return the MacroInfo it is \#defined to + /// or null if it isn't \#define'd. MacroInfo *getMacroInfo(IdentifierInfo *II) const { if (!II->hasMacroDefinition()) return 0; @@ -443,8 +466,7 @@ public: return getInfoForMacro(II); } - /// setMacroInfo - Specify a macro for this identifier. - /// + /// \brief Specify a macro for this identifier. void setMacroInfo(IdentifierInfo *II, MacroInfo *MI, bool LoadedFromAST = false); @@ -488,12 +510,12 @@ public: } /// \brief Add the specified comment handler to the preprocessor. - void AddCommentHandler(CommentHandler *Handler); + void addCommentHandler(CommentHandler *Handler); /// \brief Remove the specified comment handler. /// /// It is an error to remove a handler that has not been registered. - void RemoveCommentHandler(CommentHandler *Handler); + void removeCommentHandler(CommentHandler *Handler); /// \brief Set the code completion handler to the given object. void setCodeCompletionHandler(CodeCompletionHandler &Handler) { @@ -634,6 +656,12 @@ public: while (Result.getKind() == tok::comment); } + /// Disables macro expansion everywhere except for preprocessor directives. + void SetMacroExpansionOnlyInDirectives() { + DisableMacroExpansion = true; + MacroExpansionInDirectivesOverride = true; + } + /// LookAhead - This peeks ahead N tokens and returns that token without /// consuming any tokens. LookAhead(0) returns the next token that would be /// returned by Lex(), LookAhead(1) returns the token after it, etc. This @@ -752,25 +780,24 @@ public: getDiagnostics().setSuppressAllDiagnostics(true); } - /// \brief The location of the currently-active #pragma clang + /// \brief The location of the currently-active \#pragma clang /// arc_cf_code_audited begin. Returns an invalid location if there /// is no such pragma active. SourceLocation getPragmaARCCFCodeAuditedLoc() const { return PragmaARCCFCodeAuditedLoc; } - /// \brief Set the location of the currently-active #pragma clang + /// \brief Set the location of the currently-active \#pragma clang /// arc_cf_code_audited begin. An invalid location ends the pragma. void setPragmaARCCFCodeAuditedLoc(SourceLocation Loc) { PragmaARCCFCodeAuditedLoc = Loc; } - /// \brief Instruct the preprocessor to skip part of the main - /// the main source file. + /// \brief Instruct the preprocessor to skip part of the main source file. /// - /// \brief Bytes The number of bytes in the preamble to skip. + /// \param Bytes The number of bytes in the preamble to skip. /// - /// \brief StartOfLine Whether skipping these bytes puts the lexer at the + /// \param StartOfLine Whether skipping these bytes puts the lexer at the /// start of a line. void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine) { SkipMainFilePreamble.first = Bytes; @@ -1035,24 +1062,27 @@ public: /// \brief Retrieves the module that we're currently building, if any. Module *getCurrentModule(); - /// AllocateMacroInfo - Allocate a new MacroInfo object with the provide - /// SourceLocation. + /// \brief Allocate a new MacroInfo object with the provided SourceLocation. MacroInfo *AllocateMacroInfo(SourceLocation L); - /// CloneMacroInfo - Allocate a new MacroInfo object which is clone of MI. + /// \brief Allocate a new MacroInfo object which is clone of \p MI. MacroInfo *CloneMacroInfo(const MacroInfo &MI); - /// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully - /// checked and spelled filename, e.g. as an operand of #include. This returns - /// true if the input filename was in <>'s or false if it were in ""'s. The - /// caller is expected to provide a buffer that is large enough to hold the - /// spelling of the filename, but is also expected to handle the case when - /// this method decides to use a different buffer. + /// \brief Turn the specified lexer token into a fully checked and spelled + /// filename, e.g. as an operand of \#include. + /// + /// The caller is expected to provide a buffer that is large enough to hold + /// the spelling of the filename, but is also expected to handle the case + /// when this method decides to use a different buffer. + /// + /// \returns true if the input filename was in <>'s or false if it was + /// in ""'s. bool GetIncludeFilenameSpelling(SourceLocation Loc,StringRef &Filename); - /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file, - /// return null on failure. isAngled indicates whether the file reference is - /// for system #include's or not (i.e. using <> instead of ""). + /// \brief Given a "foo" or \<foo> reference, look up the indicated file. + /// + /// Returns null on failure. \p isAngled indicates whether the file + /// reference is for system \#include's or not (i.e. using <> instead of ""). const FileEntry *LookupFile(StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, @@ -1063,18 +1093,19 @@ public: /// GetCurLookup - The DirectoryLookup structure used to find the current /// FileEntry, if CurLexer is non-null and if applicable. This allows us to - /// implement #include_next and find directory-specific properties. + /// implement \#include_next and find directory-specific properties. const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; } - /// isInPrimaryFile - Return true if we're in the top-level file, not in a - /// #include. + /// \brief Return true if we're in the top-level file, not in a \#include. bool isInPrimaryFile() const; - /// ConcatenateIncludeName - Handle cases where the #include name is expanded + /// ConcatenateIncludeName - Handle cases where the \#include name is expanded /// from a macro as multiple tokens, which need to be glued together. This /// occurs for code like: - /// #define FOO <a/b.h> - /// #include FOO + /// \code + /// \#define FOO <a/b.h> + /// \#include FOO + /// \endcode /// because in this case, "<a/b.h>" is returned as 7 tokens, not one. /// /// This code concatenates and consumes tokens up to the '>' token. It @@ -1109,15 +1140,16 @@ private: IncludeMacroStack.pop_back(); } - /// AllocateMacroInfo - Allocate a new MacroInfo object. + /// \brief Allocate a new MacroInfo object. MacroInfo *AllocateMacroInfo(); - /// ReleaseMacroInfo - Release the specified MacroInfo. This memory will - /// be reused for allocating new MacroInfo objects. + /// \brief Release the specified MacroInfo for re-use. + /// + /// This memory will be reused for allocating new MacroInfo objects. void ReleaseMacroInfo(MacroInfo* MI); /// ReadMacroName - Lex and validate a macro name, which occurs after a - /// #define or #undef. This emits a diagnostic, sets the token kind to eod, + /// \#define or \#undef. This emits a diagnostic, sets the token kind to eod, /// and discards the rest of the macro line if the macro name is invalid. void ReadMacroName(Token &MacroNameTok, char isDefineUndef = 0); @@ -1128,20 +1160,19 @@ private: /// Return true if an error occurs parsing the arg list. bool ReadMacroDefinitionArgList(MacroInfo *MI, Token& LastTok); - /// SkipExcludedConditionalBlock - We just read a #if or related directive and - /// decided that the subsequent tokens are in the #if'd out portion of the - /// file. Lex the rest of the file, until we see an #endif. If + /// We just read a \#if or related directive and decided that the + /// subsequent tokens are in the \#if'd out portion of the + /// file. Lex the rest of the file, until we see an \#endif. If \p /// FoundNonSkipPortion is true, then we have already emitted code for part of - /// this #if directive, so #else/#elif blocks should never be entered. If - /// FoundElse is false, then #else directives are ok, if not, then we have - /// already seen one so a #else directive is a duplicate. When this returns, + /// this \#if directive, so \#else/\#elif blocks should never be entered. If + /// \p FoundElse is false, then \#else directives are ok, if not, then we have + /// already seen one so a \#else directive is a duplicate. When this returns, /// the caller can lex the first valid token. void SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, bool FoundNonSkipPortion, bool FoundElse, SourceLocation ElseLoc = SourceLocation()); - /// PTHSkipExcludedConditionalBlock - A fast PTH version of - /// SkipExcludedConditionalBlock. + /// \brief A fast PTH version of SkipExcludedConditionalBlock. void PTHSkipExcludedConditionalBlock(); /// EvaluateDirectiveExpression - Evaluate an integer constant expression that @@ -1150,11 +1181,10 @@ private: bool EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas: - /// #pragma GCC poison/system_header/dependency and #pragma once. + /// \#pragma GCC poison/system_header/dependency and \#pragma once. void RegisterBuiltinPragmas(); - /// RegisterBuiltinMacros - Register builtin macros, such as __LINE__ with the - /// identifier table. + /// \brief Register builtin macros such as __LINE__ with the identifier table. void RegisterBuiltinMacros(); /// HandleMacroExpandedIdentifier - If an identifier token is read that is to |