@@ -287,9 +287,9 @@ static size_t getSpellingSlow(const Token &Tok, const char *BufPtr,
287
287
if (tok::isStringLiteral (Tok.getKind ())) {
288
288
// Munch the encoding-prefix and opening double-quote.
289
289
while (BufPtr < BufEnd) {
290
- unsigned Size ;
291
- Spelling[Length++] = Lexer::getCharAndSizeNoWarn (BufPtr, Size, LangOpts) ;
292
- BufPtr += Size;
290
+ auto CharAndSize = Lexer::getCharAndSizeNoWarn (BufPtr, LangOpts) ;
291
+ Spelling[Length++] = CharAndSize. Char ;
292
+ BufPtr += CharAndSize. Size ;
293
293
294
294
if (Spelling[Length - 1 ] == ' "' )
295
295
break ;
@@ -316,9 +316,9 @@ static size_t getSpellingSlow(const Token &Tok, const char *BufPtr,
316
316
}
317
317
318
318
while (BufPtr < BufEnd) {
319
- unsigned Size ;
320
- Spelling[Length++] = Lexer::getCharAndSizeNoWarn (BufPtr, Size, LangOpts) ;
321
- BufPtr += Size;
319
+ auto CharAndSize = Lexer::getCharAndSizeNoWarn (BufPtr, LangOpts) ;
320
+ Spelling[Length++] = CharAndSize. Char ;
321
+ BufPtr += CharAndSize. Size ;
322
322
}
323
323
324
324
assert (Length < Tok.getLength () &&
@@ -772,10 +772,9 @@ unsigned Lexer::getTokenPrefixLength(SourceLocation TokStart, unsigned CharNo,
772
772
// If we have a character that may be a trigraph or escaped newline, use a
773
773
// lexer to parse it correctly.
774
774
for (; CharNo; --CharNo) {
775
- unsigned Size;
776
- Lexer::getCharAndSizeNoWarn (TokPtr, Size, LangOpts);
777
- TokPtr += Size;
778
- PhysOffset += Size;
775
+ auto CharAndSize = Lexer::getCharAndSizeNoWarn (TokPtr, LangOpts);
776
+ TokPtr += CharAndSize.Size ;
777
+ PhysOffset += CharAndSize.Size ;
779
778
}
780
779
781
780
// Final detail: if we end up on an escaped newline, we want to return the
@@ -1357,15 +1356,16 @@ SourceLocation Lexer::findLocationAfterToken(
1357
1356
// /
1358
1357
// / NOTE: When this method is updated, getCharAndSizeSlowNoWarn (below) should
1359
1358
// / be updated to match.
1360
- char Lexer::getCharAndSizeSlow (const char *Ptr, unsigned &Size,
1361
- Token *Tok) {
1359
+ Lexer::SizedChar Lexer::getCharAndSizeSlow (const char *Ptr, Token *Tok) {
1360
+ unsigned Size = 0 ;
1362
1361
// If we have a slash, look for an escaped newline.
1363
1362
if (Ptr[0 ] == ' \\ ' ) {
1364
1363
++Size;
1365
1364
++Ptr;
1366
1365
Slash:
1367
1366
// Common case, backslash-char where the char is not whitespace.
1368
- if (!isWhitespace (Ptr[0 ])) return ' \\ ' ;
1367
+ if (!isWhitespace (Ptr[0 ]))
1368
+ return {' \\ ' , Size};
1369
1369
1370
1370
// See if we have optional whitespace characters between the slash and
1371
1371
// newline.
@@ -1382,11 +1382,13 @@ char Lexer::getCharAndSizeSlow(const char *Ptr, unsigned &Size,
1382
1382
Ptr += EscapedNewLineSize;
1383
1383
1384
1384
// Use slow version to accumulate a correct size field.
1385
- return getCharAndSizeSlow (Ptr, Size, Tok);
1385
+ auto CharAndSize = getCharAndSizeSlow (Ptr, Tok);
1386
+ CharAndSize.Size += Size;
1387
+ return CharAndSize;
1386
1388
}
1387
1389
1388
1390
// Otherwise, this is not an escaped newline, just return the slash.
1389
- return ' \\ ' ;
1391
+ return { ' \\ ' , Size} ;
1390
1392
}
1391
1393
1392
1394
// If this is a trigraph, process it.
@@ -1401,13 +1403,12 @@ char Lexer::getCharAndSizeSlow(const char *Ptr, unsigned &Size,
1401
1403
Ptr += 3 ;
1402
1404
Size += 3 ;
1403
1405
if (C == ' \\ ' ) goto Slash;
1404
- return C ;
1406
+ return {C, Size} ;
1405
1407
}
1406
1408
}
1407
1409
1408
1410
// If this is neither, return a single character.
1409
- ++Size;
1410
- return *Ptr;
1411
+ return {*Ptr, Size + 1u };
1411
1412
}
1412
1413
1413
1414
// / getCharAndSizeSlowNoWarn - Handle the slow/uncommon case of the
@@ -1416,15 +1417,18 @@ char Lexer::getCharAndSizeSlow(const char *Ptr, unsigned &Size,
1416
1417
// /
1417
1418
// / NOTE: When this method is updated, getCharAndSizeSlow (above) should
1418
1419
// / be updated to match.
1419
- char Lexer::getCharAndSizeSlowNoWarn (const char *Ptr, unsigned &Size,
1420
- const LangOptions &LangOpts) {
1420
+ Lexer::SizedChar Lexer::getCharAndSizeSlowNoWarn (const char *Ptr,
1421
+ const LangOptions &LangOpts) {
1422
+
1423
+ unsigned Size = 0 ;
1421
1424
// If we have a slash, look for an escaped newline.
1422
1425
if (Ptr[0 ] == ' \\ ' ) {
1423
1426
++Size;
1424
1427
++Ptr;
1425
1428
Slash:
1426
1429
// Common case, backslash-char where the char is not whitespace.
1427
- if (!isWhitespace (Ptr[0 ])) return ' \\ ' ;
1430
+ if (!isWhitespace (Ptr[0 ]))
1431
+ return {' \\ ' , Size};
1428
1432
1429
1433
// See if we have optional whitespace characters followed by a newline.
1430
1434
if (unsigned EscapedNewLineSize = getEscapedNewLineSize (Ptr)) {
@@ -1433,11 +1437,13 @@ char Lexer::getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size,
1433
1437
Ptr += EscapedNewLineSize;
1434
1438
1435
1439
// Use slow version to accumulate a correct size field.
1436
- return getCharAndSizeSlowNoWarn (Ptr, Size, LangOpts);
1440
+ auto CharAndSize = getCharAndSizeSlowNoWarn (Ptr, LangOpts);
1441
+ CharAndSize.Size += Size;
1442
+ return CharAndSize;
1437
1443
}
1438
1444
1439
1445
// Otherwise, this is not an escaped newline, just return the slash.
1440
- return ' \\ ' ;
1446
+ return { ' \\ ' , Size} ;
1441
1447
}
1442
1448
1443
1449
// If this is a trigraph, process it.
@@ -1448,13 +1454,12 @@ char Lexer::getCharAndSizeSlowNoWarn(const char *Ptr, unsigned &Size,
1448
1454
Ptr += 3 ;
1449
1455
Size += 3 ;
1450
1456
if (C == ' \\ ' ) goto Slash;
1451
- return C ;
1457
+ return {C, Size} ;
1452
1458
}
1453
1459
}
1454
1460
1455
1461
// If this is neither, return a single character.
1456
- ++Size;
1457
- return *Ptr;
1462
+ return {*Ptr, Size + 1u };
1458
1463
}
1459
1464
1460
1465
// ===----------------------------------------------------------------------===//
@@ -1964,11 +1969,14 @@ bool Lexer::LexIdentifierContinue(Token &Result, const char *CurPtr) {
1964
1969
// / isHexaLiteral - Return true if Start points to a hex constant.
1965
1970
// / in microsoft mode (where this is supposed to be several different tokens).
1966
1971
bool Lexer::isHexaLiteral (const char *Start, const LangOptions &LangOpts) {
1967
- unsigned Size ;
1968
- char C1 = Lexer::getCharAndSizeNoWarn (Start, Size, LangOpts) ;
1972
+ auto CharAndSize1 = Lexer::getCharAndSizeNoWarn (Start, LangOpts) ;
1973
+ char C1 = CharAndSize1. Char ;
1969
1974
if (C1 != ' 0' )
1970
1975
return false ;
1971
- char C2 = Lexer::getCharAndSizeNoWarn (Start + Size, Size, LangOpts);
1976
+
1977
+ auto CharAndSize2 =
1978
+ Lexer::getCharAndSizeNoWarn (Start + CharAndSize1.Size , LangOpts);
1979
+ char C2 = CharAndSize2.Char ;
1972
1980
return (C2 == ' x' || C2 == ' X' );
1973
1981
}
1974
1982
@@ -2012,8 +2020,7 @@ bool Lexer::LexNumericConstant(Token &Result, const char *CurPtr) {
2012
2020
2013
2021
// If we have a digit separator, continue.
2014
2022
if (C == ' \' ' && (LangOpts.CPlusPlus14 || LangOpts.C23 )) {
2015
- unsigned NextSize;
2016
- char Next = getCharAndSizeNoWarn (CurPtr + Size, NextSize, LangOpts);
2023
+ auto [Next, NextSize] = getCharAndSizeNoWarn (CurPtr + Size, LangOpts);
2017
2024
if (isAsciiIdentifierContinue (Next)) {
2018
2025
if (!isLexingRawMode ())
2019
2026
Diag (CurPtr, LangOpts.CPlusPlus
@@ -2085,8 +2092,8 @@ const char *Lexer::LexUDSuffix(Token &Result, const char *CurPtr,
2085
2092
unsigned Consumed = Size;
2086
2093
unsigned Chars = 1 ;
2087
2094
while (true ) {
2088
- unsigned NextSize;
2089
- char Next = getCharAndSizeNoWarn (CurPtr + Consumed, NextSize , LangOpts);
2095
+ auto [Next, NextSize] =
2096
+ getCharAndSizeNoWarn (CurPtr + Consumed, LangOpts);
2090
2097
if (!isAsciiIdentifierContinue (Next)) {
2091
2098
// End of suffix. Check whether this is on the allowed list.
2092
2099
const StringRef CompleteSuffix (Buffer, Chars);
0 commit comments