14#ifndef LLVM_CLANG_LEX_LITERALSUPPORT_H 
   15#define LLVM_CLANG_LEX_LITERALSUPPORT_H 
   20#include "llvm/ADT/APFloat.h" 
   21#include "llvm/ADT/ArrayRef.h" 
   22#include "llvm/ADT/SmallString.h" 
   23#include "llvm/ADT/StringRef.h" 
   24#include "llvm/Support/DataTypes.h" 
   56  const char *
const ThisTokBegin;
 
   57  const char *
const ThisTokEnd;
 
   58  const char *DigitsBegin, *SuffixBegin; 
 
   63  bool saw_exponent, saw_period, saw_ud_suffix, saw_fixed_point_suffix;
 
   89    return (saw_period || saw_exponent) && saw_fixed_point_suffix;
 
 
  100    return saw_ud_suffix;
 
 
  103    assert(saw_ud_suffix);
 
 
  107    assert(saw_ud_suffix);
 
  108    return SuffixBegin - ThisTokBegin;
 
 
  124                                        llvm::RoundingMode RM);
 
  135    assert(!
hadError && 
"cannot reliably get the literal digits with an error");
 
  136    return StringRef(DigitsBegin, SuffixBegin - DigitsBegin);
 
 
  144  static bool isDigitSeparator(
char C) { 
return C == 
'\''; }
 
  148  bool containsDigits(
const char *Start, 
const char *End) {
 
  149    return Start != End && (Start + 1 != End || !isDigitSeparator(Start[0]));
 
  152  enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
 
  155  void checkSeparator(SourceLocation TokLoc, 
const char *Pos,
 
  156                      CheckSeparatorKind IsAfterDigits);
 
  160  const char *SkipHexDigits(
const char *ptr) {
 
  161    while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
 
  168  const char *SkipOctalDigits(
const char *ptr) {
 
  169    while (ptr != ThisTokEnd &&
 
  170           ((*ptr >= 
'0' && *ptr <= 
'7') || isDigitSeparator(*ptr)))
 
  177  const char *SkipDigits(
const char *ptr) {
 
  178    while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
 
  185  const char *SkipBinaryDigits(
const char *ptr) {
 
  186    while (ptr != ThisTokEnd &&
 
  187           (*ptr == 
'0' || *ptr == 
'1' || isDigitSeparator(*ptr)))
 
 
  202  unsigned UDSuffixOffset;
 
  209  bool isOrdinary()
 const { 
return Kind == tok::char_constant; }
 
  210  bool isWide()
 const { 
return Kind == tok::wide_char_constant; }
 
  211  bool isUTF8()
 const { 
return Kind == tok::utf8_char_constant; }
 
  212  bool isUTF16()
 const { 
return Kind == tok::utf16_char_constant; }
 
  213  bool isUTF32()
 const { 
return Kind == tok::utf32_char_constant; }
 
  218    assert(!UDSuffixBuf.empty() && 
"no ud-suffix");
 
  219    return UDSuffixOffset;
 
 
 
  237  unsigned MaxTokenLength;
 
  239  unsigned CharByteWidth;
 
  244  unsigned UDSuffixToken;
 
  245  unsigned UDSuffixOffset;
 
  255      : SM(sm), Features(features), Target(target), Diags(diags),
 
  256        MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(
tok::unknown),
 
  257        ResultPtr(ResultBuf.data()),
 
 
  282  bool isOrdinary()
 const { 
return Kind == tok::string_literal; }
 
  283  bool isWide()
 const { 
return Kind == tok::wide_string_literal; }
 
  284  bool isUTF8()
 const { 
return Kind == tok::utf8_string_literal; }
 
  285  bool isUTF16()
 const { 
return Kind == tok::utf16_string_literal; }
 
  286  bool isUTF32()
 const { 
return Kind == tok::utf32_string_literal; }
 
  296    assert(!UDSuffixBuf.empty() && 
"no ud-suffix");
 
  297    return UDSuffixToken;
 
 
  301    assert(!UDSuffixBuf.empty() && 
"no ud-suffix");
 
  302    return UDSuffixOffset;
 
 
  309  bool CopyStringFragment(
const Token &
Tok, 
const char *TokBegin,
 
 
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::TokenKind enum and support functions.
unsigned getUDSuffixOffset() const
StringRef getUDSuffix() const
uint64_t getValue() const
CharLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP, tok::TokenKind kind)
Concrete class used by the front-end to report problems and issues.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
NumericLiteralParser(StringRef TokSpelling, SourceLocation TokLoc, const SourceManager &SM, const LangOptions &LangOpts, const TargetInfo &Target, DiagnosticsEngine &Diags)
integer-constant: [C99 6.4.4.1] decimal-constant integer-suffix octal-constant integer-suffix hexadec...
StringRef getUDSuffix() const
bool isFixedPointLiteral() const
bool isFloatingLiteral() const
unsigned getRadix() const
bool isIntegerLiteral() const
llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result, llvm::RoundingMode RM)
Convert this numeric literal to a floating value, using the specified APFloat fltSemantics (specifyin...
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
bool GetIntegerValue(llvm::APInt &Val)
GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width.
unsigned getUDSuffixOffset() const
StringRef getLiteralDigits() const
Get the digits that comprise the literal.
bool GetFixedPointValue(llvm::APInt &StoreVal, unsigned Scale)
GetFixedPointValue - Convert this numeric literal value into a scaled integer that represents this va...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
unsigned getUDSuffixToken() const
Get the index of a token containing a ud-suffix.
unsigned getUDSuffixOffset() const
Get the spelling offset of the first byte of the ud-suffix.
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const
getOffsetOfStringByte - This function returns the offset of the specified byte of the string data rep...
bool isUnevaluated() const
StringRef getUDSuffix() const
StringLiteralParser(ArrayRef< Token > StringToks, Preprocessor &PP, StringLiteralEvalMethod StringMethod=StringLiteralEvalMethod::Evaluated)
unsigned GetStringLength() const
StringLiteralParser(ArrayRef< Token > StringToks, const SourceManager &sm, const LangOptions &features, const TargetInfo &target, DiagnosticsEngine *diags=nullptr)
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
unsigned GetNumStringChars() const
StringRef GetString() const
Exposes information about the current target.
Token - This structure provides full information about a lexed token.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
bool tokenIsLikeStringLiteral(const Token &Tok, const LangOptions &LO)
Return true if the token is a string literal, or a function local predefined macro,...
@ Result
The result type of a method or function.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
bool isFunctionLocalStringLiteralMacro(tok::TokenKind K, const LangOptions &LO)
Return true if the token corresponds to a function local predefined macro, which expands to a string ...
LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].