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:
Jon Ross-Perkins
2024-03-09 00:21:29 +00:00
committed by GitHub
parent a1317e61e0
commit 86a7c9ff45
57 changed files with 1050 additions and 1115 deletions
+17 -18
View File
@@ -9,45 +9,44 @@
namespace Carbon::Check {
auto HandleVariableIntroducer(Context& context,
Parse::VariableIntroducerId parse_node) -> bool {
Parse::VariableIntroducerId node_id) -> bool {
// No action, just a bracketing node.
context.node_stack().Push(parse_node);
context.node_stack().Push(node_id);
context.decl_state_stack().Push(DeclState::Var);
return true;
}
auto HandleReturnedModifier(Context& context,
Parse::ReturnedModifierId parse_node) -> bool {
auto HandleReturnedModifier(Context& context, Parse::ReturnedModifierId node_id)
-> bool {
// No action, just a bracketing node.
context.node_stack().Push(parse_node);
context.node_stack().Push(node_id);
return true;
}
auto HandleVariableInitializer(Context& context,
Parse::VariableInitializerId parse_node)
-> bool {
Parse::VariableInitializerId node_id) -> bool {
if (context.scope_stack().PeekIndex() == ScopeIndex::Package) {
context.inst_block_stack().PushGlobalInit();
}
context.node_stack().Push(parse_node);
context.node_stack().Push(node_id);
return true;
}
auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
auto HandleVariableDecl(Context& context, Parse::VariableDeclId node_id)
-> bool {
// Handle the optional initializer.
std::optional<SemIR::InstId> init_id;
if (context.node_stack().PeekNextIs<Parse::NodeKind::VariableInitializer>()) {
init_id = context.node_stack().PopExpr();
context.node_stack()
.PopAndDiscardSoloParseNode<Parse::NodeKind::VariableInitializer>();
.PopAndDiscardSoloNodeId<Parse::NodeKind::VariableInitializer>();
}
if (context.node_stack().PeekIs<Parse::NodeKind::TuplePattern>()) {
if (init_id && context.scope_stack().PeekIndex() == ScopeIndex::Package) {
context.inst_block_stack().PopGlobalInit();
}
return context.TODO(parse_node, "tuple pattern in var");
return context.TODO(node_id, "tuple pattern in var");
}
// Extract the name binding.
@@ -56,7 +55,7 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
// Form a corresponding name in the current context, and bind the name to
// the variable.
auto name_context = context.decl_name_stack().MakeUnqualifiedName(
context.insts().GetParseNode(value_id),
context.insts().GetNodeId(value_id),
context.bind_names().Get(bind_name->bind_name_id).name_id);
context.decl_name_stack().AddNameToLookup(name_context, value_id);
value_id = bind_name->value_id;
@@ -64,26 +63,26 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
context.insts().TryGetAs<SemIR::FieldDecl>(value_id)) {
// Introduce the field name into the class.
auto name_context = context.decl_name_stack().MakeUnqualifiedName(
context.insts().GetParseNode(value_id), field_decl->name_id);
context.insts().GetNodeId(value_id), field_decl->name_id);
context.decl_name_stack().AddNameToLookup(name_context, value_id);
}
// TODO: Handle other kinds of pattern.
// Pop the `returned` specifier if present.
context.node_stack()
.PopAndDiscardSoloParseNodeIf<Parse::NodeKind::ReturnedModifier>();
.PopAndDiscardSoloNodeIdIf<Parse::NodeKind::ReturnedModifier>();
// If there was an initializer, assign it to the storage.
if (init_id) {
if (context.GetCurrentScopeAs<SemIR::ClassDecl>()) {
// TODO: In a class scope, we should instead save the initializer
// somewhere so that we can use it as a default.
context.TODO(parse_node, "Field initializer");
context.TODO(node_id, "Field initializer");
} else {
init_id = Initialize(context, parse_node, value_id, *init_id);
init_id = Initialize(context, node_id, value_id, *init_id);
// TODO: Consider using different instruction kinds for assignment versus
// initialization.
context.AddInst({parse_node, SemIR::Assign{value_id, *init_id}});
context.AddInst({node_id, SemIR::Assign{value_id, *init_id}});
}
if (context.scope_stack().PeekIndex() == ScopeIndex::Package) {
context.inst_block_stack().PopGlobalInit();
@@ -91,7 +90,7 @@ auto HandleVariableDecl(Context& context, Parse::VariableDeclId parse_node)
}
context.node_stack()
.PopAndDiscardSoloParseNode<Parse::NodeKind::VariableIntroducer>();
.PopAndDiscardSoloNodeId<Parse::NodeKind::VariableIntroducer>();
// Process declaration modifiers.
// TODO: For a qualified `var` declaration, this should use the target scope