Files
carbon-lang/toolchain/semantics/semantics_node_kind.cpp
T
Jon Ross-Perkins 29b6399e4f 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.
2023-08-26 00:17:25 +00:00

42 lines
1.3 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/semantics/semantics_node_kind.h"
namespace Carbon::SemIR {
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 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"
};
return Table[AsInt()];
}
auto NodeKind::value_kind() const -> NodeValueKind {
static constexpr NodeValueKind Table[] = {
#define CARBON_SEMANTICS_NODE_KIND_WITH_VALUE_KIND(Name, Kind) \
NodeValueKind::Kind,
#include "toolchain/semantics/semantics_node_kind.def"
};
return Table[AsInt()];
}
auto NodeKind::terminator_kind() const -> TerminatorKind {
static constexpr TerminatorKind Table[] = {
#define CARBON_SEMANTICS_NODE_KIND_WITH_TERMINATOR_KIND(Name, Kind) \
TerminatorKind::Kind,
#include "toolchain/semantics/semantics_node_kind.def"
};
return Table[AsInt()];
}
} // namespace Carbon::SemIR