2222#include " swift/Basic/SourceManager.h"
2323#include " swift/Parse/LexerState.h"
2424#include " swift/Parse/Token.h"
25- #include " swift/Parse/ParsedTrivia.h"
2625#include " llvm/ADT/SmallVector.h"
2726#include " llvm/Support/SaveAndRestore.h"
2827
@@ -45,11 +44,6 @@ enum class CommentRetentionMode {
4544 ReturnAsTokens,
4645};
4746
48- enum class TriviaRetentionMode {
49- WithoutTrivia,
50- WithTrivia,
51- };
52-
5347enum class HashbangMode : bool {
5448 Disallowed,
5549 Allowed,
@@ -131,21 +125,10 @@ class Lexer {
131125
132126 const CommentRetentionMode RetainComments;
133127
134- const TriviaRetentionMode TriviaRetention;
135-
136128 // / InSILBody - This is true when we're lexing the body of a SIL declaration
137129 // / in a SIL file. This enables some context-sensitive lexing.
138130 bool InSILBody = false ;
139131
140- // / The current leading trivia for the next token.
141- // /
142- // / The StringRef points into the source buffer that is currently being lexed.
143- StringRef LeadingTrivia;
144-
145- // / The current trailing trivia for the next token.
146- // / The StringRef points into the source buffer that is currently being lexed.
147- StringRef TrailingTrivia;
148-
149132 // / The location at which the comment of the next token starts. \c nullptr if
150133 // / the next token doesn't have a comment.
151134 const char *CommentStart;
@@ -166,8 +149,8 @@ class Lexer {
166149 Lexer (const PrincipalTag &, const LangOptions &LangOpts,
167150 const SourceManager &SourceMgr, unsigned BufferID,
168151 DiagnosticEngine *Diags, LexerMode LexMode,
169- HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
170- TriviaRetentionMode TriviaRetention );
152+ HashbangMode HashbangAllowed,
153+ CommentRetentionMode RetainComments );
171154
172155 void initialize (unsigned Offset, unsigned EndOffset);
173156
@@ -202,14 +185,13 @@ class Lexer {
202185 const LangOptions &Options, const SourceManager &SourceMgr,
203186 unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
204187 HashbangMode HashbangAllowed = HashbangMode::Disallowed,
205- CommentRetentionMode RetainComments = CommentRetentionMode::None,
206- TriviaRetentionMode TriviaRetention = TriviaRetentionMode::WithoutTrivia);
188+ CommentRetentionMode RetainComments = CommentRetentionMode::None);
207189
208190 // / Create a lexer that scans a subrange of the source buffer.
209191 Lexer (const LangOptions &Options, const SourceManager &SourceMgr,
210192 unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
211193 HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
212- TriviaRetentionMode TriviaRetention, unsigned Offset,
194+ unsigned Offset,
213195 unsigned EndOffset);
214196
215197 // / Create a sub-lexer that lexes from the same buffer, but scans
@@ -233,15 +215,9 @@ class Lexer {
233215 return LexMode == LexerMode::SwiftInterface;
234216 }
235217
236- // / Lex a token. If \c TriviaRetentionMode is \c WithTrivia, passed pointers
237- // / to trivia are populated.
238- void lex (Token &Result, StringRef &LeadingTriviaResult,
239- StringRef &TrailingTriviaResult) {
218+ // / Lex a token.
219+ void lex (Token &Result) {
240220 Result = NextToken;
241- if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
242- LeadingTriviaResult = LeadingTrivia;
243- TrailingTriviaResult = TrailingTrivia;
244- }
245221 // Emit any diagnostics recorded for this token.
246222 if (DiagQueue)
247223 DiagQueue->emit ();
@@ -250,11 +226,6 @@ class Lexer {
250226 lexImpl ();
251227 }
252228
253- void lex (Token &Result) {
254- StringRef LeadingTrivia, TrailingTrivia;
255- lex (Result, LeadingTrivia, TrailingTrivia);
256- }
257-
258229 // / Reset the lexer's buffer pointer to \p Offset bytes after the buffer
259230 // / start.
260231 void resetToOffset (size_t Offset) {
@@ -304,8 +275,7 @@ class Lexer {
304275 // / Returns the lexer state for the beginning of the given token.
305276 // / After restoring the state, lexer will return this token and continue from
306277 // / there.
307- State getStateForBeginningOfToken (const Token &Tok,
308- const StringRef &LeadingTrivia = {}) const {
278+ State getStateForBeginningOfToken (const Token &Tok) const {
309279
310280 // If the token has a comment attached to it, rewind to before the comment,
311281 // not just the start of the token. This ensures that we will re-lex and
@@ -314,11 +284,6 @@ class Lexer {
314284 if (TokStart.isInvalid ())
315285 TokStart = Tok.getLoc ();
316286 auto S = getStateForBeginningOfTokenLoc (TokStart);
317- if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
318- S.LeadingTrivia = LeadingTrivia;
319- } else {
320- S.LeadingTrivia = StringRef ();
321- }
322287 return S;
323288 }
324289
@@ -340,10 +305,6 @@ class Lexer {
340305 // Don't re-emit diagnostics from readvancing the lexer.
341306 if (DiagQueue && !enableDiagnostics)
342307 DiagQueue->clear ();
343-
344- // Restore Trivia.
345- if (TriviaRetention == TriviaRetentionMode::WithTrivia)
346- LeadingTrivia = S.LeadingTrivia ;
347308 }
348309
349310 // / Restore the lexer state to a given state that is located before
@@ -681,13 +642,6 @@ class Lexer {
681642
682643};
683644
684- // / A lexer that can lex trivia into its pieces
685- class TriviaLexer {
686- public:
687- // / Decompose the trivia in \p TriviaStr into their pieces.
688- static ParsedTrivia lexTrivia (StringRef TriviaStr);
689- };
690-
691645// / Given an ordered token \param Array , get the iterator pointing to the first
692646// / token that is not before \param Loc .
693647template <typename ArrayTy, typename Iterator = typename ArrayTy::iterator>
0 commit comments