Files
carbon-lang/toolchain/sem_ir/node.cpp
T
Richard Smith c7a9e29a89 Add typed nodes to SemIR. (#3280)
Replace `SemIR::Node::GetAsFoo` and `SemIR::Node::Foo::Make` with
`SemIR::Foo` class that represents a particular kind of node, with named
fields.

Rename `SemIR::IntegerLiteral` and `SemIR::RealLiteral` to
`IntegerValue` / `RealValue` to better reflect their purpose and avoid a
name collision with the corresponding `SemIR` node kinds.

Remove `NodeKind::Invalid` and the `SemIR::Node` default constructor
entirely, as they were not used for anything.
2023-10-11 05:39:59 +00:00

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 NodeKind::Name: \
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