Lines Matching +full:quad +full:- +full:phase
1 //===--- LiteralSupport.cpp - Code to parse and process literals ----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
86 Lexer::AdvanceToTokenCharacter(TokLoc, TokRangeBegin - TokBegin, in MakeCharSourceRange()
89 Lexer::AdvanceToTokenCharacter(Begin, TokRangeEnd - TokRangeBegin, in MakeCharSourceRange()
104 Lexer::AdvanceToTokenCharacter(TokLoc, TokRangeBegin - TokBegin, in Diag()
106 return Diags->Report(Begin, DiagID) << in Diag()
128 /// ProcessCharEscape - Parse a standard C escape sequence, which can occur in
213 if (CharVal == -1) { in ProcessCharEscape()
214 // Non delimited hex escape sequences stop at the first non-hex digit. in ProcessCharEscape()
233 ResultChar &= ~0U >> (32-CharWidth); in ProcessCharEscape()
249 --ThisTokBuf; in ProcessCharEscape()
257 ResultChar |= *ThisTokBuf++ - '0'; in ProcessCharEscape()
267 ResultChar &= ~0U >> (32-CharWidth); in ProcessCharEscape()
311 ResultChar |= *ThisTokBuf++ - '0'; in ProcessCharEscape()
321 ResultChar &= ~0U >> (32 - CharWidth); in ProcessCharEscape()
365 << StringRef(EscapeBegin, ThisTokBuf - EscapeBegin); in ProcessCharEscape()
397 assert(Value != -1U); in expandUCNs()
414 CodePoint = Res->CodePoint; in expandUCNs()
429 for (; NumHexDigits != 0; ++I, --NumHexDigits) { in expandUCNs()
431 assert(Value != -1U); in expandUCNs()
438 --I; in expandUCNs()
477 << StringRef(&ThisTokBuf[-1], 1); in ProcessNumericUCNEscape()
480 UcnLen = (ThisTokBuf[-1] == 'u' ? 4 : 8); in ProcessNumericUCNEscape()
492 if (CharVal == -1) { in ProcessNumericUCNEscape()
560 Res->Name); in DiagnoseInvalidUnicodeCharacterName()
572 if (std::max(Distance, Match.Distance) - in DiagnoseInvalidUnicodeCharacterName()
609 << StringRef(&ThisTokBuf[-1], 1); in ProcessNamedUCNEscape()
629 StringRef Name(ThisTokBuf, ClosingBrace - ThisTokBuf); in ProcessNamedUCNEscape()
643 /// ProcessUCNEscape - Read the Universal Character Name, check constraints and
718 /// MeasureUCNEscape - Determine the number of bytes within the resulting string
723 // UTF-32: 4 bytes per escape. in MeasureUCNEscape()
737 // UTF-16: 2 bytes for BMP, 4 bytes otherwise. in MeasureUCNEscape()
741 // UTF-8. in MeasureUCNEscape()
751 /// EncodeUCNEscape - Read the Universal Character Name, check constraints and
797 UcnVal -= 0x10000; in EncodeUCNEscape()
804 assert(CharByteWidth == 1 && "UTF-8 encoding is only for 1 byte characters"); in EncodeUCNEscape()
806 // Now that we've parsed/checked the UCN, we convert from UTF32->UTF8. in EncodeUCNEscape()
825 // Once the bits are split out into bytes of UTF8, this is a mask OR-ed in EncodeUCNEscape()
834 *--ResultBuf = (UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6; in EncodeUCNEscape()
837 *--ResultBuf = (UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6; in EncodeUCNEscape()
840 *--ResultBuf = (UTF8)((UcnVal | byteMark) & byteMask); UcnVal >>= 6; in EncodeUCNEscape()
843 *--ResultBuf = (UTF8) (UcnVal | firstByteMark[bytesToWrite]); in EncodeUCNEscape()
849 /// integer-constant: [C99 6.4.4.1]
850 /// decimal-constant integer-suffix
851 /// octal-constant integer-suffix
852 /// hexadecimal-constant integer-suffix
853 /// binary-literal integer-suffix [GNU, C++1y]
854 /// user-defined-integer-literal: [C++11 lex.ext]
855 /// decimal-literal ud-suffix
856 /// octal-literal ud-suffix
857 /// hexadecimal-literal ud-suffix
858 /// binary-literal ud-suffix [GNU, C++1y]
859 /// decimal-constant:
860 /// nonzero-digit
861 /// decimal-constant digit
862 /// octal-constant:
864 /// octal-constant octal-digit
865 /// hexadecimal-constant:
866 /// hexadecimal-prefix hexadecimal-digit
867 /// hexadecimal-constant hexadecimal-digit
868 /// hexadecimal-prefix: one of
870 /// binary-literal:
871 /// 0b binary-digit
872 /// 0B binary-digit
873 /// binary-literal binary-digit
874 /// integer-suffix:
875 /// unsigned-suffix [long-suffix]
876 /// unsigned-suffix [long-long-suffix]
877 /// long-suffix [unsigned-suffix]
878 /// long-long-suffix [unsigned-sufix]
879 /// nonzero-digit:
881 /// octal-digit:
883 /// hexadecimal-digit:
887 /// binary-digit:
890 /// unsigned-suffix: one of
892 /// long-suffix: one of
894 /// long-long-suffix: one of
897 /// floating-constant: [C99 6.4.4.2]
930 // and FP constants (specifically, the 'pp-number' regex), and assumes that in NumericLiteralParser()
934 // 'pp-number' regex. This is required to support vector swizzles on numeric in NumericLiteralParser()
947 } else { // the first digit is non-zero in NumericLiteralParser()
1001 // OpenCL Extension v1.2 s9.5 - h or H suffix for half type. in NumericLiteralParser()
1156 // library-based UDL that resolves to a library type may be more in NumericLiteralParser()
1166 // If we reached here, there was an error or a ud-suffix. in NumericLiteralParser()
1170 // "i", "if", and "il" are user-defined suffixes in C++1y. in NumericLiteralParser()
1173 expandUCNs(UDSuffixBuf, StringRef(SuffixBegin, ThisTokEnd - SuffixBegin)); in NumericLiteralParser()
1177 // ud-suffix. in NumericLiteralParser()
1200 TokLoc, SuffixBegin - ThisTokBegin, SM, LangOpts), in NumericLiteralParser()
1202 << StringRef(SuffixBegin, ThisTokEnd - SuffixBegin) in NumericLiteralParser()
1213 /// ParseDecimalOrOctalCommon - This method is called for decimal or octal
1222 !isValidUDSuffix(LangOpts, StringRef(s, ThisTokEnd - s))) { in ParseDecimalOrOctalCommon()
1224 Lexer::AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin, SM, LangOpts), in ParseDecimalOrOctalCommon()
1245 if (s != ThisTokEnd && (*s == '+' || *s == '-')) s++; // sign in ParseDecimalOrOctalCommon()
1253 TokLoc, Exponent - ThisTokBegin, SM, LangOpts), in ParseDecimalOrOctalCommon()
1262 /// Determine whether a suffix is a valid ud-suffix. We avoid treating reserved
1263 /// suffixes as ud-suffixes, because the diagnostic experience is better if we
1270 // By C++11 [lex.ext]p10, ud-suffixes starting with an '_' are always valid. in isValidUDSuffix()
1297 --Pos; in checkSeparator()
1302 Diags.Report(Lexer::AdvanceToTokenCharacter(TokLoc, Pos - ThisTokBegin, SM, in checkSeparator()
1310 /// ParseNumberStartingWithZero - This method is called when the first character
1343 Diags.Report(Lexer::AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin, SM, in ParseNumberStartingWithZero()
1358 if (s != ThisTokEnd && (*s == '+' || *s == '-')) s++; // sign in ParseNumberStartingWithZero()
1363 TokLoc, Exponent - ThisTokBegin, SM, LangOpts), in ParseNumberStartingWithZero()
1379 Diags.Report(Lexer::AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin, SM, in ParseNumberStartingWithZero()
1409 !isValidUDSuffix(LangOpts, StringRef(s, ThisTokEnd - s))) { in ParseNumberStartingWithZero()
1410 Diags.Report(Lexer::AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin, SM, in ParseNumberStartingWithZero()
1435 // If we have some other non-octal digit that *is* a decimal digit, see if in ParseNumberStartingWithZero()
1463 /// GetIntegerValue - Convert this numeric literal value to an APInt that
1473 const unsigned NumDigits = SuffixBegin - DigitsBegin; in GetIntegerValue()
1528 unsigned n = std::min(SuffixBegin - ThisTokBegin, ThisTokEnd - ThisTokBegin); in GetFloatValue()
1555 unsigned NumDigits = SuffixBegin - DigitsBegin; in GetFixedPointValue()
1556 if (saw_period) --NumDigits; in GetFixedPointValue()
1571 NegativeExponent = *Ptr == '-'; in GetFixedPointValue()
1574 unsigned NumExpDigits = SuffixBegin - Ptr; in GetFixedPointValue()
1583 if (NegativeExponent) BaseShift -= Exponent; in GetFixedPointValue()
1591 // -------------------------------------------------- in GetFixedPointValue()
1602 // -------------------------------------------------- in GetFixedPointValue()
1634 --FractBaseShift; in GetFixedPointValue()
1669 /// user-defined-character-literal: [C++11 lex.ext]
1670 /// character-literal ud-suffix
1671 /// ud-suffix:
1673 /// character-literal: [C++11 lex.ccon]
1674 /// ' c-char-sequence '
1675 /// u' c-char-sequence '
1676 /// U' c-char-sequence '
1677 /// L' c-char-sequence '
1678 /// u8' c-char-sequence ' [C++1z lex.ccon]
1679 /// c-char-sequence:
1680 /// c-char
1681 /// c-char-sequence c-char
1682 /// c-char:
1683 /// any member of the source character set except the single-quote ',
1684 /// backslash \, or new-line character
1685 /// escape-sequence
1686 /// universal-character-name
1687 /// escape-sequence:
1688 /// simple-escape-sequence
1689 /// octal-escape-sequence
1690 /// hexadecimal-escape-sequence
1691 /// simple-escape-sequence:
1693 /// octal-escape-sequence:
1694 /// \ octal-digit
1695 /// \ octal-digit octal-digit
1696 /// \ octal-digit octal-digit octal-digit
1697 /// hexadecimal-escape-sequence:
1698 /// \x hexadecimal-digit
1699 /// hexadecimal-escape-sequence hexadecimal-digit
1700 /// universal-character-name: [C++11 lex.charset]
1701 /// \u hex-quad
1702 /// \U hex-quad hex-quad
1703 /// hex-quad:
1704 /// hex-digit hex-digit hex-digit hex-digit
1732 // Remove an optional ud-suffix. in CharLiteralParser()
1733 if (end[-1] != '\'') { in CharLiteralParser()
1736 --end; in CharLiteralParser()
1737 } while (end[-1] != '\''); in CharLiteralParser()
1739 expandUCNs(UDSuffixBuf, StringRef(end, UDSuffixEnd - end)); in CharLiteralParser()
1740 UDSuffixOffset = end - TokBegin; in CharLiteralParser()
1745 --end; in CharLiteralParser()
1748 // up to 64-bits. in CharLiteralParser()
1749 // FIXME: This extensively assumes that 'char' is 8-bits. in CharLiteralParser()
1759 codepoint_buffer.resize(end - begin); in CharLiteralParser()
1769 0xFFFFFFFFu >> (32-PP.getTargetInfo().getWCharWidth()); in CharLiteralParser()
1781 // Is this a span of non-escape characters? in CharLiteralParser()
1846 unsigned NumCharsSoFar = buffer_begin - &codepoint_buffer.front(); in CharLiteralParser()
1877 LitVal = buffer_begin[-1]; in CharLiteralParser()
1887 // If this is a single narrow character, sign extend it (e.g. '\xFF' is "-1") in CharLiteralParser()
1897 /// string-literal: [C++0x lex.string]
1898 /// encoding-prefix " [s-char-sequence] "
1899 /// encoding-prefix R raw-string
1900 /// encoding-prefix:
1905 /// s-char-sequence:
1906 /// s-char
1907 /// s-char-sequence s-char
1908 /// s-char:
1909 /// any member of the source character set except the double-quote ",
1910 /// backslash \, or new-line character
1911 /// escape-sequence
1912 /// universal-character-name
1913 /// raw-string:
1914 /// " d-char-sequence ( r-char-sequence ) d-char-sequence "
1915 /// r-char-sequence:
1916 /// r-char
1917 /// r-char-sequence r-char
1918 /// r-char:
1920 /// followed by the initial d-char-sequence (which may be empty)
1922 /// d-char-sequence:
1923 /// d-char
1924 /// d-char-sequence d-char
1925 /// d-char:
1930 /// escape-sequence: [C++0x lex.ccon]
1931 /// simple-escape-sequence
1932 /// octal-escape-sequence
1933 /// hexadecimal-escape-sequence
1934 /// simple-escape-sequence:
1936 /// octal-escape-sequence:
1937 /// \ octal-digit
1938 /// \ octal-digit octal-digit
1939 /// \ octal-digit octal-digit octal-digit
1940 /// hexadecimal-escape-sequence:
1941 /// \x hexadecimal-digit
1942 /// hexadecimal-escape-sequence hexadecimal-digit
1943 /// universal-character-name:
1944 /// \u hex-quad
1945 /// \U hex-quad hex-quad
1946 /// hex-quad:
1947 /// hex-digit hex-digit hex-digit hex-digit
1969 // piece is a wide-string. If any of the string portions is a wide-string in init()
1970 // literal, the result is a wide-string literal [C99 6.4.5p4]. in init()
1974 SizeBound = StringToks[0].getLength() - 2; // -2 for "". in init()
1988 SizeBound += Tok.getLength() - 2; // -2 for "". in init()
1994 // Remember if we see any wide or utf-8/16/32 strings. in init()
2005 Diags->Report(Tok.getLocation(), in init()
2018 Diags->Report(Tok.getLocation(), diag::err_unsupported_string_concat); in init()
2035 // This is a worst-case assumption which basically corresponds to L"" "long". in init()
2068 // Remove an optional ud-suffix. in init()
2069 if (ThisTokEnd[-1] != '"') { in init()
2072 --ThisTokEnd; in init()
2073 } while (ThisTokEnd[-1] != '"'); in init()
2075 StringRef UDSuffix(ThisTokEnd, UDSuffixEnd - ThisTokEnd); in init()
2083 UDSuffixOffset = ThisTokEnd - ThisTokBuf; in init()
2092 // C++11 [lex.ext]p8: At the end of phase 6, if a string literal is the in init()
2093 // result of a concatenation involving at least one user-defined-string- in init()
2094 // literal, all the participating user-defined-string-literals shall in init()
2095 // have the same ud-suffix. in init()
2101 Diags->Report(TokLoc, diag::err_unevaluated_string_udl) in init()
2104 Diags->Report(TokLoc, diag::err_string_concat_mixed_suffix) in init()
2115 --ThisTokEnd; in init()
2136 // C++11 [lex.string]p2: A `d-char-sequence` shall consist of at most 16 in init()
2141 while (static_cast<unsigned>(ThisTokBuf - Prefix) < MaxRawStrDelimLen && in init()
2149 ThisTokEnd -= ThisTokBuf - Prefix; in init()
2153 // C++14 [lex.string]p4: A source-file new-line in a raw string literal in init()
2154 // results in a new-line in the resulting execution string-literal. in init()
2155 StringRef RemainingTokenSpan(ThisTokBuf, ThisTokEnd - ThisTokBuf); in init()
2193 // Is this a span of non-escape characters? in init()
2202 StringRef(InStart, ThisTokBuf - InStart))) in init()
2215 // Otherwise, this is a non-UCN escape character. Process it. in init()
2248 ResultWidePtr[0] = GetNumStringChars() - 1; in init()
2253 ResultWidePtr[0] = GetNumStringChars() - 1; in init()
2256 ResultBuf[0] = GetNumStringChars() - 1; in init()
2262 Diags->Report(StringToks.front().getLocation(), in init()
2274 Diags->Report(StringToks.front().getLocation(), in init()
2286 End = Err + std::min<unsigned>(llvm::getNumBytesForUTF8(*Err), End-Err); in resyncUTF8()
2294 /// Performs widening for multi-byte characters.
2322 StringRef NextFragment(NextStart, Fragment.end()-NextStart); in CopyStringFragment()
2334 NextFragment = StringRef(NextStart, Fragment.end()-NextStart); in CopyStringFragment()
2343 Diags->Report(Loc, diag::err_lexing_string); in DiagnoseLexingError()
2346 /// getOffsetOfStringByte - This function returns the offset of the
2365 // Handle UTF-8 strings just like narrow strings. in getOffsetOfStringByte()
2383 return SpellingPtr - SpellingStart + ByteNo; in getOffsetOfStringByte()
2394 // Step over non-escapes simply. in getOffsetOfStringByte()
2397 --ByteNo; in getOffsetOfStringByte()
2413 ByteNo -= Len; in getOffsetOfStringByte()
2418 --ByteNo; in getOffsetOfStringByte()
2423 return SpellingPtr-SpellingStart; in getOffsetOfStringByte()
2426 /// Determine whether a suffix is a valid ud-suffix. We avoid treating reserved
2427 /// suffixes as ud-suffixes, because the diagnostic experience is better if we