mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:44:41 +01:00
Add typed nodes to SemIR. (#3280)
Replace `SemIR::Node::GetAsFoo` and `SemIR::Node::Foo::Make` with `SemIR::Foo` class that represents a particular kind of node, with named fields. Rename `SemIR::IntegerLiteral` and `SemIR::RealLiteral` to `IntegerValue` / `RealValue` to better reflect their purpose and avoid a name collision with the corresponding `SemIR` node kinds. Remove `NodeKind::Invalid` and the `SemIR::Node` default constructor entirely, as they were not used for anything.
This commit is contained in:
@@ -57,8 +57,8 @@ static auto BuildFunctionDeclaration(Context& context)
|
||||
.return_type_id = return_type_id,
|
||||
.return_slot_id = return_slot_id,
|
||||
.body_block_ids = {}});
|
||||
auto decl_id = context.AddNode(
|
||||
SemIR::Node::FunctionDeclaration::Make(fn_node, function_id));
|
||||
auto decl_id =
|
||||
context.AddNode(SemIR::FunctionDeclaration(fn_node, function_id));
|
||||
context.declaration_name_stack().AddNameToLookup(name_context, decl_id);
|
||||
|
||||
if (SemIR::IsEntryPoint(context.semantics_ir(), function_id)) {
|
||||
@@ -100,7 +100,7 @@ auto HandleFunctionDefinition(Context& context, Parse::Node parse_node)
|
||||
"Missing `return` at end of function with declared return type.");
|
||||
context.emitter().Emit(parse_node, MissingReturnStatement);
|
||||
} else {
|
||||
context.AddNode(SemIR::Node::Return::Make(parse_node));
|
||||
context.AddNode(SemIR::Return(parse_node));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,11 +123,10 @@ auto HandleFunctionDefinitionStart(Context& context, Parse::Node parse_node)
|
||||
context.AddCurrentCodeBlockToFunction();
|
||||
|
||||
// Bring the parameters into scope.
|
||||
for (auto ref_id :
|
||||
for (auto param_id :
|
||||
context.semantics_ir().GetNodeBlock(function.param_refs_id)) {
|
||||
auto ref = context.semantics_ir().GetNode(ref_id);
|
||||
auto name_id = ref.GetAsParameter();
|
||||
context.AddNameToLookup(ref.parse_node(), name_id, ref_id);
|
||||
auto param = context.semantics_ir().GetNodeAs<SemIR::Parameter>(param_id);
|
||||
context.AddNameToLookup(param.parse_node, param.name_id, param_id);
|
||||
}
|
||||
|
||||
context.node_stack().Push(parse_node, function_id);
|
||||
@@ -154,8 +153,8 @@ auto HandleReturnType(Context& context, Parse::Node parse_node) -> bool {
|
||||
// TODO: Use a dedicated node rather than VarStorage here.
|
||||
context.AddNodeAndPush(
|
||||
parse_node,
|
||||
SemIR::Node::VarStorage::Make(
|
||||
parse_node, type_id, context.semantics_ir().AddString("return")));
|
||||
SemIR::VarStorage(parse_node, type_id,
|
||||
context.semantics_ir().AddString("return")));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user