mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 02:38:12 +00:00
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.
41 lines
1.2 KiB
C++
41 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/semantics/semantics_node.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& /*out*/,
|
|
const Node::NoArgs /*no_args*/) -> void {}
|
|
|
|
template <typename T>
|
|
static auto PrintArgs(llvm::raw_ostream& out, T arg) -> void {
|
|
out << ", arg0: " << arg;
|
|
}
|
|
|
|
template <typename T0, typename T1>
|
|
static auto PrintArgs(llvm::raw_ostream& out, std::pair<T0, T1> args) -> void {
|
|
PrintArgs(out, args.first);
|
|
out << ", arg1: " << args.second;
|
|
}
|
|
|
|
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 (kind_) {
|
|
#define CARBON_SEMANTICS_NODE_KIND(Name) \
|
|
case NodeKind::Name: \
|
|
PrintArgs(out, GetAs##Name()); \
|
|
break;
|
|
#include "toolchain/semantics/semantics_node_kind.def"
|
|
}
|
|
if (type_id_.is_valid()) {
|
|
out << ", type: " << type_id_;
|
|
}
|
|
out << "}";
|
|
}
|
|
|
|
} // namespace Carbon::SemIR
|