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 ==
'}') {
193 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
194 diag::err_delimited_escape_empty);
197 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
199 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
200 diag::err_hex_escape_no_digits) <<
"x";
205 bool Overflow =
false;
206 for (; ThisTokBuf != ThisTokEnd; ++ThisTokBuf) {
207 if (Delimited && *ThisTokBuf ==
'}') {
209 EndDelimiterFound =
true;
212 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
219 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
220 diag::err_delimited_escape_invalid)
221 << StringRef(ThisTokBuf, 1);
225 if (ResultChar & 0xF0000000)
228 ResultChar |= CharVal;
231 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
233 ResultChar &= ~0
U >> (32-CharWidth);
237 if (!HadError && Overflow) {
240 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
241 diag::err_escape_too_large)
246 case '0':
case '1':
case '2':
case '3':
247 case '4':
case '5':
case '6':
case '7': {
254 unsigned NumDigits = 0;
257 ResultChar |= *ThisTokBuf++ -
'0';
259 }
while (ThisTokBuf != ThisTokEnd && NumDigits < 3 &&
260 ThisTokBuf[0] >=
'0' && ThisTokBuf[0] <=
'7');
263 if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) {
265 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
266 diag::err_escape_too_large) << 1;
267 ResultChar &= ~0
U >> (32-CharWidth);
272 bool Overflow =
false;
273 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
276 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
277 diag::err_delimited_escape_missing_brace)
285 if (*ThisTokBuf ==
'}') {
286 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
287 diag::err_delimited_escape_empty);
291 while (ThisTokBuf != ThisTokEnd) {
292 if (*ThisTokBuf ==
'}') {
293 EndDelimiterFound =
true;
297 if (*ThisTokBuf <
'0' || *ThisTokBuf >
'7') {
300 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
301 diag::err_delimited_escape_invalid)
302 << StringRef(ThisTokBuf, 1);
307 if (ResultChar & 0xE0000000)
311 ResultChar |= *ThisTokBuf++ -
'0';
315 (Overflow || (CharWidth != 32 && (ResultChar >> CharWidth) != 0))) {
318 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
319 diag::err_escape_too_large)
321 ResultChar &= ~0
U >> (32 - CharWidth);
326 case '(':
case '{':
case '[':
case '%':
329 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
330 diag::ext_nonstandard_escape)
331 << std::string(1, ResultChar);
338 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
339 diag::ext_unknown_escape)
340 << std::string(1, ResultChar);
342 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
343 diag::ext_unknown_escape)
344 <<
"x" + llvm::utohexstr(ResultChar);
348 if (Delimited && Diags) {
349 if (!EndDelimiterFound)
350 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
353 else if (!HadError) {
354 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
355 Features.CPlusPlus23 ? diag::warn_cxx23_delimited_escape_sequence
356 : diag::ext_delimited_escape_sequence)
357 << 0 << (Features.CPlusPlus ? 1 : 0);
361 if (EvalMethod == StringLiteralEvalMethod::Unevaluated &&
363 Diag(Diags, Features,
Loc, ThisTokBegin, EscapeBegin, ThisTokBuf,
364 diag::err_unevaluated_string_invalid_escape_sequence)
365 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin);
375 char *ResultPtr = ResultBuf;
376 if (llvm::ConvertCodePointToUTF8(Codepoint, ResultPtr))
377 Str.append(ResultBuf, ResultPtr);
381 for (StringRef::iterator I = Input.begin(),
E = Input.end(); I !=
E; ++I) {
391 assert(Kind ==
'u' || Kind ==
'U' || Kind ==
'N');
392 uint32_t CodePoint = 0;
394 if (Kind ==
'u' && *I ==
'{') {
395 for (++I; *I !=
'}'; ++I) {
396 unsigned Value = llvm::hexDigitValue(*I);
397 assert(
Value != -1U);
408 auto Delim = std::find(I, Input.end(),
'}');
409 assert(Delim != Input.end());
410 StringRef Name(I, std::distance(I, Delim));
411 std::optional<llvm::sys::unicode::LooseMatchingResult> Res =
412 llvm::sys::unicode::nameToCodepointLooseMatching(Name);
413 assert(Res &&
"could not find a codepoint that was previously found");
414 CodePoint = Res->CodePoint;
415 assert(CodePoint != 0xFFFFFFFF);
421 unsigned NumHexDigits;
427 assert(I + NumHexDigits <=
E);
429 for (; NumHexDigits != 0; ++I, --NumHexDigits) {
430 unsigned Value = llvm::hexDigitValue(*I);
431 assert(
Value != -1U);
444 return LO.MicrosoftExt &&
445 (K == tok::kw___FUNCTION__ || K == tok::kw_L__FUNCTION__ ||
446 K == tok::kw___FUNCSIG__ || K == tok::kw_L__FUNCSIG__ ||
447 K == tok::kw___FUNCDNAME__);
456 const char *&ThisTokBuf,
457 const char *ThisTokEnd, uint32_t &UcnVal,
458 unsigned short &UcnLen,
bool &Delimited,
461 bool in_char_string_literal =
false) {
462 const char *UcnBegin = ThisTokBuf;
463 bool HasError =
false;
464 bool EndDelimiterFound =
false;
469 if (UcnBegin[1] ==
'u' && in_char_string_literal &&
470 ThisTokBuf != ThisTokEnd && *ThisTokBuf ==
'{') {
473 }
else if (ThisTokBuf == ThisTokEnd || !
isHexDigit(*ThisTokBuf)) {
475 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
476 diag::err_hex_escape_no_digits)
477 << StringRef(&ThisTokBuf[-1], 1);
480 UcnLen = (ThisTokBuf[-1] ==
'u' ? 4 : 8);
482 bool Overflow =
false;
483 unsigned short Count = 0;
484 for (; ThisTokBuf != ThisTokEnd && (Delimited || Count != UcnLen);
486 if (Delimited && *ThisTokBuf ==
'}') {
488 EndDelimiterFound =
true;
491 int CharVal = llvm::hexDigitValue(*ThisTokBuf);
497 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
498 diag::err_delimited_escape_invalid)
499 << StringRef(ThisTokBuf, 1);
504 if (UcnVal & 0xF0000000) {
515 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
516 diag::err_escape_too_large)
521 if (Delimited && !EndDelimiterFound) {
523 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
531 if (Count == 0 || (!Delimited && Count != UcnLen)) {
533 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
534 Delimited ? diag::err_delimited_escape_empty
535 : diag::err_ucn_escape_incomplete);
543 const char *TokBegin,
const char *TokRangeBegin,
const char *TokRangeEnd,
544 llvm::StringRef Name) {
546 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
547 diag::err_invalid_ucn_name)
550 namespace u = llvm::sys::unicode;
552 std::optional<u::LooseMatchingResult> Res =
553 u::nameToCodepointLooseMatching(Name);
555 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
556 diag::note_invalid_ucn_name_loose_matching)
564 unsigned Distance = 0;
566 u::nearestMatchesForCodepointName(Name, 5);
567 assert(!Matches.empty() &&
"No unicode characters found");
569 for (
const auto &Match : Matches) {
571 Distance = Match.Distance;
572 if (std::max(Distance, Match.Distance) -
573 std::min(Distance, Match.Distance) >
576 Distance = Match.Distance;
579 llvm::UTF32
V = Match.Value;
583 assert(Converted &&
"Found a match wich is not a unicode character");
585 Diag(Diags, Features,
Loc, TokBegin, TokRangeBegin, TokRangeEnd,
586 diag::note_invalid_ucn_name_candidate)
587 << Match.Name << llvm::utohexstr(Match.Value)
597 const char *&ThisTokBuf,
598 const char *ThisTokEnd, uint32_t &UcnVal,
602 const char *UcnBegin = ThisTokBuf;
603 assert(UcnBegin[0] ==
'\\' && UcnBegin[1] ==
'N');
605 if (ThisTokBuf == ThisTokEnd || *ThisTokBuf !=
'{') {
607 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
608 diag::err_delimited_escape_missing_brace)
609 << StringRef(&ThisTokBuf[-1], 1);
614 const char *ClosingBrace = std::find_if(ThisTokBuf, ThisTokEnd, [](
char C) {
618 bool Empty = ClosingBrace == ThisTokBuf;
621 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
623 : diag::err_delimited_escape_empty)
624 << StringRef(&UcnBegin[1], 1);
626 ThisTokBuf = ClosingBrace == ThisTokEnd ? ClosingBrace : ClosingBrace + 1;
629 StringRef Name(ThisTokBuf, ClosingBrace - ThisTokBuf);
630 ThisTokBuf = ClosingBrace + 1;
631 std::optional<char32_t> Res = llvm::sys::unicode::nameToCodepointStrict(Name);
635 &UcnBegin[3], ClosingBrace, Name);
639 UcnLen = UcnVal > 0xFFFF ? 8 : 4;
646 const char *ThisTokEnd, uint32_t &UcnVal,
650 bool in_char_string_literal =
false) {
653 const char *UcnBegin = ThisTokBuf;
654 bool IsDelimitedEscapeSequence =
false;
655 bool IsNamedEscapeSequence =
false;
656 if (ThisTokBuf[1] ==
'N') {
657 IsNamedEscapeSequence =
true;
659 UcnVal, UcnLen,
Loc, Diags, Features);
663 UcnLen, IsDelimitedEscapeSequence,
Loc, Diags,
664 Features, in_char_string_literal);
670 if ((0xD800 <= UcnVal && UcnVal <= 0xDFFF) ||
673 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
674 diag::err_ucn_escape_invalid);
682 (UcnVal != 0x24 && UcnVal != 0x40 && UcnVal != 0x60)) {
684 (!(Features.CPlusPlus11 || Features.C23) || !in_char_string_literal);
686 char BasicSCSChar = UcnVal;
687 if (UcnVal >= 0x20 && UcnVal < 0x7f)
688 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
689 IsError ? diag::err_ucn_escape_basic_scs
691 ? diag::warn_cxx98_compat_literal_ucn_escape_basic_scs
692 : diag::warn_c23_compat_literal_ucn_escape_basic_scs)
693 << StringRef(&BasicSCSChar, 1);
695 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
696 IsError ? diag::err_ucn_control_character
698 ? diag::warn_cxx98_compat_literal_ucn_control_character
699 : diag::warn_c23_compat_literal_ucn_control_character);
705 if (!Features.CPlusPlus && !Features.C99 && Diags)
706 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
707 diag::warn_ucn_not_valid_in_c89_literal);
709 if ((IsDelimitedEscapeSequence || IsNamedEscapeSequence) && Diags)
710 Diag(Diags, Features,
Loc, ThisTokBegin, UcnBegin, ThisTokBuf,
711 Features.CPlusPlus23 ? diag::warn_cxx23_delimited_escape_sequence
712 : diag::ext_delimited_escape_sequence)
713 << (IsNamedEscapeSequence ? 1 : 0) << (Features.CPlusPlus ? 1 : 0);
721 const char *ThisTokEnd,
unsigned CharByteWidth,
724 if (CharByteWidth == 4)
728 unsigned short UcnLen = 0;
732 UcnLen,
Loc,
nullptr, Features,
true)) {
738 if (CharByteWidth == 2)
739 return UcnVal <= 0xFFFF ? 2 : 4;
746 if (UcnVal < 0x10000)
756 const char *ThisTokEnd,
757 char *&ResultBuf,
bool &HadError,
761 typedef uint32_t
UTF32;
763 unsigned short UcnLen = 0;
765 Loc, Diags, Features,
true)) {
770 assert((CharByteWidth == 1 || CharByteWidth == 2 || CharByteWidth == 4) &&
771 "only character widths of 1, 2, or 4 bytes supported");
774 assert((UcnLen== 4 || UcnLen== 8) &&
"only ucn length of 4 or 8 supported");
776 if (CharByteWidth == 4) {
779 llvm::UTF32 *ResultPtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf);
785 if (CharByteWidth == 2) {
788 llvm::UTF16 *ResultPtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf);
790 if (UcnVal <= (
UTF32)0xFFFF) {
798 *ResultPtr = 0xD800 + (UcnVal >> 10);
799 *(ResultPtr+1) = 0xDC00 + (UcnVal & 0x3FF);
804 assert(CharByteWidth == 1 &&
"UTF-8 encoding is only for 1 byte characters");
810 typedef uint8_t
UTF8;
812 unsigned short bytesToWrite = 0;
813 if (UcnVal < (
UTF32)0x80)
815 else if (UcnVal < (
UTF32)0x800)
817 else if (UcnVal < (
UTF32)0x10000)
822 const unsigned byteMask = 0xBF;
823 const unsigned byteMark = 0x80;
827 static const UTF8 firstByteMark[5] = {
828 0x00, 0x00, 0xC0, 0xE0, 0xF0
831 ResultBuf += bytesToWrite;
832 switch (bytesToWrite) {
834 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
837 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
840 *--ResultBuf = (
UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6;
843 *--ResultBuf = (
UTF8) (UcnVal | firstByteMark[bytesToWrite]);
846 ResultBuf += bytesToWrite;
906 :
SM(
SM), LangOpts(LangOpts), Diags(Diags),
907 ThisTokBegin(TokSpelling.begin()), ThisTokEnd(TokSpelling.end()) {
909 s = DigitsBegin = ThisTokBegin;
910 saw_exponent =
false;
912 saw_ud_suffix =
false;
913 saw_fixed_point_suffix =
false;
937 !(LangOpts.HLSL && *ThisTokEnd ==
'.')) {
938 Diags.
Report(TokLoc, diag::err_lexing_numeric);
944 ParseNumberStartingWithZero(TokLoc);
950 if (
s == ThisTokEnd) {
953 ParseDecimalOrOctalCommon(TokLoc);
960 checkSeparator(TokLoc,
s, CSK_AfterDigits);
963 if (LangOpts.FixedPoint) {
964 for (
const char *
c =
s;
c != ThisTokEnd; ++
c) {
965 if (*
c ==
'r' || *
c ==
'k' || *
c ==
'R' || *
c ==
'K') {
966 saw_fixed_point_suffix =
true;
976 bool HasSize =
false;
977 bool DoubleUnderscore =
false;
981 for (;
s != ThisTokEnd; ++
s) {
985 if (!LangOpts.FixedPoint)
988 if (!(saw_period || saw_exponent))
break;
993 if (!LangOpts.FixedPoint)
996 if (!(saw_period || saw_exponent))
break;
1002 if (!(LangOpts.Half || LangOpts.FixedPoint))
1012 if (!isFPConstant)
break;
1023 if ((
Target.hasFloat16Type() || LangOpts.CUDA ||
1024 (LangOpts.OpenMPIsTargetDevice &&
Target.getTriple().isNVPTX())) &&
1025 s + 2 < ThisTokEnd &&
s[1] ==
'1' &&
s[2] ==
'6') {
1035 if (!isFPConstant)
break;
1043 if (isFPConstant)
break;
1055 assert(
s + 1 < ThisTokEnd &&
"didn't maximally munch?");
1056 if (isFPConstant)
break;
1074 if (LangOpts.MicrosoftExt && !isFPConstant) {
1111 assert(
s <= ThisTokEnd &&
"didn't maximally munch?");
1128 assert(!DoubleUnderscore &&
"unhandled double underscore case");
1129 if (LangOpts.CPlusPlus &&
s + 2 < ThisTokEnd &&
1132 DoubleUnderscore =
true;
1134 if (
s + 1 < ThisTokEnd &&
1135 (*
s ==
'u' || *
s ==
'U')) {
1139 if (
s + 1 < ThisTokEnd &&
1140 ((*
s ==
'w' && *(++
s) ==
'b') || (*
s ==
'W' && *(++
s) ==
'B'))) {
1158 if ((!LangOpts.CPlusPlus || DoubleUnderscore) &&
s + 1 < ThisTokEnd &&
1159 ((
s[0] ==
'w' &&
s[1] ==
'b') || (
s[0] ==
'W' &&
s[1] ==
'B'))) {
1173 expandUCNs(UDSuffixBuf, StringRef(SuffixBegin, ThisTokEnd - SuffixBegin));
1188 saw_fixed_point_suffix =
false;
1193 saw_ud_suffix =
true;
1197 if (
s != ThisTokEnd) {
1200 TokLoc, SuffixBegin - ThisTokBegin,
SM, LangOpts),
1201 diag::err_invalid_suffix_constant)
1202 << StringRef(SuffixBegin, ThisTokEnd - SuffixBegin)
1203 << (isFixedPointConstant ? 2 : isFPConstant);
1208 if (!
hadError && saw_fixed_point_suffix) {
1216void NumericLiteralParser::ParseDecimalOrOctalCommon(
SourceLocation TokLoc){
1217 assert((radix == 8 || radix == 10) &&
"Unexpected radix");
1225 diag::err_invalid_digit)
1226 << StringRef(
s, 1) << (radix == 8 ? 1 : 0);
1232 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1236 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1239 if (*
s ==
'e' || *
s ==
'E') {
1240 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1241 const char *Exponent =
s;
1244 saw_exponent =
true;
1245 if (
s != ThisTokEnd && (*
s ==
'+' || *
s ==
'-'))
s++;
1246 const char *first_non_digit = SkipDigits(
s);
1247 if (containsDigits(
s, first_non_digit)) {
1248 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1249 s = first_non_digit;
1253 TokLoc, Exponent - ThisTokBegin,
SM, LangOpts),
1254 diag::err_exponent_has_no_digits);
1267 if (!LangOpts.CPlusPlus11 || Suffix.empty())
1273 if (Suffix.starts_with(
"_") && !Suffix.starts_with(
"__"))
1277 if (!LangOpts.CPlusPlus14)
1283 return llvm::StringSwitch<bool>(Suffix)
1284 .Cases(
"h",
"min",
"s",
true)
1285 .Cases(
"ms",
"us",
"ns",
true)
1286 .Cases(
"il",
"i",
"if",
true)
1287 .Cases(
"d",
"y", LangOpts.CPlusPlus20)
1293 CheckSeparatorKind IsAfterDigits) {
1294 if (IsAfterDigits == CSK_AfterDigits) {
1295 if (Pos == ThisTokBegin)
1298 }
else if (Pos == ThisTokEnd)
1301 if (isDigitSeparator(*Pos)) {
1304 diag::err_digit_separator_not_between_digits)
1315void NumericLiteralParser::ParseNumberStartingWithZero(
SourceLocation TokLoc) {
1316 assert(
s[0] ==
'0' &&
"Invalid method call");
1322 if ((c1 ==
'x' || c1 ==
'X') && (
isHexDigit(
s[1]) ||
s[1] ==
'.')) {
1324 assert(
s < ThisTokEnd &&
"didn't maximally munch?");
1327 s = SkipHexDigits(
s);
1328 bool HasSignificandDigits = containsDigits(DigitsBegin,
s);
1329 if (
s == ThisTokEnd) {
1331 }
else if (*
s ==
'.') {
1334 const char *floatDigitsBegin =
s;
1335 s = SkipHexDigits(
s);
1336 if (containsDigits(floatDigitsBegin,
s))
1337 HasSignificandDigits =
true;
1338 if (HasSignificandDigits)
1339 checkSeparator(TokLoc, floatDigitsBegin, CSK_BeforeDigits);
1342 if (!HasSignificandDigits) {
1345 diag::err_hex_constant_requires)
1346 << LangOpts.CPlusPlus << 1;
1353 if (*
s ==
'p' || *
s ==
'P') {
1354 checkSeparator(TokLoc,
s, CSK_AfterDigits);
1355 const char *Exponent =
s;
1357 saw_exponent =
true;
1358 if (
s != ThisTokEnd && (*
s ==
'+' || *
s ==
'-'))
s++;
1359 const char *first_non_digit = SkipDigits(
s);
1360 if (!containsDigits(
s, first_non_digit)) {
1363 TokLoc, Exponent - ThisTokBegin,
SM, LangOpts),
1364 diag::err_exponent_has_no_digits);
1369 checkSeparator(TokLoc,
s, CSK_BeforeDigits);
1370 s = first_non_digit;
1372 if (!LangOpts.HexFloats)
1373 Diags.
Report(TokLoc, LangOpts.CPlusPlus
1374 ? diag::ext_hex_literal_invalid
1375 : diag::ext_hex_constant_invalid);
1376 else if (LangOpts.CPlusPlus17)
1377 Diags.
Report(TokLoc, diag::warn_cxx17_hex_literal);
1378 }
else if (saw_period) {
1381 diag::err_hex_constant_requires)
1382 << LangOpts.CPlusPlus << 0;
1389 if ((c1 ==
'b' || c1 ==
'B') && (
s[1] ==
'0' ||
s[1] ==
'1')) {
1392 if (LangOpts.CPlusPlus14)
1393 DiagId = diag::warn_cxx11_compat_binary_literal;
1394 else if (LangOpts.C23)
1395 DiagId = diag::warn_c23_compat_binary_literal;
1396 else if (LangOpts.CPlusPlus)
1397 DiagId = diag::ext_binary_literal_cxx14;
1399 DiagId = diag::ext_binary_literal;
1400 Diags.
Report(TokLoc, DiagId);
1402 assert(
s < ThisTokEnd &&
"didn't maximally munch?");
1405 s = SkipBinaryDigits(
s);
1406 if (
s == ThisTokEnd) {
1412 diag::err_invalid_digit)
1413 << StringRef(
s, 1) << 2;
1424 const char *PossibleNewDigitStart =
s;
1425 s = SkipOctalDigits(
s);
1429 if (
s != PossibleNewDigitStart)
1430 DigitsBegin = PossibleNewDigitStart;
1432 if (
s == ThisTokEnd)
1438 const char *EndDecimal = SkipDigits(
s);
1439 if (EndDecimal[0] ==
'.' || EndDecimal[0] ==
'e' || EndDecimal[0] ==
'E') {
1445 ParseDecimalOrOctalCommon(TokLoc);
1451 return NumDigits <= 64;
1453 return NumDigits <= 64 / 3;
1455 return NumDigits <= 19;
1457 return NumDigits <= 64 / 4;
1459 llvm_unreachable(
"impossible Radix");
1473 const unsigned NumDigits = SuffixBegin - DigitsBegin;
1476 for (
const char *Ptr = DigitsBegin; Ptr != SuffixBegin; ++Ptr)
1477 if (!isDigitSeparator(*Ptr))
1478 N = N * radix + llvm::hexDigitValue(*Ptr);
1483 return Val.getZExtValue() != N;
1487 const char *Ptr = DigitsBegin;
1489 llvm::APInt RadixVal(Val.getBitWidth(), radix);
1490 llvm::APInt CharVal(Val.getBitWidth(), 0);
1491 llvm::APInt OldVal = Val;
1493 bool OverflowOccurred =
false;
1494 while (Ptr < SuffixBegin) {
1495 if (isDigitSeparator(*Ptr)) {
1500 unsigned C = llvm::hexDigitValue(*Ptr++);
1503 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1513 OverflowOccurred |= Val.udiv(RadixVal) != OldVal;
1518 OverflowOccurred |= Val.ult(CharVal);
1520 return OverflowOccurred;
1523llvm::APFloat::opStatus
1525 llvm::RoundingMode RM) {
1526 using llvm::APFloat;
1528 unsigned n = std::min(SuffixBegin - ThisTokBegin, ThisTokEnd - ThisTokBegin);
1531 StringRef Str(ThisTokBegin, n);
1532 if (Str.contains(
'\'')) {
1534 std::remove_copy_if(Str.begin(), Str.end(), std::back_inserter(Buffer),
1539 auto StatusOrErr =
Result.convertFromString(Str, RM);
1540 assert(StatusOrErr &&
"Invalid floating point representation");
1541 return !errorToBool(StatusOrErr.takeError()) ? *StatusOrErr
1542 : APFloat::opInvalidOp;
1547 return c ==
'p' ||
c ==
'P';
1548 return c ==
'e' ||
c ==
'E';
1552 assert(radix == 16 || radix == 10);
1555 unsigned NumDigits = SuffixBegin - DigitsBegin;
1556 if (saw_period) --NumDigits;
1559 bool ExpOverflowOccurred =
false;
1560 bool NegativeExponent =
false;
1561 const char *ExponentBegin;
1562 uint64_t Exponent = 0;
1563 int64_t BaseShift = 0;
1565 const char *Ptr = DigitsBegin;
1569 ExponentBegin = Ptr;
1571 NegativeExponent = *Ptr ==
'-';
1572 if (NegativeExponent) ++Ptr;
1574 unsigned NumExpDigits = SuffixBegin - Ptr;
1576 llvm::StringRef ExpStr(Ptr, NumExpDigits);
1577 llvm::APInt ExpInt(64, ExpStr, 10);
1578 Exponent = ExpInt.getZExtValue();
1580 ExpOverflowOccurred =
true;
1583 if (NegativeExponent) BaseShift -= Exponent;
1584 else BaseShift += Exponent;
1604 uint64_t NumBitsNeeded;
1606 NumBitsNeeded = 4 * (NumDigits + Exponent) + Scale;
1608 NumBitsNeeded = 4 * NumDigits + Exponent + Scale;
1610 if (NumBitsNeeded > std::numeric_limits<unsigned>::max())
1611 ExpOverflowOccurred =
true;
1612 llvm::APInt Val(
static_cast<unsigned>(NumBitsNeeded), 0,
false);
1614 bool FoundDecimal =
false;
1616 int64_t FractBaseShift = 0;
1617 const char *End = saw_exponent ? ExponentBegin : SuffixBegin;
1618 for (
const char *Ptr = DigitsBegin; Ptr < End; ++Ptr) {
1620 FoundDecimal =
true;
1625 unsigned C = llvm::hexDigitValue(*Ptr);
1626 assert(
C < radix &&
"NumericLiteralParser ctor should have rejected this");
1638 if (radix == 16) FractBaseShift *= 4;
1639 BaseShift += FractBaseShift;
1643 uint64_t
Base = (radix == 16) ? 2 : 10;
1644 if (BaseShift > 0) {
1645 for (int64_t i = 0; i < BaseShift; ++i) {
1648 }
else if (BaseShift < 0) {
1649 for (int64_t i = BaseShift; i < 0 && !Val.isZero(); ++i)
1650 Val = Val.udiv(
Base);
1653 bool IntOverflowOccurred =
false;
1654 auto MaxVal = llvm::APInt::getMaxValue(StoreVal.getBitWidth());
1655 if (Val.getBitWidth() > StoreVal.getBitWidth()) {
1656 IntOverflowOccurred |= Val.ugt(MaxVal.zext(Val.getBitWidth()));
1657 StoreVal = Val.trunc(StoreVal.getBitWidth());
1658 }
else if (Val.getBitWidth() < StoreVal.getBitWidth()) {
1659 IntOverflowOccurred |= Val.zext(MaxVal.getBitWidth()).ugt(MaxVal);
1660 StoreVal = Val.zext(StoreVal.getBitWidth());
1665 return IntOverflowOccurred || ExpOverflowOccurred;
1715 const char *TokBegin = begin;
1718 if (
Kind != tok::char_constant)
1720 if (
Kind == tok::utf8_char_constant)
1724 if (begin[0] !=
'\'') {
1725 PP.
Diag(
Loc, diag::err_lexing_char);
1733 if (end[-1] !=
'\'') {
1734 const char *UDSuffixEnd = end;
1737 }
while (end[-1] !=
'\'');
1739 expandUCNs(UDSuffixBuf, StringRef(end, UDSuffixEnd - end));
1740 UDSuffixOffset = end - TokBegin;
1744 assert(end != begin &&
"Invalid token lexed");
1751 "Assumes char is 8 bits");
1754 "Assumes sizeof(int) on target is <= 64 and a multiple of char");
1756 "Assumes sizeof(wchar) on target is <= 64");
1759 codepoint_buffer.resize(end - begin);
1760 uint32_t *buffer_begin = &codepoint_buffer.front();
1761 uint32_t *buffer_end = buffer_begin + codepoint_buffer.size();
1766 uint32_t largest_character_for_kind;
1767 if (tok::wide_char_constant ==
Kind) {
1768 largest_character_for_kind =
1770 }
else if (tok::utf8_char_constant ==
Kind) {
1771 largest_character_for_kind = 0x7F;
1772 }
else if (tok::utf16_char_constant ==
Kind) {
1773 largest_character_for_kind = 0xFFFF;
1774 }
else if (tok::utf32_char_constant ==
Kind) {
1775 largest_character_for_kind = 0x10FFFF;
1777 largest_character_for_kind = 0x7Fu;
1780 while (begin != end) {
1782 if (begin[0] !=
'\\') {
1783 char const *start = begin;
1786 }
while (begin != end && *begin !=
'\\');
1788 char const *tmp_in_start = start;
1789 uint32_t *tmp_out_start = buffer_begin;
1790 llvm::ConversionResult res =
1791 llvm::ConvertUTF8toUTF32(
reinterpret_cast<llvm::UTF8
const **
>(&start),
1792 reinterpret_cast<llvm::UTF8
const *
>(begin),
1793 &buffer_begin, buffer_end, llvm::strictConversion);
1794 if (res != llvm::conversionOK) {
1799 unsigned Msg = diag::err_bad_character_encoding;
1800 if (NoErrorOnBadEncoding)
1801 Msg = diag::warn_bad_character_encoding;
1803 if (NoErrorOnBadEncoding) {
1804 start = tmp_in_start;
1805 buffer_begin = tmp_out_start;
1806 for (; start != begin; ++start, ++buffer_begin)
1807 *buffer_begin =
static_cast<uint8_t
>(*start);
1812 for (; tmp_out_start < buffer_begin; ++tmp_out_start) {
1813 if (*tmp_out_start > largest_character_for_kind) {
1815 PP.
Diag(
Loc, diag::err_character_too_large);
1823 if (begin[1] ==
'u' || begin[1] ==
'U' || begin[1] ==
'N') {
1824 unsigned short UcnLen = 0;
1829 }
else if (*buffer_begin > largest_character_for_kind) {
1831 PP.
Diag(
Loc, diag::err_character_too_large);
1843 *buffer_begin++ = result;
1846 unsigned NumCharsSoFar = buffer_begin - &codepoint_buffer.front();
1848 if (NumCharsSoFar > 1) {
1850 PP.
Diag(
Loc, diag::warn_four_char_character_literal);
1852 PP.
Diag(
Loc, diag::warn_multichar_character_literal);
1854 PP.
Diag(
Loc, diag::err_multichar_character_literal) << (
isWide() ? 0 : 1);
1859 IsMultiChar =
false;
1866 bool multi_char_too_long =
false;
1869 for (
size_t i = 0; i < NumCharsSoFar; ++i) {
1871 multi_char_too_long |= (LitVal.countl_zero() < 8);
1873 LitVal = LitVal + (codepoint_buffer[i] & 0xFF);
1875 }
else if (NumCharsSoFar > 0) {
1877 LitVal = buffer_begin[-1];
1880 if (!HadError && multi_char_too_long) {
1881 PP.
Diag(
Loc, diag::warn_char_constant_too_large);
1885 Value = LitVal.getZExtValue();
1953 :
SM(PP.getSourceManager()), Features(PP.getLangOpts()),
1954 Target(PP.getTargetInfo()), Diags(&PP.getDiagnostics()),
1955 MaxTokenLength(0), SizeBound(0), CharByteWidth(0),
Kind(tok::unknown),
1956 ResultPtr(ResultBuf.data()), EvalMethod(EvalMethod), hadError(
false),
1964 if (StringToks.empty() || StringToks[0].getLength() < 2)
1971 assert(!StringToks.empty() &&
"expected at least one token");
1972 MaxTokenLength = StringToks[0].getLength();
1973 assert(StringToks[0].getLength() >= 2 &&
"literal token is invalid!");
1974 SizeBound = StringToks[0].getLength() - 2;
1978 Kind = tok::string_literal;
1981 for (
const Token &Tok : StringToks) {
1982 if (Tok.getLength() < 2)
1983 return DiagnoseLexingError(Tok.getLocation());
1987 assert(Tok.getLength() >= 2 &&
"literal token is invalid!");
1988 SizeBound += Tok.getLength() - 2;
1991 if (Tok.getLength() > MaxTokenLength)
1992 MaxTokenLength = Tok.getLength();
1996 if (
isUnevaluated() && Tok.getKind() != tok::string_literal) {
2003 StringRef Prefix(
SM.getCharacterData(Tok.getLocation()),
2005 Diags->
Report(Tok.getLocation(),
2006 Features.CPlusPlus26
2007 ? diag::err_unevaluated_string_prefix
2008 : diag::warn_unevaluated_string_prefix)
2011 if (Features.CPlusPlus26)
2013 }
else if (Tok.isNot(
Kind) && Tok.isNot(tok::string_literal)) {
2015 Kind = Tok.getKind();
2018 Diags->
Report(Tok.getLocation(), diag::err_unsupported_string_concat);
2031 assert((CharByteWidth & 7) == 0 &&
"Assumes character size is byte multiple");
2036 SizeBound *= CharByteWidth;
2039 ResultBuf.resize(SizeBound);
2043 TokenBuf.resize(MaxTokenLength);
2047 ResultPtr = &ResultBuf[0];
2053 for (
unsigned i = 0, e = StringToks.size(); i != e; ++i) {
2054 const char *ThisTokBuf = &TokenBuf[0];
2058 bool StringInvalid =
false;
2059 unsigned ThisTokLen =
2063 return DiagnoseLexingError(StringToks[i].getLocation());
2065 const char *ThisTokBegin = ThisTokBuf;
2066 const char *ThisTokEnd = ThisTokBuf+ThisTokLen;
2069 if (ThisTokEnd[-1] !=
'"') {
2070 const char *UDSuffixEnd = ThisTokEnd;
2073 }
while (ThisTokEnd[-1] !=
'"');
2075 StringRef UDSuffix(ThisTokEnd, UDSuffixEnd - ThisTokEnd);
2077 if (UDSuffixBuf.empty()) {
2078 if (StringToks[i].hasUCN())
2081 UDSuffixBuf.assign(UDSuffix);
2083 UDSuffixOffset = ThisTokEnd - ThisTokBuf;
2084 UDSuffixTokLoc = StringToks[i].getLocation();
2087 if (StringToks[i].hasUCN()) {
2089 UDSuffix = ExpandedUDSuffix;
2096 bool UnevaluatedStringHasUDL =
isUnevaluated() && !UDSuffix.empty();
2097 if (UDSuffixBuf != UDSuffix || UnevaluatedStringHasUDL) {
2100 if (UnevaluatedStringHasUDL) {
2101 Diags->
Report(TokLoc, diag::err_unevaluated_string_udl)
2104 Diags->
Report(TokLoc, diag::err_string_concat_mixed_suffix)
2105 << UDSuffixBuf << UDSuffix
2120 if (ThisTokBuf[0] ==
'L' || ThisTokBuf[0] ==
'u' || ThisTokBuf[0] ==
'U') {
2123 if (ThisTokBuf[0] ==
'8')
2128 if (ThisTokBuf[0] ==
'R') {
2129 if (ThisTokBuf[1] !=
'"') {
2132 return DiagnoseLexingError(StringToks[i].getLocation());
2138 constexpr unsigned MaxRawStrDelimLen = 16;
2140 const char *Prefix = ThisTokBuf;
2141 while (
static_cast<unsigned>(ThisTokBuf - Prefix) < MaxRawStrDelimLen &&
2142 ThisTokBuf[0] !=
'(')
2144 if (ThisTokBuf[0] !=
'(')
2145 return DiagnoseLexingError(StringToks[i].getLocation());
2149 ThisTokEnd -= ThisTokBuf - Prefix;
2150 if (ThisTokEnd < ThisTokBuf)
2151 return DiagnoseLexingError(StringToks[i].getLocation());
2155 StringRef RemainingTokenSpan(ThisTokBuf, ThisTokEnd - ThisTokBuf);
2156 while (!RemainingTokenSpan.empty()) {
2158 size_t CRLFPos = RemainingTokenSpan.find(
"\r\n");
2159 StringRef BeforeCRLF = RemainingTokenSpan.substr(0, CRLFPos);
2160 StringRef AfterCRLF = RemainingTokenSpan.substr(CRLFPos);
2163 if (CopyStringFragment(StringToks[i], ThisTokBegin, BeforeCRLF))
2168 RemainingTokenSpan = AfterCRLF.substr(1);
2171 if (ThisTokBuf[0] !=
'"') {
2174 return DiagnoseLexingError(StringToks[i].getLocation());
2180 ThisTokBuf + 1 != ThisTokEnd && ThisTokBuf[0] ==
'\\' &&
2181 ThisTokBuf[1] ==
'p') {
2192 while (ThisTokBuf != ThisTokEnd) {
2194 if (ThisTokBuf[0] !=
'\\') {
2195 const char *InStart = ThisTokBuf;
2198 }
while (ThisTokBuf != ThisTokEnd && ThisTokBuf[0] !=
'\\');
2201 if (CopyStringFragment(StringToks[i], ThisTokBegin,
2202 StringRef(InStart, ThisTokBuf - InStart)))
2207 if (ThisTokBuf[1] ==
'u' || ThisTokBuf[1] ==
'U' ||
2208 ThisTokBuf[1] ==
'N') {
2212 CharByteWidth, Diags, Features);
2216 unsigned ResultChar =
2219 CharByteWidth * 8, Diags, Features, EvalMethod);
2221 if (CharByteWidth == 4) {
2224 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultPtr);
2225 *ResultWidePtr = ResultChar;
2227 }
else if (CharByteWidth == 2) {
2230 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultPtr);
2231 *ResultWidePtr = ResultChar & 0xFFFF;
2234 assert(CharByteWidth == 1 &&
"Unexpected char width");
2235 *ResultPtr++ = ResultChar & 0xFF;
2242 "Pascal string in unevaluated context");
2244 if (CharByteWidth == 4) {
2247 llvm::UTF32 *ResultWidePtr =
reinterpret_cast<llvm::UTF32*
>(ResultBuf.data());
2249 }
else if (CharByteWidth == 2) {
2252 llvm::UTF16 *ResultWidePtr =
reinterpret_cast<llvm::UTF16*
>(ResultBuf.data());
2255 assert(CharByteWidth == 1 &&
"Unexpected char width");
2262 Diags->
Report(StringToks.front().getLocation(),
2263 diag::err_pascal_string_too_long)
2265 StringToks.back().getLocation());
2271 unsigned MaxChars = Features.CPlusPlus? 65536 : Features.C99 ? 4095 : 509;
2274 Diags->
Report(StringToks.front().getLocation(),
2275 diag::ext_string_too_long)
2277 << (Features.CPlusPlus ? 2 : Features.C99 ? 1 : 0)
2279 StringToks.back().getLocation());
2286 End = Err + std::min<unsigned>(llvm::getNumBytesForUTF8(*Err), End-Err);
2287 while (++Err != End && (*Err & 0xC0) == 0x80)
2295bool StringLiteralParser::CopyStringFragment(
const Token &Tok,
2296 const char *TokBegin,
2297 StringRef Fragment) {
2298 const llvm::UTF8 *ErrorPtrTmp;
2299 if (ConvertUTF8toWide(CharByteWidth, Fragment, ResultPtr, ErrorPtrTmp))
2306 if (NoErrorOnBadEncoding) {
2307 memcpy(ResultPtr, Fragment.data(), Fragment.size());
2308 ResultPtr += Fragment.size();
2312 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2316 Diag(Diags, Features, SourceLoc, TokBegin,
2317 ErrorPtr,
resyncUTF8(ErrorPtr, Fragment.end()),
2318 NoErrorOnBadEncoding ? diag::warn_bad_string_encoding
2319 : diag::err_bad_string_encoding);
2321 const char *NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2322 StringRef NextFragment(NextStart, Fragment.end()-NextStart);
2326 Dummy.reserve(Fragment.size() * CharByteWidth);
2327 char *Ptr = Dummy.data();
2329 while (!ConvertUTF8toWide(CharByteWidth, NextFragment, Ptr, ErrorPtrTmp)) {
2330 const char *ErrorPtr =
reinterpret_cast<const char *
>(ErrorPtrTmp);
2331 NextStart =
resyncUTF8(ErrorPtr, Fragment.end());
2333 ErrorPtr, NextStart);
2334 NextFragment = StringRef(NextStart, Fragment.end()-NextStart);
2337 return !NoErrorOnBadEncoding;
2343 Diags->
Report(
Loc, diag::err_lexing_string);
2350 unsigned ByteNo)
const {
2355 bool StringInvalid =
false;
2356 const char *SpellingPtr = &SpellingBuffer[0];
2362 const char *SpellingStart = SpellingPtr;
2363 const char *SpellingEnd = SpellingPtr+TokLen;
2366 if (SpellingPtr[0] ==
'u' && SpellingPtr[1] ==
'8')
2369 assert(SpellingPtr[0] !=
'L' && SpellingPtr[0] !=
'u' &&
2370 SpellingPtr[0] !=
'U' &&
"Doesn't handle wide or utf strings yet");
2373 if (SpellingPtr[0] ==
'R') {
2374 assert(SpellingPtr[1] ==
'"' &&
"Should be a raw string literal!");
2377 while (*SpellingPtr !=
'(') {
2379 assert(SpellingPtr < SpellingEnd &&
"Missing ( for raw string literal");
2383 return SpellingPtr - SpellingStart + ByteNo;
2387 assert(SpellingPtr[0] ==
'"' &&
"Should be a string literal!");
2392 assert(SpellingPtr < SpellingEnd &&
"Didn't find byte offset!");
2395 if (*SpellingPtr !=
'\\') {
2402 bool HadError =
false;
2403 if (SpellingPtr[1] ==
'u' || SpellingPtr[1] ==
'U' ||
2404 SpellingPtr[1] ==
'N') {
2405 const char *EscapePtr = SpellingPtr;
2407 1, Features, HadError);
2410 SpellingPtr = EscapePtr;
2420 assert(!HadError &&
"This method isn't valid on erroneous strings");
2423 return SpellingPtr-SpellingStart;
enum clang::sema::@1651::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.