mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 08:08:11 +00:00
Modify EnumBase to better support the namespacing of toolchain (#3156)
The different approach to Names avoids the issues with trying to define a static member (or also member function) of the templated instance of Carbon::Internal::EnumBase from a non-enclosing namespace such as Carbon::SemIR. Note, I'm trying to do this from the cpp file. An alternative might be to do `inline constexpr llvm::StringLiteral Names[]` in the .h file, but I think concerns had been raised about that needing deduplication.
This commit is contained in:
1 parent
4b4436f692
commit
29b6399e4f
10 files changed
+65
-110
No files matched your search
@@ -4,15 +4,15 @@
|
||||
|
||||
#include "toolchain/semantics/semantics_node_kind.h"
|
||||
|
||||
namespace Carbon {
|
||||
namespace Carbon::SemIR {
|
||||
|
||||
CARBON_DEFINE_ENUM_CLASS_NAMES(SemanticsNodeKind) = {
|
||||
CARBON_DEFINE_ENUM_CLASS_NAMES(NodeKind) = {
|
||||
#define CARBON_SEMANTICS_NODE_KIND(Name) CARBON_ENUM_CLASS_NAME_STRING(Name)
|
||||
#include "toolchain/semantics/semantics_node_kind.def"
|
||||
};
|
||||
|
||||
// Returns the name to use for this node kind in Semantics IR.
|
||||
[[nodiscard]] auto SemanticsNodeKind::ir_name() const -> llvm::StringRef {
|
||||
[[nodiscard]] auto NodeKind::ir_name() const -> llvm::StringRef {
|
||||
static constexpr llvm::StringRef Table[] = {
|
||||
#define CARBON_SEMANTICS_NODE_KIND_WITH_IR_NAME(Name, IR_Name) IR_Name,
|
||||
#include "toolchain/semantics/semantics_node_kind.def"
|
||||
@@ -20,22 +20,22 @@ CARBON_DEFINE_ENUM_CLASS_NAMES(SemanticsNodeKind) = {
|
||||
return Table[AsInt()];
|
||||
}
|
||||
|
||||
auto SemanticsNodeKind::value_kind() const -> SemIR::NodeValueKind {
|
||||
static constexpr SemIR::NodeValueKind Table[] = {
|
||||
auto NodeKind::value_kind() const -> NodeValueKind {
|
||||
static constexpr NodeValueKind Table[] = {
|
||||
#define CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND(Name, Kind) \
|
||||
SemIR::NodeValueKind::Kind,
|
||||
NodeValueKind::Kind,
|
||||
#include "toolchain/semantics/semantics_node_kind.def"
|
||||
};
|
||||
return Table[AsInt()];
|
||||
}
|
||||
|
||||
auto SemanticsNodeKind::terminator_kind() const -> SemIR::TerminatorKind {
|
||||
static constexpr SemIR::TerminatorKind Table[] = {
|
||||
auto NodeKind::terminator_kind() const -> TerminatorKind {
|
||||
static constexpr TerminatorKind Table[] = {
|
||||
#define CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Name, Kind) \
|
||||
SemIR::TerminatorKind::Kind,
|
||||
TerminatorKind::Kind,
|
||||
#include "toolchain/semantics/semantics_node_kind.def"
|
||||
};
|
||||
return Table[AsInt()];
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
} // namespace Carbon::SemIR
|
||||
Reference in new issue
Block a user