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
+6 -8
View File
@@ -24,7 +24,7 @@ auto HandleImplIntroducer(Context& context, Parse::ImplIntroducerId node_id)
context.node_stack().Push(node_id);
// Optional modifiers follow.
context.decl_state_stack().Push(DeclState::Impl);
context.decl_introducer_state_stack().Push(DeclIntroducerState::Impl);
// An impl doesn't have a name per se, but it makes the processing more
// consistent to imagine that it does. This also gives us a scope for implicit
@@ -192,7 +192,9 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id)
// Process modifiers.
// TODO: Should we somehow permit access specifiers on `impl`s?
// TODO: Handle `final` modifier.
LimitModifiersOnDecl(context, KeywordModifierSet::ImplDecl,
auto introducer =
context.decl_introducer_state_stack().Pop(DeclIntroducerState::Impl);
LimitModifiersOnDecl(context, introducer, KeywordModifierSet::ImplDecl,
Lex::TokenKind::Impl);
// Finish processing the name, which should be empty, but might have
@@ -214,16 +216,12 @@ static auto BuildImplDecl(Context& context, Parse::AnyImplDeclId node_id)
auto impl_decl_id = context.AddInst(node_id, impl_decl);
// For an `extend impl` declaration, mark the impl as extending this `impl`.
if (context.decl_state_stack().innermost().modifier_set.HasAnyOf(
KeywordModifierSet::Extend)) {
auto extend_node = context.decl_state_stack().innermost().modifier_node_id(
ModifierOrder::Decl);
if (introducer.modifier_set.HasAnyOf(KeywordModifierSet::Extend)) {
auto extend_node = introducer.modifier_node_id(ModifierOrder::Decl);
ExtendImpl(context, extend_node, node_id, self_type_node, self_type_id,
params_node, constraint_type_id);
}
context.decl_state_stack().Pop(DeclState::Impl);
return {impl_decl.impl_id, impl_decl_id};
}