Skip to content

Commit fd146e5

Browse files
committed
NFC
1 parent 3efb5ca commit fd146e5

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

clang/lib/Format/FormatTokenLexer.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,24 +1329,25 @@ FormatToken *FormatTokenLexer::getNextToken() {
13291329
if (FormatTok->is(tok::unknown))
13301330
FormatTok->setType(TT_ImplicitStringLiteral);
13311331

1332+
const bool IsCpp = Style.isCpp();
1333+
13321334
// JavaScript and Java do not allow to escape the end of the line with a
13331335
// backslash. Backslashes are syntax errors in plain source, but can occur in
13341336
// comments. When a single line comment ends with a \, it'll cause the next
13351337
// line of code to be lexed as a comment, breaking formatting. The code below
13361338
// finds comments that contain a backslash followed by a line break, truncates
13371339
// the comment token at the backslash, and resets the lexer to restart behind
13381340
// the backslash.
1339-
if ((Style.isCpp() || Style.isJavaScript() || Style.isJava()) &&
1340-
FormatTok->is(tok::comment)) {
1341-
if (const auto Text = FormatTok->TokenText; Text.starts_with("//")) {
1342-
for (auto Pos = Text.find('\\'); Pos++ != StringRef::npos;
1343-
Pos = Text.find('\\', Pos)) {
1344-
if (Pos < Text.size() && Text[Pos] == '\n' &&
1345-
(!Style.isCpp() ||
1346-
Text.substr(Pos + 1).ltrim().starts_with("//"))) {
1347-
truncateToken(Pos);
1348-
break;
1349-
}
1341+
if (const auto Text = FormatTok->TokenText;
1342+
Text.starts_with("//") &&
1343+
(IsCpp || Style.isJavaScript() || Style.isJava())) {
1344+
assert(FormatTok->is(tok::comment));
1345+
for (auto Pos = Text.find('\\'); Pos++ != StringRef::npos;
1346+
Pos = Text.find('\\', Pos)) {
1347+
if (Pos < Text.size() && Text[Pos] == '\n' &&
1348+
(!IsCpp || Text.substr(Pos + 1).ltrim().starts_with("//"))) {
1349+
truncateToken(Pos);
1350+
break;
13501351
}
13511352
}
13521353
}
@@ -1452,7 +1453,7 @@ FormatToken *FormatTokenLexer::getNextToken() {
14521453
Column = FormatTok->LastLineColumnWidth;
14531454
}
14541455

1455-
if (Style.isCpp()) {
1456+
if (IsCpp) {
14561457
auto *Identifier = FormatTok->Tok.getIdentifierInfo();
14571458
auto it = Macros.find(Identifier);
14581459
if ((Tokens.empty() || !Tokens.back()->Tok.getIdentifierInfo() ||

0 commit comments

Comments
 (0)