diff options
Diffstat (limited to 'include/clang/Lex/Lexer.h')
-rw-r--r-- | include/clang/Lex/Lexer.h | 75 |
1 files changed, 56 insertions, 19 deletions
diff --git a/include/clang/Lex/Lexer.h b/include/clang/Lex/Lexer.h index e01427f..04bcead 100644 --- a/include/clang/Lex/Lexer.h +++ b/include/clang/Lex/Lexer.h @@ -44,12 +44,14 @@ enum ConflictMarkerKind { /// or buffering/seeking of tokens, only forward lexing is supported. It relies /// on the specified Preprocessor object to handle preprocessor directives, etc. class Lexer : public PreprocessorLexer { + virtual void anchor(); + //===--------------------------------------------------------------------===// // Constant configuration values for this lexer. const char *BufferStart; // Start of the buffer. const char *BufferEnd; // End of the buffer. SourceLocation FileLoc; // Location for start of file. - LangOptions Features; // Features enabled by this language (cache). + LangOptions LangOpts; // LangOpts enabled by this language (cache). bool Is_PragmaLexer; // True if lexer for _Pragma handling. //===--------------------------------------------------------------------===// @@ -97,14 +99,14 @@ public: /// Lexer constructor - Create a new raw lexer object. This object is only /// suitable for calls to 'LexRawToken'. This lexer assumes that the text /// range will outlive it, so it doesn't take ownership of it. - Lexer(SourceLocation FileLoc, const LangOptions &Features, + Lexer(SourceLocation FileLoc, const LangOptions &LangOpts, const char *BufStart, const char *BufPtr, const char *BufEnd); /// Lexer constructor - Create a new raw lexer object. This object is only /// suitable for calls to 'LexRawToken'. This lexer assumes that the text /// range will outlive it, so it doesn't take ownership of it. Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, - const SourceManager &SM, const LangOptions &Features); + const SourceManager &SM, const LangOptions &LangOpts); /// Create_PragmaLexer: Lexer constructor - Create a new lexer object for /// _Pragma expansion. This has a variety of magic semantics that this method @@ -115,9 +117,9 @@ public: unsigned TokLen, Preprocessor &PP); - /// getFeatures - Return the language features currently enabled. NOTE: this - /// lexer modifies features as a file is parsed! - const LangOptions &getFeatures() const { return Features; } + /// getLangOpts - Return the language features currently enabled. + /// NOTE: this lexer modifies features as a file is parsed! + const LangOptions &getLangOpts() const { return LangOpts; } /// getFileLoc - Return the File Location for the file we are lexing out of. /// The physical location encodes the location where the characters come from, @@ -238,7 +240,7 @@ public: /// if an internal buffer is returned. static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, - const LangOptions &Features, + const LangOptions &LangOpts, bool *Invalid = 0); /// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a @@ -248,7 +250,7 @@ public: /// UCNs, etc. static std::string getSpelling(const Token &Tok, const SourceManager &SourceMgr, - const LangOptions &Features, + const LangOptions &LangOpts, bool *Invalid = 0); /// getSpelling - This method is used to get the spelling of the @@ -262,7 +264,7 @@ public: static StringRef getSpelling(SourceLocation loc, SmallVectorImpl<char> &buffer, const SourceManager &SourceMgr, - const LangOptions &Features, + const LangOptions &LangOpts, bool *invalid = 0); /// MeasureTokenLength - Relex the token at the specified location and return @@ -288,7 +290,7 @@ public: static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Character, const SourceManager &SM, - const LangOptions &Features); + const LangOptions &LangOpts); /// \brief Computes the source location just past the end of the /// token at this source location. @@ -307,19 +309,52 @@ public: /// a source location pointing to the last character in the token, etc. static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, - const LangOptions &Features); + const LangOptions &LangOpts); /// \brief Returns true if the given MacroID location points at the first /// token of the macro expansion. + /// + /// \param MacroBegin If non-null and function returns true, it is set to + /// begin location of the macro. static bool isAtStartOfMacroExpansion(SourceLocation loc, - const SourceManager &SM, - const LangOptions &LangOpts); + const SourceManager &SM, + const LangOptions &LangOpts, + SourceLocation *MacroBegin = 0); /// \brief Returns true if the given MacroID location points at the last /// token of the macro expansion. + /// + /// \param MacroBegin If non-null and function returns true, it is set to + /// end location of the macro. static bool isAtEndOfMacroExpansion(SourceLocation loc, - const SourceManager &SM, - const LangOptions &LangOpts); + const SourceManager &SM, + const LangOptions &LangOpts, + SourceLocation *MacroEnd = 0); + + /// \brief Accepts a range and returns a character range with file locations. + /// + /// Returns a null range if a part of the range resides inside a macro + /// expansion or the range does not reside on the same FileID. + static CharSourceRange makeFileCharRange(CharSourceRange Range, + const SourceManager &SM, + const LangOptions &LangOpts); + + /// \brief Returns a string for the source that the range encompasses. + static StringRef getSourceText(CharSourceRange Range, + const SourceManager &SM, + const LangOptions &LangOpts, + bool *Invalid = 0); + + /// \brief Retrieve the name of the immediate macro expansion. + /// + /// This routine starts from a source location, and finds the name of the macro + /// responsible for its immediate expansion. It looks through any intervening + /// macro argument expansions to compute this. It returns a StringRef which + /// refers to the SourceManager-owned buffer of the source where that macro + /// name is spelled. Thus, the result shouldn't out-live that SourceManager. + static StringRef getImmediateMacroName(SourceLocation Loc, + const SourceManager &SM, + const LangOptions &LangOpts); /// \brief Compute the preamble of the given file. /// @@ -337,7 +372,7 @@ public: /// of the file begins along with a boolean value indicating whether /// the preamble ends at the beginning of a new line. static std::pair<unsigned, bool> - ComputePreamble(const llvm::MemoryBuffer *Buffer, const LangOptions &Features, + ComputePreamble(const llvm::MemoryBuffer *Buffer, const LangOptions &LangOpts, unsigned MaxLines = 0); //===--------------------------------------------------------------------===// @@ -451,7 +486,7 @@ public: /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever /// emit a warning. static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size, - const LangOptions &Features) { + const LangOptions &LangOpts) { // If this is not a trigraph and not a UCN or escaped newline, return // quickly. if (isObviouslySimpleCharacter(Ptr[0])) { @@ -460,7 +495,7 @@ public: } Size = 0; - return getCharAndSizeSlowNoWarn(Ptr, Size, Features); + return getCharAndSizeSlowNoWarn(Ptr, Size, LangOpts); } /// getEscapedNewLineSize - Return the size of the specified escaped newline, @@ -489,12 +524,14 @@ private: /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a /// diagnostic. static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size, - const LangOptions &Features); + const LangOptions &LangOpts); //===--------------------------------------------------------------------===// // Other lexer functions. void SkipBytes(unsigned Bytes, bool StartOfLine); + + const char *LexUDSuffix(Token &Result, const char *CurPtr); // Helper functions to lex the remainder of a token of the specific type. void LexIdentifier (Token &Result, const char *CurPtr); |