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" 28 class DiagnosticsEngine;
37 void expandUCNs(SmallVectorImpl<char> &Buf, StringRef Input);
45 const char *
const ThisTokBegin;
46 const char *
const ThisTokEnd;
47 const char *DigitsBegin, *SuffixBegin;
52 bool saw_exponent, saw_period, saw_ud_suffix, saw_fixed_point_suffix;
87 assert(saw_ud_suffix);
91 assert(saw_ud_suffix);
92 return SuffixBegin - ThisTokBegin;
123 static bool isDigitSeparator(
char C) {
return C ==
'\''; }
127 bool containsDigits(
const char *Start,
const char *
End) {
128 return Start != End && (Start + 1 != End || !isDigitSeparator(Start[0]));
131 enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
135 CheckSeparatorKind IsAfterDigits);
139 const char *SkipHexDigits(
const char *ptr) {
140 while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
147 const char *SkipOctalDigits(
const char *ptr) {
148 while (ptr != ThisTokEnd &&
149 ((*ptr >=
'0' && *ptr <=
'7') || isDigitSeparator(*ptr)))
156 const char *SkipDigits(
const char *ptr) {
157 while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
164 const char *SkipBinaryDigits(
const char *ptr) {
165 while (ptr != ThisTokEnd &&
166 (*ptr ==
'0' || *ptr ==
'1' || isDigitSeparator(*ptr)))
181 unsigned UDSuffixOffset;
188 bool isAscii()
const {
return Kind == tok::char_constant; }
189 bool isWide()
const {
return Kind == tok::wide_char_constant; }
190 bool isUTF8()
const {
return Kind == tok::utf8_char_constant; }
191 bool isUTF16()
const {
return Kind == tok::utf16_char_constant; }
192 bool isUTF32()
const {
return Kind == tok::utf32_char_constant; }
197 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
198 return UDSuffixOffset;
211 unsigned MaxTokenLength;
213 unsigned CharByteWidth;
218 unsigned UDSuffixToken;
219 unsigned UDSuffixOffset;
227 : SM(sm), Features(features), Target(target), Diags(diags),
228 MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
238 return StringRef(ResultBuf.data(), GetStringLength());
243 return GetStringLength() / CharByteWidth;
251 unsigned getOffsetOfStringByte(
const Token &TheTok,
unsigned ByteNo)
const;
253 bool isAscii()
const {
return Kind == tok::string_literal; }
254 bool isWide()
const {
return Kind == tok::wide_string_literal; }
255 bool isUTF8()
const {
return Kind == tok::utf8_string_literal; }
256 bool isUTF16()
const {
return Kind == tok::utf16_string_literal; }
257 bool isUTF32()
const {
return Kind == tok::utf32_string_literal; }
264 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
265 return UDSuffixToken;
269 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
270 return UDSuffixOffset;
277 bool CopyStringFragment(
const Token &
Tok,
const char *TokBegin,
StringRef getUDSuffix() const
unsigned GetNumStringChars() const
uint64_t getValue() const
unsigned GetStringLength() const
unsigned getUDSuffixOffset() const
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)
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.
unsigned getUDSuffixOffset() const
NumericLiteralParser(StringRef TokSpelling, SourceLocation TokLoc, Preprocessor &PP)
integer-constant: [C99 6.4.4.1] decimal-constant integer-suffix octal-constant integer-suffix hexadec...
Exposes information about the current target.
bool GetFixedPointValue(llvm::APInt &StoreVal, unsigned Scale)
GetFixedPointValue - Convert this numeric literal value into a scaled integer that represents this va...
CharLiteralParser - Perform interpretation and semantic analysis of a character literal.
The result type of a method or function.
StringRef GetString() const
bool GetIntegerValue(llvm::APInt &Val)
GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width...
unsigned getUDSuffixOffset() const
Get the spelling offset of the first byte of the ud-suffix.
unsigned getUDSuffixToken() const
Get the index of a token containing a ud-suffix.
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...
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.
Dataflow Directional Tag Classes.
LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].
StringRef getUDSuffix() const
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
bool isFixedPointLiteral() const
bool isIntegerLiteral() const
bool isFloatingLiteral() const
Defines the clang::TokenKind enum and support functions.
unsigned getRadix() const
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.
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber...
StringRef getUDSuffix() 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.