22
22
#include " swift/Basic/SourceManager.h"
23
23
#include " swift/Parse/LexerState.h"
24
24
#include " swift/Parse/Token.h"
25
- #include " swift/Parse/ParsedTrivia.h"
26
25
#include " llvm/ADT/SmallVector.h"
27
26
#include " llvm/Support/SaveAndRestore.h"
28
27
@@ -45,11 +44,6 @@ enum class CommentRetentionMode {
45
44
ReturnAsTokens,
46
45
};
47
46
48
- enum class TriviaRetentionMode {
49
- WithoutTrivia,
50
- WithTrivia,
51
- };
52
-
53
47
enum class HashbangMode : bool {
54
48
Disallowed,
55
49
Allowed,
@@ -131,21 +125,10 @@ class Lexer {
131
125
132
126
const CommentRetentionMode RetainComments;
133
127
134
- const TriviaRetentionMode TriviaRetention;
135
-
136
128
// / InSILBody - This is true when we're lexing the body of a SIL declaration
137
129
// / in a SIL file. This enables some context-sensitive lexing.
138
130
bool InSILBody = false ;
139
131
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
-
149
132
// / The location at which the comment of the next token starts. \c nullptr if
150
133
// / the next token doesn't have a comment.
151
134
const char *CommentStart;
@@ -166,8 +149,8 @@ class Lexer {
166
149
Lexer (const PrincipalTag &, const LangOptions &LangOpts,
167
150
const SourceManager &SourceMgr, unsigned BufferID,
168
151
DiagnosticEngine *Diags, LexerMode LexMode,
169
- HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
170
- TriviaRetentionMode TriviaRetention );
152
+ HashbangMode HashbangAllowed,
153
+ CommentRetentionMode RetainComments );
171
154
172
155
void initialize (unsigned Offset, unsigned EndOffset);
173
156
@@ -202,14 +185,13 @@ class Lexer {
202
185
const LangOptions &Options, const SourceManager &SourceMgr,
203
186
unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
204
187
HashbangMode HashbangAllowed = HashbangMode::Disallowed,
205
- CommentRetentionMode RetainComments = CommentRetentionMode::None,
206
- TriviaRetentionMode TriviaRetention = TriviaRetentionMode::WithoutTrivia);
188
+ CommentRetentionMode RetainComments = CommentRetentionMode::None);
207
189
208
190
// / Create a lexer that scans a subrange of the source buffer.
209
191
Lexer (const LangOptions &Options, const SourceManager &SourceMgr,
210
192
unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
211
193
HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
212
- TriviaRetentionMode TriviaRetention, unsigned Offset,
194
+ unsigned Offset,
213
195
unsigned EndOffset);
214
196
215
197
// / Create a sub-lexer that lexes from the same buffer, but scans
@@ -233,15 +215,9 @@ class Lexer {
233
215
return LexMode == LexerMode::SwiftInterface;
234
216
}
235
217
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) {
240
220
Result = NextToken;
241
- if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
242
- LeadingTriviaResult = LeadingTrivia;
243
- TrailingTriviaResult = TrailingTrivia;
244
- }
245
221
// Emit any diagnostics recorded for this token.
246
222
if (DiagQueue)
247
223
DiagQueue->emit ();
@@ -250,11 +226,6 @@ class Lexer {
250
226
lexImpl ();
251
227
}
252
228
253
- void lex (Token &Result) {
254
- StringRef LeadingTrivia, TrailingTrivia;
255
- lex (Result, LeadingTrivia, TrailingTrivia);
256
- }
257
-
258
229
// / Reset the lexer's buffer pointer to \p Offset bytes after the buffer
259
230
// / start.
260
231
void resetToOffset (size_t Offset) {
@@ -304,8 +275,7 @@ class Lexer {
304
275
// / Returns the lexer state for the beginning of the given token.
305
276
// / After restoring the state, lexer will return this token and continue from
306
277
// / there.
307
- State getStateForBeginningOfToken (const Token &Tok,
308
- const StringRef &LeadingTrivia = {}) const {
278
+ State getStateForBeginningOfToken (const Token &Tok) const {
309
279
310
280
// If the token has a comment attached to it, rewind to before the comment,
311
281
// not just the start of the token. This ensures that we will re-lex and
@@ -314,11 +284,6 @@ class Lexer {
314
284
if (TokStart.isInvalid ())
315
285
TokStart = Tok.getLoc ();
316
286
auto S = getStateForBeginningOfTokenLoc (TokStart);
317
- if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
318
- S.LeadingTrivia = LeadingTrivia;
319
- } else {
320
- S.LeadingTrivia = StringRef ();
321
- }
322
287
return S;
323
288
}
324
289
@@ -340,10 +305,6 @@ class Lexer {
340
305
// Don't re-emit diagnostics from readvancing the lexer.
341
306
if (DiagQueue && !enableDiagnostics)
342
307
DiagQueue->clear ();
343
-
344
- // Restore Trivia.
345
- if (TriviaRetention == TriviaRetentionMode::WithTrivia)
346
- LeadingTrivia = S.LeadingTrivia ;
347
308
}
348
309
349
310
// / Restore the lexer state to a given state that is located before
@@ -681,13 +642,6 @@ class Lexer {
681
642
682
643
};
683
644
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
-
691
645
// / Given an ordered token \param Array , get the iterator pointing to the first
692
646
// / token that is not before \param Loc .
693
647
template <typename ArrayTy, typename Iterator = typename ArrayTy::iterator>
0 commit comments