mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Switch AddInst struct init style. (#4012)
Trying to conform with #4009. Changes SemIR::LocIdAndInst construction to root out struct init cases with AddInst and related functions. I'm using templating of AddInst functions in order to avoid `AddInst(loc_id, InstName{...})` and instead have `AddInst<InstName>(loc_id, {...})` with I think similar readability results. There are a couple cases where inst construction is templated and so designated initializers couldn't be used, so this may be better for those in particular due to the extra type enforcement. This probably doesn't clean up every last case, but I was trying to get the bulk at once without bleeding over into less related changes. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
6e9d0b15c8
commit
5bb318cae6
@@ -58,7 +58,7 @@ auto HandleWhileStatement(Context& context, Parse::WhileStatementId node_id)
|
||||
context.break_continue_stack().pop_back();
|
||||
|
||||
// Add the loop backedge.
|
||||
context.AddInst({node_id, SemIR::Branch{loop_header_id}});
|
||||
context.AddInst<SemIR::Branch>(node_id, {.target_id = loop_header_id});
|
||||
context.inst_block_stack().Pop();
|
||||
|
||||
// Start emitting the loop exit block.
|
||||
@@ -100,7 +100,8 @@ auto HandleBreakStatementStart(Context& context,
|
||||
"`break` can only be used in a loop.");
|
||||
context.emitter().Emit(node_id, BreakOutsideLoop);
|
||||
} else {
|
||||
context.AddInst({node_id, SemIR::Branch{stack.back().break_target}});
|
||||
context.AddInst<SemIR::Branch>(node_id,
|
||||
{.target_id = stack.back().break_target});
|
||||
}
|
||||
|
||||
context.inst_block_stack().Pop();
|
||||
@@ -125,7 +126,8 @@ auto HandleContinueStatementStart(Context& context,
|
||||
"`continue` can only be used in a loop.");
|
||||
context.emitter().Emit(node_id, ContinueOutsideLoop);
|
||||
} else {
|
||||
context.AddInst({node_id, SemIR::Branch{stack.back().continue_target}});
|
||||
context.AddInst<SemIR::Branch>(node_id,
|
||||
{.target_id = stack.back().continue_target});
|
||||
}
|
||||
|
||||
context.inst_block_stack().Pop();
|
||||
|
||||
Reference in New Issue
Block a user