Remove most of the metaprogramming in node.h in favor of listing all the members in the typed node structs. (#3310)

Split `node.h` into separate files for ID types (`id.h`) and for typed
nodes (`typed_nodes.h`). The per-node-kind data is now specified as part
of declaring the typed nodes, and is removed from the node kinds
x-macros, which now simply enumerate the node kinds.
This commit is contained in:
Richard Smith
2023-10-20 20:26:10 +00:00
committed by GitHub
parent e54deee525
commit a46e7dd967
31 changed files with 1240 additions and 957 deletions
+5 -4
View File
@@ -53,10 +53,10 @@ File::File(SharedValueStores& value_stores)
// a normal type. Every other builtin is a type, including the
// self-referential TypeType.
#define CARBON_SEM_IR_BUILTIN_KIND(Name, ...) \
nodes_.push_back(Builtin(BuiltinKind::Name == BuiltinKind::Error \
nodes_.push_back(Builtin{BuiltinKind::Name == BuiltinKind::Error \
? TypeId::Error \
: TypeId::TypeType, \
BuiltinKind::Name));
BuiltinKind::Name});
#include "toolchain/sem_ir/builtin_kind.def"
CARBON_CHECK(nodes_.size() == BuiltinKind::ValidCount)
@@ -82,7 +82,7 @@ File::File(SharedValueStores& value_stores, std::string filename,
for (auto [i, node] : llvm::enumerate(builtins->nodes_)) {
// We can reuse builtin type IDs because they're special-cased values.
nodes_.push_back(
CrossReference(node.type_id(), BuiltinIR, SemIR::NodeId(i)));
CrossReference{node.type_id(), BuiltinIR, SemIR::NodeId(i)});
}
}
@@ -374,7 +374,8 @@ auto File::StringifyTypeExpression(NodeId outer_node_id,
case StructTypeField::Kind: {
auto field = node.As<StructTypeField>();
out << "." << strings().Get(field.name_id) << ": ";
steps.push_back({.node_id = GetTypeAllowBuiltinTypes(field.type_id)});
steps.push_back(
{.node_id = GetTypeAllowBuiltinTypes(field.field_type_id)});
break;
}
case TupleType::Kind: {