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;
73 return !saw_period && !saw_exponent;
76 return saw_period || saw_exponent;
83 assert(saw_ud_suffix);
87 assert(saw_ud_suffix);
88 return SuffixBegin - ThisTokBegin;
113 static bool isDigitSeparator(
char C) {
return C ==
'\''; }
117 bool containsDigits(
const char *Start,
const char *
End) {
118 return Start != End && (Start + 1 != End || !isDigitSeparator(Start[0]));
121 enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
125 CheckSeparatorKind IsAfterDigits);
129 const char *SkipHexDigits(
const char *ptr) {
130 while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
137 const char *SkipOctalDigits(
const char *ptr) {
138 while (ptr != ThisTokEnd &&
139 ((*ptr >=
'0' && *ptr <=
'7') || isDigitSeparator(*ptr)))
146 const char *SkipDigits(
const char *ptr) {
147 while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
154 const char *SkipBinaryDigits(
const char *ptr) {
155 while (ptr != ThisTokEnd &&
156 (*ptr ==
'0' || *ptr ==
'1' || isDigitSeparator(*ptr)))
171 unsigned UDSuffixOffset;
178 bool isAscii()
const {
return Kind == tok::char_constant; }
179 bool isWide()
const {
return Kind == tok::wide_char_constant; }
180 bool isUTF8()
const {
return Kind == tok::utf8_char_constant; }
181 bool isUTF16()
const {
return Kind == tok::utf16_char_constant; }
182 bool isUTF32()
const {
return Kind == tok::utf32_char_constant; }
187 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
188 return UDSuffixOffset;
201 unsigned MaxTokenLength;
203 unsigned CharByteWidth;
208 unsigned UDSuffixToken;
209 unsigned UDSuffixOffset;
217 : SM(sm), Features(features), Target(target), Diags(diags),
218 MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
228 return StringRef(ResultBuf.data(), GetStringLength());
233 return GetStringLength() / CharByteWidth;
241 unsigned getOffsetOfStringByte(
const Token &TheTok,
unsigned ByteNo)
const;
243 bool isAscii()
const {
return Kind == tok::string_literal; }
244 bool isWide()
const {
return Kind == tok::wide_string_literal; }
245 bool isUTF8()
const {
return Kind == tok::utf8_string_literal; }
246 bool isUTF16()
const {
return Kind == tok::utf16_string_literal; }
247 bool isUTF32()
const {
return Kind == tok::utf32_string_literal; }
254 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
255 return UDSuffixToken;
259 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
260 return UDSuffixOffset;
267 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.
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 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.