mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-17 19:20:30 +00:00
This is shorter, more closely connected to code using the typed node types, and avoids using the ambiguous word `Node` in places referring to typed `SemIR` nodes.
33 lines
964 B
C++
33 lines
964 B
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.h"
|
|
|
|
namespace Carbon::SemIR {
|
|
|
|
auto Node::Print(llvm::raw_ostream& out) const -> void {
|
|
out << "{kind: " << kind_;
|
|
|
|
auto print_args = [&](auto... args) {
|
|
int n = 0;
|
|
((out << ", arg" << n++ << ": " << args), ...);
|
|
};
|
|
|
|
// 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 Name::Kind: \
|
|
std::apply(print_args, As<SemIR::Name>().args_tuple()); \
|
|
break;
|
|
#include "toolchain/sem_ir/node_kind.def"
|
|
}
|
|
if (type_id_.is_valid()) {
|
|
out << ", type: " << type_id_;
|
|
}
|
|
out << "}";
|
|
}
|
|
|
|
} // namespace Carbon::SemIR
|