Start node stack push/pop setting IdT based on ParseNodeKind. (#2985)

I think there's more we can do here, but this seemed like a good
checkpoint to make sure the path I'm going down is roughly what you
expected. There's one actual edit in if expression structure to match
the increased enforcement.
This commit is contained in:
Jon Ross-Perkins authored and GitHub committed 2023-07-12 23:26:53 +00:00
1 parent c0d18a62eb
commit 9751b4701d
16 files changed
+167 -66

No files matched your search

@@ -14,17 +14,16 @@ static auto BuildFunctionDeclaration(SemanticsContext& context)
SemanticsTypeId return_type_id = SemanticsTypeId::Invalid;
if (context.parse_tree().node_kind(context.node_stack().PeekParseNode()) ==
ParseNodeKind::ReturnType) {
return_type_id =
context.node_stack().Pop<SemanticsTypeId>(ParseNodeKind::ReturnType);
return_type_id = context.node_stack().Pop<ParseNodeKind::ReturnType>();
} else {
// Canonicalize the empty tuple for the implicit return.
context.CanonicalizeType(SemanticsNodeId::BuiltinEmptyTupleType);
}
auto param_refs_id = context.node_stack().Pop<SemanticsNodeBlockId>(
ParseNodeKind::ParameterList);
SemanticsNodeBlockId param_refs_id =
context.node_stack().Pop<ParseNodeKind::ParameterList>();
auto name_context = context.PopDeclarationName();
auto fn_node = context.node_stack().PopForSoloParseNode(
ParseNodeKind::FunctionIntroducer);
auto fn_node = context.node_stack()
.PopForSoloParseNode<ParseNodeKind::FunctionIntroducer>();
// TODO: Support out-of-line definitions, which will have a resolved
// name_context. Right now, those become errors in AddNameToLookup.
@@ -50,8 +49,8 @@ auto SemanticsHandleFunctionDeclaration(SemanticsContext& context,
auto SemanticsHandleFunctionDefinition(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto function_id = context.node_stack().Pop<SemanticsFunctionId>(
ParseNodeKind::FunctionDefinitionStart);
SemanticsFunctionId function_id =
context.node_stack().Pop<ParseNodeKind::FunctionDefinitionStart>();
// If the `}` of the function is reachable, reject if we need a return value
// and otherwise add an implicit `return;`.