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 authored and GitHub committed 2023-10-20 20:26:10 +00:00
1 parent e54deee525
commit a46e7dd967
31 files changed
+1240 -957

No files matched your search

+11 -6
View File
@@ -9,17 +9,22 @@ namespace Carbon::SemIR {
auto Node::Print(llvm::raw_ostream& out) const -> void {
out << "{kind: " << kind_;
auto print_args = [&](auto... args) {
int n = 0;
((out << ", arg" << n++ << ": " << args), ...);
auto print_args = [&](auto info) {
using Info = decltype(info);
if constexpr (Info::NumArgs > 0) {
out << ", arg0: " << FromRaw<typename Info::template ArgType<0>>(arg0_);
}
if constexpr (Info::NumArgs > 1) {
out << ", arg1: " << FromRaw<typename Info::template ArgType<1>>(arg1_);
}
};
// clang warns on unhandled enum values; clang-tidy is incorrect here.
// NOLINTNEXTLINE(bugprone-switch-missing-default-case)
switch (kind_) {
#define CARBON_SEM_IR_NODE_KIND(Name) \
case Name::Kind: \
std::apply(print_args, As<SemIR::Name>().args_tuple()); \
#define CARBON_SEM_IR_NODE_KIND(Name) \
case Name::Kind: \
print_args(TypedNodeArgsInfo<Name>()); \
break;
#include "toolchain/sem_ir/node_kind.def"
}