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:
Richard Smith
2023-10-11 05:39:59 +00:00
committed by GitHub
parent 0e8e94d8bf
commit c7a9e29a89
41 changed files with 1445 additions and 954 deletions
+3 -4
View File
@@ -24,15 +24,14 @@ auto HandleVariableDeclaration(Context& context, Parse::Node parse_node)
// Get the storage and add it to name lookup.
SemIR::NodeId var_id =
context.node_stack().Pop<Parse::NodeKind::PatternBinding>();
auto var = context.semantics_ir().GetNode(var_id);
auto name_id = var.GetAsVarStorage();
context.AddNameToLookup(var.parse_node(), name_id, var_id);
auto var = context.semantics_ir().GetNodeAs<SemIR::VarStorage>(var_id);
context.AddNameToLookup(var.parse_node, var.name_id, var_id);
// If there was an initializer, assign it to storage.
if (has_init) {
init_id = Initialize(context, parse_node, var_id, init_id);
// TODO: Consider using different node kinds for assignment versus
// initialization.
context.AddNode(SemIR::Node::Assign::Make(parse_node, var_id, init_id));
context.AddNode(SemIR::Assign(parse_node, var_id, init_id));
}
context.node_stack()