Skip to content

Commit

Permalink
refactor(fe): pass object instead of parts (round 2)
Browse files Browse the repository at this point in the history
report_error_if_variable_declaration_conflicts accepts various
parts of Declared_Variable. Make callers pass the Declared_Variable
aggregate, simplifying code a bit.
  • Loading branch information
strager committed Oct 15, 2023
1 parent 7f8e1d9 commit 8c3a473
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
22 changes: 7 additions & 15 deletions src/quick-lint-js/fe/variable-analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,7 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts_in_scope(
/*already_declared_flags=*/already_declared_variable->flags,
/*already_declared_declaration_scope=*/
already_declared_variable->declaration_scope,
/*newly_declared_name=*/var.declaration,
/*newly_declared_kind=*/var.kind,
/*newly_declared_flags=*/var.flags,
/*newly_declared_declaration_scope=*/var.declaration_scope);
/*newly_declared_var=*/var);
}
}

Expand All @@ -962,10 +959,7 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts_in_scope(
/*already_declared_flags=*/already_declared_variable->flags(),
/*already_declared_declaration_scope=*/
Declared_Variable_Scope::declared_in_current_scope,
/*newly_declared_name=*/var.declaration,
/*newly_declared_kind=*/var.kind,
/*newly_declared_flags=*/var.flags,
/*newly_declared_declaration_scope=*/var.declaration_scope);
/*newly_declared_var=*/var);
}
}
}
Expand All @@ -974,11 +968,9 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts(
const Identifier *already_declared, Variable_Kind already_declared_kind,
Variable_Declaration_Flags already_declared_flags,
Declared_Variable_Scope already_declared_declaration_scope,
Identifier newly_declared_name, Variable_Kind newly_declared_kind,
[[maybe_unused]] Variable_Declaration_Flags newly_declared_flags,
Declared_Variable_Scope newly_declared_declaration_scope) const {
const Declared_Variable &newly_declared_var) const {
using VK = Variable_Kind;
VK kind = newly_declared_kind;
VK kind = newly_declared_var.kind;
VK other_kind = already_declared_kind;

switch (other_kind) {
Expand Down Expand Up @@ -1087,7 +1079,7 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts(
!(already_declared_flags &
Variable_Declaration_Flags::non_empty_namespace)) ||
(kind == VK::_function &&
newly_declared_declaration_scope ==
newly_declared_var.declaration_scope ==
Declared_Variable_Scope::declared_in_descendant_scope) ||
(other_kind == VK::_function &&
already_declared_declaration_scope ==
Expand All @@ -1097,11 +1089,11 @@ void Variable_Analyzer::report_error_if_variable_declaration_conflicts(
bool already_declared_is_global_variable = already_declared == nullptr;
if (already_declared_is_global_variable) {
this->diag_reporter_->report(Diag_Redeclaration_Of_Global_Variable{
.redeclaration = newly_declared_name.span(),
.redeclaration = newly_declared_var.declaration.span(),
});
} else {
this->diag_reporter_->report(Diag_Redeclaration_Of_Variable{
.redeclaration = newly_declared_name.span(),
.redeclaration = newly_declared_var.declaration.span(),
.original_declaration = already_declared->span(),
});
}
Expand Down
4 changes: 1 addition & 3 deletions src/quick-lint-js/fe/variable-analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ class Variable_Analyzer final : public Parse_Visitor_Base {
const Identifier *already_declared, Variable_Kind already_declared_kind,
Variable_Declaration_Flags already_declared_flags,
Declared_Variable_Scope already_declared_declaration_scope,
Identifier newly_declared_name, Variable_Kind newly_declared_kind,
Variable_Declaration_Flags newly_declared_flags,
Declared_Variable_Scope newly_declared_declaration_scope) const;
const Declared_Variable &newly_declared_var) const;

Scope &current_scope() { return this->scopes_.current_scope(); }
Scope &parent_scope() { return this->scopes_.parent_scope(); }
Expand Down

0 comments on commit 8c3a473

Please sign in to comment.