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 llvm_unreachable(
"Unknown token type!");
64 case tok::char_constant:
65 case tok::string_literal:
67 case tok::utf8_char_constant:
68 case tok::utf8_string_literal:
70 case tok::wide_char_constant:
71 case tok::wide_string_literal:
72 case tok::utf16_char_constant:
73 case tok::utf16_string_literal:
74 case tok::utf32_char_constant:
75 case tok::utf32_string_literal:
83 const char *TokRangeBegin,
84 const char *TokRangeEnd) {
101 const char *TokBegin,
const char *TokRangeBegin,
102 const char *TokRangeEnd,
unsigned DiagID) {
131 const char *&ThisTokBuf,
132 const char *ThisTokEnd,
bool &HadError,
137 const char *EscapeBegin = ThisTokBuf;
138 bool Delimited =
false;
139 bool EndDelimiterFound =
false;
146 unsigned ResultChar = *ThisTokBuf++;
147 char Escape = ResultChar;
148 switch (ResultChar) {
150 case '\\':
case '\'':
case '"':
case '?':
break;
162 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
163 diag::ext_nonstandard_escape) <<
"e";
168 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
169 diag::ext_nonstandard_escape) <<
"E";
189 if (ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
192 if (*ThisTokBuf ==
'}') {
195 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
196 diag::err_delimited_escape_empty);
198 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
200 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
201 diag::err_hex_escape_no_digits) <<
"x";
206 bool Overflow =
false;
207 for (; ThisTokBuf != ThisTokEnd; ++ThisTokBuf) {
208 if (Delimited && *ThisTokBuf ==
'}') {
210 EndDelimiterFound =
true;
213 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
220 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
221 diag::err_delimited_escape_invalid)
222 << StringRef(ThisTokBuf, 1);
226 if (ResultChar & 0xF0000000)
229 ResultChar |= CharVal;
232 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
234 ResultChar &= ~0
U >> (32-CharWidth);
238 if (!HadError && Overflow) {
241 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
242 diag::err_escape_too_large)
247 case '0':
case '1':
case '2':
case '3':
248 case '4':
case '5':
case '6':
case '7': {
255 unsigned NumDigits = 0;
258 ResultChar |= *ThisTokBuf++ -
'0';
260 }
while (ThisTokBuf != ThisTokEnd && NumDigits < 3 &&
261 ThisTokBuf[0] >=
'0' && ThisTokBuf[0] <=
'7');
264 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
266 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
267 diag::err_escape_too_large) << 1;
268 ResultChar &= ~0
U >> (32-CharWidth);
273 bool Overflow =
false;
274 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
277 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
278 diag::err_delimited_escape_missing_brace)
286 if (*ThisTokBuf ==
'}') {
289 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
290 diag::err_delimited_escape_empty);
293 while (ThisTokBuf != ThisTokEnd) {
294 if (*ThisTokBuf ==
'}') {
295 EndDelimiterFound =
true;
299 if (*ThisTokBuf <
'0' || *ThisTokBuf >
'7') {
302 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
303 diag::err_delimited_escape_invalid)
304 << StringRef(ThisTokBuf, 1);
309 if (ResultChar & 0xE0000000)
313 ResultChar |= *ThisTokBuf++ -
'0';
317 (Overflow || (CharWidth != 32 && (ResultChar >> CharWidth) != 0))) {
320 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
321 diag::err_escape_too_large)
323 ResultChar &= ~0
U >> (32 - CharWidth);
328 case '(':
case '{':
case '[':
case '%':
331 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
332 diag::ext_nonstandard_escape)
333 << std::string(1, ResultChar);
340 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
341 diag::ext_unknown_escape)
342 << std::string(1, ResultChar);
344 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
345 diag::ext_unknown_escape)
346 <<
"x" + llvm::utohexstr(ResultChar);
350 if (Delimited && Diags) {
351 if (!EndDelimiterFound)
352 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
355 else if (!HadError) {
356 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
357 Features.CPlusPlus23 ? diag::warn_cxx23_delimited_escape_sequence
358 : diag::ext_delimited_escape_sequence)
359 << 0 << (Features.CPlusPlus ? 1 : 0);
363 if (EvalMethod == StringLiteralEvalMethod::Unevaluated &&
365 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
366 diag::err_unevaluated_string_invalid_escape_sequence)
367 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin);
377 char *ResultPtr = ResultBuf;
378 if (llvm::ConvertCodePointToUTF8(Codepoint, ResultPtr))
379 Str.append(ResultBuf, ResultPtr);
383 for (StringRef::iterator I = Input.begin(),
E = Input.end(); I !=
E; ++I) {
393 assert(Kind ==
'u' || Kind ==
'U' || Kind ==
'N');
394 uint32_t CodePoint = 0;
396 if (Kind ==
'u' && *I ==
'{') {
397 for (++I; *I !=
'}'; ++I) {
398 unsigned Value = llvm::hexDigitValue(*I);
399 assert(
Value != -1U);
410 auto Delim = std::find(I, Input.end(),
'}');
411 assert(Delim != Input.end());
412 StringRef Name(I, std::distance(I, Delim));
413 std::optional<llvm::sys::unicode::LooseMatchingResult> Res =
414 llvm::sys::unicode::nameToCodepointLooseMatching(Name);
415 assert(Res &&
"could not find a codepoint that was previously found");
416 CodePoint = Res->CodePoint;
417 assert(CodePoint != 0xFFFFFFFF);
423 unsigned NumHexDigits;
429 assert(I + NumHexDigits <=
E);
431 for (; NumHexDigits != 0; ++I, --NumHexDigits) {
432 unsigned Value = llvm::hexDigitValue(*I);
433 assert(
Value != -1U);
446 return LO.MicrosoftExt &&
447 (K == tok::kw___FUNCTION__ || K == tok::kw_L__FUNCTION__ ||
448 K == tok::kw___FUNCSIG__ || K == tok::kw_L__FUNCSIG__ ||
449 K == tok::kw___FUNCDNAME__);
458 const char *&ThisTokBuf,
459 const char *ThisTokEnd, uint32_t &UcnVal,
460 unsigned short &UcnLen,
bool &Delimited,
463 bool in_char_string_literal =
false) {
464 const char *UcnBegin = ThisTokBuf;
465 bool HasError =
false;
466 bool EndDelimiterFound =
false;
471 if (UcnBegin[1] ==
'u' && in_char_string_literal &&
472 ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
475 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
477 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
478 diag::err_hex_escape_no_digits)
479 << StringRef(&ThisTokBuf[-1], 1);
482 UcnLen = (ThisTokBuf[-1] ==
'u' ? 4 : 8);
484 bool Overflow =
false;
485 unsigned short Count = 0;
486 for (; ThisTokBuf != ThisTokEnd && (Delimited || Count != UcnLen);
488 if (Delimited && *ThisTokBuf ==
'}') {
490 EndDelimiterFound =
true;
493 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
499 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
500 diag::err_delimited_escape_invalid)
501 << StringRef(ThisTokBuf, 1);
506 if (UcnVal & 0xF0000000) {
517 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
518 diag::err_escape_too_large)
523 if (Delimited && !EndDelimiterFound) {
525 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
533 if (Count == 0 || (!Delimited && Count != UcnLen)) {
535 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
536 Delimited ? diag::err_delimited_escape_empty
537 : diag::err_ucn_escape_incomplete);
545 const char *TokBegin,
const char *TokRangeBegin,
const char *TokRangeEnd,
546 llvm::StringRef Name) {
548 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
549 diag::err_invalid_ucn_name)
552 namespace u = llvm::sys::unicode;
554 std::optional<u::LooseMatchingResult> Res =
555 u::nameToCodepointLooseMatching(Name);
557 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
558 diag::note_invalid_ucn_name_loose_matching)
566 unsigned Distance = 0;
568 u::nearestMatchesForCodepointName(Name, 5);
569 assert(!Matches.empty() &&
"No unicode characters found");
571 for (
const auto &Match : Matches) {
573 Distance = Match.Distance;
574 if (std::max(Distance, Match.Distance) -
575 std::min(Distance, Match.Distance) >
578 Distance = Match.Distance;
581 llvm::UTF32
V = Match.Value;
585 assert(Converted &&
"Found a match wich is not a unicode character");
587 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
588 diag::note_invalid_ucn_name_candidate)
589 << Match.Name << llvm::utohexstr(Match.Value)
599 const char *&ThisTokBuf,
600 const char *ThisTokEnd, uint32_t &UcnVal,
604 const char *UcnBegin = ThisTokBuf;
605 assert(UcnBegin[0] ==
'\\' && UcnBegin[1] ==
'N');
607 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
609 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
610 diag::err_delimited_escape_missing_brace)
611 << StringRef(&ThisTokBuf[-1], 1);
616 const char *ClosingBrace = std::find_if(ThisTokBuf, ThisTokEnd, [](
char C) {
620 bool Empty = ClosingBrace == ThisTokBuf;
623 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
625 : diag::err_delimited_escape_empty)
626 << StringRef(&UcnBegin[1], 1);
628 ThisTokBuf = ClosingBrace == ThisTokEnd ? ClosingBrace : ClosingBrace + 1;
631 StringRef Name(ThisTokBuf, ClosingBrace - ThisTokBuf);
632 ThisTokBuf = ClosingBrace + 1;
633 std::optional<char32_t> Res = llvm::sys::unicode::nameToCodepointStrict(Name);
637 &UcnBegin[3], ClosingBrace, Name);
641 UcnLen = UcnVal > 0xFFFF ? 8 : 4;
648 const char *ThisTokEnd, uint32_t &UcnVal,
652 bool in_char_string_literal =
false) {
655 const char *UcnBegin = ThisTokBuf;
656 bool IsDelimitedEscapeSequence =
false;
657 bool IsNamedEscapeSequence =
false;
658 if (ThisTokBuf[1] ==
'N') {
659 IsNamedEscapeSequence =
true;
661 UcnVal, UcnLen,
Loc, Diags, Features);
665 UcnLen, IsDelimitedEscapeSequence,
Loc, Diags,
666 Features, in_char_string_literal);
672 if ((0xD800 <= UcnVal && UcnVal <= 0xDFFF) ||
675 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
676 diag::err_ucn_escape_invalid);
684 (UcnVal != 0x24 && UcnVal != 0x40 && UcnVal != 0x60)) {
686 (!(Features.CPlusPlus11 || Features.C23) || !in_char_string_literal);
688 char BasicSCSChar = UcnVal;
689 if (UcnVal >= 0x20 && UcnVal < 0x7f)
690 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
691 IsError ? diag::err_ucn_escape_basic_scs
693 ? diag::warn_cxx98_compat_literal_ucn_escape_basic_scs
694 : diag::warn_c23_compat_literal_ucn_escape_basic_scs)
695 << StringRef(&BasicSCSChar, 1);
697 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
698 IsError ? diag::err_ucn_control_character
700 ? diag::warn_cxx98_compat_literal_ucn_control_character
701 : diag::warn_c23_compat_literal_ucn_control_character);
707 if (!Features.CPlusPlus && !Features.C99 && Diags)
708 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
709 diag::warn_ucn_not_valid_in_c89_literal);
711 if ((IsDelimitedEscapeSequence || IsNamedEscapeSequence) && Diags)
712 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
713 Features.CPlusPlus23 ? diag::warn_cxx23_delimited_escape_sequence
714 : diag::ext_delimited_escape_sequence)
715 << (IsNamedEscapeSequence ? 1 : 0) << (Features.CPlusPlus ? 1 : 0);
723 const char *ThisTokEnd,
unsigned CharByteWidth,
726 if (CharByteWidth == 4)
730 unsigned short UcnLen = 0;
734 UcnLen,
Loc,
nullptr, Features,
true)) {
740 if (CharByteWidth == 2)
741 return UcnVal <= 0xFFFF ? 2 : 4;
748 if (UcnVal < 0x10000)
758 const char *ThisTokEnd,
759 char *&ResultBuf,
bool &HadError,
763 typedef uint32_t
UTF32;
765 unsigned short UcnLen = 0;
767 Loc, Diags, Features,
true)) {
772 assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
773 "only character widths of 1, 2, or 4 bytes supported");
776 assert((UcnLen== 4 || UcnLen== 8) &&
"only ucn length of 4 or 8 supported");
778 if (CharByteWidth == 4) {
781 llvm::UTF32 *ResultPtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf);
787 if (CharByteWidth == 2) {
790 llvm::UTF16 *ResultPtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf);
792 if (UcnVal <= (
UTF32)0xFFFF) {
800 *ResultPtr = 0xD800 + (UcnVal >> 10);
801 *(ResultPtr+1) = 0xDC00 + (UcnVal & 0x3FF);
806 assert(CharByteWidth == 1 &&
"UTF-8 encoding is only for 1 byte characters");
812 typedef uint8_t
UTF8;
814 unsigned short bytesToWrite = 0;
815 if (UcnVal < (
UTF32)0x80)
817 else if (UcnVal < (
UTF32)0x800)
819 else if (UcnVal < (
UTF32)0x10000)
824 const unsigned byteMask = 0xBF;
825 const unsigned byteMark = 0x80;
829 static const UTF8 firstByteMark[5] = {
830 0x00, 0x00, 0xC0, 0xE0, 0xF0
833 ResultBuf += bytesToWrite;
834 switch (bytesToWrite) {
836 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
839 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
842 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
845 *--ResultBuf = (
UTF8) (UcnVal | firstByteMark[bytesToWrite]);
848 ResultBuf += bytesToWrite;
908 :
SM(
SM), LangOpts(LangOpts), Diags(Diags),
909 ThisTokBegin(TokSpelling.begin()), ThisTokEnd(TokSpelling.end()) {
911 s = DigitsBegin = ThisTokBegin;
912 saw_exponent =
false;
914 saw_ud_suffix =
false;
915 saw_fixed_point_suffix =
false;
939 !(LangOpts.HLSL && *ThisTokEnd ==
'.')) {
940 Diags.
Report(TokLoc, diag::err_lexing_numeric);
946 ParseNumberStartingWithZero(TokLoc);
952 if (
s == ThisTokEnd) {
955 ParseDecimalOrOctalCommon(TokLoc);
962 checkSeparator(TokLoc,
s, CSK_AfterDigits);
965 if (LangOpts.FixedPoint) {
966 for (
const char *
c =
s;
c != ThisTokEnd; ++
c) {
967 if (*
c ==
'r' || *
c ==
'k' || *
c ==
'R' || *
c ==
'K') {
968 saw_fixed_point_suffix =
true;
978 bool HasSize =
false;
979 bool DoubleUnderscore =
false;
983 for (;
s != ThisTokEnd; ++
s) {
987 if (!LangOpts.FixedPoint)
990 if (!(saw_period || saw_exponent))
break;
995 if (!LangOpts.FixedPoint)
998 if (!(saw_period || saw_exponent))
break;
1004 if (!(LangOpts.Half || LangOpts.FixedPoint))
1014 if (!isFPConstant)
break;
1025 if ((
Target.hasFloat16Type() || LangOpts.CUDA ||
1026 (LangOpts.OpenMPIsTargetDevice &&
Target.getTriple().isNVPTX())) &&
1027 s + 2 < ThisTokEnd &&
s[1] ==
'1' &&
s[2] ==
'6') {
1037 if (!isFPConstant)
break;
1045 if (isFPConstant)
break;
1057 assert(
s + 1 < ThisTokEnd &&
"didn't maximally munch?");
1058 if (isFPConstant)
break;
1076 if (LangOpts.MicrosoftExt && !isFPConstant) {
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;
1426 const char *PossibleNewDigitStart =
s;
1427 s = SkipOctalDigits(
s);
1431 if (
s != PossibleNewDigitStart)
1432 DigitsBegin = PossibleNewDigitStart;
1434 if (
s == ThisTokEnd)
1440 const char *EndDecimal = SkipDigits(
s);
1441 if (EndDecimal[0] ==
'.' || EndDecimal[0] ==
'e' || EndDecimal[0] ==
'E') {
1447 ParseDecimalOrOctalCommon(TokLoc);
1453 return NumDigits <= 64;
1455 return NumDigits <= 64 / 3;
1457 return NumDigits <= 19;
1459 return NumDigits <= 64 / 4;
1461 llvm_unreachable(
"impossible Radix");
1475 const unsigned NumDigits = SuffixBegin - DigitsBegin;
1478 for (
const char *Ptr = DigitsBegin; Ptr != SuffixBegin; ++Ptr)
1479 if (!isDigitSeparator(*Ptr))
1480 N = N * radix + llvm::hexDigitValue(*Ptr);
1485 return Val.getZExtValue() != N;
1489 const char *Ptr = DigitsBegin;
1491 llvm::APInt RadixVal(Val.getBitWidth(), radix);
1492 llvm::APInt CharVal(Val.getBitWidth(), 0);
1493 llvm::APInt OldVal = Val;
1495 bool OverflowOccurred =
false;
1496 while (Ptr < SuffixBegin) {
1497 if (isDigitSeparator(*Ptr)) {
1502 unsigned C = llvm::hexDigitValue(*Ptr++);
1505 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1515 OverflowOccurred |= Val.udiv(RadixVal) != OldVal;
1520 OverflowOccurred |= Val.ult(CharVal);
1522 return OverflowOccurred;
1525llvm::APFloat::opStatus
1527 llvm::RoundingMode RM) {
1528 using llvm::APFloat;
1530 unsigned n = std::min(SuffixBegin - ThisTokBegin, ThisTokEnd - ThisTokBegin);
1533 StringRef Str(ThisTokBegin, n);
1534 if (Str.contains(
'\'')) {
1536 std::remove_copy_if(Str.begin(), Str.end(), std::back_inserter(Buffer),
1541 auto StatusOrErr =
Result.convertFromString(Str, RM);
1542 assert(StatusOrErr &&
"Invalid floating point representation");
1543 return !errorToBool(StatusOrErr.takeError()) ? *StatusOrErr
1544 : APFloat::opInvalidOp;
1549 return c ==
'p' ||
c ==
'P';
1550 return c ==
'e' ||
c ==
'E';
1554 assert(radix == 16 || radix == 10);
1557 unsigned NumDigits = SuffixBegin - DigitsBegin;
1558 if (saw_period) --NumDigits;
1561 bool ExpOverflowOccurred =
false;
1562 bool NegativeExponent =
false;
1563 const char *ExponentBegin;
1564 uint64_t Exponent = 0;
1565 int64_t BaseShift = 0;
1567 const char *Ptr = DigitsBegin;
1571 ExponentBegin = Ptr;
1573 NegativeExponent = *Ptr ==
'-';
1574 if (NegativeExponent) ++Ptr;
1576 unsigned NumExpDigits = SuffixBegin - Ptr;
1578 llvm::StringRef ExpStr(Ptr, NumExpDigits);
1579 llvm::APInt ExpInt(64, ExpStr, 10);
1580 Exponent = ExpInt.getZExtValue();
1582 ExpOverflowOccurred =
true;
1585 if (NegativeExponent) BaseShift -= Exponent;
1586 else BaseShift += Exponent;
1606 uint64_t NumBitsNeeded;
1608 NumBitsNeeded = 4 * (NumDigits + Exponent) + Scale;
1610 NumBitsNeeded = 4 * NumDigits + Exponent + Scale;
1612 if (NumBitsNeeded > std::numeric_limits<unsigned>::max())
1613 ExpOverflowOccurred =
true;
1614 llvm::APInt Val(
static_cast<unsigned>(NumBitsNeeded), 0,
false);
1616 bool FoundDecimal =
false;
1618 int64_t FractBaseShift = 0;
1619 const char *End = saw_exponent ? ExponentBegin : SuffixBegin;
1620 for (
const char *Ptr = DigitsBegin; Ptr < End; ++Ptr) {
1622 FoundDecimal =
true;
1627 unsigned C = llvm::hexDigitValue(*Ptr);
1628 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1640 if (radix == 16) FractBaseShift *= 4;
1641 BaseShift += FractBaseShift;
1645 uint64_t
Base = (radix == 16) ? 2 : 10;
1646 if (BaseShift > 0) {
1647 for (int64_t i = 0; i < BaseShift; ++i) {
1650 }
else if (BaseShift < 0) {
1651 for (int64_t i = BaseShift; i < 0 && !Val.isZero(); ++i)
1652 Val = Val.udiv(
Base);
1655 bool IntOverflowOccurred =
false;
1656 auto MaxVal = llvm::APInt::getMaxValue(StoreVal.getBitWidth());
1657 if (Val.getBitWidth() > StoreVal.getBitWidth()) {
1658 IntOverflowOccurred |= Val.ugt(MaxVal.zext(Val.getBitWidth()));
1659 StoreVal = Val.trunc(StoreVal.getBitWidth());
1660 }
else if (Val.getBitWidth() < StoreVal.getBitWidth()) {
1661 IntOverflowOccurred |= Val.zext(MaxVal.getBitWidth()).ugt(MaxVal);
1662 StoreVal = Val.zext(StoreVal.getBitWidth());
1667 return IntOverflowOccurred || ExpOverflowOccurred;
1717 const char *TokBegin = begin;
1720 if (
Kind != tok::char_constant)
1722 if (
Kind == tok::utf8_char_constant)
1726 if (begin[0] !=
'\'') {
1727 PP.
Diag(
Loc, diag::err_lexing_char);
1735 if (end[-1] !=
'\'') {
1736 const char *UDSuffixEnd = end;
1739 }
while (end[-1] !=
'\'');
1741 expandUCNs(UDSuffixBuf, StringRef(end, UDSuffixEnd - end));
1742 UDSuffixOffset = end - TokBegin;
1746 assert(end != begin &&
"Invalid token lexed");
1753 "Assumes char is 8 bits");
1756 "Assumes sizeof(int) on target is <= 64 and a multiple of char");
1758 "Assumes sizeof(wchar) on target is <= 64");
1761 codepoint_buffer.resize(end - begin);
1762 uint32_t *buffer_begin = &codepoint_buffer.front();
1763 uint32_t *buffer_end = buffer_begin + codepoint_buffer.size();
1768 uint32_t largest_character_for_kind;
1769 if (tok::wide_char_constant ==
Kind) {
1770 largest_character_for_kind =
1772 }
else if (tok::utf8_char_constant ==
Kind) {
1773 largest_character_for_kind = 0x7F;
1774 }
else if (tok::utf16_char_constant ==
Kind) {
1775 largest_character_for_kind = 0xFFFF;
1776 }
else if (tok::utf32_char_constant ==
Kind) {
1777 largest_character_for_kind = 0x10FFFF;
1779 largest_character_for_kind = 0x7Fu;
1782 while (begin != end) {
1784 if (begin[0] !=
'\\') {
1785 char const *start = begin;
1788 }
while (begin != end && *begin !=
'\\');
1790 char const *tmp_in_start = start;
1791 uint32_t *tmp_out_start = buffer_begin;
1792 llvm::ConversionResult res =
1793 llvm::ConvertUTF8toUTF32(
reinterpret_cast<llvm::UTF8
const **
>(&start),
1794 reinterpret_cast<llvm::UTF8
const *
>(begin),
1795 &buffer_begin, buffer_end, llvm::strictConversion);
1796 if (res != llvm::conversionOK) {
1801 unsigned Msg = diag::err_bad_character_encoding;
1802 if (NoErrorOnBadEncoding)
1803 Msg = diag::warn_bad_character_encoding;
1805 if (NoErrorOnBadEncoding) {
1806 start = tmp_in_start;
1807 buffer_begin = tmp_out_start;
1808 for (; start != begin; ++start, ++buffer_begin)
1809 *buffer_begin =
static_cast<uint8_t
>(*start);
1814 for (; tmp_out_start < buffer_begin; ++tmp_out_start) {
1815 if (*tmp_out_start > largest_character_for_kind) {
1817 PP.
Diag(
Loc, diag::err_character_too_large);
1825 if (begin[1] ==
'u' || begin[1] ==
'U' || begin[1] ==
'N') {
1826 unsigned short UcnLen = 0;
1831 }
else if (*buffer_begin > largest_character_for_kind) {
1833 PP.
Diag(
Loc, diag::err_character_too_large);
1845 *buffer_begin++ = result;
1848 unsigned NumCharsSoFar = buffer_begin - &codepoint_buffer.front();
1850 if (NumCharsSoFar > 1) {
1852 PP.
Diag(
Loc, diag::warn_four_char_character_literal);
1854 PP.
Diag(
Loc, diag::warn_multichar_character_literal);
1856 PP.
Diag(
Loc, diag::err_multichar_character_literal) << (
isWide() ? 0 : 1);
1861 IsMultiChar =
false;
1868 bool multi_char_too_long =
false;
1871 for (
size_t i = 0; i < NumCharsSoFar; ++i) {
1873 multi_char_too_long |= (LitVal.countl_zero() < 8);
1875 LitVal = LitVal + (codepoint_buffer[i] & 0xFF);
1877 }
else if (NumCharsSoFar > 0) {
1879 LitVal = buffer_begin[-1];
1882 if (!HadError && multi_char_too_long) {
1883 PP.
Diag(
Loc, diag::warn_char_constant_too_large);
1887 Value = LitVal.getZExtValue();
1955 :
SM(PP.getSourceManager()), Features(PP.getLangOpts()),
1956 Target(PP.getTargetInfo()), Diags(&PP.getDiagnostics()),
1957 MaxTokenLength(0), SizeBound(0), CharByteWidth(0),
Kind(tok::unknown),
1958 ResultPtr(ResultBuf.data()), EvalMethod(EvalMethod), hadError(
false),
1966 if (StringToks.empty() || StringToks[0].getLength() < 2)
1973 assert(!StringToks.empty() &&
"expected at least one token");
1974 MaxTokenLength = StringToks[0].getLength();
1975 assert(StringToks[0].getLength() >= 2 &&
"literal token is invalid!");
1976 SizeBound = StringToks[0].getLength() - 2;
1980 Kind = tok::string_literal;
1983 for (
const Token &Tok : StringToks) {
1984 if (Tok.getLength() < 2)
1985 return DiagnoseLexingError(Tok.getLocation());
1989 assert(Tok.getLength() >= 2 &&
"literal token is invalid!");
1990 SizeBound += Tok.getLength() - 2;
1993 if (Tok.getLength() > MaxTokenLength)
1994 MaxTokenLength = Tok.getLength();
1998 if (
isUnevaluated() && Tok.getKind() != tok::string_literal) {
2005 StringRef Prefix(
SM.getCharacterData(Tok.getLocation()),
2007 Diags->
Report(Tok.getLocation(),
2008 Features.CPlusPlus26
2009 ? diag::err_unevaluated_string_prefix
2010 : diag::warn_unevaluated_string_prefix)
2013 if (Features.CPlusPlus26)
2015 }
else if (Tok.isNot(
Kind) && Tok.isNot(tok::string_literal)) {
2017 Kind = Tok.getKind();
2020 Diags->
Report(Tok.getLocation(), diag::err_unsupported_string_concat);
2033 assert((CharByteWidth & 7) == 0 &&
"Assumes character size is byte multiple");
2038 SizeBound *= CharByteWidth;
2041 ResultBuf.resize(SizeBound);
2045 TokenBuf.resize(MaxTokenLength);
2049 ResultPtr = &ResultBuf[0];
2055 for (
unsigned i = 0, e = StringToks.size(); i != e; ++i) {
2056 const char *ThisTokBuf = &TokenBuf[0];
2060 bool StringInvalid =
false;
2061 unsigned ThisTokLen =
2065 return DiagnoseLexingError(StringToks[i].getLocation());
2067 const char *ThisTokBegin = ThisTokBuf;
2068 const char *ThisTokEnd = ThisTokBuf+ThisTokLen;
2071 if (ThisTokEnd[-1] !=
'"') {
2072 const char *UDSuffixEnd = ThisTokEnd;
2075 }
while (ThisTokEnd[-1] !=
'"');
2077 StringRef UDSuffix(ThisTokEnd, UDSuffixEnd - ThisTokEnd);
2079 if (UDSuffixBuf.empty()) {
2080 if (StringToks[i].hasUCN())
2083 UDSuffixBuf.assign(UDSuffix);
2085 UDSuffixOffset = ThisTokEnd - ThisTokBuf;
2086 UDSuffixTokLoc = StringToks[i].getLocation();
2089 if (StringToks[i].hasUCN()) {
2091 UDSuffix = ExpandedUDSuffix;
2098 bool UnevaluatedStringHasUDL =
isUnevaluated() && !UDSuffix.empty();
2099 if (UDSuffixBuf != UDSuffix || UnevaluatedStringHasUDL) {
2102 if (UnevaluatedStringHasUDL) {
2103 Diags->
Report(TokLoc, diag::err_unevaluated_string_udl)
2106 Diags->
Report(TokLoc, diag::err_string_concat_mixed_suffix)
2107 << UDSuffixBuf << UDSuffix
2122 if (ThisTokBuf[0] ==
'L' || ThisTokBuf[0] ==
'u' || ThisTokBuf[0] ==
'U') {
2125 if (ThisTokBuf[0] ==
'8')
2130 if (ThisTokBuf[0] ==
'R') {
2131 if (ThisTokBuf[1] !=
'"') {
2134 return DiagnoseLexingError(StringToks[i].getLocation());
2140 constexpr unsigned MaxRawStrDelimLen = 16;
2142 const char *Prefix = ThisTokBuf;
2143 while (
static_cast<unsigned>(ThisTokBuf - Prefix) < MaxRawStrDelimLen &&
2144 ThisTokBuf[0] !=
'(')
2146 if (ThisTokBuf[0] !=
'(')
2147 return DiagnoseLexingError(StringToks[i].getLocation());
2151 ThisTokEnd -= ThisTokBuf - Prefix;
2152 if (ThisTokEnd < ThisTokBuf)
2153 return DiagnoseLexingError(StringToks[i].getLocation());
2157 StringRef RemainingTokenSpan(ThisTokBuf, ThisTokEnd - ThisTokBuf);
2158 while (!RemainingTokenSpan.empty()) {
2160 size_t CRLFPos = RemainingTokenSpan.find(
"\r\n");
2161 StringRef BeforeCRLF = RemainingTokenSpan.substr(0, CRLFPos);
2162 StringRef AfterCRLF = RemainingTokenSpan.substr(CRLFPos);
2165 if (CopyStringFragment(StringToks[i], ThisTokBegin, BeforeCRLF))
2170 RemainingTokenSpan = AfterCRLF.substr(1);
2173 if (ThisTokBuf[0] !=
'"') {
2176 return DiagnoseLexingError(StringToks[i].getLocation());
2182 ThisTokBuf + 1 != ThisTokEnd && ThisTokBuf[0] ==
'\\' &&
2183 ThisTokBuf[1] ==
'p') {
2194 while (ThisTokBuf != ThisTokEnd) {
2196 if (ThisTokBuf[0] !=
'\\') {
2197 const char *InStart = ThisTokBuf;
2200 }
while (ThisTokBuf != ThisTokEnd && ThisTokBuf[0] !=
'\\');
2203 if (CopyStringFragment(StringToks[i], ThisTokBegin,
2204 StringRef(InStart, ThisTokBuf - InStart)))
2209 if (ThisTokBuf[1] ==
'u' || ThisTokBuf[1] ==
'U' ||
2210 ThisTokBuf[1] ==
'N') {
2214 CharByteWidth, Diags, Features);
2218 unsigned ResultChar =
2221 CharByteWidth * 8, Diags, Features, EvalMethod);
2223 if (CharByteWidth == 4) {
2226 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultPtr);
2227 *ResultWidePtr = ResultChar;
2229 }
else if (CharByteWidth == 2) {
2232 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultPtr);
2233 *ResultWidePtr = ResultChar & 0xFFFF;
2236 assert(CharByteWidth == 1 &&
"Unexpected char width");
2237 *ResultPtr++ = ResultChar & 0xFF;
2244 "Pascal string in unevaluated context");
2246 if (CharByteWidth == 4) {
2249 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf.data());
2251 }
else if (CharByteWidth == 2) {
2254 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf.data());
2257 assert(CharByteWidth == 1 &&
"Unexpected char width");
2264 Diags->
Report(StringToks.front().getLocation(),
2265 diag::err_pascal_string_too_long)
2267 StringToks.back().getLocation());
2273 unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
2276 Diags->
Report(StringToks.front().getLocation(),
2277 diag::ext_string_too_long)
2279 << (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
2281 StringToks.back().getLocation());
2288 End = Err + std::min<unsigned>(llvm::getNumBytesForUTF8(*Err), End-Err);
2289 while (++Err != End && (*Err & 0xC0) == 0x80)
2297bool StringLiteralParser::CopyStringFragment(
const Token &Tok,
2298 const char *TokBegin,
2299 StringRef Fragment) {
2300 const llvm::UTF8 *ErrorPtrTmp;
2301 if (ConvertUTF8toWide(CharByteWidth, Fragment, ResultPtr, ErrorPtrTmp))
2308 if (NoErrorOnBadEncoding) {
2309 memcpy(ResultPtr, Fragment.data(), Fragment.size());
2310 ResultPtr += Fragment.size();
2314 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2318 Diag(Diags, Features, SourceLoc, TokBegin,
2319 ErrorPtr,
resyncUTF8(ErrorPtr, Fragment.end()),
2320 NoErrorOnBadEncoding ? diag::warn_bad_string_encoding
2321 : diag::err_bad_string_encoding);
2323 const char *NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2324 StringRef NextFragment(NextStart, Fragment.end()-NextStart);
2328 Dummy.reserve(Fragment.size() * CharByteWidth);
2329 char *Ptr = Dummy.data();
2331 while (!ConvertUTF8toWide(CharByteWidth, NextFragment, Ptr, ErrorPtrTmp)) {
2332 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2333 NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2335 ErrorPtr, NextStart);
2336 NextFragment = StringRef(NextStart, Fragment.end()-NextStart);
2339 return !NoErrorOnBadEncoding;
2345 Diags->
Report(
Loc, diag::err_lexing_string);
2352 unsigned ByteNo)
const {
2357 bool StringInvalid =
false;
2358 const char *SpellingPtr = &SpellingBuffer[0];
2364 const char *SpellingStart = SpellingPtr;
2365 const char *SpellingEnd = SpellingPtr+TokLen;
2368 if (SpellingPtr[0] ==
'u' && SpellingPtr[1] ==
'8')
2371 assert(SpellingPtr[0] !=
'L' && SpellingPtr[0] !=
'u' &&
2372 SpellingPtr[0] !=
'U' &&
"Doesn't handle wide or utf strings yet");
2375 if (SpellingPtr[0] ==
'R') {
2376 assert(SpellingPtr[1] ==
'"' &&
"Should be a raw string literal!");
2379 while (*SpellingPtr !=
'(') {
2381 assert(SpellingPtr < SpellingEnd &&
"Missing ( for raw string literal");
2385 return SpellingPtr - SpellingStart + ByteNo;
2389 assert(SpellingPtr[0] ==
'"' &&
"Should be a string literal!");
2394 assert(SpellingPtr < SpellingEnd &&
"Didn't find byte offset!");
2397 if (*SpellingPtr !=
'\\') {
2404 bool HadError =
false;
2405 if (SpellingPtr[1] ==
'u' || SpellingPtr[1] ==
'U' ||
2406 SpellingPtr[1] ==
'N') {
2407 const char *EscapePtr = SpellingPtr;
2409 1, Features, HadError);
2412 SpellingPtr = EscapePtr;
2422 assert(!HadError &&
"This method isn't valid on erroneous strings");
2425 return SpellingPtr-SpellingStart;
enum clang::sema::@1655::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 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.
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.