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;
38 void expandUCNs(SmallVectorImpl<char> &Buf, StringRef Input);
46 const char *
const ThisTokBegin;
47 const char *
const ThisTokEnd;
48 const char *DigitsBegin, *SuffixBegin;
53 bool saw_exponent, saw_period, saw_ud_suffix, saw_fixed_point_suffix;
88 assert(saw_ud_suffix);
92 assert(saw_ud_suffix);
93 return SuffixBegin - ThisTokBegin;
124 static bool isDigitSeparator(
char C) {
return C ==
'\''; }
128 bool containsDigits(
const char *Start,
const char *
End) {
129 return Start != End && (Start + 1 != End || !isDigitSeparator(Start[0]));
132 enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
136 CheckSeparatorKind IsAfterDigits);
140 const char *SkipHexDigits(
const char *ptr) {
141 while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
148 const char *SkipOctalDigits(
const char *ptr) {
149 while (ptr != ThisTokEnd &&
150 ((*ptr >=
'0' && *ptr <=
'7') || isDigitSeparator(*ptr)))
157 const char *SkipDigits(
const char *ptr) {
158 while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
165 const char *SkipBinaryDigits(
const char *ptr) {
166 while (ptr != ThisTokEnd &&
167 (*ptr ==
'0' || *ptr ==
'1' || isDigitSeparator(*ptr)))
182 unsigned UDSuffixOffset;
189 bool isAscii()
const {
return Kind == tok::char_constant; }
190 bool isWide()
const {
return Kind == tok::wide_char_constant; }
191 bool isUTF8()
const {
return Kind == tok::utf8_char_constant; }
192 bool isUTF16()
const {
return Kind == tok::utf16_char_constant; }
193 bool isUTF32()
const {
return Kind == tok::utf32_char_constant; }
198 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
199 return UDSuffixOffset;
212 unsigned MaxTokenLength;
214 unsigned CharByteWidth;
219 unsigned UDSuffixToken;
220 unsigned UDSuffixOffset;
228 : SM(sm), Features(features), Target(target), Diags(diags),
229 MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
239 return StringRef(ResultBuf.data(), GetStringLength());
244 return GetStringLength() / CharByteWidth;
252 unsigned getOffsetOfStringByte(
const Token &TheTok,
unsigned ByteNo)
const;
254 bool isAscii()
const {
return Kind == tok::string_literal; }
255 bool isWide()
const {
return Kind == tok::wide_string_literal; }
256 bool isUTF8()
const {
return Kind == tok::utf8_string_literal; }
257 bool isUTF16()
const {
return Kind == tok::utf16_string_literal; }
258 bool isUTF32()
const {
return Kind == tok::utf32_string_literal; }
265 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
266 return UDSuffixToken;
270 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
271 return UDSuffixOffset;
278 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.