Skip to content

Commit

Permalink
refactor(fe): store Diag_List directly in Lexer
Browse files Browse the repository at this point in the history
Stop using a Diag_List_Diag_Reporter in Lexer.
  • Loading branch information
strager committed Aug 21, 2024
1 parent 45d339c commit 5890d87
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/quick-lint-js/diag/diag-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Span_Size Diag_List::size() const {
}

bool Diag_List::reported_any_diagnostic_except_since(
std::initializer_list<Diag_Type> ignored_types, const Rewind_State &r) {
std::initializer_list<Diag_Type> ignored_types,
const Rewind_State &r) const {
for (Node_Base *node = r.last_ == nullptr ? this->first_ : r.last_;
node != nullptr; node = node->next) {
if (!contains(ignored_types, node->type)) {
Expand Down
3 changes: 2 additions & 1 deletion src/quick-lint-js/diag/diag-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class Diag_List {
Span_Size size() const;

bool reported_any_diagnostic_except_since(
std::initializer_list<Diag_Type> ignored_types, const Rewind_State &);
std::initializer_list<Diag_Type> ignored_types,
const Rewind_State &) const;
bool have_diagnostic(Diag_Type type) const;

// Removes all diagnostics, but does not deallocate memory.
Expand Down
2 changes: 1 addition & 1 deletion src/quick-lint-js/fe/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ void Lexer::roll_back_transaction(Lexer_Transaction&& transaction) {
this->last_last_token_end_ = transaction.old_last_last_token_end;
this->input_ = transaction.old_input;

this->diag_list_.diags().rewind(std::move(transaction.diag_list_rewind));
this->diags_.rewind(std::move(transaction.diag_list_rewind));
}

bool Lexer::transaction_has_lex_diagnostics(const Lexer_Transaction& transaction) const {
Expand Down
11 changes: 2 additions & 9 deletions src/quick-lint-js/fe/lex.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,7 @@ class Lexer {
bool test_for_regexp(const Char8* regexp_begin);

// Returns all the diagnostics reported so far by the the lexer.
Diag_List& diags() { return this->diag_list_.diags(); }

// TODO(#1154): Delete.
Diag_List_Diag_Reporter& diag_list_diag_reporter() {
return this->diag_list_;
}
Diag_List& diags() { return this->diags_; }

// Save lexer state.
//
Expand Down Expand Up @@ -348,9 +343,7 @@ class Lexer {

Monotonic_Allocator allocator_{"lexer::allocator_"};

Diag_List_Diag_Reporter diag_list_ =
Diag_List_Diag_Reporter(&this->allocator_);
Diag_List& diags_ = diag_list_.diags();
Diag_List diags_ = Diag_List(&this->allocator_);

friend struct Lex_Tables;
};
Expand Down

0 comments on commit 5890d87

Please sign in to comment.