Go to the documentation of this file.
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);
47 const char *
const ThisTokBegin;
48 const char *
const ThisTokEnd;
49 const char *DigitsBegin, *SuffixBegin;
54 bool saw_exponent, saw_period, saw_ud_suffix, saw_fixed_point_suffix;
79 return (saw_period || saw_exponent) && saw_fixed_point_suffix;
93 assert(saw_ud_suffix);
97 assert(saw_ud_suffix);
98 return SuffixBegin - ThisTokBegin;
116 llvm::APFloat::opStatus
GetFloatValue(llvm::APFloat &Result);
127 assert(!
hadError &&
"cannot reliably get the literal digits with an error");
128 return StringRef(DigitsBegin, SuffixBegin - DigitsBegin);
136 static bool isDigitSeparator(
char C) {
return C ==
'\''; }
140 bool containsDigits(
const char *Start,
const char *
End) {
141 return Start !=
End && (Start + 1 !=
End || !isDigitSeparator(Start[0]));
144 enum CheckSeparatorKind { CSK_BeforeDigits, CSK_AfterDigits };
147 void checkSeparator(SourceLocation TokLoc,
const char *Pos,
148 CheckSeparatorKind IsAfterDigits);
152 const char *SkipHexDigits(
const char *ptr) {
153 while (ptr != ThisTokEnd && (
isHexDigit(*ptr) || isDigitSeparator(*ptr)))
160 const char *SkipOctalDigits(
const char *ptr) {
161 while (ptr != ThisTokEnd &&
162 ((*ptr >=
'0' && *ptr <=
'7') || isDigitSeparator(*ptr)))
169 const char *SkipDigits(
const char *ptr) {
170 while (ptr != ThisTokEnd && (
isDigit(*ptr) || isDigitSeparator(*ptr)))
177 const char *SkipBinaryDigits(
const char *ptr) {
178 while (ptr != ThisTokEnd &&
179 (*ptr ==
'0' || *ptr ==
'1' || isDigitSeparator(*ptr)))
194 unsigned UDSuffixOffset;
201 bool isAscii()
const {
return Kind == tok::char_constant; }
202 bool isWide()
const {
return Kind == tok::wide_char_constant; }
203 bool isUTF8()
const {
return Kind == tok::utf8_char_constant; }
204 bool isUTF16()
const {
return Kind == tok::utf16_char_constant; }
205 bool isUTF32()
const {
return Kind == tok::utf32_char_constant; }
210 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
211 return UDSuffixOffset;
224 unsigned MaxTokenLength;
226 unsigned CharByteWidth;
231 unsigned UDSuffixToken;
232 unsigned UDSuffixOffset;
240 :
SM(sm), Features(features),
Target(target), Diags(diags),
241 MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
266 bool isAscii()
const {
return Kind == tok::string_literal; }
267 bool isWide()
const {
return Kind == tok::wide_string_literal; }
268 bool isUTF8()
const {
return Kind == tok::utf8_string_literal; }
269 bool isUTF16()
const {
return Kind == tok::utf16_string_literal; }
270 bool isUTF32()
const {
return Kind == tok::utf32_string_literal; }
277 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
278 return UDSuffixToken;
282 assert(!UDSuffixBuf.empty() &&
"no ud-suffix");
283 return UDSuffixOffset;
290 bool CopyStringFragment(
const Token &Tok,
const char *TokBegin,
StringRef getUDSuffix() const
uint64_t getValue() const
CharLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP, tok::TokenKind kind)
Encodes a location in the source.
Concrete class used by the front-end to report problems and issues.
Exposes information about the current target.
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
NumericLiteralParser(StringRef TokSpelling, SourceLocation TokLoc, const SourceManager &SM, const LangOptions &LangOpts, const TargetInfo &Target, DiagnosticsEngine &Diags)
integer-constant: [C99 6.4.4.1] decimal-constant integer-suffix octal-constant integer-suffix hexadec...
unsigned getUDSuffixOffset() const
Token - This structure provides full information about a lexed token.
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
This class handles loading and caching of source files into memory.
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const
getOffsetOfStringByte - This function returns the offset of the specified byte of the string data rep...
StringLiteralParser(ArrayRef< Token > StringToks, const SourceManager &sm, const LangOptions &features, const TargetInfo &target, DiagnosticsEngine *diags=nullptr)
unsigned getUDSuffixOffset() const
Get the spelling offset of the first byte of the ud-suffix.
StringRef getLiteralDigits() const
Get the digits that comprise the literal.
unsigned GetStringLength() const
StringLiteralParser(ArrayRef< Token > StringToks, Preprocessor &PP)
bool GetFixedPointValue(llvm::APInt &StoreVal, unsigned Scale)
GetFixedPointValue - Convert this numeric literal value into a scaled integer that represents this va...
LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
StringRef getUDSuffix() const
StringRef GetString() const
bool GetIntegerValue(llvm::APInt &Val)
GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width.
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber,...
bool isIntegerLiteral() const
bool isFloatingLiteral() const
StringRef getUDSuffix() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
unsigned getUDSuffixOffset() const
llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result)
GetFloatValue - Convert this numeric literal to a floating value, using the specified APFloat fltSema...
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
CharLiteralParser - Perform interpretation and semantic analysis of a character literal.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned getRadix() const
unsigned getUDSuffixToken() const
Get the index of a token containing a ud-suffix.
bool isFixedPointLiteral() const
unsigned kind
All of the diagnostics that can be emitted by the frontend.
unsigned GetNumStringChars() const