Files
carbon-lang/toolchain/sem_ir/node_kind.cpp
T
Richard Smith a46e7dd967 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.
2023-10-20 20:26:10 +00:00

42 lines
1.2 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/sem_ir/node_kind.h"
#include "toolchain/sem_ir/typed_nodes.h"
namespace Carbon::SemIR {
CARBON_DEFINE_ENUM_CLASS_NAMES(NodeKind) = {
#define CARBON_SEM_IR_NODE_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
#include "toolchain/sem_ir/node_kind.def"
};
auto NodeKind::ir_name() const -> llvm::StringLiteral {
return definition().ir_name();
}
auto NodeKind::value_kind() const -> NodeValueKind {
static constexpr NodeValueKind Table[] = {
#define CARBON_SEM_IR_NODE_KIND(Name) \
HasTypeId<SemIR::Name> ? NodeValueKind::Typed : NodeValueKind::None,
#include "toolchain/sem_ir/node_kind.def"
};
return Table[AsInt()];
}
auto NodeKind::terminator_kind() const -> TerminatorKind {
return definition().terminator_kind();
}
auto NodeKind::definition() const -> const Definition& {
static constexpr const Definition* Table[] = {
#define CARBON_SEM_IR_NODE_KIND(Name) &SemIR::Name::Kind,
#include "toolchain/sem_ir/node_kind.def"
};
return *Table[AsInt()];
}
} // namespace Carbon::SemIR