Lexer.h revision c7629d941557f7179eb8fa8a2e2a74d749cbaf7c
1//===--- Lexer.h - C Language Family Lexer ----------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the Lexer interface. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_LEXER_H 15#define LLVM_CLANG_LEXER_H 16 17#include "clang/Basic/LangOptions.h" 18#include "clang/Lex/PreprocessorLexer.h" 19#include "llvm/ADT/SmallVector.h" 20#include <cassert> 21#include <string> 22 23namespace clang { 24class DiagnosticsEngine; 25class SourceManager; 26class Preprocessor; 27class DiagnosticBuilder; 28 29/// ConflictMarkerKind - Kinds of conflict marker which the lexer might be 30/// recovering from. 31enum ConflictMarkerKind { 32 /// Not within a conflict marker. 33 CMK_None, 34 /// A normal or diff3 conflict marker, initiated by at least 7 "<"s, 35 /// separated by at least 7 "="s or "|"s, and terminated by at least 7 ">"s. 36 CMK_Normal, 37 /// A Perforce-style conflict marker, initiated by 4 ">"s, 38 /// separated by 4 "="s, and terminated by 4 "<"s. 39 CMK_Perforce 40}; 41 42/// Lexer - This provides a simple interface that turns a text buffer into a 43/// stream of tokens. This provides no support for file reading or buffering, 44/// or buffering/seeking of tokens, only forward lexing is supported. It relies 45/// on the specified Preprocessor object to handle preprocessor directives, etc. 46class Lexer : public PreprocessorLexer { 47 virtual void anchor(); 48 49 //===--------------------------------------------------------------------===// 50 // Constant configuration values for this lexer. 51 const char *BufferStart; // Start of the buffer. 52 const char *BufferEnd; // End of the buffer. 53 SourceLocation FileLoc; // Location for start of file. 54 LangOptions LangOpts; // LangOpts enabled by this language (cache). 55 bool Is_PragmaLexer; // True if lexer for _Pragma handling. 56 57 //===--------------------------------------------------------------------===// 58 // Context-specific lexing flags set by the preprocessor. 59 // 60 61 /// ExtendedTokenMode - The lexer can optionally keep comments and whitespace 62 /// and return them as tokens. This is used for -C and -CC modes, and 63 /// whitespace preservation can be useful for some clients that want to lex 64 /// the file in raw mode and get every character from the file. 65 /// 66 /// When this is set to 2 it returns comments and whitespace. When set to 1 67 /// it returns comments, when it is set to 0 it returns normal tokens only. 68 unsigned char ExtendedTokenMode; 69 70 //===--------------------------------------------------------------------===// 71 // Context that changes as the file is lexed. 72 // NOTE: any state that mutates when in raw mode must have save/restore code 73 // in Lexer::isNextPPTokenLParen. 74 75 // BufferPtr - Current pointer into the buffer. This is the next character 76 // to be lexed. 77 const char *BufferPtr; 78 79 // IsAtStartOfLine - True if the next lexed token should get the "start of 80 // line" flag set on it. 81 bool IsAtStartOfLine; 82 83 // CurrentConflictMarkerState - The kind of conflict marker we are handling. 84 ConflictMarkerKind CurrentConflictMarkerState; 85 86 Lexer(const Lexer &) LLVM_DELETED_FUNCTION; 87 void operator=(const Lexer &) LLVM_DELETED_FUNCTION; 88 friend class Preprocessor; 89 90 void InitLexer(const char *BufStart, const char *BufPtr, const char *BufEnd); 91public: 92 93 /// Lexer constructor - Create a new lexer object for the specified buffer 94 /// with the specified preprocessor managing the lexing process. This lexer 95 /// assumes that the associated file buffer and Preprocessor objects will 96 /// outlive it, so it doesn't take ownership of either of them. 97 Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, Preprocessor &PP); 98 99 /// Lexer constructor - Create a new raw lexer object. This object is only 100 /// suitable for calls to 'LexFromRawLexer'. This lexer assumes that the 101 /// text range will outlive it, so it doesn't take ownership of it. 102 Lexer(SourceLocation FileLoc, const LangOptions &LangOpts, 103 const char *BufStart, const char *BufPtr, const char *BufEnd); 104 105 /// Lexer constructor - Create a new raw lexer object. This object is only 106 /// suitable for calls to 'LexFromRawLexer'. This lexer assumes that the 107 /// text range will outlive it, so it doesn't take ownership of it. 108 Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, 109 const SourceManager &SM, const LangOptions &LangOpts); 110 111 /// Create_PragmaLexer: Lexer constructor - Create a new lexer object for 112 /// _Pragma expansion. This has a variety of magic semantics that this method 113 /// sets up. It returns a new'd Lexer that must be delete'd when done. 114 static Lexer *Create_PragmaLexer(SourceLocation SpellingLoc, 115 SourceLocation ExpansionLocStart, 116 SourceLocation ExpansionLocEnd, 117 unsigned TokLen, Preprocessor &PP); 118 119 120 /// getLangOpts - Return the language features currently enabled. 121 /// NOTE: this lexer modifies features as a file is parsed! 122 const LangOptions &getLangOpts() const { return LangOpts; } 123 124 /// getFileLoc - Return the File Location for the file we are lexing out of. 125 /// The physical location encodes the location where the characters come from, 126 /// the virtual location encodes where we should *claim* the characters came 127 /// from. Currently this is only used by _Pragma handling. 128 SourceLocation getFileLoc() const { return FileLoc; } 129 130 /// Lex - Return the next token in the file. If this is the end of file, it 131 /// return the tok::eof token. This implicitly involves the preprocessor. 132 void Lex(Token &Result) { 133 // Start a new token. 134 Result.startToken(); 135 136 // NOTE, any changes here should also change code after calls to 137 // Preprocessor::HandleDirective 138 if (IsAtStartOfLine) { 139 Result.setFlag(Token::StartOfLine); 140 IsAtStartOfLine = false; 141 } 142 143 // Get a token. Note that this may delete the current lexer if the end of 144 // file is reached. 145 LexTokenInternal(Result); 146 } 147 148 /// isPragmaLexer - Returns true if this Lexer is being used to lex a pragma. 149 bool isPragmaLexer() const { return Is_PragmaLexer; } 150 151 /// IndirectLex - An indirect call to 'Lex' that can be invoked via 152 /// the PreprocessorLexer interface. 153 void IndirectLex(Token &Result) { Lex(Result); } 154 155 /// LexFromRawLexer - Lex a token from a designated raw lexer (one with no 156 /// associated preprocessor object. Return true if the 'next character to 157 /// read' pointer points at the end of the lexer buffer, false otherwise. 158 bool LexFromRawLexer(Token &Result) { 159 assert(LexingRawMode && "Not already in raw mode!"); 160 Lex(Result); 161 // Note that lexing to the end of the buffer doesn't implicitly delete the 162 // lexer when in raw mode. 163 return BufferPtr == BufferEnd; 164 } 165 166 /// isKeepWhitespaceMode - Return true if the lexer should return tokens for 167 /// every character in the file, including whitespace and comments. This 168 /// should only be used in raw mode, as the preprocessor is not prepared to 169 /// deal with the excess tokens. 170 bool isKeepWhitespaceMode() const { 171 return ExtendedTokenMode > 1; 172 } 173 174 /// SetKeepWhitespaceMode - This method lets clients enable or disable 175 /// whitespace retention mode. 176 void SetKeepWhitespaceMode(bool Val) { 177 assert((!Val || LexingRawMode) && 178 "Can only enable whitespace retention in raw mode"); 179 ExtendedTokenMode = Val ? 2 : 0; 180 } 181 182 /// inKeepCommentMode - Return true if the lexer should return comments as 183 /// tokens. 184 bool inKeepCommentMode() const { 185 return ExtendedTokenMode > 0; 186 } 187 188 /// SetCommentRetentionMode - Change the comment retention mode of the lexer 189 /// to the specified mode. This is really only useful when lexing in raw 190 /// mode, because otherwise the lexer needs to manage this. 191 void SetCommentRetentionState(bool Mode) { 192 assert(!isKeepWhitespaceMode() && 193 "Can't play with comment retention state when retaining whitespace"); 194 ExtendedTokenMode = Mode ? 1 : 0; 195 } 196 197 const char *getBufferStart() const { return BufferStart; } 198 199 /// ReadToEndOfLine - Read the rest of the current preprocessor line as an 200 /// uninterpreted string. This switches the lexer out of directive mode. 201 void ReadToEndOfLine(SmallVectorImpl<char> *Result = 0); 202 203 204 /// Diag - Forwarding function for diagnostics. This translate a source 205 /// position in the current buffer into a SourceLocation object for rendering. 206 DiagnosticBuilder Diag(const char *Loc, unsigned DiagID) const; 207 208 /// getSourceLocation - Return a source location identifier for the specified 209 /// offset in the current file. 210 SourceLocation getSourceLocation(const char *Loc, unsigned TokLen = 1) const; 211 212 /// getSourceLocation - Return a source location for the next character in 213 /// the current file. 214 SourceLocation getSourceLocation() { return getSourceLocation(BufferPtr); } 215 216 /// \brief Return the current location in the buffer. 217 const char *getBufferLocation() const { return BufferPtr; } 218 219 /// Stringify - Convert the specified string into a C string by escaping '\' 220 /// and " characters. This does not add surrounding ""'s to the string. 221 /// If Charify is true, this escapes the ' character instead of ". 222 static std::string Stringify(const std::string &Str, bool Charify = false); 223 224 /// Stringify - Convert the specified string into a C string by escaping '\' 225 /// and " characters. This does not add surrounding ""'s to the string. 226 static void Stringify(SmallVectorImpl<char> &Str); 227 228 229 /// getSpelling - This method is used to get the spelling of a token into a 230 /// preallocated buffer, instead of as an std::string. The caller is required 231 /// to allocate enough space for the token, which is guaranteed to be at least 232 /// Tok.getLength() bytes long. The length of the actual result is returned. 233 /// 234 /// Note that this method may do two possible things: it may either fill in 235 /// the buffer specified with characters, or it may *change the input pointer* 236 /// to point to a constant buffer with the data already in it (avoiding a 237 /// copy). The caller is not allowed to modify the returned buffer pointer 238 /// if an internal buffer is returned. 239 static unsigned getSpelling(const Token &Tok, const char *&Buffer, 240 const SourceManager &SourceMgr, 241 const LangOptions &LangOpts, 242 bool *Invalid = 0); 243 244 /// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a 245 /// token is the characters used to represent the token in the source file 246 /// after trigraph expansion and escaped-newline folding. In particular, this 247 /// wants to get the true, uncanonicalized, spelling of things like digraphs 248 /// UCNs, etc. 249 static std::string getSpelling(const Token &Tok, 250 const SourceManager &SourceMgr, 251 const LangOptions &LangOpts, 252 bool *Invalid = 0); 253 254 /// getSpelling - This method is used to get the spelling of the 255 /// token at the given source location. If, as is usually true, it 256 /// is not necessary to copy any data, then the returned string may 257 /// not point into the provided buffer. 258 /// 259 /// This method lexes at the expansion depth of the given 260 /// location and does not jump to the expansion or spelling 261 /// location. 262 static StringRef getSpelling(SourceLocation loc, 263 SmallVectorImpl<char> &buffer, 264 const SourceManager &SourceMgr, 265 const LangOptions &LangOpts, 266 bool *invalid = 0); 267 268 /// MeasureTokenLength - Relex the token at the specified location and return 269 /// its length in bytes in the input file. If the token needs cleaning (e.g. 270 /// includes a trigraph or an escaped newline) then this count includes bytes 271 /// that are part of that. 272 static unsigned MeasureTokenLength(SourceLocation Loc, 273 const SourceManager &SM, 274 const LangOptions &LangOpts); 275 276 /// \brief Relex the token at the specified location. 277 /// \returns true if there was a failure, false on success. 278 static bool getRawToken(SourceLocation Loc, Token &Result, 279 const SourceManager &SM, 280 const LangOptions &LangOpts); 281 282 /// \brief Given a location any where in a source buffer, find the location 283 /// that corresponds to the beginning of the token in which the original 284 /// source location lands. 285 static SourceLocation GetBeginningOfToken(SourceLocation Loc, 286 const SourceManager &SM, 287 const LangOptions &LangOpts); 288 289 /// AdvanceToTokenCharacter - If the current SourceLocation specifies a 290 /// location at the start of a token, return a new location that specifies a 291 /// character within the token. This handles trigraphs and escaped newlines. 292 static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, 293 unsigned Character, 294 const SourceManager &SM, 295 const LangOptions &LangOpts); 296 297 /// \brief Computes the source location just past the end of the 298 /// token at this source location. 299 /// 300 /// This routine can be used to produce a source location that 301 /// points just past the end of the token referenced by \p Loc, and 302 /// is generally used when a diagnostic needs to point just after a 303 /// token where it expected something different that it received. If 304 /// the returned source location would not be meaningful (e.g., if 305 /// it points into a macro), this routine returns an invalid 306 /// source location. 307 /// 308 /// \param Offset an offset from the end of the token, where the source 309 /// location should refer to. The default offset (0) produces a source 310 /// location pointing just past the end of the token; an offset of 1 produces 311 /// a source location pointing to the last character in the token, etc. 312 static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, 313 const SourceManager &SM, 314 const LangOptions &LangOpts); 315 316 /// \brief Returns true if the given MacroID location points at the first 317 /// token of the macro expansion. 318 /// 319 /// \param MacroBegin If non-null and function returns true, it is set to 320 /// begin location of the macro. 321 static bool isAtStartOfMacroExpansion(SourceLocation loc, 322 const SourceManager &SM, 323 const LangOptions &LangOpts, 324 SourceLocation *MacroBegin = 0); 325 326 /// \brief Returns true if the given MacroID location points at the last 327 /// token of the macro expansion. 328 /// 329 /// \param MacroEnd If non-null and function returns true, it is set to 330 /// end location of the macro. 331 static bool isAtEndOfMacroExpansion(SourceLocation loc, 332 const SourceManager &SM, 333 const LangOptions &LangOpts, 334 SourceLocation *MacroEnd = 0); 335 336 /// \brief Accepts a range and returns a character range with file locations. 337 /// 338 /// Returns a null range if a part of the range resides inside a macro 339 /// expansion or the range does not reside on the same FileID. 340 /// 341 /// This function is trying to deal with macros and return a range based on 342 /// file locations. The cases where it can successfully handle macros are: 343 /// 344 /// -begin or end range lies at the start or end of a macro expansion, in 345 /// which case the location will be set to the expansion point, e.g: 346 /// \#define M 1 2 347 /// a M 348 /// If you have a range [a, 2] (where 2 came from the macro), the function 349 /// will return a range for "a M" 350 /// if you have range [a, 1], the function will fail because the range 351 /// overlaps with only a part of the macro 352 /// 353 /// -The macro is a function macro and the range can be mapped to the macro 354 /// arguments, e.g: 355 /// \#define M 1 2 356 /// \#define FM(x) x 357 /// FM(a b M) 358 /// if you have range [b, 2], the function will return the file range "b M" 359 /// inside the macro arguments. 360 /// if you have range [a, 2], the function will return the file range 361 /// "FM(a b M)" since the range includes all of the macro expansion. 362 static CharSourceRange makeFileCharRange(CharSourceRange Range, 363 const SourceManager &SM, 364 const LangOptions &LangOpts); 365 366 /// \brief Returns a string for the source that the range encompasses. 367 static StringRef getSourceText(CharSourceRange Range, 368 const SourceManager &SM, 369 const LangOptions &LangOpts, 370 bool *Invalid = 0); 371 372 /// \brief Retrieve the name of the immediate macro expansion. 373 /// 374 /// This routine starts from a source location, and finds the name of the macro 375 /// responsible for its immediate expansion. It looks through any intervening 376 /// macro argument expansions to compute this. It returns a StringRef which 377 /// refers to the SourceManager-owned buffer of the source where that macro 378 /// name is spelled. Thus, the result shouldn't out-live that SourceManager. 379 static StringRef getImmediateMacroName(SourceLocation Loc, 380 const SourceManager &SM, 381 const LangOptions &LangOpts); 382 383 /// \brief Compute the preamble of the given file. 384 /// 385 /// The preamble of a file contains the initial comments, include directives, 386 /// and other preprocessor directives that occur before the code in this 387 /// particular file actually begins. The preamble of the main source file is 388 /// a potential prefix header. 389 /// 390 /// \param Buffer The memory buffer containing the file's contents. 391 /// 392 /// \param MaxLines If non-zero, restrict the length of the preamble 393 /// to fewer than this number of lines. 394 /// 395 /// \returns The offset into the file where the preamble ends and the rest 396 /// of the file begins along with a boolean value indicating whether 397 /// the preamble ends at the beginning of a new line. 398 static std::pair<unsigned, bool> 399 ComputePreamble(const llvm::MemoryBuffer *Buffer, const LangOptions &LangOpts, 400 unsigned MaxLines = 0); 401 402 /// \brief Checks that the given token is the first token that occurs after 403 /// the given location (this excludes comments and whitespace). Returns the 404 /// location immediately after the specified token. If the token is not found 405 /// or the location is inside a macro, the returned source location will be 406 /// invalid. 407 static SourceLocation findLocationAfterToken(SourceLocation loc, 408 tok::TokenKind TKind, 409 const SourceManager &SM, 410 const LangOptions &LangOpts, 411 bool SkipTrailingWhitespaceAndNewLine); 412 413 /// \brief Returns true if the given character could appear in an identifier. 414 static bool isIdentifierBodyChar(char c, const LangOptions &LangOpts); 415 416 /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever 417 /// emit a warning. 418 static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size, 419 const LangOptions &LangOpts) { 420 // If this is not a trigraph and not a UCN or escaped newline, return 421 // quickly. 422 if (isObviouslySimpleCharacter(Ptr[0])) { 423 Size = 1; 424 return *Ptr; 425 } 426 427 Size = 0; 428 return getCharAndSizeSlowNoWarn(Ptr, Size, LangOpts); 429 } 430 431 //===--------------------------------------------------------------------===// 432 // Internal implementation interfaces. 433private: 434 435 /// LexTokenInternal - Internal interface to lex a preprocessing token. Called 436 /// by Lex. 437 /// 438 void LexTokenInternal(Token &Result); 439 440 /// Given that a token begins with the Unicode character \p C, figure out 441 /// what kind of token it is and dispatch to the appropriate lexing helper 442 /// function. 443 void LexUnicode(Token &Result, uint32_t C, const char *CurPtr); 444 445 /// FormTokenWithChars - When we lex a token, we have identified a span 446 /// starting at BufferPtr, going to TokEnd that forms the token. This method 447 /// takes that range and assigns it to the token as its location and size. In 448 /// addition, since tokens cannot overlap, this also updates BufferPtr to be 449 /// TokEnd. 450 void FormTokenWithChars(Token &Result, const char *TokEnd, 451 tok::TokenKind Kind) { 452 unsigned TokLen = TokEnd-BufferPtr; 453 Result.setLength(TokLen); 454 Result.setLocation(getSourceLocation(BufferPtr, TokLen)); 455 Result.setKind(Kind); 456 BufferPtr = TokEnd; 457 } 458 459 /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 460 /// tok::l_paren token, 0 if it is something else and 2 if there are no more 461 /// tokens in the buffer controlled by this lexer. 462 unsigned isNextPPTokenLParen(); 463 464 //===--------------------------------------------------------------------===// 465 // Lexer character reading interfaces. 466 467 // This lexer is built on two interfaces for reading characters, both of which 468 // automatically provide phase 1/2 translation. getAndAdvanceChar is used 469 // when we know that we will be reading a character from the input buffer and 470 // that this character will be part of the result token. This occurs in (f.e.) 471 // string processing, because we know we need to read until we find the 472 // closing '"' character. 473 // 474 // The second interface is the combination of getCharAndSize with 475 // ConsumeChar. getCharAndSize reads a phase 1/2 translated character, 476 // returning it and its size. If the lexer decides that this character is 477 // part of the current token, it calls ConsumeChar on it. This two stage 478 // approach allows us to emit diagnostics for characters (e.g. warnings about 479 // trigraphs), knowing that they only are emitted if the character is 480 // consumed. 481 482 /// isObviouslySimpleCharacter - Return true if the specified character is 483 /// obviously the same in translation phase 1 and translation phase 3. This 484 /// can return false for characters that end up being the same, but it will 485 /// never return true for something that needs to be mapped. 486 static bool isObviouslySimpleCharacter(char C) { 487 return C != '?' && C != '\\'; 488 } 489 490 /// getAndAdvanceChar - Read a single 'character' from the specified buffer, 491 /// advance over it, and return it. This is tricky in several cases. Here we 492 /// just handle the trivial case and fall-back to the non-inlined 493 /// getCharAndSizeSlow method to handle the hard case. 494 inline char getAndAdvanceChar(const char *&Ptr, Token &Tok) { 495 // If this is not a trigraph and not a UCN or escaped newline, return 496 // quickly. 497 if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++; 498 499 unsigned Size = 0; 500 char C = getCharAndSizeSlow(Ptr, Size, &Tok); 501 Ptr += Size; 502 return C; 503 } 504 505 /// ConsumeChar - When a character (identified by getCharAndSize) is consumed 506 /// and added to a given token, check to see if there are diagnostics that 507 /// need to be emitted or flags that need to be set on the token. If so, do 508 /// it. 509 const char *ConsumeChar(const char *Ptr, unsigned Size, Token &Tok) { 510 // Normal case, we consumed exactly one token. Just return it. 511 if (Size == 1) 512 return Ptr+Size; 513 514 // Otherwise, re-lex the character with a current token, allowing 515 // diagnostics to be emitted and flags to be set. 516 Size = 0; 517 getCharAndSizeSlow(Ptr, Size, &Tok); 518 return Ptr+Size; 519 } 520 521 /// getCharAndSize - Peek a single 'character' from the specified buffer, 522 /// get its size, and return it. This is tricky in several cases. Here we 523 /// just handle the trivial case and fall-back to the non-inlined 524 /// getCharAndSizeSlow method to handle the hard case. 525 inline char getCharAndSize(const char *Ptr, unsigned &Size) { 526 // If this is not a trigraph and not a UCN or escaped newline, return 527 // quickly. 528 if (isObviouslySimpleCharacter(Ptr[0])) { 529 Size = 1; 530 return *Ptr; 531 } 532 533 Size = 0; 534 return getCharAndSizeSlow(Ptr, Size); 535 } 536 537 /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize 538 /// method. 539 char getCharAndSizeSlow(const char *Ptr, unsigned &Size, Token *Tok = 0); 540 541 /// getEscapedNewLineSize - Return the size of the specified escaped newline, 542 /// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry 543 /// to this function. 544 static unsigned getEscapedNewLineSize(const char *P); 545 546 /// SkipEscapedNewLines - If P points to an escaped newline (or a series of 547 /// them), skip over them and return the first non-escaped-newline found, 548 /// otherwise return P. 549 static const char *SkipEscapedNewLines(const char *P); 550 551 /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a 552 /// diagnostic. 553 static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size, 554 const LangOptions &LangOpts); 555 556 //===--------------------------------------------------------------------===// 557 // Other lexer functions. 558 559 void SkipBytes(unsigned Bytes, bool StartOfLine); 560 561 const char *LexUDSuffix(Token &Result, const char *CurPtr); 562 563 // Helper functions to lex the remainder of a token of the specific type. 564 void LexIdentifier (Token &Result, const char *CurPtr); 565 void LexNumericConstant (Token &Result, const char *CurPtr); 566 void LexStringLiteral (Token &Result, const char *CurPtr, 567 tok::TokenKind Kind); 568 void LexRawStringLiteral (Token &Result, const char *CurPtr, 569 tok::TokenKind Kind); 570 void LexAngledStringLiteral(Token &Result, const char *CurPtr); 571 void LexCharConstant (Token &Result, const char *CurPtr, 572 tok::TokenKind Kind); 573 bool LexEndOfFile (Token &Result, const char *CurPtr); 574 575 bool SkipWhitespace (Token &Result, const char *CurPtr); 576 bool SkipLineComment (Token &Result, const char *CurPtr); 577 bool SkipBlockComment (Token &Result, const char *CurPtr); 578 bool SaveLineComment (Token &Result, const char *CurPtr); 579 580 bool IsStartOfConflictMarker(const char *CurPtr); 581 bool HandleEndOfConflictMarker(const char *CurPtr); 582 583 bool isCodeCompletionPoint(const char *CurPtr) const; 584 void cutOffLexing() { BufferPtr = BufferEnd; } 585 586 bool isHexaLiteral(const char *Start, const LangOptions &LangOpts); 587 588 589 /// Read a universal character name. 590 /// 591 /// \param CurPtr The position in the source buffer after the initial '\'. 592 /// If the UCN is syntactically well-formed (but not necessarily 593 /// valid), this parameter will be updated to point to the 594 /// character after the UCN. 595 /// \param SlashLoc The position in the source buffer of the '\'. 596 /// \param Tok The token being formed. Pass \c NULL to suppress diagnostics 597 /// and handle token formation in the caller. 598 /// 599 /// \return The Unicode codepoint specified by the UCN, or 0 if the UCN is 600 /// invalid. 601 uint32_t tryReadUCN(const char *&CurPtr, const char *SlashLoc, Token *Tok); 602}; 603 604 605} // end namespace clang 606 607#endif 608