Skip to content

Commit

Permalink
Refactor HandleIdentifierName away
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmeow committed Feb 28, 2025
1 parent ec58a48 commit 267d83c
Showing 1 changed file with 10 additions and 21 deletions.
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),
"Unreachable until we 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

0 comments on commit 267d83c

Please sign in to comment.