mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 20:28:12 +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
@@ -20,23 +20,21 @@ static auto PrintArgs(llvm::raw_ostream& out, std::pair<T0, T1> args) -> void {
|
||||
out << ", arg1: " << args.second;
|
||||
}
|
||||
|
||||
auto operator<<(llvm::raw_ostream& out, const Node& node)
|
||||
-> llvm::raw_ostream& {
|
||||
out << "{kind: " << node.kind_;
|
||||
auto Node::Print(llvm::raw_ostream& out) const -> void {
|
||||
out << "{kind: " << kind_;
|
||||
// clang warns on unhandled enum values; clang-tidy is incorrect here.
|
||||
// NOLINTNEXTLINE(bugprone-switch-missing-default-case)
|
||||
switch (node.kind_) {
|
||||
switch (kind_) {
|
||||
#define CARBON_SEMANTICS_NODE_KIND(Name) \
|
||||
case NodeKind::Name: \
|
||||
PrintArgs(out, node.GetAs##Name()); \
|
||||
PrintArgs(out, GetAs##Name()); \
|
||||
break;
|
||||
#include "toolchain/semantics/semantics_node_kind.def"
|
||||
}
|
||||
if (node.type_id_.is_valid()) {
|
||||
out << ", type: " << node.type_id_;
|
||||
if (type_id_.is_valid()) {
|
||||
out << ", type: " << type_id_;
|
||||
}
|
||||
out << "}";
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace Carbon::SemIR
|
||||
Reference in new issue
Block a user