Switch decl_state to an arg for modifier functions (#4027)

With private modifiers, we'll want to start checking modifiers later,
e.g. after a name conflict is detected (and potentially merged). I think
we've agreed to be more explicit about whether the modifier functions
are manipulating state, versus trying to keep the state on the stack a
little longer (moving Pop to the end of these functions).

Removing FileScope from the stack and renaming it to DeclIntroducerStack
to better reflect the usage and behavior. The FileScope mostly reflects
an approach that wasn't ultimately adopted.
This commit is contained in:
Jon Ross-Perkins
2024-06-04 23:12:12 +00:00
committed by GitHub
parent 8c64f0bfdd
commit a910eda020
17 changed files with 192 additions and 174 deletions
+8 -9
View File
@@ -13,7 +13,7 @@ auto HandleVariableIntroducer(Context& context,
Parse::VariableIntroducerId node_id) -> bool {
// No action, just a bracketing node.
context.node_stack().Push(node_id);
context.decl_state_stack().Push(DeclState::Var);
context.decl_introducer_state_stack().Push(DeclIntroducerState::Var);
return true;
}
@@ -101,18 +101,17 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId node_id)
// of the name introduced in the declaration. See #2590.
auto [_, parent_scope_inst] = context.name_scopes().GetInstIfValid(
context.scope_stack().PeekNameScopeId());
CheckAccessModifiersOnDecl(context, Lex::TokenKind::Var, parent_scope_inst);
LimitModifiersOnDecl(context, KeywordModifierSet::Access,
auto introducer =
context.decl_introducer_state_stack().Pop(DeclIntroducerState::Var);
CheckAccessModifiersOnDecl(context, introducer, Lex::TokenKind::Var,
parent_scope_inst);
LimitModifiersOnDecl(context, introducer, KeywordModifierSet::Access,
Lex::TokenKind::Var);
auto modifiers = context.decl_state_stack().innermost().modifier_set;
if (modifiers.HasAnyOf(KeywordModifierSet::Access)) {
context.TODO(context.decl_state_stack().innermost().modifier_node_id(
ModifierOrder::Access),
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Access)) {
context.TODO(introducer.modifier_node_id(ModifierOrder::Access),
"access modifier");
}
context.decl_state_stack().Pop(DeclState::Var);
return true;
}