mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Rename parse_node -> node_id (#3760)
This was previously discussed at https://discord.com/channels/655572317891461132/655578254970716160/1209975051588210729. I'm initiating this mainly because we typically use "id" suffixes to indicate an `IdBase` being passed around and the non-id suffix of `parse_node` suggests at it carrying more data than it actually does. There used to be more reason for avoiding `node_id` because `SemIR::InstId` used to be named `NodeId`, but that's no longer necessary. As a consequence, I'd like to rename `parse_node` to more precisely reflect its type. In full, this is doing: ``` parse_node_kind -> node_kind parse_node -> node_id ParseNodeCategory -> NodeCategory ParseNodeKind -> NodeKind ParseNode -> NodeId ``` This is primarily in check and sem_ir, but with some `parse_node_kind` references in parse too. Pluralization is consistent with name forms on both sides, so that wasn't part of my replacements.
This commit is contained in:
@@ -8,53 +8,51 @@
|
||||
namespace Carbon::Check {
|
||||
|
||||
auto HandleIfConditionStart(Context& /*context*/,
|
||||
Parse::IfConditionStartId /*parse_node*/) -> bool {
|
||||
Parse::IfConditionStartId /*node_id*/) -> bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleIfCondition(Context& context, Parse::IfConditionId parse_node)
|
||||
-> bool {
|
||||
auto HandleIfCondition(Context& context, Parse::IfConditionId node_id) -> bool {
|
||||
// Convert the condition to `bool`.
|
||||
auto cond_value_id = context.node_stack().PopExpr();
|
||||
cond_value_id = ConvertToBoolValue(context, parse_node, cond_value_id);
|
||||
cond_value_id = ConvertToBoolValue(context, node_id, cond_value_id);
|
||||
|
||||
// Create the then block and the else block, and branch to the right one. If
|
||||
// there is no `else`, the then block will terminate with a branch to the
|
||||
// else block, which will be reused as the resumption block.
|
||||
auto then_block_id =
|
||||
context.AddDominatedBlockAndBranchIf(parse_node, cond_value_id);
|
||||
auto else_block_id = context.AddDominatedBlockAndBranch(parse_node);
|
||||
context.AddDominatedBlockAndBranchIf(node_id, cond_value_id);
|
||||
auto else_block_id = context.AddDominatedBlockAndBranch(node_id);
|
||||
|
||||
// Start emitting the `then` block.
|
||||
context.inst_block_stack().Pop();
|
||||
context.inst_block_stack().Push(then_block_id);
|
||||
context.AddCurrentCodeBlockToFunction();
|
||||
|
||||
context.node_stack().Push(parse_node, else_block_id);
|
||||
context.node_stack().Push(node_id, else_block_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleIfStatementElse(Context& context,
|
||||
Parse::IfStatementElseId parse_node) -> bool {
|
||||
auto HandleIfStatementElse(Context& context, Parse::IfStatementElseId node_id)
|
||||
-> bool {
|
||||
auto else_block_id = context.node_stack().Pop<Parse::NodeKind::IfCondition>();
|
||||
|
||||
// Switch to emitting the `else` block.
|
||||
context.inst_block_stack().Push(else_block_id);
|
||||
context.AddCurrentCodeBlockToFunction();
|
||||
|
||||
context.node_stack().Push(parse_node);
|
||||
context.node_stack().Push(node_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleIfStatement(Context& context, Parse::IfStatementId parse_node)
|
||||
-> bool {
|
||||
switch (auto kind = context.node_stack().PeekParseNodeKind()) {
|
||||
auto HandleIfStatement(Context& context, Parse::IfStatementId node_id) -> bool {
|
||||
switch (auto kind = context.node_stack().PeekNodeKind()) {
|
||||
case Parse::NodeKind::IfCondition: {
|
||||
// Branch from then block to else block, and start emitting the else
|
||||
// block.
|
||||
auto else_block_id =
|
||||
context.node_stack().Pop<Parse::NodeKind::IfCondition>();
|
||||
context.AddInst({parse_node, SemIR::Branch{else_block_id}});
|
||||
context.AddInst({node_id, SemIR::Branch{else_block_id}});
|
||||
context.inst_block_stack().Pop();
|
||||
context.inst_block_stack().Push(else_block_id);
|
||||
break;
|
||||
@@ -63,8 +61,8 @@ auto HandleIfStatement(Context& context, Parse::IfStatementId parse_node)
|
||||
case Parse::NodeKind::IfStatementElse: {
|
||||
// Branch from the then and else blocks to a new resumption block.
|
||||
context.node_stack()
|
||||
.PopAndDiscardSoloParseNode<Parse::NodeKind::IfStatementElse>();
|
||||
context.AddConvergenceBlockAndPush(parse_node, /*num_blocks=*/2);
|
||||
.PopAndDiscardSoloNodeId<Parse::NodeKind::IfStatementElse>();
|
||||
context.AddConvergenceBlockAndPush(node_id, /*num_blocks=*/2);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user