15 #ifndef LLVM_CLANG_LEX_LITERALSUPPORT_H
16 #define LLVM_CLANG_LEX_LITERALSUPPORT_H
21 #include "llvm/ADT/APFloat.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/Support/DataTypes.h"
28 class DiagnosticsEngine;
45 const char *
const ThisTokBegin;
46 const char *
const ThisTokEnd;
47 const char *DigitsBegin, *SuffixBegin;
52 bool saw_exponent, saw_period, saw_ud_suffix;
69 return !saw_period && !saw_exponent;
72 return saw_period || saw_exponent;
79 assert(saw_ud_suffix);
83 assert(saw_ud_suffix);
84 return SuffixBegin - ThisTokBegin;
108 static bool isDigitSeparator(
char C) {
return C ==
'\''; }
110 enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
113 void checkSeparator(SourceLocation TokLoc,
const char *Pos,
114 CheckSeparatorKind IsAfterDigits);
118 const char *SkipHexDigits(
const char *ptr) {
119 while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
126 const char *SkipOctalDigits(
const char *ptr) {
127 while (ptr != ThisTokEnd &&
128 ((*ptr >=
'0' && *ptr <=
'7') || isDigitSeparator(*ptr)))
135 const char *SkipDigits(
const char *ptr) {
136 while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
143 const char *SkipBinaryDigits(
const char *ptr) {
144 while (ptr != ThisTokEnd &&
145 (*ptr ==
'0' || *ptr ==
'1' || isDigitSeparator(*ptr)))
160 unsigned UDSuffixOffset;
168 bool isWide()
const {
return Kind == tok::wide_char_constant; }
175 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
176 return UDSuffixOffset;
189 unsigned MaxTokenLength;
191 unsigned CharByteWidth;
196 unsigned UDSuffixToken;
197 unsigned UDSuffixOffset;
205 : SM(sm), Features(features), Target(target), Diags(diags),
206 MaxTokenLength(0), SizeBound(0), CharByteWidth(0),
Kind(tok::unknown),
232 bool isWide()
const {
return Kind == tok::wide_string_literal; }
233 bool isUTF8()
const {
return Kind == tok::utf8_string_literal; }
234 bool isUTF16()
const {
return Kind == tok::utf16_string_literal; }
235 bool isUTF32()
const {
return Kind == tok::utf32_string_literal; }
242 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
243 return UDSuffixToken;
247 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
248 return UDSuffixOffset;
253 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
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)
NumericLiteralParser(StringRef TokSpelling, SourceLocation TokLoc, Preprocessor &PP)
bool isFloatingLiteral() const
Exposes information about the current target.
CharLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP, tok::TokenKind kind)
bool isIntegerLiteral() const
StringRef getUDSuffix() const
The result type of a method or function.
bool GetIntegerValue(llvm::APInt &Val)
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result)
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.
unsigned kind
All of the diagnostics that can be emitted by the frontend.
unsigned GetStringLength() const
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].