15 #ifndef LLVM_CLANG_LEX_LITERALSUPPORT_H
16 #define LLVM_CLANG_LEX_LITERALSUPPORT_H
21 #include "llvm/ADT/APFloat.h"
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/ADT/SmallString.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/Support/DataTypes.h"
29 class DiagnosticsEngine;
46 const char *
const ThisTokBegin;
47 const char *
const ThisTokEnd;
48 const char *DigitsBegin, *SuffixBegin;
53 bool saw_exponent, saw_period, saw_ud_suffix;
72 return !saw_period && !saw_exponent;
75 return saw_period || saw_exponent;
82 assert(saw_ud_suffix);
86 assert(saw_ud_suffix);
87 return SuffixBegin - ThisTokBegin;
112 static bool isDigitSeparator(
char C) {
return C ==
'\''; }
116 bool containsDigits(
const char *Start,
const char *
End) {
117 return Start != End && (Start + 1 != End || !isDigitSeparator(Start[0]));
120 enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
123 void checkSeparator(SourceLocation TokLoc,
const char *Pos,
124 CheckSeparatorKind IsAfterDigits);
128 const char *SkipHexDigits(
const char *ptr) {
129 while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
136 const char *SkipOctalDigits(
const char *ptr) {
137 while (ptr != ThisTokEnd &&
138 ((*ptr >=
'0' && *ptr <=
'7') || isDigitSeparator(*ptr)))
145 const char *SkipDigits(
const char *ptr) {
146 while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
153 const char *SkipBinaryDigits(
const char *ptr) {
154 while (ptr != ThisTokEnd &&
155 (*ptr ==
'0' || *ptr ==
'1' || isDigitSeparator(*ptr)))
170 unsigned UDSuffixOffset;
178 bool isWide()
const {
return Kind == tok::wide_char_constant; }
179 bool isUTF8()
const {
return Kind == tok::utf8_char_constant; }
186 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
187 return UDSuffixOffset;
200 unsigned MaxTokenLength;
202 unsigned CharByteWidth;
207 unsigned UDSuffixToken;
208 unsigned UDSuffixOffset;
216 : SM(sm), Features(features), Target(target), Diags(diags),
217 MaxTokenLength(0), SizeBound(0), CharByteWidth(0),
Kind(tok::unknown),
243 bool isWide()
const {
return Kind == tok::wide_string_literal; }
244 bool isUTF8()
const {
return Kind == tok::utf8_string_literal; }
245 bool isUTF16()
const {
return Kind == tok::utf16_string_literal; }
246 bool isUTF32()
const {
return Kind == tok::utf32_string_literal; }
253 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
254 return UDSuffixToken;
258 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
259 return UDSuffixOffset;
264 bool CopyStringFragment(
const Token &Tok,
const char *TokBegin,
static LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
StringLiteralParser(ArrayRef< Token > StringToks, Preprocessor &PP, bool Complain=true)
unsigned getRadix() const
StringRef getUDSuffix() const
unsigned getUDSuffixToken() const
Get the index of a token containing a 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...
Token - This structure provides full information about a lexed token.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
StringLiteralParser(ArrayRef< Token > StringToks, const SourceManager &sm, const LangOptions &features, const TargetInfo &target, DiagnosticsEngine *diags=nullptr)
uint64_t getValue() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
NumericLiteralParser(StringRef TokSpelling, SourceLocation TokLoc, Preprocessor &PP)
integer-constant: [C99 6.4.4.1] decimal-constant integer-suffix octal-constant integer-suffix hexadec...
bool isFloatingLiteral() const
Exposes information about the current target.
CharLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP, tok::TokenKind kind)
CharLiteralParser - Perform interpretation and semantic analysis of a character literal.
bool isIntegerLiteral() const
StringRef getUDSuffix() const
The result type of a method or function.
bool GetIntegerValue(llvm::APInt &Val)
GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width...
Encodes a location in the source.
llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result)
GetFloatValue - Convert this numeric literal to a floating value, using the specified APFloat fltSema...
StringRef GetString() const
StringRef getUDSuffix() const
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
unsigned getUDSuffixOffset() const
Get the spelling offset of the first byte of the ud-suffix.
unsigned getUDSuffixOffset() const
Defines the clang::TokenKind enum and support functions.
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
unsigned GetStringLength() const
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber...
unsigned getUDSuffixOffset() const
unsigned GetNumStringChars() const
This class handles loading and caching of source files into memory.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
static LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].