Skip to content

Commit 3c8057e

Browse files
committed
[Parse] Remove unnecessary Lexer fields
1 parent 420291b commit 3c8057e

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

include/swift/Parse/Lexer.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ class Lexer {
9292
/// Pointer to the next not consumed character.
9393
const char *CurPtr;
9494

95-
/// @{
96-
/// Members that are *not* permanent lexer state. The values only make sense
97-
/// during the lexImpl() invocation. These variables are declared as members
98-
/// rather than locals so that we don't have to thread them through to all
99-
/// lexing helpers.
100-
101-
/// Points to the point in the source buffer where we started scanning for
102-
/// the current token. Thus, the range [LastCommentBlockStart, CurPtr)
103-
/// covers all comments and whitespace that we skipped, and the token itself.
104-
const char *LastCommentBlockStart = nullptr;
105-
106-
/// True if we have seen a comment while scanning for the current token.
107-
bool SeenComment = false;
108-
109-
/// @}
110-
11195
Token NextToken;
11296

11397
/// \brief This is true if we're lexing a .sil file instead of a .swift

lib/Parse/Lexer.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,14 @@ void Lexer::formToken(tok Kind, const char *TokStart, bool MultilineString) {
278278
Kind = tok::eof;
279279
}
280280
unsigned CommentLength = 0;
281-
if (RetainComments == CommentRetentionMode::AttachToNextToken && SeenComment)
282-
CommentLength = TokStart - LastCommentBlockStart;
281+
if (RetainComments == CommentRetentionMode::AttachToNextToken) {
282+
auto Iter = llvm::find_if(LeadingTrivia, [](const TriviaPiece &Piece) {
283+
return Piece.isComment();
284+
});
285+
for (auto End = LeadingTrivia.end(); Iter != End; Iter++) {
286+
CommentLength += Iter->getTextLength();
287+
}
288+
}
283289

284290
StringRef TokenText { TokStart, static_cast<size_t>(CurPtr - TokStart) };
285291

@@ -2160,10 +2166,6 @@ void Lexer::lexImpl() {
21602166
NextToken.setAtStartOfLine(false);
21612167
}
21622168

2163-
// Remember where we started so that we can find the comment range.
2164-
LastCommentBlockStart = CurPtr;
2165-
SeenComment = false;
2166-
21672169
lexTrivia(LeadingTrivia, /* IsForTrailingTrivia */ false);
21682170

21692171
// Remember the start of the token so we can form the text range.
@@ -2253,14 +2255,12 @@ void Lexer::lexImpl() {
22532255
case '/':
22542256
if (CurPtr[0] == '/') { // "//"
22552257
skipSlashSlashComment(/*EatNewline=*/true);
2256-
SeenComment = true;
22572258
assert(isKeepingComments() &&
22582259
"Non token comment should be eaten by lexTrivia as LeadingTrivia");
22592260
return formToken(tok::comment, TokStart);
22602261
}
22612262
if (CurPtr[0] == '*') { // "/*"
22622263
skipSlashStarComment();
2263-
SeenComment = true;
22642264
assert(isKeepingComments() &&
22652265
"Non token comment should be eaten by lexTrivia as LeadingTrivia");
22662266
return formToken(tok::comment, TokStart);
@@ -2393,7 +2393,6 @@ void Lexer::lexTrivia(syntax::Trivia &Pieces, bool IsForTrailingTrivia) {
23932393
break;
23942394
} else if (*CurPtr == '/') {
23952395
// '// ...' comment.
2396-
SeenComment = true;
23972396
bool isDocComment = CurPtr[1] == '/';
23982397
skipSlashSlashComment(/*EatNewline=*/false);
23992398
size_t Length = CurPtr - TriviaStart;
@@ -2403,7 +2402,6 @@ void Lexer::lexTrivia(syntax::Trivia &Pieces, bool IsForTrailingTrivia) {
24032402
goto Restart;
24042403
} else if (*CurPtr == '*') {
24052404
// '/* ... */' comment.
2406-
SeenComment = true;
24072405
bool isDocComment = CurPtr[1] == '*';
24082406
skipSlashStarComment();
24092407
size_t Length = CurPtr - TriviaStart;

0 commit comments

Comments
 (0)