Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor HandleIdentifierName away #5044

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions toolchain/check/handle_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ auto HandleParseNode(Context& context, Parse::PointerMemberAccessExprId node_id)
}

static auto GetIdentifierAsName(Context& context, Parse::NodeId node_id)
-> std::optional<SemIR::NameId> {
-> SemIR::NameId {
CARBON_CHECK(!context.parse_tree().node_has_error(node_id),
"TODO: Support checking error parse nodes");
auto token = context.parse_tree().node_token(node_id);
if (context.tokens().GetKind(token) != Lex::TokenKind::Identifier) {
CARBON_CHECK(context.parse_tree().node_has_error(node_id));
return std::nullopt;
}
return SemIR::NameId::ForIdentifier(context.tokens().GetIdentifier(token));
}

Expand Down Expand Up @@ -128,20 +126,11 @@ static auto HandleNameAsExpr(Context& context, Parse::NodeId node_id,
{.type_id = type_id, .name_id = name_id, .value_id = inst_id});
}

static auto HandleIdentifierName(Context& context,
Parse::AnyNonExprIdentifierNameId node_id)
-> bool {
// The parent is responsible for binding the name.
auto name_id = GetIdentifierAsName(context, node_id);
CARBON_CHECK(name_id,
"Unreachable until we support checking error parse nodes");
context.node_stack().Push(node_id, *name_id);
return true;
}

auto HandleParseNode(Context& context,
Parse::IdentifierNameNotBeforeParamsId node_id) -> bool {
return HandleIdentifierName(context, node_id);
// The parent is responsible for binding the name.
context.node_stack().Push(node_id, GetIdentifierAsName(context, node_id));
return true;
}

auto HandleParseNode(Context& context,
Expand All @@ -150,16 +139,16 @@ auto HandleParseNode(Context& context,
context.pattern_block_stack().Push();
context.full_pattern_stack().PushFullPattern(
FullPatternStack::Kind::ImplicitParamList);
return HandleIdentifierName(context, node_id);
// The parent is responsible for binding the name.
context.node_stack().Push(node_id, GetIdentifierAsName(context, node_id));
return true;
}

auto HandleParseNode(Context& context, Parse::IdentifierNameExprId node_id)
-> bool {
auto name_id = GetIdentifierAsName(context, node_id);
CARBON_CHECK(name_id,
"Unreachable until we support checking error parse nodes");
context.node_stack().Push(node_id,
HandleNameAsExpr(context, node_id, *name_id));
HandleNameAsExpr(context, node_id, name_id));
return true;
}

Expand Down