Skip to content

Commit 1a4d375

Browse files
committed
[Lexer] Remove unnecessary logic from lexCharacter
EOF and newline (in non-multiline string literal) must be handled by call site. lexCharacter doesn't need to handle them. Added assertion instead.
1 parent ba51727 commit 1a4d375

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/Parse/Lexer.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,23 +1344,14 @@ unsigned Lexer::lexCharacter(const char *&CurPtr, char StopQuote,
13441344
return CurPtr[-1];
13451345

13461346
case 0:
1347-
if (CurPtr-1 != BufferEnd) {
1348-
if (EmitDiagnostics)
1349-
diagnose(CurPtr-1, diag::lex_nul_character);
1350-
return CurPtr[-1];
1351-
}
1352-
// Move the pointer back to EOF.
1353-
--CurPtr;
1347+
assert(CurPtr - 1 != BufferEnd && "Caller must handle EOF");
13541348
if (EmitDiagnostics)
1355-
diagnose(CurPtr-1, diag::lex_unterminated_string);
1356-
return ~1U;
1349+
diagnose(CurPtr-1, diag::lex_nul_character);
1350+
return CurPtr[-1];
13571351
case '\n': // String literals cannot have \n or \r in them.
13581352
case '\r':
1359-
if (IsMultilineString) // ... unless they are multiline
1360-
return CurPtr[-1];
1361-
if (EmitDiagnostics)
1362-
diagnose(CurPtr-1, diag::lex_unterminated_string);
1363-
return ~1U;
1353+
assert(IsMultilineString && "Caller must handle newlines in non-multiline");
1354+
return CurPtr[-1];
13641355
case '\\': // Escapes.
13651356
if (!delimiterMatches(CustomDelimiterLen, CurPtr,
13661357
EmitDiagnostics ? Diags : nullptr))

0 commit comments

Comments
 (0)