mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-03 22:02:51 +01:00
Restructure handling of expressions in patterns (#7445)
Instead of maintaining a stack of pending subpatterns which might or might not contain expressions, we mark non-nesting regions during pattern handling that might contain an expression. The implementation remains largely the same; the difference is that callers are expected to end a pending expression region as soon as possible, rather than wait for the end of the subpattern. This makes it possible to emit non-pattern insts during pattern handling, without the risk that they will get caught in a pending expression region further up the stack.
This commit is contained in:
@@ -117,14 +117,14 @@ auto HandleParseNode(Context& context, Parse::ForHeaderStartId node_id)
|
||||
context.decl_introducer_state_stack().Push<Lex::TokenKind::Let>();
|
||||
context.pattern_block_stack().Push();
|
||||
context.full_pattern_stack().PushNameBindingDecl();
|
||||
BeginSubpattern(context);
|
||||
BeginExprRegionForPattern(context);
|
||||
|
||||
context.node_stack().Push(node_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleParseNode(Context& context, Parse::ForInId node_id) -> bool {
|
||||
EndSubpattern(context, context.node_stack());
|
||||
EndExprRegionForPattern(context, context.node_stack());
|
||||
auto pattern_block_id = context.pattern_block_stack().Pop();
|
||||
AddInst<SemIR::NameBindingDecl>(context, node_id,
|
||||
{.pattern_block_id = pattern_block_id});
|
||||
|
||||
Reference in New Issue
Block a user