@@ -40,7 +40,6 @@ void Parser_registerRegexLiteralLexingFn(RegexLiteralLexingFn fn) {
40
40
}
41
41
42
42
using namespace swift ;
43
- using namespace swift ::syntax;
44
43
45
44
// clang::isAsciiIdentifierStart and clang::isAsciiIdentifierContinue are
46
45
// deliberately not in this list as a reminder that they are using C rules for
@@ -179,12 +178,12 @@ uint32_t swift::validateUTF8CharacterAndAdvance(const char *&Ptr,
179
178
Lexer::Lexer (const PrincipalTag &, const LangOptions &LangOpts,
180
179
const SourceManager &SourceMgr, unsigned BufferID,
181
180
DiagnosticEngine *Diags, LexerMode LexMode,
182
- HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
183
- TriviaRetentionMode TriviaRetention )
181
+ HashbangMode HashbangAllowed,
182
+ CommentRetentionMode RetainComments )
184
183
: LangOpts(LangOpts), SourceMgr(SourceMgr), BufferID(BufferID),
185
184
LexMode(LexMode),
186
185
IsHashbangAllowed(HashbangAllowed == HashbangMode::Allowed),
187
- RetainComments(RetainComments), TriviaRetention(TriviaRetention) {
186
+ RetainComments(RetainComments) {
188
187
if (Diags)
189
188
DiagQueue.emplace (*Diags, /* emitOnDestruction*/ false );
190
189
}
@@ -227,21 +226,20 @@ void Lexer::initialize(unsigned Offset, unsigned EndOffset) {
227
226
228
227
Lexer::Lexer (const LangOptions &Options, const SourceManager &SourceMgr,
229
228
unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
230
- HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
231
- TriviaRetentionMode TriviaRetention )
229
+ HashbangMode HashbangAllowed,
230
+ CommentRetentionMode RetainComments )
232
231
: Lexer(PrincipalTag(), Options, SourceMgr, BufferID, Diags, LexMode,
233
- HashbangAllowed, RetainComments, TriviaRetention ) {
232
+ HashbangAllowed, RetainComments) {
234
233
unsigned EndOffset = SourceMgr.getRangeForBuffer (BufferID).getByteLength ();
235
234
initialize (/* Offset=*/ 0 , EndOffset);
236
235
}
237
236
238
237
Lexer::Lexer (const LangOptions &Options, const SourceManager &SourceMgr,
239
238
unsigned BufferID, DiagnosticEngine *Diags, LexerMode LexMode,
240
239
HashbangMode HashbangAllowed, CommentRetentionMode RetainComments,
241
- TriviaRetentionMode TriviaRetention, unsigned Offset,
242
- unsigned EndOffset)
240
+ unsigned Offset, unsigned EndOffset)
243
241
: Lexer(PrincipalTag(), Options, SourceMgr, BufferID, Diags, LexMode,
244
- HashbangAllowed, RetainComments, TriviaRetention ) {
242
+ HashbangAllowed, RetainComments) {
245
243
initialize (Offset, EndOffset);
246
244
}
247
245
@@ -253,7 +251,7 @@ Lexer::Lexer(const Lexer &Parent, State BeginState, State EndState,
253
251
Parent.IsHashbangAllowed
254
252
? HashbangMode::Allowed
255
253
: HashbangMode::Disallowed,
256
- Parent.RetainComments, Parent.TriviaRetention ) {
254
+ Parent.RetainComments) {
257
255
assert (BufferID == SourceMgr.findBufferContainingLoc (BeginState.Loc ) &&
258
256
" state for the wrong buffer" );
259
257
assert (BufferID == SourceMgr.findBufferContainingLoc (EndState.Loc ) &&
@@ -277,8 +275,7 @@ Token Lexer::getTokenAt(SourceLoc Loc) {
277
275
" location from the wrong buffer" );
278
276
279
277
Lexer L (LangOpts, SourceMgr, BufferID, getUnderlyingDiags (), LexMode,
280
- HashbangMode::Allowed, CommentRetentionMode::None,
281
- TriviaRetentionMode::WithoutTrivia);
278
+ HashbangMode::Allowed, CommentRetentionMode::None);
282
279
L.restoreState (State (Loc));
283
280
return L.peekNextToken ();
284
281
}
@@ -301,13 +298,6 @@ void Lexer::formToken(tok Kind, const char *TokStart) {
301
298
}
302
299
303
300
StringRef TokenText { TokStart, static_cast <size_t >(CurPtr - TokStart) };
304
-
305
- if (TriviaRetention == TriviaRetentionMode::WithTrivia && Kind != tok::eof) {
306
- TrailingTrivia = lexTrivia (/* IsForTrailingTrivia=*/ true , CurPtr);
307
- } else {
308
- TrailingTrivia = StringRef ();
309
- }
310
-
311
301
NextToken.setToken (Kind, TokenText, CommentLength);
312
302
}
313
303
@@ -654,12 +644,12 @@ bool Lexer::isOperator(StringRef string) {
654
644
tok Lexer::kindOfIdentifier (StringRef Str, bool InSILMode) {
655
645
#define SIL_KEYWORD (kw )
656
646
#define KEYWORD (kw ) if (Str == #kw) return tok::kw_##kw;
657
- #include " swift/Syntax /TokenKinds.def"
647
+ #include " swift/AST /TokenKinds.def"
658
648
659
649
// SIL keywords are only active in SIL mode.
660
650
if (InSILMode) {
661
651
#define SIL_KEYWORD (kw ) if (Str == #kw) return tok::kw_##kw;
662
- #include " swift/Syntax /TokenKinds.def"
652
+ #include " swift/AST /TokenKinds.def"
663
653
}
664
654
return tok::identifier;
665
655
}
@@ -696,7 +686,7 @@ void Lexer::lexHash() {
696
686
tok Kind = llvm::StringSwitch<tok>(StringRef (CurPtr, tmpPtr-CurPtr))
697
687
#define POUND_KEYWORD (id ) \
698
688
.Case (#id, tok::pound_##id)
699
- #include " swift/Syntax /TokenKinds.def"
689
+ #include " swift/AST /TokenKinds.def"
700
690
.Default (tok::pound);
701
691
702
692
// If we didn't find a match, then just return tok::pound. This is highly
@@ -2615,7 +2605,7 @@ void Lexer::lexImpl() {
2615
2605
NextToken.setAtStartOfLine (false );
2616
2606
}
2617
2607
2618
- LeadingTrivia = lexTrivia (/* IsForTrailingTrivia=*/ false , LeadingTriviaStart);
2608
+ lexTrivia (/* IsForTrailingTrivia=*/ false , LeadingTriviaStart);
2619
2609
2620
2610
// Remember the start of the token so we can form the text range.
2621
2611
const char *TokStart = CurPtr;
@@ -2955,7 +2945,7 @@ static SourceLoc getLocForStartOfTokenInBuf(SourceManager &SM,
2955
2945
2956
2946
Lexer L (FakeLangOptions, SM, BufferID, nullptr , LexerMode::Swift,
2957
2947
HashbangMode::Allowed, CommentRetentionMode::None,
2958
- TriviaRetentionMode::WithoutTrivia, BufferStart, BufferEnd);
2948
+ BufferStart, BufferEnd);
2959
2949
2960
2950
// Lex tokens until we find the token that contains the source location.
2961
2951
Token Tok;
@@ -3145,138 +3135,6 @@ bool tryAdvanceToEndOfConflictMarker(const char *&CurPtr,
3145
3135
return false ;
3146
3136
}
3147
3137
3148
- ParsedTrivia TriviaLexer::lexTrivia (StringRef TriviaStr) {
3149
- const char *CurPtr = TriviaStr.begin ();
3150
- const char *BufferEnd = TriviaStr.end ();
3151
-
3152
- ParsedTrivia Pieces;
3153
-
3154
- while (CurPtr < BufferEnd) {
3155
- // Iterate through the trivia and lex them into pieces. In the switch
3156
- // statement in this loop we can
3157
- // - 'continue' if we have successfully lexed a trivia piece to continue
3158
- // with the next piece. In this case CurPtr points to the next character
3159
- // to be lexed (which is not part of the lexed trivia).
3160
- // - 'break' to perform the default handling defined towards the bottom of
3161
- // the loop.
3162
-
3163
- const char *TriviaStart = CurPtr;
3164
-
3165
- switch (*CurPtr++) {
3166
- case ' \n ' :
3167
- Pieces.appendOrSquash (TriviaKind::Newline, 1 );
3168
- continue ;
3169
- case ' \r ' :
3170
- if (CurPtr < BufferEnd && CurPtr[0 ] == ' \n ' ) {
3171
- Pieces.appendOrSquash (TriviaKind::CarriageReturnLineFeed, 2 );
3172
- ++CurPtr;
3173
- continue ;
3174
- } else {
3175
- Pieces.appendOrSquash (TriviaKind::CarriageReturn, 1 );
3176
- continue ;
3177
- }
3178
- case ' ' :
3179
- Pieces.appendOrSquash (TriviaKind::Space, 1 );
3180
- continue ;
3181
- case ' \t ' :
3182
- Pieces.appendOrSquash (TriviaKind::Tab, 1 );
3183
- continue ;
3184
- case ' \v ' :
3185
- Pieces.appendOrSquash (TriviaKind::VerticalTab, 1 );
3186
- continue ;
3187
- case ' \f ' :
3188
- Pieces.appendOrSquash (TriviaKind::Formfeed, 1 );
3189
- continue ;
3190
- case ' /' :
3191
- if (CurPtr < BufferEnd && CurPtr[0 ] == ' /' ) {
3192
- // '// ...' comment.
3193
- bool isDocComment = CurPtr[1 ] == ' /' ;
3194
- advanceToEndOfLine (CurPtr, BufferEnd);
3195
- size_t Length = CurPtr - TriviaStart;
3196
- Pieces.push_back (isDocComment ? TriviaKind::DocLineComment
3197
- : TriviaKind::LineComment,
3198
- Length);
3199
- continue ;
3200
- } else if (CurPtr < BufferEnd && CurPtr[0 ] == ' *' ) {
3201
- // '/* ... */' comment.
3202
- bool isDocComment = CurPtr[1 ] == ' *' ;
3203
- skipToEndOfSlashStarComment (CurPtr, BufferEnd);
3204
- size_t Length = CurPtr - TriviaStart;
3205
- Pieces.push_back (isDocComment ? TriviaKind::DocBlockComment
3206
- : TriviaKind::BlockComment,
3207
- Length);
3208
- continue ;
3209
- }
3210
- break ;
3211
- case ' #' :
3212
- if (CurPtr < BufferEnd && CurPtr[0 ] == ' !' ) {
3213
- // Hashbang '#!/path/to/swift'.
3214
- advanceToEndOfLine (CurPtr, BufferEnd);
3215
- size_t Length = CurPtr - TriviaStart;
3216
- Pieces.push_back (TriviaKind::Shebang, Length);
3217
- continue ;
3218
- }
3219
- break ;
3220
- case ' <' :
3221
- case ' >' :
3222
- if (tryAdvanceToEndOfConflictMarker (CurPtr, BufferEnd)) {
3223
- // Conflict marker.
3224
- size_t Length = CurPtr - TriviaStart;
3225
- Pieces.push_back (TriviaKind::UnexpectedText, Length);
3226
- continue ;
3227
- }
3228
- break ;
3229
- case ' \xEF ' :
3230
- if ((CurPtr + 1 ) < BufferEnd && CurPtr[0 ] == ' \xBB ' && CurPtr[1 ] == ' \xBF ' ) {
3231
- // BOM marker.
3232
- CurPtr = CurPtr + 2 ;
3233
- size_t Length = CurPtr - TriviaStart;
3234
- Pieces.push_back (TriviaKind::UnexpectedText, Length);
3235
- continue ;
3236
- }
3237
- break ;
3238
- case 0 : {
3239
- size_t Length = CurPtr - TriviaStart;
3240
- Pieces.push_back (TriviaKind::UnexpectedText, Length);
3241
- continue ;
3242
- }
3243
- default :
3244
- break ;
3245
- }
3246
-
3247
- // Default handling for anything that didn't 'continue' in the above switch
3248
- // statement.
3249
-
3250
- for (; CurPtr < BufferEnd; ++CurPtr) {
3251
- bool HasFoundNextTriviaStart = false ;
3252
- switch (*CurPtr) {
3253
- case ' \n ' :
3254
- case ' \r ' :
3255
- case ' ' :
3256
- case ' \t ' :
3257
- case ' \v ' :
3258
- case ' \f ' :
3259
- case ' /' :
3260
- case 0 :
3261
- HasFoundNextTriviaStart = true ;
3262
- break ;
3263
- }
3264
- if (HasFoundNextTriviaStart) {
3265
- break ;
3266
- }
3267
- }
3268
-
3269
- size_t Length = CurPtr - TriviaStart;
3270
- Pieces.push_back (TriviaKind::UnexpectedText, Length);
3271
- continue ;
3272
- }
3273
-
3274
- assert (Pieces.getLength () == TriviaStr.size () &&
3275
- " Not all characters in the source string have been used in trivia "
3276
- " pieces" );
3277
- return Pieces;
3278
- }
3279
-
3280
3138
ArrayRef<Token> swift::
3281
3139
slice_token_array (ArrayRef<Token> AllTokens, SourceLoc StartLoc,
3282
3140
SourceLoc EndLoc) {
0 commit comments