23#include "llvm/ADT/APInt.h"
24#include "llvm/ADT/ScopeExit.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringExtras.h"
27#include "llvm/ADT/StringSwitch.h"
28#include "llvm/Support/ConvertUTF.h"
29#include "llvm/Support/Error.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/Unicode.h"
43 default: llvm_unreachable(
"Unknown token type!");
44 case tok::char_constant:
45 case tok::string_literal:
46 case tok::utf8_char_constant:
47 case tok::utf8_string_literal:
48 return Target.getCharWidth();
49 case tok::wide_char_constant:
50 case tok::wide_string_literal:
51 return Target.getWCharWidth();
52 case tok::utf16_char_constant:
53 case tok::utf16_string_literal:
54 return Target.getChar16Width();
55 case tok::utf32_char_constant:
56 case tok::utf32_string_literal:
57 return Target.getChar32Width();
64 llvm_unreachable(
"Unknown token type!");
65 case tok::char_constant:
66 case tok::string_literal:
68 case tok::utf8_char_constant:
69 case tok::utf8_string_literal:
71 case tok::wide_char_constant:
72 case tok::wide_string_literal:
73 case tok::utf16_char_constant:
74 case tok::utf16_string_literal:
75 case tok::utf32_char_constant:
76 case tok::utf32_string_literal:
84 const char *TokRangeBegin,
85 const char *TokRangeEnd) {
102 const char *TokBegin,
const char *TokRangeBegin,
103 const char *TokRangeEnd,
unsigned DiagID) {
132 const char *&ThisTokBuf,
133 const char *ThisTokEnd,
bool &HadError,
138 const char *EscapeBegin = ThisTokBuf;
139 bool Delimited =
false;
140 bool EndDelimiterFound =
false;
147 unsigned ResultChar = *ThisTokBuf++;
148 char Escape = ResultChar;
149 switch (ResultChar) {
151 case '\\':
case '\'':
case '"':
case '?':
break;
163 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
164 diag::ext_nonstandard_escape) <<
"e";
169 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
170 diag::ext_nonstandard_escape) <<
"E";
190 if (ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
193 if (*ThisTokBuf ==
'}') {
196 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
197 diag::err_delimited_escape_empty);
199 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
201 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
202 diag::err_hex_escape_no_digits) <<
"x";
207 bool Overflow =
false;
208 for (; ThisTokBuf != ThisTokEnd; ++ThisTokBuf) {
209 if (Delimited && *ThisTokBuf ==
'}') {
211 EndDelimiterFound =
true;
214 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
221 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
222 diag::err_delimited_escape_invalid)
223 << StringRef(ThisTokBuf, 1);
227 if (ResultChar & 0xF0000000)
230 ResultChar |= CharVal;
233 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
235 ResultChar &= ~0
U >> (32-CharWidth);
239 if (!HadError && Overflow) {
242 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
243 diag::err_escape_too_large)
248 case '0':
case '1':
case '2':
case '3':
249 case '4':
case '5':
case '6':
case '7': {
256 unsigned NumDigits = 0;
259 ResultChar |= *ThisTokBuf++ -
'0';
261 }
while (ThisTokBuf != ThisTokEnd && NumDigits < 3 &&
262 ThisTokBuf[0] >=
'0' && ThisTokBuf[0] <=
'7');
265 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
267 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
268 diag::err_escape_too_large) << 1;
269 ResultChar &= ~0
U >> (32-CharWidth);
274 bool Overflow =
false;
275 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
278 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
279 diag::err_delimited_escape_missing_brace)
287 if (*ThisTokBuf ==
'}') {
290 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
291 diag::err_delimited_escape_empty);
294 while (ThisTokBuf != ThisTokEnd) {
295 if (*ThisTokBuf ==
'}') {
296 EndDelimiterFound =
true;
300 if (*ThisTokBuf <
'0' || *ThisTokBuf >
'7') {
303 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
304 diag::err_delimited_escape_invalid)
305 << StringRef(ThisTokBuf, 1);
310 if (ResultChar & 0xE0000000)
314 ResultChar |= *ThisTokBuf++ -
'0';
318 (Overflow || (CharWidth != 32 && (ResultChar >> CharWidth) != 0))) {
321 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
322 diag::err_escape_too_large)
324 ResultChar &= ~0
U >> (32 - CharWidth);
329 case '(':
case '{':
case '[':
case '%':
332 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
333 diag::ext_nonstandard_escape)
334 << std::string(1, ResultChar);
341 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
342 diag::ext_unknown_escape)
343 << std::string(1, ResultChar);
345 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
346 diag::ext_unknown_escape)
347 <<
"x" + llvm::utohexstr(ResultChar);
351 if (Delimited && Diags) {
352 if (!EndDelimiterFound)
353 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
356 else if (!HadError) {
362 if (EvalMethod == StringLiteralEvalMethod::Unevaluated &&
364 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
365 diag::err_unevaluated_string_invalid_escape_sequence)
366 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin);
376 char *ResultPtr = ResultBuf;
377 if (llvm::ConvertCodePointToUTF8(Codepoint, ResultPtr))
378 Str.append(ResultBuf, ResultPtr);
382 for (StringRef::iterator I = Input.begin(),
E = Input.end(); I !=
E; ++I) {
392 assert(Kind ==
'u' || Kind ==
'U' || Kind ==
'N');
393 uint32_t CodePoint = 0;
395 if (Kind ==
'u' && *I ==
'{') {
396 for (++I; *I !=
'}'; ++I) {
397 unsigned Value = llvm::hexDigitValue(*I);
398 assert(
Value != -1U);
409 auto Delim = std::find(I, Input.end(),
'}');
410 assert(Delim != Input.end());
411 StringRef Name(I, std::distance(I, Delim));
412 std::optional<llvm::sys::unicode::LooseMatchingResult> Res =
413 llvm::sys::unicode::nameToCodepointLooseMatching(Name);
414 assert(Res &&
"could not find a codepoint that was previously found");
415 CodePoint = Res->CodePoint;
416 assert(CodePoint != 0xFFFFFFFF);
422 unsigned NumHexDigits;
428 assert(I + NumHexDigits <=
E);
430 for (; NumHexDigits != 0; ++I, --NumHexDigits) {
431 unsigned Value = llvm::hexDigitValue(*I);
432 assert(
Value != -1U);
445 return LO.MicrosoftExt &&
446 (K == tok::kw___FUNCTION__ || K == tok::kw_L__FUNCTION__ ||
447 K == tok::kw___FUNCSIG__ || K == tok::kw_L__FUNCSIG__ ||
448 K == tok::kw___FUNCDNAME__);
457 const char *&ThisTokBuf,
458 const char *ThisTokEnd, uint32_t &UcnVal,
459 unsigned short &UcnLen,
bool &Delimited,
462 bool in_char_string_literal =
false) {
463 const char *UcnBegin = ThisTokBuf;
464 bool HasError =
false;
465 bool EndDelimiterFound =
false;
470 if (UcnBegin[1] ==
'u' && in_char_string_literal &&
471 ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
474 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
476 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
477 diag::err_hex_escape_no_digits)
478 << StringRef(&ThisTokBuf[-1], 1);
481 UcnLen = (ThisTokBuf[-1] ==
'u' ? 4 : 8);
483 bool Overflow =
false;
484 unsigned short Count = 0;
485 for (; ThisTokBuf != ThisTokEnd && (Delimited || Count != UcnLen);
487 if (Delimited && *ThisTokBuf ==
'}') {
489 EndDelimiterFound =
true;
492 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
498 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
499 diag::err_delimited_escape_invalid)
500 << StringRef(ThisTokBuf, 1);
505 if (UcnVal & 0xF0000000) {
516 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
517 diag::err_escape_too_large)
522 if (Delimited && !EndDelimiterFound) {
524 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
532 if (Count == 0 || (!Delimited && Count != UcnLen)) {
534 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
535 Delimited ? diag::err_delimited_escape_empty
536 : diag::err_ucn_escape_incomplete);
544 const char *TokBegin,
const char *TokRangeBegin,
const char *TokRangeEnd,
545 llvm::StringRef Name) {
547 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
548 diag::err_invalid_ucn_name)
551 namespace u = llvm::sys::unicode;
553 std::optional<u::LooseMatchingResult> Res =
554 u::nameToCodepointLooseMatching(Name);
556 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
557 diag::note_invalid_ucn_name_loose_matching)
565 unsigned Distance = 0;
567 u::nearestMatchesForCodepointName(Name, 5);
568 assert(!Matches.empty() &&
"No unicode characters found");
570 for (
const auto &
Match : Matches) {
572 Distance =
Match.Distance;
573 if (std::max(Distance,
Match.Distance) -
574 std::min(Distance,
Match.Distance) >
577 Distance =
Match.Distance;
580 llvm::UTF32
V =
Match.Value;
584 assert(Converted &&
"Found a match wich is not a unicode character");
586 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
587 diag::note_invalid_ucn_name_candidate)
598 const char *&ThisTokBuf,
599 const char *ThisTokEnd, uint32_t &UcnVal,
603 const char *UcnBegin = ThisTokBuf;
604 assert(UcnBegin[0] ==
'\\' && UcnBegin[1] ==
'N');
606 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
608 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
609 diag::err_delimited_escape_missing_brace)
610 << StringRef(&ThisTokBuf[-1], 1);
615 const char *ClosingBrace = std::find_if(ThisTokBuf, ThisTokEnd, [](
char C) {
619 bool Empty = ClosingBrace == ThisTokBuf;
622 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
624 : diag::err_delimited_escape_empty)
625 << StringRef(&UcnBegin[1], 1);
627 ThisTokBuf = ClosingBrace == ThisTokEnd ? ClosingBrace : ClosingBrace + 1;
630 StringRef Name(ThisTokBuf, ClosingBrace - ThisTokBuf);
631 ThisTokBuf = ClosingBrace + 1;
632 std::optional<char32_t> Res = llvm::sys::unicode::nameToCodepointStrict(Name);
636 &UcnBegin[3], ClosingBrace, Name);
640 UcnLen = UcnVal > 0xFFFF ? 8 : 4;
647 const char *ThisTokEnd, uint32_t &UcnVal,
651 bool in_char_string_literal =
false) {
654 const char *UcnBegin = ThisTokBuf;
655 bool IsDelimitedEscapeSequence =
false;
656 bool IsNamedEscapeSequence =
false;
657 if (ThisTokBuf[1] ==
'N') {
658 IsNamedEscapeSequence =
true;
660 UcnVal, UcnLen,
Loc, Diags, Features);
664 UcnLen, IsDelimitedEscapeSequence,
Loc, Diags,
665 Features, in_char_string_literal);
671 if ((0xD800 <= UcnVal && UcnVal <= 0xDFFF) ||
674 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
675 diag::err_ucn_escape_invalid);
683 (UcnVal != 0x24 && UcnVal != 0x40 && UcnVal != 0x60)) {
685 (!(Features.CPlusPlus11 || Features.C23) || !in_char_string_literal);
687 char BasicSCSChar = UcnVal;
688 if (UcnVal >= 0x20 && UcnVal < 0x7f)
689 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
690 IsError ? diag::err_ucn_escape_basic_scs
692 ? diag::warn_cxx98_compat_literal_ucn_escape_basic_scs
693 : diag::warn_c23_compat_literal_ucn_escape_basic_scs)
694 << StringRef(&BasicSCSChar, 1);
696 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
697 IsError ? diag::err_ucn_control_character
699 ? diag::warn_cxx98_compat_literal_ucn_control_character
700 : diag::warn_c23_compat_literal_ucn_control_character);
706 if (!Features.CPlusPlus && !Features.C99 && Diags)
707 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
708 diag::warn_ucn_not_valid_in_c89_literal);
710 if ((IsDelimitedEscapeSequence || IsNamedEscapeSequence) && Diags)
719 const char *ThisTokEnd,
unsigned CharByteWidth,
722 if (CharByteWidth == 4)
726 unsigned short UcnLen = 0;
730 UcnLen,
Loc,
nullptr, Features,
true)) {
736 if (CharByteWidth == 2)
737 return UcnVal <= 0xFFFF ? 2 : 4;
744 if (UcnVal < 0x10000)
754 const char *ThisTokEnd,
755 char *&ResultBuf,
bool &HadError,
759 typedef uint32_t
UTF32;
761 unsigned short UcnLen = 0;
763 Loc, Diags, Features,
true)) {
768 assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
769 "only character widths of 1, 2, or 4 bytes supported");
772 assert((UcnLen== 4 || UcnLen== 8) &&
"only ucn length of 4 or 8 supported");
774 if (CharByteWidth == 4) {
777 llvm::UTF32 *ResultPtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf);
783 if (CharByteWidth == 2) {
786 llvm::UTF16 *ResultPtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf);
788 if (UcnVal <= (
UTF32)0xFFFF) {
796 *ResultPtr = 0xD800 + (UcnVal >> 10);
797 *(ResultPtr+1) = 0xDC00 + (UcnVal & 0x3FF);
802 assert(CharByteWidth == 1 &&
"UTF-8 encoding is only for 1 byte characters");
808 typedef uint8_t
UTF8;
810 unsigned short bytesToWrite = 0;
811 if (UcnVal < (
UTF32)0x80)
813 else if (UcnVal < (
UTF32)0x800)
815 else if (UcnVal < (
UTF32)0x10000)
820 const unsigned byteMask = 0xBF;
821 const unsigned byteMark = 0x80;
825 static const UTF8 firstByteMark[5] = {
826 0x00, 0x00, 0xC0, 0xE0, 0xF0
829 ResultBuf += bytesToWrite;
830 switch (bytesToWrite) {
832 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
835 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
838 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
841 *--ResultBuf = (
UTF8) (UcnVal | firstByteMark[bytesToWrite]);
844 ResultBuf += bytesToWrite;
904 :
SM(
SM), LangOpts(LangOpts), Diags(Diags),
905 ThisTokBegin(TokSpelling.begin()), ThisTokEnd(TokSpelling.end()) {
907 s = DigitsBegin = ThisTokBegin;
908 saw_exponent =
false;
910 saw_ud_suffix =
false;
911 saw_fixed_point_suffix =
false;
935 !(LangOpts.HLSL && *ThisTokEnd ==
'.')) {
936 Diags.
Report(TokLoc, diag::err_lexing_numeric);
942 ParseNumberStartingWithZero(TokLoc);
948 if (
s == ThisTokEnd) {
951 ParseDecimalOrOctalCommon(TokLoc);
958 checkSeparator(TokLoc,
s, CSK_AfterDigits);
961 if (LangOpts.FixedPoint) {
962 for (
const char *
c =
s;
c != ThisTokEnd; ++
c) {
963 if (*
c ==
'r' || *
c ==
'k' || *
c ==
'R' || *
c ==
'K') {
964 saw_fixed_point_suffix =
true;
974 bool HasSize =
false;
975 bool DoubleUnderscore =
false;
979 for (;
s != ThisTokEnd; ++
s) {
983 if (!LangOpts.FixedPoint)
986 if (!(saw_period || saw_exponent))
break;
991 if (!LangOpts.FixedPoint)
994 if (!(saw_period || saw_exponent))
break;
1000 if (!(LangOpts.Half || LangOpts.FixedPoint))
1010 if (!isFPConstant)
break;
1021 if ((
Target.hasFloat16Type() || LangOpts.CUDA ||
1022 (LangOpts.OpenMPIsTargetDevice &&
Target.getTriple().isNVPTX())) &&
1023 s + 2 < ThisTokEnd &&
s[1] ==
'1' &&
s[2] ==
'6') {
1033 if (!isFPConstant)
break;
1041 if (isFPConstant)
break;
1053 assert(
s + 1 < ThisTokEnd &&
"didn't maximally munch?");
1054 if (isFPConstant)
break;
1072 if (LangOpts.MicrosoftExt &&
s + 1 < ThisTokEnd && !isFPConstant) {
1083 if (
s + 2 < ThisTokEnd &&
s[2] ==
'6') {
1086 }
else if (
s + 3 < ThisTokEnd &&
s[2] ==
'2' &&
1093 if (
s + 2 < ThisTokEnd &&
s[2] ==
'2') {
1099 if (
s + 2 < ThisTokEnd &&
s[2] ==
'4') {
1113 assert(
s <= ThisTokEnd &&
"didn't maximally munch?");
1130 assert(!DoubleUnderscore &&
"unhandled double underscore case");
1131 if (LangOpts.CPlusPlus &&
s + 2 < ThisTokEnd &&
1134 DoubleUnderscore =
true;
1136 if (
s + 1 < ThisTokEnd &&
1137 (*
s ==
'u' || *
s ==
'U')) {
1141 if (
s + 1 < ThisTokEnd &&
1142 ((*
s ==
'w' && *(++
s) ==
'b') || (*
s ==
'W' && *(++
s) ==
'B'))) {
1160 if ((!LangOpts.CPlusPlus || DoubleUnderscore) &&
s + 1 < ThisTokEnd &&
1161 ((
s[0] ==
'w' &&
s[1] ==
'b') || (
s[0] ==
'W' &&
s[1] ==
'B'))) {
1175 expandUCNs(UDSuffixBuf, StringRef(SuffixBegin, ThisTokEnd - SuffixBegin));
1190 saw_fixed_point_suffix =
false;
1195 saw_ud_suffix =
true;
1199 if (
s != ThisTokEnd) {
1202 TokLoc, SuffixBegin - ThisTokBegin,
SM, LangOpts),
1203 diag::err_invalid_suffix_constant)
1204 << StringRef(SuffixBegin, ThisTokEnd - SuffixBegin)
1205 << (isFixedPointConstant ? 2 : isFPConstant);
1210 if (!
hadError && saw_fixed_point_suffix) {
1218void NumericLiteralParser::ParseDecimalOrOctalCommon(
SourceLocation TokLoc){
1219 assert((radix == 8 || radix == 10) &&
"Unexpected radix");
1227 diag::err_invalid_digit)
1228 << StringRef(
s, 1) << (radix == 8 ? 1 : 0);
1234 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1238 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1241 if (*
s ==
'e' || *
s ==
'E') {
1242 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1243 const char *Exponent =
s;
1246 saw_exponent =
true;
1247 if (
s != ThisTokEnd && (*
s ==
'+' || *
s ==
'-'))
s++;
1248 const char *first_non_digit = SkipDigits(
s);
1249 if (containsDigits(
s, first_non_digit)) {
1250 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1251 s = first_non_digit;
1255 TokLoc, Exponent - ThisTokBegin,
SM, LangOpts),
1256 diag::err_exponent_has_no_digits);
1269 if (!LangOpts.CPlusPlus11 || Suffix.empty())
1275 if (Suffix.starts_with(
"_") && !Suffix.starts_with(
"__"))
1279 if (!LangOpts.CPlusPlus14)
1285 return llvm::StringSwitch<bool>(Suffix)
1286 .Cases(
"h",
"min",
"s",
true)
1287 .Cases(
"ms",
"us",
"ns",
true)
1288 .Cases(
"il",
"i",
"if",
true)
1289 .Cases(
"d",
"y", LangOpts.CPlusPlus20)
1295 CheckSeparatorKind IsAfterDigits) {
1296 if (IsAfterDigits == CSK_AfterDigits) {
1297 if (Pos == ThisTokBegin)
1300 }
else if (Pos == ThisTokEnd)
1303 if (isDigitSeparator(*Pos)) {
1306 diag::err_digit_separator_not_between_digits)
1317void NumericLiteralParser::ParseNumberStartingWithZero(
SourceLocation TokLoc) {
1318 assert(
s[0] ==
'0' &&
"Invalid method call");
1324 if ((c1 ==
'x' || c1 ==
'X') && (
isHexDigit(
s[1]) ||
s[1] ==
'.')) {
1326 assert(
s < ThisTokEnd &&
"didn't maximally munch?");
1329 s = SkipHexDigits(
s);
1330 bool HasSignificandDigits = containsDigits(DigitsBegin,
s);
1331 if (
s == ThisTokEnd) {
1333 }
else if (*
s ==
'.') {
1336 const char *floatDigitsBegin =
s;
1337 s = SkipHexDigits(
s);
1338 if (containsDigits(floatDigitsBegin,
s))
1339 HasSignificandDigits =
true;
1340 if (HasSignificandDigits)
1341 checkSeparator(TokLoc, floatDigitsBegin, CSK_BeforeDigits);
1344 if (!HasSignificandDigits) {
1347 diag::err_hex_constant_requires)
1348 << LangOpts.CPlusPlus << 1;
1355 if (*
s ==
'p' || *
s ==
'P') {
1356 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1357 const char *Exponent =
s;
1359 saw_exponent =
true;
1360 if (
s != ThisTokEnd && (*
s ==
'+' || *
s ==
'-'))
s++;
1361 const char *first_non_digit = SkipDigits(
s);
1362 if (!containsDigits(
s, first_non_digit)) {
1365 TokLoc, Exponent - ThisTokBegin,
SM, LangOpts),
1366 diag::err_exponent_has_no_digits);
1371 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1372 s = first_non_digit;
1374 if (!LangOpts.HexFloats)
1375 Diags.
Report(TokLoc, LangOpts.CPlusPlus
1376 ? diag::ext_hex_literal_invalid
1377 : diag::ext_hex_constant_invalid);
1378 else if (LangOpts.CPlusPlus17)
1379 Diags.
Report(TokLoc, diag::warn_cxx17_hex_literal);
1380 }
else if (saw_period) {
1383 diag::err_hex_constant_requires)
1384 << LangOpts.CPlusPlus << 0;
1391 if ((c1 ==
'b' || c1 ==
'B') && (
s[1] ==
'0' ||
s[1] ==
'1')) {
1394 if (LangOpts.CPlusPlus14)
1395 DiagId = diag::warn_cxx11_compat_binary_literal;
1396 else if (LangOpts.C23)
1397 DiagId = diag::warn_c23_compat_binary_literal;
1398 else if (LangOpts.CPlusPlus)
1399 DiagId = diag::ext_binary_literal_cxx14;
1401 DiagId = diag::ext_binary_literal;
1402 Diags.
Report(TokLoc, DiagId);
1404 assert(
s < ThisTokEnd &&
"didn't maximally munch?");
1407 s = SkipBinaryDigits(
s);
1408 if (
s == ThisTokEnd) {
1414 diag::err_invalid_digit)
1415 << StringRef(
s, 1) << 2;
1423 bool IsSingleZero =
false;
1424 if ((c1 ==
'O' || c1 ==
'o') && (
s[1] >=
'0' &&
s[1] <=
'7')) {
1427 DiagId = diag::warn_c2y_compat_octal_literal;
1428 else if (LangOpts.CPlusPlus)
1429 DiagId = diag::ext_cpp_octal_literal;
1431 DiagId = diag::ext_octal_literal;
1432 Diags.
Report(TokLoc, DiagId);
1436 s = SkipOctalDigits(
s);
1437 if (
s == ThisTokEnd) {
1439 }
else if ((
isHexDigit(*
s) && *
s !=
'e' && *
s !=
'E' && *
s !=
'.') &&
1442 TokLoc,
s - ThisTokBegin,
SM, LangOpts);
1443 Diags.
Report(InvalidDigitLoc, diag::err_invalid_digit)
1444 << StringRef(
s, 1) << 1;
1451 auto _ = llvm::make_scope_exit([&] {
1454 if (radix == 8 && LangOpts.C2y && !
hadError && !IsSingleZero)
1455 Diags.
Report(TokLoc, diag::warn_unprefixed_octal_deprecated);
1462 const char *PossibleNewDigitStart =
s;
1463 s = SkipOctalDigits(
s);
1467 if (
s != PossibleNewDigitStart)
1468 DigitsBegin = PossibleNewDigitStart;
1470 IsSingleZero = (
s == ThisTokBegin + 1);
1472 if (
s == ThisTokEnd)
1478 const char *EndDecimal = SkipDigits(
s);
1479 if (EndDecimal[0] ==
'.' || EndDecimal[0] ==
'e' || EndDecimal[0] ==
'E') {
1485 ParseDecimalOrOctalCommon(TokLoc);
1491 return NumDigits <= 64;
1493 return NumDigits <= 64 / 3;
1495 return NumDigits <= 19;
1497 return NumDigits <= 64 / 4;
1499 llvm_unreachable(
"impossible Radix");
1513 const unsigned NumDigits = SuffixBegin - DigitsBegin;
1516 for (
const char *Ptr = DigitsBegin; Ptr != SuffixBegin; ++Ptr)
1517 if (!isDigitSeparator(*Ptr))
1518 N = N * radix + llvm::hexDigitValue(*Ptr);
1523 return Val.getZExtValue() != N;
1527 const char *Ptr = DigitsBegin;
1529 llvm::APInt RadixVal(Val.getBitWidth(), radix);
1530 llvm::APInt CharVal(Val.getBitWidth(), 0);
1531 llvm::APInt OldVal = Val;
1533 bool OverflowOccurred =
false;
1534 while (Ptr < SuffixBegin) {
1535 if (isDigitSeparator(*Ptr)) {
1540 unsigned C = llvm::hexDigitValue(*Ptr++);
1543 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1553 OverflowOccurred |= Val.udiv(RadixVal) != OldVal;
1558 OverflowOccurred |= Val.ult(CharVal);
1560 return OverflowOccurred;
1563llvm::APFloat::opStatus
1565 llvm::RoundingMode RM) {
1566 using llvm::APFloat;
1568 unsigned n = std::min(SuffixBegin - ThisTokBegin, ThisTokEnd - ThisTokBegin);
1571 StringRef Str(ThisTokBegin, n);
1572 if (Str.contains(
'\'')) {
1574 std::remove_copy_if(Str.begin(), Str.end(), std::back_inserter(Buffer),
1579 auto StatusOrErr =
Result.convertFromString(Str, RM);
1580 assert(StatusOrErr &&
"Invalid floating point representation");
1581 return !errorToBool(StatusOrErr.takeError()) ? *StatusOrErr
1582 : APFloat::opInvalidOp;
1587 return c ==
'p' ||
c ==
'P';
1588 return c ==
'e' ||
c ==
'E';
1592 assert(radix == 16 || radix == 10);
1595 unsigned NumDigits = SuffixBegin - DigitsBegin;
1596 if (saw_period) --NumDigits;
1599 bool ExpOverflowOccurred =
false;
1600 bool NegativeExponent =
false;
1601 const char *ExponentBegin;
1602 uint64_t Exponent = 0;
1603 int64_t BaseShift = 0;
1605 const char *Ptr = DigitsBegin;
1609 ExponentBegin = Ptr;
1611 NegativeExponent = *Ptr ==
'-';
1612 if (NegativeExponent) ++Ptr;
1614 unsigned NumExpDigits = SuffixBegin - Ptr;
1616 llvm::StringRef ExpStr(Ptr, NumExpDigits);
1617 llvm::APInt ExpInt(64, ExpStr, 10);
1618 Exponent = ExpInt.getZExtValue();
1620 ExpOverflowOccurred =
true;
1623 if (NegativeExponent) BaseShift -= Exponent;
1624 else BaseShift += Exponent;
1644 uint64_t NumBitsNeeded;
1646 NumBitsNeeded = 4 * (NumDigits + Exponent) + Scale;
1648 NumBitsNeeded = 4 * NumDigits + Exponent + Scale;
1650 if (NumBitsNeeded > std::numeric_limits<unsigned>::max())
1651 ExpOverflowOccurred =
true;
1652 llvm::APInt Val(
static_cast<unsigned>(NumBitsNeeded), 0,
false);
1654 bool FoundDecimal =
false;
1656 int64_t FractBaseShift = 0;
1657 const char *End = saw_exponent ? ExponentBegin : SuffixBegin;
1658 for (
const char *Ptr = DigitsBegin; Ptr < End; ++Ptr) {
1660 FoundDecimal =
true;
1665 unsigned C = llvm::hexDigitValue(*Ptr);
1666 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1678 if (radix == 16) FractBaseShift *= 4;
1679 BaseShift += FractBaseShift;
1683 uint64_t
Base = (radix == 16) ? 2 : 10;
1684 if (BaseShift > 0) {
1685 for (int64_t i = 0; i < BaseShift; ++i) {
1688 }
else if (BaseShift < 0) {
1689 for (int64_t i = BaseShift; i < 0 && !Val.isZero(); ++i)
1690 Val = Val.udiv(
Base);
1693 bool IntOverflowOccurred =
false;
1694 auto MaxVal = llvm::APInt::getMaxValue(StoreVal.getBitWidth());
1695 if (Val.getBitWidth() > StoreVal.getBitWidth()) {
1696 IntOverflowOccurred |= Val.ugt(MaxVal.zext(Val.getBitWidth()));
1697 StoreVal = Val.trunc(StoreVal.getBitWidth());
1698 }
else if (Val.getBitWidth() < StoreVal.getBitWidth()) {
1699 IntOverflowOccurred |= Val.zext(MaxVal.getBitWidth()).ugt(MaxVal);
1700 StoreVal = Val.zext(StoreVal.getBitWidth());
1705 return IntOverflowOccurred || ExpOverflowOccurred;
1755 const char *TokBegin = begin;
1758 if (
Kind != tok::char_constant)
1760 if (
Kind == tok::utf8_char_constant)
1764 if (begin[0] !=
'\'') {
1765 PP.
Diag(
Loc, diag::err_lexing_char);
1773 if (end[-1] !=
'\'') {
1774 const char *UDSuffixEnd = end;
1777 }
while (end[-1] !=
'\'');
1779 expandUCNs(UDSuffixBuf, StringRef(end, UDSuffixEnd - end));
1780 UDSuffixOffset = end - TokBegin;
1784 assert(end != begin &&
"Invalid token lexed");
1791 "Assumes char is 8 bits");
1794 "Assumes sizeof(int) on target is <= 64 and a multiple of char");
1796 "Assumes sizeof(wchar) on target is <= 64");
1799 codepoint_buffer.resize(end - begin);
1800 uint32_t *buffer_begin = &codepoint_buffer.front();
1801 uint32_t *buffer_end = buffer_begin + codepoint_buffer.size();
1806 uint32_t largest_character_for_kind;
1807 if (tok::wide_char_constant ==
Kind) {
1808 largest_character_for_kind =
1810 }
else if (tok::utf8_char_constant ==
Kind) {
1811 largest_character_for_kind = 0x7F;
1812 }
else if (tok::utf16_char_constant ==
Kind) {
1813 largest_character_for_kind = 0xFFFF;
1814 }
else if (tok::utf32_char_constant ==
Kind) {
1815 largest_character_for_kind = 0x10FFFF;
1817 largest_character_for_kind = 0x7Fu;
1820 while (begin != end) {
1822 if (begin[0] !=
'\\') {
1823 char const *start = begin;
1826 }
while (begin != end && *begin !=
'\\');
1828 char const *tmp_in_start = start;
1829 uint32_t *tmp_out_start = buffer_begin;
1830 llvm::ConversionResult res =
1831 llvm::ConvertUTF8toUTF32(
reinterpret_cast<llvm::UTF8
const **
>(&start),
1832 reinterpret_cast<llvm::UTF8
const *
>(begin),
1833 &buffer_begin, buffer_end, llvm::strictConversion);
1834 if (res != llvm::conversionOK) {
1839 unsigned Msg = diag::err_bad_character_encoding;
1840 if (NoErrorOnBadEncoding)
1841 Msg = diag::warn_bad_character_encoding;
1843 if (NoErrorOnBadEncoding) {
1844 start = tmp_in_start;
1845 buffer_begin = tmp_out_start;
1846 for (; start != begin; ++start, ++buffer_begin)
1847 *buffer_begin =
static_cast<uint8_t
>(*start);
1852 for (; tmp_out_start < buffer_begin; ++tmp_out_start) {
1853 if (*tmp_out_start > largest_character_for_kind) {
1855 PP.
Diag(
Loc, diag::err_character_too_large);
1863 if (begin[1] ==
'u' || begin[1] ==
'U' || begin[1] ==
'N') {
1864 unsigned short UcnLen = 0;
1869 }
else if (*buffer_begin > largest_character_for_kind) {
1871 PP.
Diag(
Loc, diag::err_character_too_large);
1883 *buffer_begin++ = result;
1886 unsigned NumCharsSoFar = buffer_begin - &codepoint_buffer.front();
1888 if (NumCharsSoFar > 1) {
1890 PP.
Diag(
Loc, diag::warn_four_char_character_literal);
1892 PP.
Diag(
Loc, diag::warn_multichar_character_literal);
1894 PP.
Diag(
Loc, diag::err_multichar_character_literal) << (
isWide() ? 0 : 1);
1899 IsMultiChar =
false;
1906 bool multi_char_too_long =
false;
1909 for (
size_t i = 0; i < NumCharsSoFar; ++i) {
1911 multi_char_too_long |= (LitVal.countl_zero() < 8);
1913 LitVal = LitVal + (codepoint_buffer[i] & 0xFF);
1915 }
else if (NumCharsSoFar > 0) {
1917 LitVal = buffer_begin[-1];
1920 if (!HadError && multi_char_too_long) {
1921 PP.
Diag(
Loc, diag::warn_char_constant_too_large);
1925 Value = LitVal.getZExtValue();
1993 :
SM(PP.getSourceManager()), Features(PP.getLangOpts()),
1994 Target(PP.getTargetInfo()), Diags(&PP.getDiagnostics()),
1995 MaxTokenLength(0), SizeBound(0), CharByteWidth(0),
Kind(tok::unknown),
1996 ResultPtr(ResultBuf.data()), EvalMethod(EvalMethod), hadError(
false),
2004 if (StringToks.empty() || StringToks[0].getLength() < 2)
2011 assert(!StringToks.empty() &&
"expected at least one token");
2012 MaxTokenLength = StringToks[0].getLength();
2013 assert(StringToks[0].getLength() >= 2 &&
"literal token is invalid!");
2014 SizeBound = StringToks[0].getLength() - 2;
2018 Kind = tok::string_literal;
2021 for (
const Token &Tok : StringToks) {
2022 if (Tok.getLength() < 2)
2023 return DiagnoseLexingError(Tok.getLocation());
2027 assert(Tok.getLength() >= 2 &&
"literal token is invalid!");
2028 SizeBound += Tok.getLength() - 2;
2031 if (Tok.getLength() > MaxTokenLength)
2032 MaxTokenLength = Tok.getLength();
2036 if (
isUnevaluated() && Tok.getKind() != tok::string_literal) {
2043 StringRef Prefix(
SM.getCharacterData(Tok.getLocation()),
2045 Diags->
Report(Tok.getLocation(),
2046 Features.CPlusPlus26
2047 ? diag::err_unevaluated_string_prefix
2048 : diag::warn_unevaluated_string_prefix)
2051 if (Features.CPlusPlus26)
2053 }
else if (Tok.isNot(
Kind) && Tok.isNot(tok::string_literal)) {
2055 Kind = Tok.getKind();
2058 Diags->
Report(Tok.getLocation(), diag::err_unsupported_string_concat);
2071 assert((CharByteWidth & 7) == 0 &&
"Assumes character size is byte multiple");
2076 SizeBound *= CharByteWidth;
2079 ResultBuf.resize(SizeBound);
2083 TokenBuf.resize(MaxTokenLength);
2087 ResultPtr = &ResultBuf[0];
2093 for (
unsigned i = 0, e = StringToks.size(); i != e; ++i) {
2094 const char *ThisTokBuf = &TokenBuf[0];
2098 bool StringInvalid =
false;
2099 unsigned ThisTokLen =
2103 return DiagnoseLexingError(StringToks[i].getLocation());
2105 const char *ThisTokBegin = ThisTokBuf;
2106 const char *ThisTokEnd = ThisTokBuf+ThisTokLen;
2109 if (ThisTokEnd[-1] !=
'"') {
2110 const char *UDSuffixEnd = ThisTokEnd;
2113 }
while (ThisTokEnd[-1] !=
'"');
2115 StringRef UDSuffix(ThisTokEnd, UDSuffixEnd - ThisTokEnd);
2117 if (UDSuffixBuf.empty()) {
2118 if (StringToks[i].hasUCN())
2121 UDSuffixBuf.assign(UDSuffix);
2123 UDSuffixOffset = ThisTokEnd - ThisTokBuf;
2124 UDSuffixTokLoc = StringToks[i].getLocation();
2127 if (StringToks[i].hasUCN()) {
2129 UDSuffix = ExpandedUDSuffix;
2136 bool UnevaluatedStringHasUDL =
isUnevaluated() && !UDSuffix.empty();
2137 if (UDSuffixBuf != UDSuffix || UnevaluatedStringHasUDL) {
2140 if (UnevaluatedStringHasUDL) {
2141 Diags->
Report(TokLoc, diag::err_unevaluated_string_udl)
2144 Diags->
Report(TokLoc, diag::err_string_concat_mixed_suffix)
2145 << UDSuffixBuf << UDSuffix
2160 if (ThisTokBuf[0] ==
'L' || ThisTokBuf[0] ==
'u' || ThisTokBuf[0] ==
'U') {
2163 if (ThisTokBuf[0] ==
'8')
2168 if (ThisTokBuf[0] ==
'R') {
2169 if (ThisTokBuf[1] !=
'"') {
2172 return DiagnoseLexingError(StringToks[i].getLocation());
2178 constexpr unsigned MaxRawStrDelimLen = 16;
2180 const char *Prefix = ThisTokBuf;
2181 while (
static_cast<unsigned>(ThisTokBuf - Prefix) < MaxRawStrDelimLen &&
2182 ThisTokBuf[0] !=
'(')
2184 if (ThisTokBuf[0] !=
'(')
2185 return DiagnoseLexingError(StringToks[i].getLocation());
2189 ThisTokEnd -= ThisTokBuf - Prefix;
2190 if (ThisTokEnd < ThisTokBuf)
2191 return DiagnoseLexingError(StringToks[i].getLocation());
2195 StringRef RemainingTokenSpan(ThisTokBuf, ThisTokEnd - ThisTokBuf);
2196 while (!RemainingTokenSpan.empty()) {
2198 size_t CRLFPos = RemainingTokenSpan.find(
"\r\n");
2199 StringRef BeforeCRLF = RemainingTokenSpan.substr(0, CRLFPos);
2200 StringRef AfterCRLF = RemainingTokenSpan.substr(CRLFPos);
2203 if (CopyStringFragment(StringToks[i], ThisTokBegin, BeforeCRLF))
2208 RemainingTokenSpan = AfterCRLF.substr(1);
2211 if (ThisTokBuf[0] !=
'"') {
2214 return DiagnoseLexingError(StringToks[i].getLocation());
2220 ThisTokBuf + 1 != ThisTokEnd && ThisTokBuf[0] ==
'\\' &&
2221 ThisTokBuf[1] ==
'p') {
2232 while (ThisTokBuf != ThisTokEnd) {
2234 if (ThisTokBuf[0] !=
'\\') {
2235 const char *InStart = ThisTokBuf;
2238 }
while (ThisTokBuf != ThisTokEnd && ThisTokBuf[0] !=
'\\');
2241 if (CopyStringFragment(StringToks[i], ThisTokBegin,
2242 StringRef(InStart, ThisTokBuf - InStart)))
2247 if (ThisTokBuf[1] ==
'u' || ThisTokBuf[1] ==
'U' ||
2248 ThisTokBuf[1] ==
'N') {
2252 CharByteWidth, Diags, Features);
2256 unsigned ResultChar =
2259 CharByteWidth * 8, Diags, Features, EvalMethod);
2261 if (CharByteWidth == 4) {
2264 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultPtr);
2265 *ResultWidePtr = ResultChar;
2267 }
else if (CharByteWidth == 2) {
2270 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultPtr);
2271 *ResultWidePtr = ResultChar & 0xFFFF;
2274 assert(CharByteWidth == 1 &&
"Unexpected char width");
2275 *ResultPtr++ = ResultChar & 0xFF;
2282 "Pascal string in unevaluated context");
2284 if (CharByteWidth == 4) {
2287 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf.data());
2289 }
else if (CharByteWidth == 2) {
2292 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf.data());
2295 assert(CharByteWidth == 1 &&
"Unexpected char width");
2302 Diags->
Report(StringToks.front().getLocation(),
2303 diag::err_pascal_string_too_long)
2305 StringToks.back().getLocation());
2311 unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
2314 Diags->
Report(StringToks.front().getLocation(),
2315 diag::ext_string_too_long)
2317 << (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
2319 StringToks.back().getLocation());
2326 End = Err + std::min<unsigned>(llvm::getNumBytesForUTF8(*Err), End-Err);
2327 while (++Err != End && (*Err & 0xC0) == 0x80)
2335bool StringLiteralParser::CopyStringFragment(
const Token &Tok,
2336 const char *TokBegin,
2337 StringRef Fragment) {
2338 const llvm::UTF8 *ErrorPtrTmp;
2339 if (ConvertUTF8toWide(CharByteWidth, Fragment, ResultPtr, ErrorPtrTmp))
2346 if (NoErrorOnBadEncoding) {
2347 memcpy(ResultPtr, Fragment.data(), Fragment.size());
2348 ResultPtr += Fragment.size();
2352 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2356 Diag(Diags, Features, SourceLoc, TokBegin,
2357 ErrorPtr,
resyncUTF8(ErrorPtr, Fragment.end()),
2358 NoErrorOnBadEncoding ? diag::warn_bad_string_encoding
2359 : diag::err_bad_string_encoding);
2361 const char *NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2362 StringRef NextFragment(NextStart, Fragment.end()-NextStart);
2366 Dummy.reserve(Fragment.size() * CharByteWidth);
2367 char *Ptr = Dummy.data();
2369 while (!ConvertUTF8toWide(CharByteWidth, NextFragment, Ptr, ErrorPtrTmp)) {
2370 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2371 NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2373 ErrorPtr, NextStart);
2374 NextFragment = StringRef(NextStart, Fragment.end()-NextStart);
2377 return !NoErrorOnBadEncoding;
2383 Diags->
Report(
Loc, diag::err_lexing_string);
2390 unsigned ByteNo)
const {
2395 bool StringInvalid =
false;
2396 const char *SpellingPtr = &SpellingBuffer[0];
2402 const char *SpellingStart = SpellingPtr;
2403 const char *SpellingEnd = SpellingPtr+TokLen;
2406 if (SpellingPtr[0] ==
'u' && SpellingPtr[1] ==
'8')
2409 assert(SpellingPtr[0] !=
'L' && SpellingPtr[0] !=
'u' &&
2410 SpellingPtr[0] !=
'U' &&
"Doesn't handle wide or utf strings yet");
2413 if (SpellingPtr[0] ==
'R') {
2414 assert(SpellingPtr[1] ==
'"' &&
"Should be a raw string literal!");
2417 while (*SpellingPtr !=
'(') {
2419 assert(SpellingPtr < SpellingEnd &&
"Missing ( for raw string literal");
2423 return SpellingPtr - SpellingStart + ByteNo;
2427 assert(SpellingPtr[0] ==
'"' &&
"Should be a string literal!");
2432 assert(SpellingPtr < SpellingEnd &&
"Didn't find byte offset!");
2435 if (*SpellingPtr !=
'\\') {
2442 bool HadError =
false;
2443 if (SpellingPtr[1] ==
'u' || SpellingPtr[1] ==
'U' ||
2444 SpellingPtr[1] ==
'N') {
2445 const char *EscapePtr = SpellingPtr;
2447 1, Features, HadError);
2450 SpellingPtr = EscapePtr;
2460 assert(!HadError &&
"This method isn't valid on erroneous strings");
2463 return SpellingPtr-SpellingStart;
enum clang::sema::@1840::IndirectLocalPathEntry::EntryKind Kind
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 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 unsigned getEncodingPrefixLen(tok::TokenKind kind)
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 IsEscapeValidInUnevaluatedStringLiteral(char Escape)
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 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 IsExponentPart(char c, bool isHex)
static bool alwaysFitsInto64Bits(unsigned Radix, unsigned NumDigits)
static unsigned ProcessCharEscape(const char *ThisTokBegin, const char *&ThisTokBuf, const char *ThisTokEnd, bool &HadError, FullSourceLoc Loc, unsigned CharWidth, DiagnosticsEngine *Diags, const LangOptions &Features, StringLiteralEvalMethod EvalMethod)
ProcessCharEscape - Parse a standard C escape sequence, which can occur in either a character or a st...
static unsigned getCharWidth(tok::TokenKind kind, const TargetInfo &Target)
llvm::MachO::Target 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 __ockl_bool s
__device__ __2f16 float c
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.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
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 void DiagnoseDelimitedOrNamedEscapeSequence(SourceLocation Loc, bool Named, const LangOptions &Opts, DiagnosticsEngine &Diags)
Diagnose use of a delimited or named escape sequence.
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, llvm::RoundingMode RM)
Convert this numeric literal to a floating value, using the specified APFloat fltSemantics (specifyin...
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...
bool isUnevaluated() const
StringLiteralParser(ArrayRef< Token > StringToks, Preprocessor &PP, StringLiteralEvalMethod StringMethod=StringLiteralEvalMethod::Evaluated)
unsigned GetStringLength() const
static bool isValidUDSuffix(const LangOptions &LangOpts, StringRef Suffix)
Determine whether a suffix is a valid ud-suffix.
unsigned GetNumStringChars() const
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
tok::TokenKind getKind() const
Defines the clang::TargetInfo interface.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
The JSON file list parser is used to communicate input to InstallAPI.
@ Match
This is not an overload because the signature exactly matches an existing declaration.
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.
bool tokenIsLikeStringLiteral(const Token &Tok, const LangOptions &LO)
Return true if the token is a string literal, or a function local predefined macro,...
@ 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].
bool isFunctionLocalStringLiteralMacro(tok::TokenKind K, const LangOptions &LO)
Return true if the token corresponds to a function local predefined macro, which expands to a string ...
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].
@ Incomplete
Template argument deduction did not deduce a value for every template parameter.