Lexer.h revision 226633
1193326Sed//===--- Lexer.h - C Language Family Lexer ----------------------*- C++ -*-===// 2193326Sed// 3193326Sed// The LLVM Compiler Infrastructure 4193326Sed// 5193326Sed// This file is distributed under the University of Illinois Open Source 6193326Sed// License. See LICENSE.TXT for details. 7193326Sed// 8193326Sed//===----------------------------------------------------------------------===// 9193326Sed// 10193326Sed// This file defines the Lexer interface. 11193326Sed// 12193326Sed//===----------------------------------------------------------------------===// 13193326Sed 14193326Sed#ifndef LLVM_CLANG_LEXER_H 15193326Sed#define LLVM_CLANG_LEXER_H 16193326Sed 17193326Sed#include "clang/Lex/PreprocessorLexer.h" 18193326Sed#include "clang/Basic/LangOptions.h" 19193326Sed#include "llvm/ADT/SmallVector.h" 20193326Sed#include <string> 21193326Sed#include <cassert> 22193326Sed 23193326Sednamespace clang { 24226633Sdimclass DiagnosticsEngine; 25193326Sedclass SourceManager; 26193326Sedclass Preprocessor; 27193326Sedclass DiagnosticBuilder; 28193326Sed 29226633Sdim/// ConflictMarkerKind - Kinds of conflict marker which the lexer might be 30226633Sdim/// recovering from. 31226633Sdimenum ConflictMarkerKind { 32226633Sdim /// Not within a conflict marker. 33226633Sdim CMK_None, 34226633Sdim /// A normal or diff3 conflict marker, initiated by at least 7 <s, 35226633Sdim /// separated by at least 7 =s or |s, and terminated by at least 7 >s. 36226633Sdim CMK_Normal, 37226633Sdim /// A Perforce-style conflict marker, initiated by 4 >s, separated by 4 =s, 38226633Sdim /// and terminated by 4 <s. 39226633Sdim CMK_Perforce 40226633Sdim}; 41226633Sdim 42193326Sed/// Lexer - This provides a simple interface that turns a text buffer into a 43193326Sed/// stream of tokens. This provides no support for file reading or buffering, 44193326Sed/// or buffering/seeking of tokens, only forward lexing is supported. It relies 45193326Sed/// on the specified Preprocessor object to handle preprocessor directives, etc. 46193326Sedclass Lexer : public PreprocessorLexer { 47193326Sed //===--------------------------------------------------------------------===// 48193326Sed // Constant configuration values for this lexer. 49193326Sed const char *BufferStart; // Start of the buffer. 50193326Sed const char *BufferEnd; // End of the buffer. 51193326Sed SourceLocation FileLoc; // Location for start of file. 52193326Sed LangOptions Features; // Features enabled by this language (cache). 53226633Sdim bool Is_PragmaLexer; // True if lexer for _Pragma handling. 54193326Sed 55193326Sed //===--------------------------------------------------------------------===// 56193326Sed // Context-specific lexing flags set by the preprocessor. 57193326Sed // 58198092Srdivacky 59193326Sed /// ExtendedTokenMode - The lexer can optionally keep comments and whitespace 60193326Sed /// and return them as tokens. This is used for -C and -CC modes, and 61193326Sed /// whitespace preservation can be useful for some clients that want to lex 62193326Sed /// the file in raw mode and get every character from the file. 63193326Sed /// 64193326Sed /// When this is set to 2 it returns comments and whitespace. When set to 1 65193326Sed /// it returns comments, when it is set to 0 it returns normal tokens only. 66193326Sed unsigned char ExtendedTokenMode; 67198092Srdivacky 68193326Sed //===--------------------------------------------------------------------===// 69193326Sed // Context that changes as the file is lexed. 70193326Sed // NOTE: any state that mutates when in raw mode must have save/restore code 71193326Sed // in Lexer::isNextPPTokenLParen. 72193326Sed 73193326Sed // BufferPtr - Current pointer into the buffer. This is the next character 74193326Sed // to be lexed. 75193326Sed const char *BufferPtr; 76193326Sed 77193326Sed // IsAtStartOfLine - True if the next lexed token should get the "start of 78193326Sed // line" flag set on it. 79193326Sed bool IsAtStartOfLine; 80198092Srdivacky 81226633Sdim // CurrentConflictMarkerState - The kind of conflict marker we are handling. 82226633Sdim ConflictMarkerKind CurrentConflictMarkerState; 83226633Sdim 84193326Sed Lexer(const Lexer&); // DO NOT IMPLEMENT 85193326Sed void operator=(const Lexer&); // DO NOT IMPLEMENT 86193326Sed friend class Preprocessor; 87198092Srdivacky 88193326Sed void InitLexer(const char *BufStart, const char *BufPtr, const char *BufEnd); 89193326Sedpublic: 90198092Srdivacky 91193326Sed /// Lexer constructor - Create a new lexer object for the specified buffer 92193326Sed /// with the specified preprocessor managing the lexing process. This lexer 93193326Sed /// assumes that the associated file buffer and Preprocessor objects will 94193326Sed /// outlive it, so it doesn't take ownership of either of them. 95199990Srdivacky Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, Preprocessor &PP); 96193326Sed 97193326Sed /// Lexer constructor - Create a new raw lexer object. This object is only 98193326Sed /// suitable for calls to 'LexRawToken'. This lexer assumes that the text 99193326Sed /// range will outlive it, so it doesn't take ownership of it. 100193326Sed Lexer(SourceLocation FileLoc, const LangOptions &Features, 101193326Sed const char *BufStart, const char *BufPtr, const char *BufEnd); 102198092Srdivacky 103193326Sed /// Lexer constructor - Create a new raw lexer object. This object is only 104193326Sed /// suitable for calls to 'LexRawToken'. This lexer assumes that the text 105193326Sed /// range will outlive it, so it doesn't take ownership of it. 106199990Srdivacky Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, 107199990Srdivacky const SourceManager &SM, const LangOptions &Features); 108198092Srdivacky 109193326Sed /// Create_PragmaLexer: Lexer constructor - Create a new lexer object for 110193326Sed /// _Pragma expansion. This has a variety of magic semantics that this method 111193326Sed /// sets up. It returns a new'd Lexer that must be delete'd when done. 112198092Srdivacky static Lexer *Create_PragmaLexer(SourceLocation SpellingLoc, 113224145Sdim SourceLocation ExpansionLocStart, 114224145Sdim SourceLocation ExpansionLocEnd, 115193326Sed unsigned TokLen, Preprocessor &PP); 116198092Srdivacky 117198092Srdivacky 118193326Sed /// getFeatures - Return the language features currently enabled. NOTE: this 119193326Sed /// lexer modifies features as a file is parsed! 120193326Sed const LangOptions &getFeatures() const { return Features; } 121193326Sed 122193326Sed /// getFileLoc - Return the File Location for the file we are lexing out of. 123193326Sed /// The physical location encodes the location where the characters come from, 124193326Sed /// the virtual location encodes where we should *claim* the characters came 125193326Sed /// from. Currently this is only used by _Pragma handling. 126193326Sed SourceLocation getFileLoc() const { return FileLoc; } 127198092Srdivacky 128193326Sed /// Lex - Return the next token in the file. If this is the end of file, it 129193326Sed /// return the tok::eof token. Return true if an error occurred and 130193326Sed /// compilation should terminate, false if normal. This implicitly involves 131193326Sed /// the preprocessor. 132193326Sed void Lex(Token &Result) { 133193326Sed // Start a new token. 134193326Sed Result.startToken(); 135198092Srdivacky 136198092Srdivacky // NOTE, any changes here should also change code after calls to 137193326Sed // Preprocessor::HandleDirective 138193326Sed if (IsAtStartOfLine) { 139193326Sed Result.setFlag(Token::StartOfLine); 140193326Sed IsAtStartOfLine = false; 141193326Sed } 142198092Srdivacky 143193326Sed // Get a token. Note that this may delete the current lexer if the end of 144193326Sed // file is reached. 145193326Sed LexTokenInternal(Result); 146193326Sed } 147193326Sed 148193326Sed /// isPragmaLexer - Returns true if this Lexer is being used to lex a pragma. 149193326Sed bool isPragmaLexer() const { return Is_PragmaLexer; } 150198092Srdivacky 151193326Sed /// IndirectLex - An indirect call to 'Lex' that can be invoked via 152193326Sed /// the PreprocessorLexer interface. 153193326Sed void IndirectLex(Token &Result) { Lex(Result); } 154198092Srdivacky 155193326Sed /// LexFromRawLexer - Lex a token from a designated raw lexer (one with no 156193326Sed /// associated preprocessor object. Return true if the 'next character to 157193326Sed /// read' pointer points at the end of the lexer buffer, false otherwise. 158193326Sed bool LexFromRawLexer(Token &Result) { 159193326Sed assert(LexingRawMode && "Not already in raw mode!"); 160193326Sed Lex(Result); 161193326Sed // Note that lexing to the end of the buffer doesn't implicitly delete the 162193326Sed // lexer when in raw mode. 163198092Srdivacky return BufferPtr == BufferEnd; 164193326Sed } 165193326Sed 166193326Sed /// isKeepWhitespaceMode - Return true if the lexer should return tokens for 167193326Sed /// every character in the file, including whitespace and comments. This 168193326Sed /// should only be used in raw mode, as the preprocessor is not prepared to 169193326Sed /// deal with the excess tokens. 170193326Sed bool isKeepWhitespaceMode() const { 171193326Sed return ExtendedTokenMode > 1; 172193326Sed } 173193326Sed 174193326Sed /// SetKeepWhitespaceMode - This method lets clients enable or disable 175193326Sed /// whitespace retention mode. 176193326Sed void SetKeepWhitespaceMode(bool Val) { 177193326Sed assert((!Val || LexingRawMode) && 178193326Sed "Can only enable whitespace retention in raw mode"); 179193326Sed ExtendedTokenMode = Val ? 2 : 0; 180193326Sed } 181193326Sed 182193326Sed /// inKeepCommentMode - Return true if the lexer should return comments as 183193326Sed /// tokens. 184193326Sed bool inKeepCommentMode() const { 185193326Sed return ExtendedTokenMode > 0; 186193326Sed } 187198092Srdivacky 188193326Sed /// SetCommentRetentionMode - Change the comment retention mode of the lexer 189193326Sed /// to the specified mode. This is really only useful when lexing in raw 190193326Sed /// mode, because otherwise the lexer needs to manage this. 191198092Srdivacky void SetCommentRetentionState(bool Mode) { 192193326Sed assert(!isKeepWhitespaceMode() && 193193326Sed "Can't play with comment retention state when retaining whitespace"); 194193326Sed ExtendedTokenMode = Mode ? 1 : 0; 195193326Sed } 196198092Srdivacky 197193326Sed const char *getBufferStart() const { return BufferStart; } 198198092Srdivacky 199193326Sed /// ReadToEndOfLine - Read the rest of the current preprocessor line as an 200193326Sed /// uninterpreted string. This switches the lexer out of directive mode. 201193326Sed std::string ReadToEndOfLine(); 202198092Srdivacky 203198092Srdivacky 204193326Sed /// Diag - Forwarding function for diagnostics. This translate a source 205193326Sed /// position in the current buffer into a SourceLocation object for rendering. 206193326Sed DiagnosticBuilder Diag(const char *Loc, unsigned DiagID) const; 207193326Sed 208193326Sed /// getSourceLocation - Return a source location identifier for the specified 209193326Sed /// offset in the current file. 210193326Sed SourceLocation getSourceLocation(const char *Loc, unsigned TokLen = 1) const; 211198092Srdivacky 212193326Sed /// getSourceLocation - Return a source location for the next character in 213193326Sed /// the current file. 214193326Sed SourceLocation getSourceLocation() { return getSourceLocation(BufferPtr); } 215198092Srdivacky 216203955Srdivacky /// \brief Return the current location in the buffer. 217203955Srdivacky const char *getBufferLocation() const { return BufferPtr; } 218203955Srdivacky 219193326Sed /// Stringify - Convert the specified string into a C string by escaping '\' 220193326Sed /// and " characters. This does not add surrounding ""'s to the string. 221193326Sed /// If Charify is true, this escapes the ' character instead of ". 222193326Sed static std::string Stringify(const std::string &Str, bool Charify = false); 223198092Srdivacky 224193326Sed /// Stringify - Convert the specified string into a C string by escaping '\' 225193326Sed /// and " characters. This does not add surrounding ""'s to the string. 226226633Sdim static void Stringify(SmallVectorImpl<char> &Str); 227198092Srdivacky 228218893Sdim 229218893Sdim /// getSpelling - This method is used to get the spelling of a token into a 230218893Sdim /// preallocated buffer, instead of as an std::string. The caller is required 231218893Sdim /// to allocate enough space for the token, which is guaranteed to be at least 232218893Sdim /// Tok.getLength() bytes long. The length of the actual result is returned. 233218893Sdim /// 234218893Sdim /// Note that this method may do two possible things: it may either fill in 235218893Sdim /// the buffer specified with characters, or it may *change the input pointer* 236218893Sdim /// to point to a constant buffer with the data already in it (avoiding a 237218893Sdim /// copy). The caller is not allowed to modify the returned buffer pointer 238218893Sdim /// if an internal buffer is returned. 239218893Sdim static unsigned getSpelling(const Token &Tok, const char *&Buffer, 240218893Sdim const SourceManager &SourceMgr, 241218893Sdim const LangOptions &Features, 242218893Sdim bool *Invalid = 0); 243218893Sdim 244218893Sdim /// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a 245218893Sdim /// token is the characters used to represent the token in the source file 246218893Sdim /// after trigraph expansion and escaped-newline folding. In particular, this 247218893Sdim /// wants to get the true, uncanonicalized, spelling of things like digraphs 248218893Sdim /// UCNs, etc. 249218893Sdim static std::string getSpelling(const Token &Tok, 250218893Sdim const SourceManager &SourceMgr, 251218893Sdim const LangOptions &Features, 252218893Sdim bool *Invalid = 0); 253221345Sdim 254221345Sdim /// getSpelling - This method is used to get the spelling of the 255221345Sdim /// token at the given source location. If, as is usually true, it 256221345Sdim /// is not necessary to copy any data, then the returned string may 257221345Sdim /// not point into the provided buffer. 258221345Sdim /// 259224145Sdim /// This method lexes at the expansion depth of the given 260224145Sdim /// location and does not jump to the expansion or spelling 261221345Sdim /// location. 262226633Sdim static StringRef getSpelling(SourceLocation loc, 263226633Sdim SmallVectorImpl<char> &buffer, 264221345Sdim const SourceManager &SourceMgr, 265221345Sdim const LangOptions &Features, 266221345Sdim bool *invalid = 0); 267218893Sdim 268193326Sed /// MeasureTokenLength - Relex the token at the specified location and return 269193326Sed /// its length in bytes in the input file. If the token needs cleaning (e.g. 270193326Sed /// includes a trigraph or an escaped newline) then this count includes bytes 271193326Sed /// that are part of that. 272193326Sed static unsigned MeasureTokenLength(SourceLocation Loc, 273193326Sed const SourceManager &SM, 274193326Sed const LangOptions &LangOpts); 275198092Srdivacky 276212904Sdim /// \brief Given a location any where in a source buffer, find the location 277212904Sdim /// that corresponds to the beginning of the token in which the original 278212904Sdim /// source location lands. 279212904Sdim /// 280212904Sdim /// \param Loc 281212904Sdim static SourceLocation GetBeginningOfToken(SourceLocation Loc, 282212904Sdim const SourceManager &SM, 283212904Sdim const LangOptions &LangOpts); 284212904Sdim 285218893Sdim /// AdvanceToTokenCharacter - If the current SourceLocation specifies a 286218893Sdim /// location at the start of a token, return a new location that specifies a 287218893Sdim /// character within the token. This handles trigraphs and escaped newlines. 288218893Sdim static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, 289218893Sdim unsigned Character, 290218893Sdim const SourceManager &SM, 291218893Sdim const LangOptions &Features); 292218893Sdim 293218893Sdim /// \brief Computes the source location just past the end of the 294218893Sdim /// token at this source location. 295218893Sdim /// 296218893Sdim /// This routine can be used to produce a source location that 297218893Sdim /// points just past the end of the token referenced by \p Loc, and 298218893Sdim /// is generally used when a diagnostic needs to point just after a 299218893Sdim /// token where it expected something different that it received. If 300218893Sdim /// the returned source location would not be meaningful (e.g., if 301218893Sdim /// it points into a macro), this routine returns an invalid 302218893Sdim /// source location. 303218893Sdim /// 304218893Sdim /// \param Offset an offset from the end of the token, where the source 305218893Sdim /// location should refer to. The default offset (0) produces a source 306218893Sdim /// location pointing just past the end of the token; an offset of 1 produces 307218893Sdim /// a source location pointing to the last character in the token, etc. 308218893Sdim static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, 309218893Sdim const SourceManager &SM, 310218893Sdim const LangOptions &Features); 311224145Sdim 312224145Sdim /// \brief Returns true if the given MacroID location points at the first 313224145Sdim /// token of the macro expansion. 314224145Sdim static bool isAtStartOfMacroExpansion(SourceLocation loc, 315224145Sdim const SourceManager &SM, 316224145Sdim const LangOptions &LangOpts); 317224145Sdim 318224145Sdim /// \brief Returns true if the given MacroID location points at the last 319224145Sdim /// token of the macro expansion. 320224145Sdim static bool isAtEndOfMacroExpansion(SourceLocation loc, 321224145Sdim const SourceManager &SM, 322224145Sdim const LangOptions &LangOpts); 323224145Sdim 324212904Sdim /// \brief Compute the preamble of the given file. 325212904Sdim /// 326212904Sdim /// The preamble of a file contains the initial comments, include directives, 327212904Sdim /// and other preprocessor directives that occur before the code in this 328212904Sdim /// particular file actually begins. The preamble of the main source file is 329212904Sdim /// a potential prefix header. 330212904Sdim /// 331212904Sdim /// \param Buffer The memory buffer containing the file's contents. 332212904Sdim /// 333212904Sdim /// \param MaxLines If non-zero, restrict the length of the preamble 334212904Sdim /// to fewer than this number of lines. 335212904Sdim /// 336212904Sdim /// \returns The offset into the file where the preamble ends and the rest 337212904Sdim /// of the file begins along with a boolean value indicating whether 338212904Sdim /// the preamble ends at the beginning of a new line. 339212904Sdim static std::pair<unsigned, bool> 340226633Sdim ComputePreamble(const llvm::MemoryBuffer *Buffer, const LangOptions &Features, 341226633Sdim unsigned MaxLines = 0); 342212904Sdim 343193326Sed //===--------------------------------------------------------------------===// 344193326Sed // Internal implementation interfaces. 345193326Sedprivate: 346193326Sed 347193326Sed /// LexTokenInternal - Internal interface to lex a preprocessing token. Called 348193326Sed /// by Lex. 349193326Sed /// 350193326Sed void LexTokenInternal(Token &Result); 351193326Sed 352193326Sed /// FormTokenWithChars - When we lex a token, we have identified a span 353193326Sed /// starting at BufferPtr, going to TokEnd that forms the token. This method 354193326Sed /// takes that range and assigns it to the token as its location and size. In 355193326Sed /// addition, since tokens cannot overlap, this also updates BufferPtr to be 356193326Sed /// TokEnd. 357198092Srdivacky void FormTokenWithChars(Token &Result, const char *TokEnd, 358193326Sed tok::TokenKind Kind) { 359193326Sed unsigned TokLen = TokEnd-BufferPtr; 360193326Sed Result.setLength(TokLen); 361193326Sed Result.setLocation(getSourceLocation(BufferPtr, TokLen)); 362193326Sed Result.setKind(Kind); 363193326Sed BufferPtr = TokEnd; 364193326Sed } 365198092Srdivacky 366193326Sed /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 367193326Sed /// tok::l_paren token, 0 if it is something else and 2 if there are no more 368193326Sed /// tokens in the buffer controlled by this lexer. 369193326Sed unsigned isNextPPTokenLParen(); 370193326Sed 371193326Sed //===--------------------------------------------------------------------===// 372193326Sed // Lexer character reading interfaces. 373193326Sedpublic: 374198092Srdivacky 375193326Sed // This lexer is built on two interfaces for reading characters, both of which 376193326Sed // automatically provide phase 1/2 translation. getAndAdvanceChar is used 377193326Sed // when we know that we will be reading a character from the input buffer and 378193326Sed // that this character will be part of the result token. This occurs in (f.e.) 379193326Sed // string processing, because we know we need to read until we find the 380193326Sed // closing '"' character. 381193326Sed // 382201361Srdivacky // The second interface is the combination of getCharAndSize with 383201361Srdivacky // ConsumeChar. getCharAndSize reads a phase 1/2 translated character, 384193326Sed // returning it and its size. If the lexer decides that this character is 385193326Sed // part of the current token, it calls ConsumeChar on it. This two stage 386193326Sed // approach allows us to emit diagnostics for characters (e.g. warnings about 387193326Sed // trigraphs), knowing that they only are emitted if the character is 388193326Sed // consumed. 389198092Srdivacky 390193326Sed /// isObviouslySimpleCharacter - Return true if the specified character is 391193326Sed /// obviously the same in translation phase 1 and translation phase 3. This 392193326Sed /// can return false for characters that end up being the same, but it will 393193326Sed /// never return true for something that needs to be mapped. 394193326Sed static bool isObviouslySimpleCharacter(char C) { 395193326Sed return C != '?' && C != '\\'; 396193326Sed } 397198092Srdivacky 398193326Sed /// getAndAdvanceChar - Read a single 'character' from the specified buffer, 399193326Sed /// advance over it, and return it. This is tricky in several cases. Here we 400193326Sed /// just handle the trivial case and fall-back to the non-inlined 401193326Sed /// getCharAndSizeSlow method to handle the hard case. 402193326Sed inline char getAndAdvanceChar(const char *&Ptr, Token &Tok) { 403193326Sed // If this is not a trigraph and not a UCN or escaped newline, return 404193326Sed // quickly. 405193326Sed if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++; 406198092Srdivacky 407193326Sed unsigned Size = 0; 408193326Sed char C = getCharAndSizeSlow(Ptr, Size, &Tok); 409193326Sed Ptr += Size; 410193326Sed return C; 411193326Sed } 412198092Srdivacky 413193326Sedprivate: 414201361Srdivacky /// ConsumeChar - When a character (identified by getCharAndSize) is consumed 415193326Sed /// and added to a given token, check to see if there are diagnostics that 416193326Sed /// need to be emitted or flags that need to be set on the token. If so, do 417193326Sed /// it. 418193326Sed const char *ConsumeChar(const char *Ptr, unsigned Size, Token &Tok) { 419193326Sed // Normal case, we consumed exactly one token. Just return it. 420193326Sed if (Size == 1) 421193326Sed return Ptr+Size; 422193326Sed 423193326Sed // Otherwise, re-lex the character with a current token, allowing 424193326Sed // diagnostics to be emitted and flags to be set. 425193326Sed Size = 0; 426193326Sed getCharAndSizeSlow(Ptr, Size, &Tok); 427193326Sed return Ptr+Size; 428193326Sed } 429198092Srdivacky 430193326Sed /// getCharAndSize - Peek a single 'character' from the specified buffer, 431193326Sed /// get its size, and return it. This is tricky in several cases. Here we 432193326Sed /// just handle the trivial case and fall-back to the non-inlined 433193326Sed /// getCharAndSizeSlow method to handle the hard case. 434193326Sed inline char getCharAndSize(const char *Ptr, unsigned &Size) { 435193326Sed // If this is not a trigraph and not a UCN or escaped newline, return 436193326Sed // quickly. 437193326Sed if (isObviouslySimpleCharacter(Ptr[0])) { 438193326Sed Size = 1; 439193326Sed return *Ptr; 440193326Sed } 441198092Srdivacky 442193326Sed Size = 0; 443193326Sed return getCharAndSizeSlow(Ptr, Size); 444193326Sed } 445198092Srdivacky 446193326Sed /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize 447193326Sed /// method. 448193326Sed char getCharAndSizeSlow(const char *Ptr, unsigned &Size, Token *Tok = 0); 449193326Sedpublic: 450198092Srdivacky 451193326Sed /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever 452193326Sed /// emit a warning. 453193326Sed static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size, 454193326Sed const LangOptions &Features) { 455193326Sed // If this is not a trigraph and not a UCN or escaped newline, return 456193326Sed // quickly. 457193326Sed if (isObviouslySimpleCharacter(Ptr[0])) { 458193326Sed Size = 1; 459193326Sed return *Ptr; 460193326Sed } 461198092Srdivacky 462193326Sed Size = 0; 463193326Sed return getCharAndSizeSlowNoWarn(Ptr, Size, Features); 464193326Sed } 465198092Srdivacky 466193326Sed /// getEscapedNewLineSize - Return the size of the specified escaped newline, 467193326Sed /// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry 468193326Sed /// to this function. 469193326Sed static unsigned getEscapedNewLineSize(const char *P); 470198092Srdivacky 471193326Sed /// SkipEscapedNewLines - If P points to an escaped newline (or a series of 472193326Sed /// them), skip over them and return the first non-escaped-newline found, 473193326Sed /// otherwise return P. 474193326Sed static const char *SkipEscapedNewLines(const char *P); 475226633Sdim 476226633Sdim /// \brief Checks that the given token is the first token that occurs after 477226633Sdim /// the given location (this excludes comments and whitespace). Returns the 478226633Sdim /// location immediately after the specified token. If the token is not found 479226633Sdim /// or the location is inside a macro, the returned source location will be 480226633Sdim /// invalid. 481226633Sdim static SourceLocation findLocationAfterToken(SourceLocation loc, 482226633Sdim tok::TokenKind TKind, 483226633Sdim const SourceManager &SM, 484226633Sdim const LangOptions &LangOpts, 485226633Sdim bool SkipTrailingWhitespaceAndNewLine); 486226633Sdim 487193326Sedprivate: 488198092Srdivacky 489193326Sed /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a 490193326Sed /// diagnostic. 491193326Sed static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size, 492193326Sed const LangOptions &Features); 493198092Srdivacky 494193326Sed //===--------------------------------------------------------------------===// 495193326Sed // Other lexer functions. 496198092Srdivacky 497212904Sdim void SkipBytes(unsigned Bytes, bool StartOfLine); 498212904Sdim 499193326Sed // Helper functions to lex the remainder of a token of the specific type. 500193326Sed void LexIdentifier (Token &Result, const char *CurPtr); 501193326Sed void LexNumericConstant (Token &Result, const char *CurPtr); 502226633Sdim void LexStringLiteral (Token &Result, const char *CurPtr, 503226633Sdim tok::TokenKind Kind); 504226633Sdim void LexRawStringLiteral (Token &Result, const char *CurPtr, 505226633Sdim tok::TokenKind Kind); 506193326Sed void LexAngledStringLiteral(Token &Result, const char *CurPtr); 507226633Sdim void LexCharConstant (Token &Result, const char *CurPtr, 508226633Sdim tok::TokenKind Kind); 509193326Sed bool LexEndOfFile (Token &Result, const char *CurPtr); 510198092Srdivacky 511193326Sed bool SkipWhitespace (Token &Result, const char *CurPtr); 512193326Sed bool SkipBCPLComment (Token &Result, const char *CurPtr); 513193326Sed bool SkipBlockComment (Token &Result, const char *CurPtr); 514193326Sed bool SaveBCPLComment (Token &Result, const char *CurPtr); 515200583Srdivacky 516200583Srdivacky bool IsStartOfConflictMarker(const char *CurPtr); 517200583Srdivacky bool HandleEndOfConflictMarker(const char *CurPtr); 518226633Sdim 519226633Sdim bool isCodeCompletionPoint(const char *CurPtr) const; 520226633Sdim void cutOffLexing() { BufferPtr = BufferEnd; } 521193326Sed}; 522193326Sed 523193326Sed 524193326Sed} // end namespace clang 525193326Sed 526193326Sed#endif 527