@@ -412,18 +412,17 @@ namespace {
412
412
// / underlying corrected token stream.
413
413
class TokenRecorder : public ConsumeTokenReceiver {
414
414
ASTContext &Ctx;
415
- SourceManager &SM ;
415
+ unsigned BufferID ;
416
416
417
417
// Token list ordered by their appearance in the source file.
418
- std::vector<Token> &Bag;
419
- unsigned BufferID;
418
+ std::vector<Token> &Tokens;
420
419
421
420
// Registered token kind change. These changes are regiestered before the
422
421
// token is consumed, so we need to keep track of them here.
423
422
llvm::DenseMap<const void *, tok> TokenKindChangeMap;
424
423
425
424
std::vector<Token>::iterator lower_bound (SourceLoc Loc) {
426
- return token_lower_bound (Bag , Loc);
425
+ return token_lower_bound (Tokens , Loc);
427
426
}
428
427
429
428
std::vector<Token>::iterator lower_bound (Token Tok) {
@@ -432,9 +431,9 @@ class TokenRecorder: public ConsumeTokenReceiver {
432
431
433
432
void relexComment (CharSourceRange CommentRange,
434
433
llvm::SmallVectorImpl<Token> &Scratch) {
435
- Lexer L (Ctx. LangOpts , Ctx.SourceMgr , BufferID, nullptr , LexerMode::Swift,
436
- HashbangMode::Disallowed ,
437
- CommentRetentionMode::ReturnAsTokens,
434
+ auto &SM = Ctx.SourceMgr ;
435
+ Lexer L (Ctx. LangOpts , SM, BufferID, nullptr , LexerMode::Swift ,
436
+ HashbangMode::Disallowed, CommentRetentionMode::ReturnAsTokens,
438
437
TriviaRetentionMode::WithoutTrivia,
439
438
SM.getLocOffsetInBuffer (CommentRange.getStart (), BufferID),
440
439
SM.getLocOffsetInBuffer (CommentRange.getEnd (), BufferID));
@@ -449,19 +448,18 @@ class TokenRecorder: public ConsumeTokenReceiver {
449
448
}
450
449
451
450
public:
452
- TokenRecorder (SourceFile &SF, unsigned BufferID):
453
- Ctx (SF.getASTContext()),
454
- SM (SF.getASTContext().SourceMgr),
455
- Bag (SF.getTokenVector()),
456
- BufferID (BufferID) {};
451
+ TokenRecorder (SourceFile &SF, unsigned BufferID)
452
+ : Ctx(SF.getASTContext()), BufferID(BufferID),
453
+ Tokens (SF.getTokenVector()) {}
457
454
458
455
void finalize () override {
456
+ auto &SM = Ctx.SourceMgr ;
459
457
460
458
// We should consume the comments at the end of the file that don't attach
461
459
// to any tokens.
462
460
SourceLoc TokEndLoc;
463
- if (!Bag .empty ()) {
464
- Token Last = Bag .back ();
461
+ if (!Tokens .empty ()) {
462
+ Token Last = Tokens .back ();
465
463
TokEndLoc = Last.getLoc ().getAdvancedLoc (Last.getLength ());
466
464
} else {
467
465
@@ -473,14 +471,14 @@ class TokenRecorder: public ConsumeTokenReceiver {
473
471
SM.getRangeForBuffer (BufferID).getEnd ()),
474
472
Scratch);
475
473
// Accept these orphaned comments.
476
- Bag .insert (Bag .end (), Scratch.begin (), Scratch.end ());
474
+ Tokens .insert (Tokens .end (), Scratch.begin (), Scratch.end ());
477
475
}
478
476
479
477
void registerTokenKindChange (SourceLoc Loc, tok NewKind) override {
480
478
// If a token with the same location is already in the bag, update its kind.
481
479
auto Pos = lower_bound (Loc);
482
- if (Pos != Bag .end () && Pos-> getLoc (). getOpaquePointerValue () ==
483
- Loc.getOpaquePointerValue ()) {
480
+ if (Pos != Tokens .end () &&
481
+ Pos-> getLoc (). getOpaquePointerValue () == Loc.getOpaquePointerValue ()) {
484
482
Pos->setKind (NewKind);
485
483
return ;
486
484
}
@@ -496,8 +494,8 @@ class TokenRecorder: public ConsumeTokenReceiver {
496
494
497
495
// If a token with the same location is already in the bag, skip this token.
498
496
auto Pos = lower_bound (Tok);
499
- if (Pos != Bag .end () && Pos->getLoc ().getOpaquePointerValue () ==
500
- Tok.getLoc ().getOpaquePointerValue ()) {
497
+ if (Pos != Tokens .end () && Pos->getLoc ().getOpaquePointerValue () ==
498
+ Tok.getLoc ().getOpaquePointerValue ()) {
501
499
return ;
502
500
}
503
501
@@ -516,7 +514,7 @@ class TokenRecorder: public ConsumeTokenReceiver {
516
514
}
517
515
518
516
TokensToConsume.push_back (Tok);
519
- Bag .insert (Pos, TokensToConsume.begin (), TokensToConsume.end ());
517
+ Tokens .insert (Pos, TokensToConsume.begin (), TokensToConsume.end ());
520
518
}
521
519
};
522
520
} // End of an anonymous namespace.
0 commit comments