23#include "llvm/ADT/APInt.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/ADT/StringExtras.h"
26#include "llvm/ADT/StringSwitch.h"
27#include "llvm/Support/ConvertUTF.h"
28#include "llvm/Support/Error.h"
29#include "llvm/Support/ErrorHandling.h"
30#include "llvm/Support/Unicode.h"
42 default: llvm_unreachable(
"Unknown token type!");
43 case tok::char_constant:
44 case tok::string_literal:
45 case tok::utf8_char_constant:
46 case tok::utf8_string_literal:
47 return Target.getCharWidth();
48 case tok::wide_char_constant:
49 case tok::wide_string_literal:
50 return Target.getWCharWidth();
51 case tok::utf16_char_constant:
52 case tok::utf16_string_literal:
53 return Target.getChar16Width();
54 case tok::utf32_char_constant:
55 case tok::utf32_string_literal:
56 return Target.getChar32Width();
63 const char *TokRangeBegin,
64 const char *TokRangeEnd) {
81 const char *TokBegin,
const char *TokRangeBegin,
82 const char *TokRangeEnd,
unsigned DiagID) {
93 const char *&ThisTokBuf,
94 const char *ThisTokEnd,
bool &HadError,
98 const char *EscapeBegin = ThisTokBuf;
99 bool Delimited =
false;
100 bool EndDelimiterFound =
false;
107 unsigned ResultChar = *ThisTokBuf++;
108 switch (ResultChar) {
110 case '\\':
case '\'':
case '"':
case '?':
break;
122 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
123 diag::ext_nonstandard_escape) <<
"e";
128 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
129 diag::ext_nonstandard_escape) <<
"E";
149 if (ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
152 if (*ThisTokBuf ==
'}') {
153 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
154 diag::err_delimited_escape_empty);
157 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
159 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
160 diag::err_hex_escape_no_digits) <<
"x";
165 bool Overflow =
false;
166 for (; ThisTokBuf != ThisTokEnd; ++ThisTokBuf) {
167 if (Delimited && *ThisTokBuf ==
'}') {
169 EndDelimiterFound =
true;
172 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
179 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
180 diag::err_delimited_escape_invalid)
181 << StringRef(ThisTokBuf, 1);
185 if (ResultChar & 0xF0000000)
188 ResultChar |= CharVal;
191 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
193 ResultChar &= ~0
U >> (32-CharWidth);
197 if (!HadError && Overflow) {
200 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
201 diag::err_escape_too_large)
206 case '0':
case '1':
case '2':
case '3':
207 case '4':
case '5':
case '6':
case '7': {
214 unsigned NumDigits = 0;
217 ResultChar |= *ThisTokBuf++ -
'0';
219 }
while (ThisTokBuf != ThisTokEnd && NumDigits < 3 &&
220 ThisTokBuf[0] >=
'0' && ThisTokBuf[0] <=
'7');
223 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
225 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
226 diag::err_escape_too_large) << 1;
227 ResultChar &= ~0
U >> (32-CharWidth);
232 bool Overflow =
false;
233 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
236 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
237 diag::err_delimited_escape_missing_brace)
245 if (*ThisTokBuf ==
'}') {
246 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
247 diag::err_delimited_escape_empty);
251 while (ThisTokBuf != ThisTokEnd) {
252 if (*ThisTokBuf ==
'}') {
253 EndDelimiterFound =
true;
257 if (*ThisTokBuf <
'0' || *ThisTokBuf >
'7') {
260 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
261 diag::err_delimited_escape_invalid)
262 << StringRef(ThisTokBuf, 1);
267 if (ResultChar & 0xE0000000)
271 ResultChar |= *ThisTokBuf++ -
'0';
275 (Overflow || (CharWidth != 32 && (ResultChar >> CharWidth) != 0))) {
278 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
279 diag::err_escape_too_large)
281 ResultChar &= ~0
U >> (32 - CharWidth);
286 case '(':
case '{':
case '[':
case '%':
289 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
290 diag::ext_nonstandard_escape)
291 << std::string(1, ResultChar);
298 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
299 diag::ext_unknown_escape)
300 << std::string(1, ResultChar);
302 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
303 diag::ext_unknown_escape)
304 <<
"x" + llvm::utohexstr(ResultChar);
308 if (Delimited && Diags) {
309 if (!EndDelimiterFound)
310 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
313 else if (!HadError) {
314 Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
315 Features.CPlusPlus2b ? diag::warn_cxx2b_delimited_escape_sequence
316 : diag::ext_delimited_escape_sequence)
317 << 0 << (Features.CPlusPlus ? 1 : 0);
327 char *ResultPtr = ResultBuf;
328 if (llvm::ConvertCodePointToUTF8(Codepoint, ResultPtr))
329 Str.append(ResultBuf, ResultPtr);
333 for (StringRef::iterator I = Input.begin(), E = Input.end(); I != E; ++I) {
343 assert(Kind ==
'u' || Kind ==
'U' || Kind ==
'N');
344 uint32_t CodePoint = 0;
346 if (Kind ==
'u' && *I ==
'{') {
347 for (++I; *I !=
'}'; ++I) {
348 unsigned Value = llvm::hexDigitValue(*I);
349 assert(
Value != -1U);
360 auto Delim = std::find(I, Input.end(),
'}');
361 assert(Delim != Input.end());
362 std::optional<llvm::sys::unicode::LooseMatchingResult> Res =
363 llvm::sys::unicode::nameToCodepointLooseMatching(
364 StringRef(I, std::distance(I, Delim)));
366 CodePoint = Res->CodePoint;
367 assert(CodePoint != 0xFFFFFFFF);
373 unsigned NumHexDigits;
379 assert(I + NumHexDigits <= E);
381 for (; NumHexDigits != 0; ++I, --NumHexDigits) {
382 unsigned Value = llvm::hexDigitValue(*I);
383 assert(
Value != -1U);
395 const char *&ThisTokBuf,
396 const char *ThisTokEnd, uint32_t &UcnVal,
397 unsigned short &UcnLen,
bool &Delimited,
400 bool in_char_string_literal =
false) {
401 const char *UcnBegin = ThisTokBuf;
402 bool HasError =
false;
403 bool EndDelimiterFound =
false;
408 if (UcnBegin[1] ==
'u' && in_char_string_literal &&
409 ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
412 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
414 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
415 diag::err_hex_escape_no_digits)
416 << StringRef(&ThisTokBuf[-1], 1);
419 UcnLen = (ThisTokBuf[-1] ==
'u' ? 4 : 8);
421 bool Overflow =
false;
422 unsigned short Count = 0;
423 for (; ThisTokBuf != ThisTokEnd && (Delimited || Count != UcnLen);
425 if (Delimited && *ThisTokBuf ==
'}') {
427 EndDelimiterFound =
true;
430 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
436 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
437 diag::err_delimited_escape_invalid)
438 << StringRef(ThisTokBuf, 1);
443 if (UcnVal & 0xF0000000) {
454 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
455 diag::err_escape_too_large)
460 if (Delimited && !EndDelimiterFound) {
462 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
470 if (Count == 0 || (!Delimited && Count != UcnLen)) {
472 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
473 Delimited ? diag::err_delimited_escape_empty
474 : diag::err_ucn_escape_incomplete);
482 const char *TokBegin,
const char *TokRangeBegin,
const char *TokRangeEnd,
483 llvm::StringRef Name) {
485 Diag(Diags, Features, Loc, TokBegin, TokRangeBegin, TokRangeEnd,
486 diag::err_invalid_ucn_name)
489 namespace u = llvm::sys::unicode;
491 std::optional<u::LooseMatchingResult> Res =
492 u::nameToCodepointLooseMatching(Name);
494 Diag(Diags, Features, Loc, TokBegin, TokRangeBegin, TokRangeEnd,
495 diag::note_invalid_ucn_name_loose_matching)
503 unsigned Distance = 0;
505 u::nearestMatchesForCodepointName(Name, 5);
506 assert(!Matches.empty() &&
"No unicode characters found");
508 for (
const auto &Match : Matches) {
510 Distance = Match.Distance;
511 if (std::max(Distance, Match.Distance) -
512 std::min(Distance, Match.Distance) >
515 Distance = Match.Distance;
518 llvm::UTF32
V = Match.Value;
522 assert(Converted &&
"Found a match wich is not a unicode character");
524 Diag(Diags, Features, Loc, TokBegin, TokRangeBegin, TokRangeEnd,
525 diag::note_invalid_ucn_name_candidate)
526 << Match.Name << llvm::utohexstr(Match.Value)
536 const char *&ThisTokBuf,
537 const char *ThisTokEnd, uint32_t &UcnVal,
541 const char *UcnBegin = ThisTokBuf;
542 assert(UcnBegin[0] ==
'\\' && UcnBegin[1] ==
'N');
544 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
546 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
547 diag::err_delimited_escape_missing_brace)
548 << StringRef(&ThisTokBuf[-1], 1);
553 const char *ClosingBrace = std::find_if(ThisTokBuf, ThisTokEnd, [](
char C) {
556 bool Incomplete = ClosingBrace == ThisTokEnd;
557 bool Empty = ClosingBrace == ThisTokBuf;
558 if (Incomplete || Empty) {
560 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
561 Incomplete ? diag::err_ucn_escape_incomplete
562 : diag::err_delimited_escape_empty)
563 << StringRef(&UcnBegin[1], 1);
565 ThisTokBuf = ClosingBrace == ThisTokEnd ? ClosingBrace : ClosingBrace + 1;
568 StringRef Name(ThisTokBuf, ClosingBrace - ThisTokBuf);
569 ThisTokBuf = ClosingBrace + 1;
570 std::optional<char32_t> Res = llvm::sys::unicode::nameToCodepointStrict(Name);
574 &UcnBegin[3], ClosingBrace, Name);
578 UcnLen = UcnVal > 0xFFFF ? 8 : 4;
585 const char *ThisTokEnd, uint32_t &UcnVal,
589 bool in_char_string_literal =
false) {
592 const char *UcnBegin = ThisTokBuf;
593 bool IsDelimitedEscapeSequence =
false;
594 bool IsNamedEscapeSequence =
false;
595 if (ThisTokBuf[1] ==
'N') {
596 IsNamedEscapeSequence =
true;
598 UcnVal, UcnLen, Loc, Diags, Features);
602 UcnLen, IsDelimitedEscapeSequence, Loc, Diags,
603 Features, in_char_string_literal);
609 if ((0xD800 <= UcnVal && UcnVal <= 0xDFFF) ||
612 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
613 diag::err_ucn_escape_invalid);
620 (UcnVal != 0x24 && UcnVal != 0x40 && UcnVal != 0x60)) {
621 bool IsError = (!Features.CPlusPlus11 || !in_char_string_literal);
623 char BasicSCSChar = UcnVal;
624 if (UcnVal >= 0x20 && UcnVal < 0x7f)
625 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
626 IsError ? diag::err_ucn_escape_basic_scs :
627 diag::warn_cxx98_compat_literal_ucn_escape_basic_scs)
628 << StringRef(&BasicSCSChar, 1);
630 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
631 IsError ? diag::err_ucn_control_character :
632 diag::warn_cxx98_compat_literal_ucn_control_character);
638 if (!Features.CPlusPlus && !Features.C99 && Diags)
639 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
640 diag::warn_ucn_not_valid_in_c89_literal);
642 if ((IsDelimitedEscapeSequence || IsNamedEscapeSequence) && Diags)
643 Diag(Diags, Features, Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
644 Features.CPlusPlus2b ? diag::warn_cxx2b_delimited_escape_sequence
645 : diag::ext_delimited_escape_sequence)
646 << (IsNamedEscapeSequence ? 1 : 0) << (Features.CPlusPlus ? 1 : 0);
654 const char *ThisTokEnd,
unsigned CharByteWidth,
657 if (CharByteWidth == 4)
661 unsigned short UcnLen = 0;
665 UcnLen, Loc,
nullptr, Features,
true)) {
671 if (CharByteWidth == 2)
672 return UcnVal <= 0xFFFF ? 2 : 4;
679 if (UcnVal < 0x10000)
689 const char *ThisTokEnd,
690 char *&ResultBuf,
bool &HadError,
694 typedef uint32_t UTF32;
696 unsigned short UcnLen = 0;
698 Loc, Diags, Features,
true)) {
703 assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
704 "only character widths of 1, 2, or 4 bytes supported");
707 assert((UcnLen== 4 || UcnLen== 8) &&
"only ucn length of 4 or 8 supported");
709 if (CharByteWidth == 4) {
712 llvm::UTF32 *ResultPtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf);
718 if (CharByteWidth == 2) {
721 llvm::UTF16 *ResultPtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf);
723 if (UcnVal <= (UTF32)0xFFFF) {
731 *ResultPtr = 0xD800 + (UcnVal >> 10);
732 *(ResultPtr+1) = 0xDC00 + (UcnVal & 0x3FF);
737 assert(CharByteWidth == 1 &&
"UTF-8 encoding is only for 1 byte characters");
743 typedef uint8_t UTF8;
745 unsigned short bytesToWrite = 0;
746 if (UcnVal < (UTF32)0x80)
748 else if (UcnVal < (UTF32)0x800)
750 else if (UcnVal < (UTF32)0x10000)
755 const unsigned byteMask = 0xBF;
756 const unsigned byteMark = 0x80;
760 static const UTF8 firstByteMark[5] = {
761 0x00, 0x00, 0xC0, 0xE0, 0xF0
764 ResultBuf += bytesToWrite;
765 switch (bytesToWrite) {
767 *--ResultBuf = (UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
770 *--ResultBuf = (UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
773 *--ResultBuf = (UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
776 *--ResultBuf = (UTF8) (UcnVal | firstByteMark[bytesToWrite]);
779 ResultBuf += bytesToWrite;
839 :
SM(
SM), LangOpts(LangOpts), Diags(Diags),
840 ThisTokBegin(TokSpelling.begin()), ThisTokEnd(TokSpelling.end()) {
842 s = DigitsBegin = ThisTokBegin;
843 saw_exponent =
false;
845 saw_ud_suffix =
false;
846 saw_fixed_point_suffix =
false;
867 Diags.
Report(TokLoc, diag::err_lexing_numeric);
873 ParseNumberStartingWithZero(TokLoc);
879 if (
s == ThisTokEnd) {
882 ParseDecimalOrOctalCommon(TokLoc);
889 checkSeparator(TokLoc,
s, CSK_AfterDigits);
892 if (LangOpts.FixedPoint) {
893 for (
const char *
c =
s;
c != ThisTokEnd; ++
c) {
894 if (*
c ==
'r' || *
c ==
'k' || *
c ==
'R' || *
c ==
'K') {
895 saw_fixed_point_suffix =
true;
905 bool HasSize =
false;
909 for (;
s != ThisTokEnd; ++
s) {
913 if (!LangOpts.FixedPoint)
916 if (!(saw_period || saw_exponent))
break;
921 if (!LangOpts.FixedPoint)
924 if (!(saw_period || saw_exponent))
break;
930 if (!(LangOpts.Half || LangOpts.FixedPoint))
940 if (!isFPConstant)
break;
951 if ((
Target.hasFloat16Type() || LangOpts.CUDA ||
952 (LangOpts.OpenMPIsDevice &&
Target.getTriple().isNVPTX())) &&
953 s + 2 < ThisTokEnd &&
s[1] ==
'1' &&
s[2] ==
'6') {
963 if (!isFPConstant)
break;
971 if (isFPConstant)
break;
983 assert(
s + 1 < ThisTokEnd &&
"didn't maximally munch?");
984 if (isFPConstant)
break;
1002 if (LangOpts.MicrosoftExt && !isFPConstant) {
1039 assert(
s <= ThisTokEnd &&
"didn't maximally munch?");
1060 if (!LangOpts.CPlusPlus && ((
s[0] ==
'w' &&
s[1] ==
'b') ||
1061 (
s[0] ==
'W' &&
s[1] ==
'B'))) {
1075 expandUCNs(UDSuffixBuf, StringRef(SuffixBegin, ThisTokEnd - SuffixBegin));
1090 saw_fixed_point_suffix =
false;
1095 saw_ud_suffix =
true;
1099 if (
s != ThisTokEnd) {
1102 TokLoc, SuffixBegin - ThisTokBegin,
SM, LangOpts),
1103 diag::err_invalid_suffix_constant)
1104 << StringRef(SuffixBegin, ThisTokEnd - SuffixBegin)
1105 << (isFixedPointConstant ? 2 : isFPConstant);
1110 if (!
hadError && saw_fixed_point_suffix) {
1118void NumericLiteralParser::ParseDecimalOrOctalCommon(
SourceLocation TokLoc){
1119 assert((radix == 8 || radix == 10) &&
"Unexpected radix");
1127 diag::err_invalid_digit)
1128 << StringRef(
s, 1) << (radix == 8 ? 1 : 0);
1134 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1138 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1141 if (*
s ==
'e' || *
s ==
'E') {
1142 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1143 const char *Exponent =
s;
1146 saw_exponent =
true;
1147 if (
s != ThisTokEnd && (*
s ==
'+' || *
s ==
'-'))
s++;
1148 const char *first_non_digit = SkipDigits(
s);
1149 if (containsDigits(
s, first_non_digit)) {
1150 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1151 s = first_non_digit;
1155 TokLoc, Exponent - ThisTokBegin,
SM, LangOpts),
1156 diag::err_exponent_has_no_digits);
1169 if (!LangOpts.CPlusPlus11 || Suffix.empty())
1173 if (Suffix[0] ==
'_')
1177 if (!LangOpts.CPlusPlus14)
1183 return llvm::StringSwitch<bool>(Suffix)
1184 .Cases(
"h",
"min",
"s",
true)
1185 .Cases(
"ms",
"us",
"ns",
true)
1186 .Cases(
"il",
"i",
"if",
true)
1187 .Cases(
"d",
"y", LangOpts.CPlusPlus20)
1193 CheckSeparatorKind IsAfterDigits) {
1194 if (IsAfterDigits == CSK_AfterDigits) {
1195 if (Pos == ThisTokBegin)
1198 }
else if (Pos == ThisTokEnd)
1201 if (isDigitSeparator(*Pos)) {
1204 diag::err_digit_separator_not_between_digits)
1215void NumericLiteralParser::ParseNumberStartingWithZero(
SourceLocation TokLoc) {
1216 assert(
s[0] ==
'0' &&
"Invalid method call");
1222 if ((c1 ==
'x' || c1 ==
'X') && (
isHexDigit(
s[1]) ||
s[1] ==
'.')) {
1224 assert(
s < ThisTokEnd &&
"didn't maximally munch?");
1227 s = SkipHexDigits(
s);
1228 bool HasSignificandDigits = containsDigits(DigitsBegin,
s);
1229 if (
s == ThisTokEnd) {
1231 }
else if (*
s ==
'.') {
1234 const char *floatDigitsBegin =
s;
1235 s = SkipHexDigits(
s);
1236 if (containsDigits(floatDigitsBegin,
s))
1237 HasSignificandDigits =
true;
1238 if (HasSignificandDigits)
1239 checkSeparator(TokLoc, floatDigitsBegin, CSK_BeforeDigits);
1242 if (!HasSignificandDigits) {
1245 diag::err_hex_constant_requires)
1246 << LangOpts.CPlusPlus << 1;
1253 if (*
s ==
'p' || *
s ==
'P') {
1254 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1255 const char *Exponent =
s;
1257 saw_exponent =
true;
1258 if (
s != ThisTokEnd && (*
s ==
'+' || *
s ==
'-'))
s++;
1259 const char *first_non_digit = SkipDigits(
s);
1260 if (!containsDigits(
s, first_non_digit)) {
1263 TokLoc, Exponent - ThisTokBegin,
SM, LangOpts),
1264 diag::err_exponent_has_no_digits);
1269 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1270 s = first_non_digit;
1272 if (!LangOpts.HexFloats)
1273 Diags.
Report(TokLoc, LangOpts.CPlusPlus
1274 ? diag::ext_hex_literal_invalid
1275 : diag::ext_hex_constant_invalid);
1276 else if (LangOpts.CPlusPlus17)
1277 Diags.
Report(TokLoc, diag::warn_cxx17_hex_literal);
1278 }
else if (saw_period) {
1281 diag::err_hex_constant_requires)
1282 << LangOpts.CPlusPlus << 0;
1289 if ((c1 ==
'b' || c1 ==
'B') && (
s[1] ==
'0' ||
s[1] ==
'1')) {
1291 Diags.
Report(TokLoc, LangOpts.CPlusPlus14
1292 ? diag::warn_cxx11_compat_binary_literal
1293 : LangOpts.CPlusPlus ? diag::ext_binary_literal_cxx14
1294 : diag::ext_binary_literal);
1296 assert(
s < ThisTokEnd &&
"didn't maximally munch?");
1299 s = SkipBinaryDigits(
s);
1300 if (
s == ThisTokEnd) {
1306 diag::err_invalid_digit)
1307 << StringRef(
s, 1) << 2;
1318 const char *PossibleNewDigitStart =
s;
1319 s = SkipOctalDigits(
s);
1323 if (
s != PossibleNewDigitStart)
1324 DigitsBegin = PossibleNewDigitStart;
1326 if (
s == ThisTokEnd)
1332 const char *EndDecimal = SkipDigits(
s);
1333 if (EndDecimal[0] ==
'.' || EndDecimal[0] ==
'e' || EndDecimal[0] ==
'E') {
1339 ParseDecimalOrOctalCommon(TokLoc);
1345 return NumDigits <= 64;
1347 return NumDigits <= 64 / 3;
1349 return NumDigits <= 19;
1351 return NumDigits <= 64 / 4;
1353 llvm_unreachable(
"impossible Radix");
1367 const unsigned NumDigits = SuffixBegin - DigitsBegin;
1370 for (
const char *Ptr = DigitsBegin; Ptr != SuffixBegin; ++Ptr)
1371 if (!isDigitSeparator(*Ptr))
1372 N = N * radix + llvm::hexDigitValue(*Ptr);
1377 return Val.getZExtValue() != N;
1381 const char *Ptr = DigitsBegin;
1383 llvm::APInt RadixVal(Val.getBitWidth(), radix);
1384 llvm::APInt CharVal(Val.getBitWidth(), 0);
1385 llvm::APInt OldVal = Val;
1387 bool OverflowOccurred =
false;
1388 while (Ptr < SuffixBegin) {
1389 if (isDigitSeparator(*Ptr)) {
1394 unsigned C = llvm::hexDigitValue(*Ptr++);
1397 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1407 OverflowOccurred |= Val.udiv(RadixVal) != OldVal;
1412 OverflowOccurred |= Val.ult(CharVal);
1414 return OverflowOccurred;
1417llvm::APFloat::opStatus
1419 using llvm::APFloat;
1421 unsigned n = std::min(SuffixBegin - ThisTokBegin, ThisTokEnd - ThisTokBegin);
1424 StringRef Str(ThisTokBegin, n);
1425 if (Str.contains(
'\'')) {
1427 std::remove_copy_if(Str.begin(), Str.end(), std::back_inserter(Buffer),
1433 Result.convertFromString(Str, APFloat::rmNearestTiesToEven);
1434 assert(StatusOrErr &&
"Invalid floating point representation");
1435 return !errorToBool(StatusOrErr.takeError()) ? *StatusOrErr
1436 : APFloat::opInvalidOp;
1440 return c ==
'p' ||
c ==
'P' ||
c ==
'e' ||
c ==
'E';
1444 assert(radix == 16 || radix == 10);
1447 unsigned NumDigits = SuffixBegin - DigitsBegin;
1448 if (saw_period) --NumDigits;
1451 bool ExpOverflowOccurred =
false;
1452 bool NegativeExponent =
false;
1453 const char *ExponentBegin;
1454 uint64_t Exponent = 0;
1455 int64_t BaseShift = 0;
1457 const char *Ptr = DigitsBegin;
1460 ExponentBegin = Ptr;
1462 NegativeExponent = *Ptr ==
'-';
1463 if (NegativeExponent) ++Ptr;
1465 unsigned NumExpDigits = SuffixBegin - Ptr;
1467 llvm::StringRef ExpStr(Ptr, NumExpDigits);
1468 llvm::APInt ExpInt(64, ExpStr, 10);
1469 Exponent = ExpInt.getZExtValue();
1471 ExpOverflowOccurred =
true;
1474 if (NegativeExponent) BaseShift -= Exponent;
1475 else BaseShift += Exponent;
1495 uint64_t NumBitsNeeded;
1497 NumBitsNeeded = 4 * (NumDigits + Exponent) + Scale;
1499 NumBitsNeeded = 4 * NumDigits + Exponent + Scale;
1501 if (NumBitsNeeded > std::numeric_limits<unsigned>::max())
1502 ExpOverflowOccurred =
true;
1503 llvm::APInt Val(
static_cast<unsigned>(NumBitsNeeded), 0,
false);
1505 bool FoundDecimal =
false;
1507 int64_t FractBaseShift = 0;
1508 const char *End = saw_exponent ? ExponentBegin : SuffixBegin;
1509 for (
const char *Ptr = DigitsBegin; Ptr < End; ++Ptr) {
1511 FoundDecimal =
true;
1516 unsigned C = llvm::hexDigitValue(*Ptr);
1517 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1529 if (radix == 16) FractBaseShift *= 4;
1530 BaseShift += FractBaseShift;
1534 uint64_t
Base = (radix == 16) ? 2 : 10;
1535 if (BaseShift > 0) {
1536 for (int64_t i = 0; i < BaseShift; ++i) {
1539 }
else if (BaseShift < 0) {
1540 for (int64_t i = BaseShift; i < 0 && !Val.isZero(); ++i)
1541 Val = Val.udiv(
Base);
1544 bool IntOverflowOccurred =
false;
1545 auto MaxVal = llvm::APInt::getMaxValue(StoreVal.getBitWidth());
1546 if (Val.getBitWidth() > StoreVal.getBitWidth()) {
1547 IntOverflowOccurred |= Val.ugt(MaxVal.zext(Val.getBitWidth()));
1548 StoreVal = Val.trunc(StoreVal.getBitWidth());
1549 }
else if (Val.getBitWidth() < StoreVal.getBitWidth()) {
1550 IntOverflowOccurred |= Val.zext(MaxVal.getBitWidth()).ugt(MaxVal);
1551 StoreVal = Val.zext(StoreVal.getBitWidth());
1556 return IntOverflowOccurred || ExpOverflowOccurred;
1606 const char *TokBegin = begin;
1609 if (Kind != tok::char_constant)
1611 if (Kind == tok::utf8_char_constant)
1615 if (begin[0] !=
'\'') {
1616 PP.
Diag(Loc, diag::err_lexing_char);
1624 if (end[-1] !=
'\'') {
1625 const char *UDSuffixEnd = end;
1628 }
while (end[-1] !=
'\'');
1630 expandUCNs(UDSuffixBuf, StringRef(end, UDSuffixEnd - end));
1631 UDSuffixOffset = end - TokBegin;
1635 assert(end != begin &&
"Invalid token lexed");
1642 "Assumes char is 8 bits");
1645 "Assumes sizeof(int) on target is <= 64 and a multiple of char");
1647 "Assumes sizeof(wchar) on target is <= 64");
1650 codepoint_buffer.resize(end - begin);
1651 uint32_t *buffer_begin = &codepoint_buffer.front();
1652 uint32_t *buffer_end = buffer_begin + codepoint_buffer.size();
1657 uint32_t largest_character_for_kind;
1658 if (tok::wide_char_constant == Kind) {
1659 largest_character_for_kind =
1661 }
else if (tok::utf8_char_constant == Kind) {
1662 largest_character_for_kind = 0x7F;
1663 }
else if (tok::utf16_char_constant == Kind) {
1664 largest_character_for_kind = 0xFFFF;
1665 }
else if (tok::utf32_char_constant == Kind) {
1666 largest_character_for_kind = 0x10FFFF;
1668 largest_character_for_kind = 0x7Fu;
1671 while (begin != end) {
1673 if (begin[0] !=
'\\') {
1674 char const *start = begin;
1677 }
while (begin != end && *begin !=
'\\');
1679 char const *tmp_in_start = start;
1680 uint32_t *tmp_out_start = buffer_begin;
1681 llvm::ConversionResult res =
1682 llvm::ConvertUTF8toUTF32(
reinterpret_cast<llvm::UTF8
const **
>(&start),
1683 reinterpret_cast<llvm::UTF8
const *
>(begin),
1684 &buffer_begin, buffer_end, llvm::strictConversion);
1685 if (res != llvm::conversionOK) {
1690 unsigned Msg = diag::err_bad_character_encoding;
1691 if (NoErrorOnBadEncoding)
1692 Msg = diag::warn_bad_character_encoding;
1694 if (NoErrorOnBadEncoding) {
1695 start = tmp_in_start;
1696 buffer_begin = tmp_out_start;
1697 for (; start != begin; ++start, ++buffer_begin)
1698 *buffer_begin =
static_cast<uint8_t
>(*start);
1703 for (; tmp_out_start < buffer_begin; ++tmp_out_start) {
1704 if (*tmp_out_start > largest_character_for_kind) {
1706 PP.
Diag(Loc, diag::err_character_too_large);
1714 if (begin[1] ==
'u' || begin[1] ==
'U' || begin[1] ==
'N') {
1715 unsigned short UcnLen = 0;
1720 }
else if (*buffer_begin > largest_character_for_kind) {
1722 PP.
Diag(Loc, diag::err_character_too_large);
1733 *buffer_begin++ = result;
1736 unsigned NumCharsSoFar = buffer_begin - &codepoint_buffer.front();
1738 if (NumCharsSoFar > 1) {
1740 PP.
Diag(Loc, diag::warn_four_char_character_literal);
1742 PP.
Diag(Loc, diag::warn_multichar_character_literal);
1744 PP.
Diag(Loc, diag::err_multichar_character_literal) << (
isWide() ? 0 : 1);
1749 IsMultiChar =
false;
1756 bool multi_char_too_long =
false;
1759 for (
size_t i = 0; i < NumCharsSoFar; ++i) {
1761 multi_char_too_long |= (LitVal.countl_zero() < 8);
1763 LitVal = LitVal + (codepoint_buffer[i] & 0xFF);
1765 }
else if (NumCharsSoFar > 0) {
1767 LitVal = buffer_begin[-1];
1770 if (!HadError && multi_char_too_long) {
1771 PP.
Diag(Loc, diag::warn_char_constant_too_large);
1775 Value = LitVal.getZExtValue();
1843 :
SM(PP.getSourceManager()), Features(PP.getLangOpts()),
1844 Target(PP.getTargetInfo()), Diags(&PP.getDiagnostics()),
1845 MaxTokenLength(0), SizeBound(0), CharByteWidth(0), Kind(tok::unknown),
1846 ResultPtr(ResultBuf.data()), hadError(
false), Pascal(
false) {
1853 if (StringToks.empty() || StringToks[0].getLength() < 2)
1860 assert(!StringToks.empty() &&
"expected at least one token");
1861 MaxTokenLength = StringToks[0].getLength();
1862 assert(StringToks[0].getLength() >= 2 &&
"literal token is invalid!");
1863 SizeBound = StringToks[0].getLength()-2;
1864 Kind = StringToks[0].getKind();
1870 for (
unsigned i = 1; i != StringToks.size(); ++i) {
1871 if (StringToks[i].getLength() < 2)
1872 return DiagnoseLexingError(StringToks[i].getLocation());
1876 assert(StringToks[i].getLength() >= 2 &&
"literal token is invalid!");
1877 SizeBound += StringToks[i].getLength()-2;
1880 if (StringToks[i].getLength() > MaxTokenLength)
1881 MaxTokenLength = StringToks[i].getLength();
1885 if (StringToks[i].isNot(Kind) && StringToks[i].isNot(tok::string_literal)) {
1887 Kind = StringToks[i].getKind();
1890 Diags->
Report(StringToks[i].getLocation(),
1891 diag::err_unsupported_string_concat);
1904 assert((CharByteWidth & 7) == 0 &&
"Assumes character size is byte multiple");
1909 SizeBound *= CharByteWidth;
1912 ResultBuf.resize(SizeBound);
1916 TokenBuf.resize(MaxTokenLength);
1920 ResultPtr = &ResultBuf[0];
1926 for (
unsigned i = 0, e = StringToks.size(); i != e; ++i) {
1927 const char *ThisTokBuf = &TokenBuf[0];
1931 bool StringInvalid =
false;
1932 unsigned ThisTokLen =
1936 return DiagnoseLexingError(StringToks[i].getLocation());
1938 const char *ThisTokBegin = ThisTokBuf;
1939 const char *ThisTokEnd = ThisTokBuf+ThisTokLen;
1942 if (ThisTokEnd[-1] !=
'"') {
1943 const char *UDSuffixEnd = ThisTokEnd;
1946 }
while (ThisTokEnd[-1] !=
'"');
1948 StringRef UDSuffix(ThisTokEnd, UDSuffixEnd - ThisTokEnd);
1950 if (UDSuffixBuf.empty()) {
1951 if (StringToks[i].hasUCN())
1954 UDSuffixBuf.assign(UDSuffix);
1956 UDSuffixOffset = ThisTokEnd - ThisTokBuf;
1957 UDSuffixTokLoc = StringToks[i].getLocation();
1960 if (StringToks[i].hasUCN()) {
1962 UDSuffix = ExpandedUDSuffix;
1969 if (UDSuffixBuf != UDSuffix) {
1972 Diags->
Report(TokLoc, diag::err_string_concat_mixed_suffix)
1973 << UDSuffixBuf << UDSuffix
1988 if (ThisTokBuf[0] ==
'L' || ThisTokBuf[0] ==
'u' || ThisTokBuf[0] ==
'U') {
1991 if (ThisTokBuf[0] ==
'8')
1996 if (ThisTokBuf[0] ==
'R') {
1997 if (ThisTokBuf[1] !=
'"') {
2000 return DiagnoseLexingError(StringToks[i].getLocation());
2006 constexpr unsigned MaxRawStrDelimLen = 16;
2008 const char *Prefix = ThisTokBuf;
2009 while (
static_cast<unsigned>(ThisTokBuf - Prefix) < MaxRawStrDelimLen &&
2010 ThisTokBuf[0] !=
'(')
2012 if (ThisTokBuf[0] !=
'(')
2013 return DiagnoseLexingError(StringToks[i].getLocation());
2017 ThisTokEnd -= ThisTokBuf - Prefix;
2018 if (ThisTokEnd < ThisTokBuf)
2019 return DiagnoseLexingError(StringToks[i].getLocation());
2023 StringRef RemainingTokenSpan(ThisTokBuf, ThisTokEnd - ThisTokBuf);
2024 while (!RemainingTokenSpan.empty()) {
2026 size_t CRLFPos = RemainingTokenSpan.find(
"\r\n");
2027 StringRef BeforeCRLF = RemainingTokenSpan.substr(0, CRLFPos);
2028 StringRef AfterCRLF = RemainingTokenSpan.substr(CRLFPos);
2031 if (CopyStringFragment(StringToks[i], ThisTokBegin, BeforeCRLF))
2036 RemainingTokenSpan = AfterCRLF.substr(1);
2039 if (ThisTokBuf[0] !=
'"') {
2042 return DiagnoseLexingError(StringToks[i].getLocation());
2047 if (Features.PascalStrings && ThisTokBuf + 1 != ThisTokEnd &&
2048 ThisTokBuf[0] ==
'\\' && ThisTokBuf[1] ==
'p') {
2059 while (ThisTokBuf != ThisTokEnd) {
2061 if (ThisTokBuf[0] !=
'\\') {
2062 const char *InStart = ThisTokBuf;
2065 }
while (ThisTokBuf != ThisTokEnd && ThisTokBuf[0] !=
'\\');
2068 if (CopyStringFragment(StringToks[i], ThisTokBegin,
2069 StringRef(InStart, ThisTokBuf - InStart)))
2074 if (ThisTokBuf[1] ==
'u' || ThisTokBuf[1] ==
'U' ||
2075 ThisTokBuf[1] ==
'N') {
2079 CharByteWidth, Diags, Features);
2083 unsigned ResultChar =
2086 CharByteWidth*8, Diags, Features);
2088 if (CharByteWidth == 4) {
2091 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultPtr);
2092 *ResultWidePtr = ResultChar;
2094 }
else if (CharByteWidth == 2) {
2097 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultPtr);
2098 *ResultWidePtr = ResultChar & 0xFFFF;
2101 assert(CharByteWidth == 1 &&
"Unexpected char width");
2102 *ResultPtr++ = ResultChar & 0xFF;
2109 if (CharByteWidth == 4) {
2112 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf.data());
2114 }
else if (CharByteWidth == 2) {
2117 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf.data());
2120 assert(CharByteWidth == 1 &&
"Unexpected char width");
2127 Diags->
Report(StringToks.front().getLocation(),
2128 diag::err_pascal_string_too_long)
2130 StringToks.back().getLocation());
2136 unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
2139 Diags->
Report(StringToks.front().getLocation(),
2140 diag::ext_string_too_long)
2142 << (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
2144 StringToks.back().getLocation());
2151 End = Err + std::min<unsigned>(llvm::getNumBytesForUTF8(*Err), End-Err);
2152 while (++Err != End && (*Err & 0xC0) == 0x80)
2160bool StringLiteralParser::CopyStringFragment(
const Token &Tok,
2161 const char *TokBegin,
2162 StringRef Fragment) {
2163 const llvm::UTF8 *ErrorPtrTmp;
2164 if (ConvertUTF8toWide(CharByteWidth, Fragment, ResultPtr, ErrorPtrTmp))
2171 if (NoErrorOnBadEncoding) {
2172 memcpy(ResultPtr, Fragment.data(), Fragment.size());
2173 ResultPtr += Fragment.size();
2177 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2181 Diag(Diags, Features, SourceLoc, TokBegin,
2182 ErrorPtr,
resyncUTF8(ErrorPtr, Fragment.end()),
2183 NoErrorOnBadEncoding ? diag::warn_bad_string_encoding
2184 : diag::err_bad_string_encoding);
2186 const char *NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2187 StringRef NextFragment(NextStart, Fragment.end()-NextStart);
2191 Dummy.reserve(Fragment.size() * CharByteWidth);
2192 char *Ptr = Dummy.data();
2194 while (!ConvertUTF8toWide(CharByteWidth, NextFragment, Ptr, ErrorPtrTmp)) {
2195 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2196 NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2198 ErrorPtr, NextStart);
2199 NextFragment = StringRef(NextStart, Fragment.end()-NextStart);
2202 return !NoErrorOnBadEncoding;
2205void StringLiteralParser::DiagnoseLexingError(
SourceLocation Loc) {
2208 Diags->
Report(Loc, diag::err_lexing_string);
2215 unsigned ByteNo)
const {
2220 bool StringInvalid =
false;
2221 const char *SpellingPtr = &SpellingBuffer[0];
2227 const char *SpellingStart = SpellingPtr;
2228 const char *SpellingEnd = SpellingPtr+TokLen;
2231 if (SpellingPtr[0] ==
'u' && SpellingPtr[1] ==
'8')
2234 assert(SpellingPtr[0] !=
'L' && SpellingPtr[0] !=
'u' &&
2235 SpellingPtr[0] !=
'U' &&
"Doesn't handle wide or utf strings yet");
2238 if (SpellingPtr[0] ==
'R') {
2239 assert(SpellingPtr[1] ==
'"' &&
"Should be a raw string literal!");
2242 while (*SpellingPtr !=
'(') {
2244 assert(SpellingPtr < SpellingEnd &&
"Missing ( for raw string literal");
2248 return SpellingPtr - SpellingStart + ByteNo;
2252 assert(SpellingPtr[0] ==
'"' &&
"Should be a string literal!");
2257 assert(SpellingPtr < SpellingEnd &&
"Didn't find byte offset!");
2260 if (*SpellingPtr !=
'\\') {
2267 bool HadError =
false;
2268 if (SpellingPtr[1] ==
'u' || SpellingPtr[1] ==
'U' ||
2269 SpellingPtr[1] ==
'N') {
2270 const char *EscapePtr = SpellingPtr;
2272 1, Features, HadError);
2275 SpellingPtr = EscapePtr;
2282 CharByteWidth*8, Diags, Features);
2285 assert(!HadError &&
"This method isn't valid on erroneous strings");
2288 return SpellingPtr-SpellingStart;
Defines the clang::LangOptions interface.
static void EncodeUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, char *&ResultBuf, bool &HadError, FullSourceLoc Loc, unsigned CharByteWidth, DiagnosticsEngine *Diags, const LangOptions &Features)
EncodeUCNEscape - Read the Universal Character Name, check constraints and convert the UTF32 to UTF8 ...
static unsigned ProcessCharEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, bool &HadError, FullSourceLoc Loc, unsigned CharWidth, DiagnosticsEngine *Diags, const LangOptions &Features)
ProcessCharEscape - Parse a standard C escape sequence, which can occur in either a character or a st...
static bool ProcessUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, FullSourceLoc Loc, DiagnosticsEngine *Diags, const LangOptions &Features, bool in_char_string_literal=false)
ProcessUCNEscape - Read the Universal Character Name, check constraints and return the UTF32.
static CharSourceRange MakeCharSourceRange(const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd)
static const char * resyncUTF8(const char *Err, const char *End)
static int MeasureUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, unsigned CharByteWidth, const LangOptions &Features, bool &HadError)
MeasureUCNEscape - Determine the number of bytes within the resulting string which this UCN will occu...
static void appendCodePoint(unsigned Codepoint, llvm::SmallVectorImpl< char > &Str)
static void DiagnoseInvalidUnicodeCharacterName(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc Loc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, llvm::StringRef Name)
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
static bool ProcessNumericUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, bool &Delimited, FullSourceLoc Loc, DiagnosticsEngine *Diags, const LangOptions &Features, bool in_char_string_literal=false)
static bool IsExponentPart(char c)
static bool ProcessNamedUCNEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, uint32_t &UcnVal, unsigned short &UcnLen, FullSourceLoc Loc, DiagnosticsEngine *Diags, const LangOptions &Features)
static bool alwaysFitsInto64Bits(unsigned Radix, unsigned NumDigits)
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
Defines the clang::Preprocessor interface.
Defines the clang::SourceLocation class and associated facilities.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
__device__ __2f16 float c
__device__ __2f16 float bool s
CharLiteralParser(const char *begin, const char *end, SourceLocation Loc, Preprocessor &PP, tok::TokenKind kind)
Represents a character-granular source range.
static CharSourceRange getCharRange(SourceRange R)
A little helper class used to produce diagnostics.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
A SourceLocation and its associated SourceManager.
const SourceManager & getManager() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
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...
bool isFixedPointLiteral() const
bool isFloatingLiteral() const
bool isIntegerLiteral() const
llvm::APFloat::opStatus GetFloatValue(llvm::APFloat &Result)
GetFloatValue - Convert this numeric literal to a floating value, using the specified APFloat fltSema...
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
bool GetIntegerValue(llvm::APInt &Val)
GetIntegerValue - Convert this numeric literal value to an APInt that matches Val's input width.
bool GetFixedPointValue(llvm::APInt &StoreVal, unsigned Scale)
GetFixedPointValue - Convert this numeric literal value into a scaled integer that represents this va...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
SourceManager & getSourceManager() const
const TargetInfo & getTargetInfo() const
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
unsigned getOffsetOfStringByte(const Token &TheTok, unsigned ByteNo) const
getOffsetOfStringByte - This function returns the offset of the specified byte of the string data rep...
unsigned GetStringLength() const
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
unsigned GetNumStringChars() const
StringLiteralParser(ArrayRef< Token > StringToks, Preprocessor &PP)
Exposes information about the current target.
unsigned getIntWidth() const
getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for this target,...
unsigned getWCharWidth() const
getWCharWidth/Align - Return the size of 'wchar_t' for this target, in bits.
unsigned getCharWidth() const
Token - This structure provides full information about a lexed token.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
Defines the clang::TargetInfo interface.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
LLVM_READONLY bool isVerticalWhitespace(unsigned char c)
Returns true if this character is vertical ASCII whitespace: '\n', '\r'.
LLVM_READONLY bool isPrintable(unsigned char c)
Return true if this character is an ASCII printable character; that is, a character that should take ...
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
LLVM_READONLY bool isPreprocessingNumberBody(unsigned char c)
Return true if this is the body character of a C preprocessing number, which is [a-zA-Z0-9_.
LLVM_READONLY bool isHexDigit(unsigned char c)
Return true if this character is an ASCII hex digit: [0-9a-fA-F].