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
+4 -4
View File
@@ -35,14 +35,14 @@ auto HandleArrayExpression(Context& context, Parse::Node parse_node) -> bool {
.PopAndDiscardSoloParseNode<Parse::NodeKind::ArrayExpressionSemi>();
auto element_type_node_id = context.node_stack().PopExpression();
auto bound_node = context.semantics_ir().GetNode(bound_node_id);
if (bound_node.kind() == SemIR::NodeKind::IntegerLiteral) {
auto bound_value = context.semantics_ir().GetIntegerLiteral(
bound_node.GetAsIntegerLiteral());
if (auto literal = bound_node.TryAs<SemIR::IntegerLiteral>()) {
const auto& bound_value =
context.semantics_ir().GetInteger(literal->integer_id);
// TODO: Produce an error if the array type is too large.
if (bound_value.getActiveBits() <= 64) {
context.AddNodeAndPush(
parse_node,
SemIR::Node::ArrayType::Make(
SemIR::ArrayType(
parse_node, SemIR::TypeId::TypeType, bound_node_id,
ExpressionAsType(context, parse_node, element_type_node_id)));
return true;