Skip to content

[Parser] Pass token to TokenReceiver by reference #36237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace swift {
class ConsumeTokenReceiver {
public:
/// This is called when a token is consumed.
virtual void receive(Token Tok) {}
virtual void receive(const Token &Tok) {}

/// This is called to update the kind of a token whose start location is Loc.
virtual void registerTokenKindChange(SourceLoc Loc, tok NewKind) {};
Expand Down Expand Up @@ -488,9 +488,7 @@ class Parser {
std::vector<Token> delayedTokens;
DelayedTokenReceiver(ConsumeTokenReceiver *&receiver):
savedConsumer(receiver, this) {}
void receive(Token tok) override {
delayedTokens.push_back(tok);
}
void receive(const Token &tok) override { delayedTokens.push_back(tok); }
Optional<std::vector<Token>> finalize() override {
llvm_unreachable("Cannot finalize a DelayedTokenReciever");
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ class TokenRecorder: public ConsumeTokenReceiver {
TokenKindChangeMap[Loc.getOpaquePointerValue()] = NewKind;
}

void receive(Token Tok) override {
void receive(const Token &TokParam) override {
Token Tok = TokParam;
// We filter out all tokens without valid location
if(Tok.getLoc().isInvalid())
return;
Expand Down