15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===--- Lexer.h - C Language Family Lexer ----------------------*- C++ -*-===// 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// The LLVM Compiler Infrastructure 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// This file is distributed under the University of Illinois Open Source 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner// License. See LICENSE.TXT for details. 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// This file defines the Lexer interface. 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer// 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer//===----------------------------------------------------------------------===// 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#ifndef LLVM_CLANG_LEXER_H 155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#define LLVM_CLANG_LEXER_H 165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#include "clang/Basic/LangOptions.h" 1830a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "clang/Lex/PreprocessorLexer.h" 19d8e3083840fef752d11ca183f42786470ed061e3Chris Lattner#include "llvm/ADT/SmallVector.h" 209dc62f044a6ba21f503bd56607d94b32704e7945Chris Lattner#include <cassert> 2130a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include <string> 225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencernamespace clang { 24d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikieclass DiagnosticsEngine; 259a6119437672f42be5f50c3fe89fe843b1bfa5b5Chris Lattnerclass SourceManager; 265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerclass Preprocessor; 273cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattnerclass DiagnosticBuilder; 285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 29d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith/// ConflictMarkerKind - Kinds of conflict marker which the lexer might be 30d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith/// recovering from. 31d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smithenum ConflictMarkerKind { 32d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith /// Not within a conflict marker. 33d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith CMK_None, 3464f9b500987394c69cd9a2f5483d06b5cafb0824Dmitri Gribenko /// A normal or diff3 conflict marker, initiated by at least 7 "<"s, 3564f9b500987394c69cd9a2f5483d06b5cafb0824Dmitri Gribenko /// separated by at least 7 "="s or "|"s, and terminated by at least 7 ">"s. 36d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith CMK_Normal, 3764f9b500987394c69cd9a2f5483d06b5cafb0824Dmitri Gribenko /// A Perforce-style conflict marker, initiated by 4 ">"s, 3864f9b500987394c69cd9a2f5483d06b5cafb0824Dmitri Gribenko /// separated by 4 "="s, and terminated by 4 "<"s. 39d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith CMK_Perforce 40d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith}; 41d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith 425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// Lexer - This provides a simple interface that turns a text buffer into a 435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// stream of tokens. This provides no support for file reading or buffering, 445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// or buffering/seeking of tokens, only forward lexing is supported. It relies 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/// on the specified Preprocessor object to handle preprocessor directives, etc. 460e977de1eacfbc143bdedad87c14b53814159023Ted Kremenekclass Lexer : public PreprocessorLexer { 4799ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie virtual void anchor(); 4899ba9e3bd70671f3441fb974895f226a83ce0e66David Blaikie 495f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 505f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Constant configuration values for this lexer. 51448cec4c1c3705f6f49ffdefb58a7329942a2dd8Chris Lattner const char *BufferStart; // Start of the buffer. 5225bdb51276d3bfc180a68688082071505a00ed27Chris Lattner const char *BufferEnd; // End of the buffer. 539dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner SourceLocation FileLoc; // Location for start of file. 544e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie LangOptions LangOpts; // LangOpts enabled by this language (cache). 55d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith bool Is_PragmaLexer; // True if lexer for _Pragma handling. 5681b747b7fcc91c2fba9a3183d8fac80adbfc1d3eDouglas Gregor 575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 585f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Context-specific lexing flags set by the preprocessor. 595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// ExtendedTokenMode - The lexer can optionally keep comments and whitespace 62d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// and return them as tokens. This is used for -C and -CC modes, and 63d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// whitespace preservation can be useful for some clients that want to lex 64d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// the file in raw mode and get every character from the file. 65d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// 66d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// When this is set to 2 it returns comments and whitespace. When set to 1 67d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// it returns comments, when it is set to 0 it returns normal tokens only. 68d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner unsigned char ExtendedTokenMode; 691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Context that changes as the file is lexed. 725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // NOTE: any state that mutates when in raw mode must have save/restore code 735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // in Lexer::isNextPPTokenLParen. 745f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // BufferPtr - Current pointer into the buffer. This is the next character 765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // to be lexed. 775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer const char *BufferPtr; 785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // IsAtStartOfLine - True if the next lexed token should get the "start of 805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // line" flag set on it. 815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer bool IsAtStartOfLine; 821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith // CurrentConflictMarkerState - The kind of conflict marker we are handling. 84d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith ConflictMarkerKind CurrentConflictMarkerState; 85d5e1d606f8c22ebda17c6fbf952f8c1696428758Richard Smith 86f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko Lexer(const Lexer &) LLVM_DELETED_FUNCTION; 87f56faa01936b9cf909623d7f06e3c2569ca4a78eDmitri Gribenko void operator=(const Lexer &) LLVM_DELETED_FUNCTION; 885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer friend class Preprocessor; 891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9022d91ca8d7c134eac5cc6a4869e6a84c461ad624Chris Lattner void InitLexer(const char *BufStart, const char *BufPtr, const char *BufEnd); 915f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerpublic: 921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 935f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Lexer constructor - Create a new lexer object for the specified buffer 945f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// with the specified preprocessor managing the lexing process. This lexer 95168ae2d44a443da75ea85db5f3b5081eb0bce113Chris Lattner /// assumes that the associated file buffer and Preprocessor objects will 9625bdb51276d3bfc180a68688082071505a00ed27Chris Lattner /// outlive it, so it doesn't take ownership of either of them. 976e2901407bff59aeb4cc301cc58b034723d0eb49Chris Lattner Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, Preprocessor &PP); 9842e00d19b0dac64732eb5449d52a076282fcbf77Chris Lattner 99168ae2d44a443da75ea85db5f3b5081eb0bce113Chris Lattner /// Lexer constructor - Create a new raw lexer object. This object is only 100092bf67e5ca560d2fc6aa70be1f172b8b3a5ff96Dmitri Gribenko /// suitable for calls to 'LexFromRawLexer'. This lexer assumes that the 101092bf67e5ca560d2fc6aa70be1f172b8b3a5ff96Dmitri Gribenko /// text range will outlive it, so it doesn't take ownership of it. 1024e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie Lexer(SourceLocation FileLoc, const LangOptions &LangOpts, 103de96c0f29c4cacabe6ea577c61db87c2a85aea6cChris Lattner const char *BufStart, const char *BufPtr, const char *BufEnd); 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105025c3a66402fb713c2d9bf5dc174ff264765379aChris Lattner /// Lexer constructor - Create a new raw lexer object. This object is only 106092bf67e5ca560d2fc6aa70be1f172b8b3a5ff96Dmitri Gribenko /// suitable for calls to 'LexFromRawLexer'. This lexer assumes that the 107092bf67e5ca560d2fc6aa70be1f172b8b3a5ff96Dmitri Gribenko /// text range will outlive it, so it doesn't take ownership of it. 1086e2901407bff59aeb4cc301cc58b034723d0eb49Chris Lattner Lexer(FileID FID, const llvm::MemoryBuffer *InputBuffer, 1094e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const SourceManager &SM, const LangOptions &LangOpts); 1101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11142e00d19b0dac64732eb5449d52a076282fcbf77Chris Lattner /// Create_PragmaLexer: Lexer constructor - Create a new lexer object for 11242e00d19b0dac64732eb5449d52a076282fcbf77Chris Lattner /// _Pragma expansion. This has a variety of magic semantics that this method 11342e00d19b0dac64732eb5449d52a076282fcbf77Chris Lattner /// sets up. It returns a new'd Lexer that must be delete'd when done. 1141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static Lexer *Create_PragmaLexer(SourceLocation SpellingLoc, 115433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth SourceLocation ExpansionLocStart, 116433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth SourceLocation ExpansionLocEnd, 117bcc2a67e5180612417727cbdd8afd0f79fdf726dChris Lattner unsigned TokLen, Preprocessor &PP); 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1204e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie /// getLangOpts - Return the language features currently enabled. 1214e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie /// NOTE: this lexer modifies features as a file is parsed! 1224e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &getLangOpts() const { return LangOpts; } 1235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 1249dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner /// getFileLoc - Return the File Location for the file we are lexing out of. 1259dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner /// The physical location encodes the location where the characters come from, 1269dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner /// the virtual location encodes where we should *claim* the characters came 1279dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner /// from. Currently this is only used by _Pragma handling. 1289dc1f530c086d2c16f8cba758b0f59a5bf41323aChris Lattner SourceLocation getFileLoc() const { return FileLoc; } 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Lex - Return the next token in the file. If this is the end of file, it 131164fcd022185fddc0e689f61ac8ad4b3ac744c2aNico Weber /// return the tok::eof token. This implicitly involves the preprocessor. 132d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner void Lex(Token &Result) { 1335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Start a new token. 1345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Result.startToken(); 1351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // NOTE, any changes here should also change code after calls to 1375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Preprocessor::HandleDirective 1385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (IsAtStartOfLine) { 139d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner Result.setFlag(Token::StartOfLine); 1405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer IsAtStartOfLine = false; 1415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Get a token. Note that this may delete the current lexer if the end of 1445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // file is reached. 1455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer LexTokenInternal(Result); 1465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 1474b391087f9c5582d448ab66ccbc7028f7673f380Ted Kremenek 1484b391087f9c5582d448ab66ccbc7028f7673f380Ted Kremenek /// isPragmaLexer - Returns true if this Lexer is being used to lex a pragma. 1494b391087f9c5582d448ab66ccbc7028f7673f380Ted Kremenek bool isPragmaLexer() const { return Is_PragmaLexer; } 1501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 151ab91b7086cceadce2cfd6a69cc90cebcdfcea07fTed Kremenek /// IndirectLex - An indirect call to 'Lex' that can be invoked via 152ab91b7086cceadce2cfd6a69cc90cebcdfcea07fTed Kremenek /// the PreprocessorLexer interface. 153ab91b7086cceadce2cfd6a69cc90cebcdfcea07fTed Kremenek void IndirectLex(Token &Result) { Lex(Result); } 1541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155590f0cc643274267d4d41125b62557e1d87886c3Chris Lattner /// LexFromRawLexer - Lex a token from a designated raw lexer (one with no 156590f0cc643274267d4d41125b62557e1d87886c3Chris Lattner /// associated preprocessor object. Return true if the 'next character to 1571fa495304c81e03f07f278a47b5efe9317104aabChris Lattner /// read' pointer points at the end of the lexer buffer, false otherwise. 158590f0cc643274267d4d41125b62557e1d87886c3Chris Lattner bool LexFromRawLexer(Token &Result) { 159590f0cc643274267d4d41125b62557e1d87886c3Chris Lattner assert(LexingRawMode && "Not already in raw mode!"); 1605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Lex(Result); 161e5956bd2730c051835f9acd9e957c5d79f99e7c3Chris Lattner // Note that lexing to the end of the buffer doesn't implicitly delete the 162e5956bd2730c051835f9acd9e957c5d79f99e7c3Chris Lattner // lexer when in raw mode. 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return BufferPtr == BufferEnd; 1645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 165d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner 166d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// isKeepWhitespaceMode - Return true if the lexer should return tokens for 167d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// every character in the file, including whitespace and comments. This 168d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// should only be used in raw mode, as the preprocessor is not prepared to 169d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// deal with the excess tokens. 170d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner bool isKeepWhitespaceMode() const { 171d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner return ExtendedTokenMode > 1; 172d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner } 173d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner 174d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// SetKeepWhitespaceMode - This method lets clients enable or disable 175d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// whitespace retention mode. 176d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner void SetKeepWhitespaceMode(bool Val) { 1776aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose assert((!Val || LexingRawMode || LangOpts.TraditionalCPP) && 1786aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose "Can only retain whitespace in raw mode or -traditional-cpp"); 179d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner ExtendedTokenMode = Val ? 2 : 0; 180d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner } 181d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner 182d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// inKeepCommentMode - Return true if the lexer should return comments as 183d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner /// tokens. 184d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner bool inKeepCommentMode() const { 185d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner return ExtendedTokenMode > 0; 186d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner } 1871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 188678c6358c8d4e368c78629099142397c63c1ee35Chris Lattner /// SetCommentRetentionMode - Change the comment retention mode of the lexer 189678c6358c8d4e368c78629099142397c63c1ee35Chris Lattner /// to the specified mode. This is really only useful when lexing in raw 190678c6358c8d4e368c78629099142397c63c1ee35Chris Lattner /// mode, because otherwise the lexer needs to manage this. 1911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void SetCommentRetentionState(bool Mode) { 192d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner assert(!isKeepWhitespaceMode() && 193d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner "Can't play with comment retention state when retaining whitespace"); 194d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner ExtendedTokenMode = Mode ? 1 : 0; 195fa95a019da00b926d64ff83358ba73bbc6ae1e37Chris Lattner } 1961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1976aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose /// Sets the extended token mode back to its initial value, according to the 1986aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose /// language options and preprocessor. This controls whether the lexer 1996aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose /// produces comment and whitespace tokens. 2006aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose /// 2016aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose /// This requires the lexer to have an associated preprocessor. A standalone 2026aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose /// lexer has nothing to reset to. 2036aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose void resetExtendedTokenMode(); 2046aad4a31b35df07fe818f193fcfd3c0197aea467Jordan Rose 205025c3a66402fb713c2d9bf5dc174ff264765379aChris Lattner const char *getBufferStart() const { return BufferStart; } 2061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// ReadToEndOfLine - Read the rest of the current preprocessor line as an 2085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// uninterpreted string. This switches the lexer out of directive mode. 2093093b20d824a953d8bc7a786dd952414898f8d6dBenjamin Kramer void ReadToEndOfLine(SmallVectorImpl<char> *Result = 0); 2101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Diag - Forwarding function for diagnostics. This translate a source 2135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// position in the current buffer into a SourceLocation object for rendering. 2143cbfe2c4159e0a219ae660d50625c013aa4afbd0Chris Lattner DiagnosticBuilder Diag(const char *Loc, unsigned DiagID) const; 2155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 2165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getSourceLocation - Return a source location identifier for the specified 2175f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// offset in the current file. 218de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner SourceLocation getSourceLocation(const char *Loc, unsigned TokLen = 1) const; 2191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 220bc0f6bc0391ecdff331885cdc769c20b2cb628a6Ted Kremenek /// getSourceLocation - Return a source location for the next character in 221bc0f6bc0391ecdff331885cdc769c20b2cb628a6Ted Kremenek /// the current file. 222bc0f6bc0391ecdff331885cdc769c20b2cb628a6Ted Kremenek SourceLocation getSourceLocation() { return getSourceLocation(BufferPtr); } 2231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 224fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor /// \brief Return the current location in the buffer. 225fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor const char *getBufferLocation() const { return BufferPtr; } 226fc8ea23eb6cbaaa5046f2abb4c033e24c8659efdDouglas Gregor 2275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// Stringify - Convert the specified string into a C string by escaping '\' 2285f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and " characters. This does not add surrounding ""'s to the string. 2295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// If Charify is true, this escapes the ' character instead of ". 2305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static std::string Stringify(const std::string &Str, bool Charify = false); 2311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 232d8e3083840fef752d11ca183f42786470ed061e3Chris Lattner /// Stringify - Convert the specified string into a C string by escaping '\' 233d8e3083840fef752d11ca183f42786470ed061e3Chris Lattner /// and " characters. This does not add surrounding ""'s to the string. 234686775deca8b8685eb90801495880e3abdd844c2Chris Lattner static void Stringify(SmallVectorImpl<char> &Str); 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 236b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner 237b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// getSpelling - This method is used to get the spelling of a token into a 238b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// preallocated buffer, instead of as an std::string. The caller is required 239b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// to allocate enough space for the token, which is guaranteed to be at least 240b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// Tok.getLength() bytes long. The length of the actual result is returned. 241b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// 242b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// Note that this method may do two possible things: it may either fill in 243b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// the buffer specified with characters, or it may *change the input pointer* 244b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// to point to a constant buffer with the data already in it (avoiding a 245b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// copy). The caller is not allowed to modify the returned buffer pointer 246b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// if an internal buffer is returned. 247b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner static unsigned getSpelling(const Token &Tok, const char *&Buffer, 248b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner const SourceManager &SourceMgr, 2494e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts, 250b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner bool *Invalid = 0); 251b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner 252b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// getSpelling() - Return the 'spelling' of the Tok token. The spelling of a 253b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// token is the characters used to represent the token in the source file 254b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// after trigraph expansion and escaped-newline folding. In particular, this 255b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// wants to get the true, uncanonicalized, spelling of things like digraphs 256b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner /// UCNs, etc. 257b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner static std::string getSpelling(const Token &Tok, 258b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner const SourceManager &SourceMgr, 2594e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts, 260b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner bool *Invalid = 0); 261834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall 262834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall /// getSpelling - This method is used to get the spelling of the 263834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall /// token at the given source location. If, as is usually true, it 264834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall /// is not necessary to copy any data, then the returned string may 265834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall /// not point into the provided buffer. 266834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall /// 267433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth /// This method lexes at the expansion depth of the given 268433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth /// location and does not jump to the expansion or spelling 269834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall /// location. 270686775deca8b8685eb90801495880e3abdd844c2Chris Lattner static StringRef getSpelling(SourceLocation loc, 271686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<char> &buffer, 272834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall const SourceManager &SourceMgr, 2734e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts, 274834e3f6c77d9ac03997a3f0c56934edcf406a355John McCall bool *invalid = 0); 275b0607279cb98bbf2bbfe0db170aed39ef91e86a2Chris Lattner 2769a6119437672f42be5f50c3fe89fe843b1bfa5b5Chris Lattner /// MeasureTokenLength - Relex the token at the specified location and return 2779a6119437672f42be5f50c3fe89fe843b1bfa5b5Chris Lattner /// its length in bytes in the input file. If the token needs cleaning (e.g. 2789a6119437672f42be5f50c3fe89fe843b1bfa5b5Chris Lattner /// includes a trigraph or an escaped newline) then this count includes bytes 2799a6119437672f42be5f50c3fe89fe843b1bfa5b5Chris Lattner /// that are part of that. 2809a6119437672f42be5f50c3fe89fe843b1bfa5b5Chris Lattner static unsigned MeasureTokenLength(SourceLocation Loc, 2812c78b873f4f3823ae859c15674cb3d76c8554113Chris Lattner const SourceManager &SM, 2822c78b873f4f3823ae859c15674cb3d76c8554113Chris Lattner const LangOptions &LangOpts); 2831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 284d93335c43fd462145fee3ea8f4d84d430577c821Argyrios Kyrtzidis /// \brief Relex the token at the specified location. 285d93335c43fd462145fee3ea8f4d84d430577c821Argyrios Kyrtzidis /// \returns true if there was a failure, false on success. 286d93335c43fd462145fee3ea8f4d84d430577c821Argyrios Kyrtzidis static bool getRawToken(SourceLocation Loc, Token &Result, 287d93335c43fd462145fee3ea8f4d84d430577c821Argyrios Kyrtzidis const SourceManager &SM, 288d93335c43fd462145fee3ea8f4d84d430577c821Argyrios Kyrtzidis const LangOptions &LangOpts); 289d93335c43fd462145fee3ea8f4d84d430577c821Argyrios Kyrtzidis 290a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor /// \brief Given a location any where in a source buffer, find the location 291a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor /// that corresponds to the beginning of the token in which the original 292a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor /// source location lands. 293a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor static SourceLocation GetBeginningOfToken(SourceLocation Loc, 294a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor const SourceManager &SM, 295a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor const LangOptions &LangOpts); 296a8e5c5bdbe387b2552c1c23b828f54abcf085a40Douglas Gregor 2977ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// AdvanceToTokenCharacter - If the current SourceLocation specifies a 2987ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// location at the start of a token, return a new location that specifies a 2997ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// character within the token. This handles trigraphs and escaped newlines. 3007ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, 3017ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner unsigned Character, 3027ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner const SourceManager &SM, 3034e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts); 3047ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner 3057ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// \brief Computes the source location just past the end of the 3067ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// token at this source location. 3077ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// 3087ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// This routine can be used to produce a source location that 3097ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// points just past the end of the token referenced by \p Loc, and 3107ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// is generally used when a diagnostic needs to point just after a 3117ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// token where it expected something different that it received. If 3127ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// the returned source location would not be meaningful (e.g., if 3137ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// it points into a macro), this routine returns an invalid 3147ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// source location. 3157ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// 3167ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// \param Offset an offset from the end of the token, where the source 3177ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// location should refer to. The default offset (0) produces a source 3187ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// location pointing just past the end of the token; an offset of 1 produces 3197ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner /// a source location pointing to the last character in the token, etc. 3207ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, 3217ef5c27eb6e8ebe58b52013246c06753c3613263Chris Lattner const SourceManager &SM, 3224e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts); 3237a759606d93975866051f67104ae58446e55f404Argyrios Kyrtzidis 3247a759606d93975866051f67104ae58446e55f404Argyrios Kyrtzidis /// \brief Returns true if the given MacroID location points at the first 325433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth /// token of the macro expansion. 32669bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis /// 32769bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis /// \param MacroBegin If non-null and function returns true, it is set to 32869bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis /// begin location of the macro. 329433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth static bool isAtStartOfMacroExpansion(SourceLocation loc, 33069bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis const SourceManager &SM, 33169bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis const LangOptions &LangOpts, 33269bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis SourceLocation *MacroBegin = 0); 3337a759606d93975866051f67104ae58446e55f404Argyrios Kyrtzidis 3347a759606d93975866051f67104ae58446e55f404Argyrios Kyrtzidis /// \brief Returns true if the given MacroID location points at the last 335433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth /// token of the macro expansion. 33669bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis /// 33770517ca5c07c4b41ff8662b94ee22047b0299f8cDmitri Gribenko /// \param MacroEnd If non-null and function returns true, it is set to 33869bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis /// end location of the macro. 339433db06b614f26dc6829e86d6ff469e2cca7d4f9Chandler Carruth static bool isAtEndOfMacroExpansion(SourceLocation loc, 34069bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis const SourceManager &SM, 34169bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis const LangOptions &LangOpts, 34269bda4c027671df7163619f215209529eb236620Argyrios Kyrtzidis SourceLocation *MacroEnd = 0); 3437a759606d93975866051f67104ae58446e55f404Argyrios Kyrtzidis 344a83f4d2315dbeb3914868f1ccb8e74fb2ccdbb0cArgyrios Kyrtzidis /// \brief Accepts a range and returns a character range with file locations. 345a83f4d2315dbeb3914868f1ccb8e74fb2ccdbb0cArgyrios Kyrtzidis /// 34611b652d41d0d97380ab321a1dba48ecb044f9de8Argyrios Kyrtzidis /// Returns a null range if a part of the range resides inside a macro 34711b652d41d0d97380ab321a1dba48ecb044f9de8Argyrios Kyrtzidis /// expansion or the range does not reside on the same FileID. 34895da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// 34995da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// This function is trying to deal with macros and return a range based on 35095da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// file locations. The cases where it can successfully handle macros are: 35195da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// 35295da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// -begin or end range lies at the start or end of a macro expansion, in 35395da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// which case the location will be set to the expansion point, e.g: 3547e6f1a23fe26748a4eafc5c64ff6c319f6d932f3James Dennett /// \#define M 1 2 35595da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// a M 35695da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// If you have a range [a, 2] (where 2 came from the macro), the function 35795da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// will return a range for "a M" 35895da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// if you have range [a, 1], the function will fail because the range 35995da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// overlaps with only a part of the macro 36095da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// 36195da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// -The macro is a function macro and the range can be mapped to the macro 36295da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// arguments, e.g: 3637e6f1a23fe26748a4eafc5c64ff6c319f6d932f3James Dennett /// \#define M 1 2 3647e6f1a23fe26748a4eafc5c64ff6c319f6d932f3James Dennett /// \#define FM(x) x 36595da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// FM(a b M) 36695da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// if you have range [b, 2], the function will return the file range "b M" 36795da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// inside the macro arguments. 36895da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// if you have range [a, 2], the function will return the file range 36995da18142abeec5099dedc50d6f418917bd6167dArgyrios Kyrtzidis /// "FM(a b M)" since the range includes all of the macro expansion. 370a83f4d2315dbeb3914868f1ccb8e74fb2ccdbb0cArgyrios Kyrtzidis static CharSourceRange makeFileCharRange(CharSourceRange Range, 37111b652d41d0d97380ab321a1dba48ecb044f9de8Argyrios Kyrtzidis const SourceManager &SM, 37211b652d41d0d97380ab321a1dba48ecb044f9de8Argyrios Kyrtzidis const LangOptions &LangOpts); 37311b652d41d0d97380ab321a1dba48ecb044f9de8Argyrios Kyrtzidis 374e64d9037658a1b95c79ea275af6167a110b3c563Argyrios Kyrtzidis /// \brief Returns a string for the source that the range encompasses. 375e64d9037658a1b95c79ea275af6167a110b3c563Argyrios Kyrtzidis static StringRef getSourceText(CharSourceRange Range, 376e64d9037658a1b95c79ea275af6167a110b3c563Argyrios Kyrtzidis const SourceManager &SM, 377e64d9037658a1b95c79ea275af6167a110b3c563Argyrios Kyrtzidis const LangOptions &LangOpts, 378e64d9037658a1b95c79ea275af6167a110b3c563Argyrios Kyrtzidis bool *Invalid = 0); 379e64d9037658a1b95c79ea275af6167a110b3c563Argyrios Kyrtzidis 380c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// \brief Retrieve the name of the immediate macro expansion. 381c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// 382c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// This routine starts from a source location, and finds the name of the macro 383c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// responsible for its immediate expansion. It looks through any intervening 384c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// macro argument expansions to compute this. It returns a StringRef which 385c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// refers to the SourceManager-owned buffer of the source where that macro 386c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks /// name is spelled. Thus, the result shouldn't out-live that SourceManager. 387c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks static StringRef getImmediateMacroName(SourceLocation Loc, 388c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks const SourceManager &SM, 389c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks const LangOptions &LangOpts); 390c2a8d6cee01fc4845f5409bf5c021a64616ac8c3Anna Zaks 391f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// \brief Compute the preamble of the given file. 392f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// 393f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// The preamble of a file contains the initial comments, include directives, 394f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// and other preprocessor directives that occur before the code in this 395f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// particular file actually begins. The preamble of the main source file is 396f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// a potential prefix header. 397f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// 398f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// \param Buffer The memory buffer containing the file's contents. 399f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// 400df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// \param MaxLines If non-zero, restrict the length of the preamble 401df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// to fewer than this number of lines. 402df95a13ec73d2cdaea79555cb412d767f4963120Douglas Gregor /// 403f033f1da4a34f8df6e95e9929dc04ff54bb8fb01Douglas Gregor /// \returns The offset into the file where the preamble ends and the rest 404f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// of the file begins along with a boolean value indicating whether 405f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor /// the preamble ends at the beginning of a new line. 406f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor static std::pair<unsigned, bool> 4074e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie ComputePreamble(const llvm::MemoryBuffer *Buffer, const LangOptions &LangOpts, 40803c107a42fae79e89d0016999a1a04c07d65591aArgyrios Kyrtzidis unsigned MaxLines = 0); 409e506f8a41063410c75945ebb804758bd0202947fEli Friedman 410e506f8a41063410c75945ebb804758bd0202947fEli Friedman /// \brief Checks that the given token is the first token that occurs after 411e506f8a41063410c75945ebb804758bd0202947fEli Friedman /// the given location (this excludes comments and whitespace). Returns the 412e506f8a41063410c75945ebb804758bd0202947fEli Friedman /// location immediately after the specified token. If the token is not found 413e506f8a41063410c75945ebb804758bd0202947fEli Friedman /// or the location is inside a macro, the returned source location will be 414e506f8a41063410c75945ebb804758bd0202947fEli Friedman /// invalid. 415e506f8a41063410c75945ebb804758bd0202947fEli Friedman static SourceLocation findLocationAfterToken(SourceLocation loc, 416e506f8a41063410c75945ebb804758bd0202947fEli Friedman tok::TokenKind TKind, 417e506f8a41063410c75945ebb804758bd0202947fEli Friedman const SourceManager &SM, 418e506f8a41063410c75945ebb804758bd0202947fEli Friedman const LangOptions &LangOpts, 419e506f8a41063410c75945ebb804758bd0202947fEli Friedman bool SkipTrailingWhitespaceAndNewLine); 420e506f8a41063410c75945ebb804758bd0202947fEli Friedman 421e506f8a41063410c75945ebb804758bd0202947fEli Friedman /// \brief Returns true if the given character could appear in an identifier. 422e506f8a41063410c75945ebb804758bd0202947fEli Friedman static bool isIdentifierBodyChar(char c, const LangOptions &LangOpts); 423e506f8a41063410c75945ebb804758bd0202947fEli Friedman 4249366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara /// getCharAndSizeNoWarn - Like the getCharAndSize method, but does not ever 4259366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara /// emit a warning. 4269366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara static inline char getCharAndSizeNoWarn(const char *Ptr, unsigned &Size, 4279366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara const LangOptions &LangOpts) { 4289366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara // If this is not a trigraph and not a UCN or escaped newline, return 4299366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara // quickly. 4309366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara if (isObviouslySimpleCharacter(Ptr[0])) { 4319366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara Size = 1; 4329366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara return *Ptr; 4339366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara } 4349366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara 4359366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara Size = 0; 4369366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara return getCharAndSizeSlowNoWarn(Ptr, Size, LangOpts); 4379366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara } 4389366a5a8d0c5834cffda2c31c924605fb9dffc9bAbramo Bagnara 4395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4405f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Internal implementation interfaces. 4415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencerprivate: 4425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// LexTokenInternal - Internal interface to lex a preprocessing token. Called 4445f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// by Lex. 4455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// 446d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner void LexTokenInternal(Token &Result); 4475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 448c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// Given that a token begins with the Unicode character \p C, figure out 449c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// what kind of token it is and dispatch to the appropriate lexing helper 450c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// function. 451c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose void LexUnicode(Token &Result, uint32_t C, const char *CurPtr); 452c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose 4535f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// FormTokenWithChars - When we lex a token, we have identified a span 4545f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// starting at BufferPtr, going to TokEnd that forms the token. This method 4555f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// takes that range and assigns it to the token as its location and size. In 4565f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// addition, since tokens cannot overlap, this also updates BufferPtr to be 4575f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// TokEnd. 4581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump void FormTokenWithChars(Token &Result, const char *TokEnd, 4599e6293d4dfd688429f77ee3b6edba9dfd7ada3a2Chris Lattner tok::TokenKind Kind) { 460de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner unsigned TokLen = TokEnd-BufferPtr; 461de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner Result.setLength(TokLen); 462de7aeefc5573d669ed476d7bda7a8940d3bcadb7Chris Lattner Result.setLocation(getSourceLocation(BufferPtr, TokLen)); 4639e6293d4dfd688429f77ee3b6edba9dfd7ada3a2Chris Lattner Result.setKind(Kind); 4645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer BufferPtr = TokEnd; 4655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 4661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4675f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// isNextPPTokenLParen - Return 1 if the next unexpanded token will return a 4685f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tok::l_paren token, 0 if it is something else and 2 if there are no more 4695f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// tokens in the buffer controlled by this lexer. 4705f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned isNextPPTokenLParen(); 4715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 4725f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 4735f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Lexer character reading interfaces. 4741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4755f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // This lexer is built on two interfaces for reading characters, both of which 4765f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // automatically provide phase 1/2 translation. getAndAdvanceChar is used 4775f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // when we know that we will be reading a character from the input buffer and 4785f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // that this character will be part of the result token. This occurs in (f.e.) 4795f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // string processing, because we know we need to read until we find the 4805f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // closing '"' character. 4815f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // 4824718e67ca9018342483dccb40d43e339101ac386Chris Lattner // The second interface is the combination of getCharAndSize with 4834718e67ca9018342483dccb40d43e339101ac386Chris Lattner // ConsumeChar. getCharAndSize reads a phase 1/2 translated character, 4845f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // returning it and its size. If the lexer decides that this character is 4855f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // part of the current token, it calls ConsumeChar on it. This two stage 4865f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // approach allows us to emit diagnostics for characters (e.g. warnings about 4875f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // trigraphs), knowing that they only are emitted if the character is 4885f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // consumed. 4891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 490f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner /// isObviouslySimpleCharacter - Return true if the specified character is 491f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner /// obviously the same in translation phase 1 and translation phase 3. This 492f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner /// can return false for characters that end up being the same, but it will 493f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner /// never return true for something that needs to be mapped. 494f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner static bool isObviouslySimpleCharacter(char C) { 495f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner return C != '?' && C != '\\'; 496f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner } 4971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4985f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getAndAdvanceChar - Read a single 'character' from the specified buffer, 4995f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// advance over it, and return it. This is tricky in several cases. Here we 5005f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// just handle the trivial case and fall-back to the non-inlined 5015f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCharAndSizeSlow method to handle the hard case. 502d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner inline char getAndAdvanceChar(const char *&Ptr, Token &Tok) { 5035f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this is not a trigraph and not a UCN or escaped newline, return 5045f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // quickly. 505f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner if (isObviouslySimpleCharacter(Ptr[0])) return *Ptr++; 5061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5075f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer unsigned Size = 0; 5085f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer char C = getCharAndSizeSlow(Ptr, Size, &Tok); 5095f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Ptr += Size; 5105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return C; 5115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5134718e67ca9018342483dccb40d43e339101ac386Chris Lattner /// ConsumeChar - When a character (identified by getCharAndSize) is consumed 5145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// and added to a given token, check to see if there are diagnostics that 5155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// need to be emitted or flags that need to be set on the token. If so, do 5165f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// it. 517d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner const char *ConsumeChar(const char *Ptr, unsigned Size, Token &Tok) { 5185f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Normal case, we consumed exactly one token. Just return it. 5195f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer if (Size == 1) 5205f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Ptr+Size; 5215f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 5225f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Otherwise, re-lex the character with a current token, allowing 5235f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // diagnostics to be emitted and flags to be set. 5245f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Size = 0; 5255f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer getCharAndSizeSlow(Ptr, Size, &Tok); 5265f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return Ptr+Size; 5275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5295f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCharAndSize - Peek a single 'character' from the specified buffer, 5305f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// get its size, and return it. This is tricky in several cases. Here we 5315f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// just handle the trivial case and fall-back to the non-inlined 5325f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCharAndSizeSlow method to handle the hard case. 5335f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer inline char getCharAndSize(const char *Ptr, unsigned &Size) { 5345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // If this is not a trigraph and not a UCN or escaped newline, return 5355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // quickly. 536f66d3e390fac1dce6b0e3ff1a3d0180638e560f6Chris Lattner if (isObviouslySimpleCharacter(Ptr[0])) { 5375f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Size = 1; 5385f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return *Ptr; 5395f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5415f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer Size = 0; 5425f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer return getCharAndSizeSlow(Ptr, Size); 5435f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer } 5441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCharAndSizeSlow - Handle the slow/uncommon case of the getCharAndSize 5465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// method. 547d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner char getCharAndSizeSlow(const char *Ptr, unsigned &Size, Token *Tok = 0); 5481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54924f0e48c0aa62f2268e061aad70f9b19a59e7b52Chris Lattner /// getEscapedNewLineSize - Return the size of the specified escaped newline, 55024f0e48c0aa62f2268e061aad70f9b19a59e7b52Chris Lattner /// or 0 if it is not an escaped newline. P[-1] is known to be a "\" on entry 55124f0e48c0aa62f2268e061aad70f9b19a59e7b52Chris Lattner /// to this function. 55224f0e48c0aa62f2268e061aad70f9b19a59e7b52Chris Lattner static unsigned getEscapedNewLineSize(const char *P); 5531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 554033749571f8d4c804eeb357c70b06424aa24503bChris Lattner /// SkipEscapedNewLines - If P points to an escaped newline (or a series of 555033749571f8d4c804eeb357c70b06424aa24503bChris Lattner /// them), skip over them and return the first non-escaped-newline found, 556033749571f8d4c804eeb357c70b06424aa24503bChris Lattner /// otherwise return P. 557033749571f8d4c804eeb357c70b06424aa24503bChris Lattner static const char *SkipEscapedNewLines(const char *P); 558aca25bccefe56121b686706afc84c8cb5d46e65bAnna Zaks 5595f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// getCharAndSizeSlowNoWarn - Same as getCharAndSizeSlow, but never emits a 5605f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer /// diagnostic. 5615f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer static char getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size, 5624e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie const LangOptions &LangOpts); 5631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5645f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer //===--------------------------------------------------------------------===// 5655f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Other lexer functions. 5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 567f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor void SkipBytes(unsigned Bytes, bool StartOfLine); 5685cc2c6eb67b6e5361bbe96f79b519fd62ec666d6Richard Smith 5695cc2c6eb67b6e5361bbe96f79b519fd62ec666d6Richard Smith const char *LexUDSuffix(Token &Result, const char *CurPtr); 570f4f6c9db68465b886ec2e596feaa6ecc782395a4Douglas Gregor 5715f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer // Helper functions to lex the remainder of a token of the specific type. 572d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner void LexIdentifier (Token &Result, const char *CurPtr); 573d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner void LexNumericConstant (Token &Result, const char *CurPtr); 5745cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor void LexStringLiteral (Token &Result, const char *CurPtr, 5755cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor tok::TokenKind Kind); 5762fa4e86b4fdada3b9ecbbbd99965b83ed879f69bCraig Topper void LexRawStringLiteral (Token &Result, const char *CurPtr, 5772fa4e86b4fdada3b9ecbbbd99965b83ed879f69bCraig Topper tok::TokenKind Kind); 578d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner void LexAngledStringLiteral(Token &Result, const char *CurPtr); 5795cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor void LexCharConstant (Token &Result, const char *CurPtr, 5805cee1195584fa8672253139c86e922daeda69b9eDouglas Gregor tok::TokenKind Kind); 581d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner bool LexEndOfFile (Token &Result, const char *CurPtr); 5821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 583d88dc48e33d71732708960170e57a3d1bdc8f847Chris Lattner bool SkipWhitespace (Token &Result, const char *CurPtr); 584bb23628148f555a4cf71f98c27096a7a804c085cNico Weber bool SkipLineComment (Token &Result, const char *CurPtr); 585d217773f106856a11879ec79dc468efefaf2ee75Chris Lattner bool SkipBlockComment (Token &Result, const char *CurPtr); 586bb23628148f555a4cf71f98c27096a7a804c085cNico Weber bool SaveLineComment (Token &Result, const char *CurPtr); 58734f349da38a7bd99103e12d8ea6c73bc8d025193Chris Lattner 58834f349da38a7bd99103e12d8ea6c73bc8d025193Chris Lattner bool IsStartOfConflictMarker(const char *CurPtr); 58934f349da38a7bd99103e12d8ea6c73bc8d025193Chris Lattner bool HandleEndOfConflictMarker(const char *CurPtr); 5907d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis 5917d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis bool isCodeCompletionPoint(const char *CurPtr) const; 5927d100872341f233c81e1d7b72b40457e62c36862Argyrios Kyrtzidis void cutOffLexing() { BufferPtr = BufferEnd; } 593e506f8a41063410c75945ebb804758bd0202947fEli Friedman 594e506f8a41063410c75945ebb804758bd0202947fEli Friedman bool isHexaLiteral(const char *Start, const LangOptions &LangOpts); 595c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose 596c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose 597c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// Read a universal character name. 598c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// 599c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// \param CurPtr The position in the source buffer after the initial '\'. 600c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// If the UCN is syntactically well-formed (but not necessarily 601c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// valid), this parameter will be updated to point to the 602c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// character after the UCN. 603c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// \param SlashLoc The position in the source buffer of the '\'. 604c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// \param Tok The token being formed. Pass \c NULL to suppress diagnostics 605c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// and handle token formation in the caller. 606c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// 607c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// \return The Unicode codepoint specified by the UCN, or 0 if the UCN is 608c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose /// invalid. 609c7629d941557f7179eb8fa8a2e2a74d749cbaf7cJordan Rose uint32_t tryReadUCN(const char *&CurPtr, const char *SlashLoc, Token *Tok); 6105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer}; 6115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer} // end namespace clang 6145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 6155f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer#endif 616