mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 13:11:04 +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,20 +8,19 @@
|
||||
|
||||
namespace Carbon::Check {
|
||||
|
||||
auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
|
||||
bool is_generic) -> bool {
|
||||
auto [type_node, parsed_type_id] =
|
||||
context.node_stack().PopExprWithParseNode();
|
||||
auto [type_node, parsed_type_id] = context.node_stack().PopExprWithNodeId();
|
||||
auto cast_type_id = ExprAsType(context, type_node, parsed_type_id);
|
||||
|
||||
// TODO: Handle `_` bindings.
|
||||
|
||||
// Every other kind of pattern binding has a name.
|
||||
auto [name_node, name_id] = context.node_stack().PopNameWithParseNode();
|
||||
auto [name_node, name_id] = context.node_stack().PopNameWithNodeId();
|
||||
|
||||
// Create the appropriate kind of binding for this pattern.
|
||||
auto make_bind_name = [&](SemIR::TypeId type_id,
|
||||
SemIR::InstId value_id) -> SemIR::ParseNodeAndInst {
|
||||
SemIR::InstId value_id) -> SemIR::NodeIdAndInst {
|
||||
// TODO: Eventually the name will need to support associations with other
|
||||
// scopes, but right now we don't support qualified names here.
|
||||
auto bind_name_id = context.bind_names().Add(
|
||||
@@ -42,15 +41,14 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
CARBON_DIAGNOSTIC(
|
||||
SelfOutsideImplicitParamList, Error,
|
||||
"`self` can only be declared in an implicit parameter list.");
|
||||
context.emitter().Emit(parse_node, SelfOutsideImplicitParamList);
|
||||
context.emitter().Emit(node_id, SelfOutsideImplicitParamList);
|
||||
}
|
||||
|
||||
// Allocate an instruction of the appropriate kind, linked to the name for
|
||||
// error locations.
|
||||
// TODO: The node stack is a fragile way of getting context information.
|
||||
// Get this information from somewhere else.
|
||||
switch (auto context_parse_node_kind =
|
||||
context.node_stack().PeekParseNodeKind()) {
|
||||
switch (auto context_node_kind = context.node_stack().PeekNodeKind()) {
|
||||
case Parse::NodeKind::ReturnedModifier:
|
||||
case Parse::NodeKind::VariableIntroducer: {
|
||||
if (is_generic) {
|
||||
@@ -62,7 +60,7 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
auto binding_id =
|
||||
is_generic
|
||||
? Parse::NodeId::Invalid
|
||||
: context.parse_tree().As<Parse::BindingPatternId>(parse_node);
|
||||
: context.parse_tree().As<Parse::BindingPatternId>(node_id);
|
||||
|
||||
// A `var` declaration at class scope introduces a field.
|
||||
auto enclosing_class_decl = context.GetCurrentScopeAs<SemIR::ClassDecl>();
|
||||
@@ -77,8 +75,7 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
cast_type_id);
|
||||
});
|
||||
if (enclosing_class_decl) {
|
||||
CARBON_CHECK(context_parse_node_kind ==
|
||||
Parse::NodeKind::VariableIntroducer)
|
||||
CARBON_CHECK(context_node_kind == Parse::NodeKind::VariableIntroducer)
|
||||
<< "`returned var` at class scope";
|
||||
auto& class_info =
|
||||
context.classes().Get(enclosing_class_decl->class_id);
|
||||
@@ -94,25 +91,25 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
// Add a corresponding field to the object representation of the class.
|
||||
context.args_type_info_stack().AddInstId(context.AddInstInNoBlock(
|
||||
{binding_id, SemIR::StructTypeField{name_id, cast_type_id}}));
|
||||
context.node_stack().Push(parse_node, field_id);
|
||||
context.node_stack().Push(node_id, field_id);
|
||||
break;
|
||||
}
|
||||
|
||||
SemIR::InstId value_id = SemIR::InstId::Invalid;
|
||||
if (context_parse_node_kind == Parse::NodeKind::ReturnedModifier) {
|
||||
if (context_node_kind == Parse::NodeKind::ReturnedModifier) {
|
||||
// TODO: Should we check this for the `var` as a whole, rather than for
|
||||
// the name binding?
|
||||
value_id =
|
||||
CheckReturnedVar(context, context.node_stack().PeekParseNode(),
|
||||
CheckReturnedVar(context, context.node_stack().PeekNodeId(),
|
||||
name_node, name_id, type_node, cast_type_id);
|
||||
} else {
|
||||
value_id = context.AddInst(
|
||||
{name_node, SemIR::VarStorage{cast_type_id, name_id}});
|
||||
}
|
||||
auto bind_id = context.AddInst(make_bind_name(cast_type_id, value_id));
|
||||
context.node_stack().Push(parse_node, bind_id);
|
||||
context.node_stack().Push(node_id, bind_id);
|
||||
|
||||
if (context_parse_node_kind == Parse::NodeKind::ReturnedModifier) {
|
||||
if (context_node_kind == Parse::NodeKind::ReturnedModifier) {
|
||||
RegisterReturnedVar(context, bind_id);
|
||||
}
|
||||
break;
|
||||
@@ -130,7 +127,7 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
// TODO: Bindings should come into scope immediately in other contexts
|
||||
// too.
|
||||
context.AddNameToLookup(name_id, bind_id);
|
||||
context.node_stack().Push(parse_node, bind_id);
|
||||
context.node_stack().Push(node_id, bind_id);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -147,28 +144,29 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
|
||||
// TODO: For general pattern parsing, we'll need to create a block to hold
|
||||
// the `let` pattern before we see the initializer.
|
||||
context.node_stack().Push(
|
||||
parse_node, context.AddPlaceholderInstInNoBlock(make_bind_name(
|
||||
cast_type_id, SemIR::InstId::Invalid)));
|
||||
node_id, context.AddPlaceholderInstInNoBlock(
|
||||
make_bind_name(cast_type_id, SemIR::InstId::Invalid)));
|
||||
break;
|
||||
|
||||
default:
|
||||
CARBON_FATAL() << "Found a pattern binding in unexpected context "
|
||||
<< context_parse_node_kind;
|
||||
<< context_node_kind;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleBindingPattern(Context& context, Parse::BindingPatternId parse_node)
|
||||
auto HandleBindingPattern(Context& context, Parse::BindingPatternId node_id)
|
||||
-> bool {
|
||||
return HandleAnyBindingPattern(context, parse_node, /*is_generic=*/false);
|
||||
return HandleAnyBindingPattern(context, node_id, /*is_generic=*/false);
|
||||
}
|
||||
|
||||
auto HandleCompileTimeBindingPattern(
|
||||
Context& context, Parse::CompileTimeBindingPatternId parse_node) -> bool {
|
||||
return HandleAnyBindingPattern(context, parse_node, /*is_generic=*/true);
|
||||
auto HandleCompileTimeBindingPattern(Context& context,
|
||||
Parse::CompileTimeBindingPatternId node_id)
|
||||
-> bool {
|
||||
return HandleAnyBindingPattern(context, node_id, /*is_generic=*/true);
|
||||
}
|
||||
|
||||
auto HandleAddr(Context& context, Parse::AddrId parse_node) -> bool {
|
||||
auto HandleAddr(Context& context, Parse::AddrId node_id) -> bool {
|
||||
auto self_param_id = context.node_stack().PopPattern();
|
||||
if (auto self_param =
|
||||
context.insts().TryGetAs<SemIR::AnyBindName>(self_param_id);
|
||||
@@ -178,18 +176,18 @@ auto HandleAddr(Context& context, Parse::AddrId parse_node) -> bool {
|
||||
// TODO: The type of an `addr_pattern` should probably be the non-pointer
|
||||
// type, because that's the type that the pattern matches.
|
||||
context.AddInstAndPush(
|
||||
{parse_node, SemIR::AddrPattern{self_param->type_id, self_param_id}});
|
||||
{node_id, SemIR::AddrPattern{self_param->type_id, self_param_id}});
|
||||
} else {
|
||||
CARBON_DIAGNOSTIC(AddrOnNonSelfParam, Error,
|
||||
"`addr` can only be applied to a `self` parameter.");
|
||||
context.emitter().Emit(TokenOnly(parse_node), AddrOnNonSelfParam);
|
||||
context.node_stack().Push(parse_node, self_param_id);
|
||||
context.emitter().Emit(TokenOnly(node_id), AddrOnNonSelfParam);
|
||||
context.node_stack().Push(node_id, self_param_id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
auto HandleTemplate(Context& context, Parse::TemplateId parse_node) -> bool {
|
||||
return context.TODO(parse_node, "HandleTemplate");
|
||||
auto HandleTemplate(Context& context, Parse::TemplateId node_id) -> bool {
|
||||
return context.TODO(node_id, "HandleTemplate");
|
||||
}
|
||||
|
||||
} // namespace Carbon::Check
|
||||
|
||||
Reference in New Issue
Block a user