mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
As I'm looking at adding builtins, it feels a bit like the types of args will end up scaling close to the number of semantic kinds. Rather than having this lead to a bunch of macros, this approach drops the macros for plain code. Note, this adds Get functions too -- I'd planned those regardless for type safety, this is just getting ahead of the issue so that the Print function is pretty clean.
35 lines
967 B
C++
35 lines
967 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/semantics/semantics_node.h"
|
|
|
|
namespace Carbon {
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& /*out*/,
|
|
const SemanticsNode::NoArgs /*no_args*/) {}
|
|
|
|
template <typename T>
|
|
static auto PrintArgs(llvm::raw_ostream& out, T arg) {
|
|
out << arg;
|
|
}
|
|
|
|
template <typename T0, typename T1>
|
|
static auto PrintArgs(llvm::raw_ostream& out, std::pair<T0, T1> args) {
|
|
out << args.first << ", " << args.second;
|
|
}
|
|
|
|
void SemanticsNode::Print(llvm::raw_ostream& out) const {
|
|
out << kind_ << "(";
|
|
switch (kind_) {
|
|
#define CARBON_SEMANTICS_NODE_KIND(Name) \
|
|
case SemanticsNodeKind::Name(): \
|
|
PrintArgs(out, GetAs##Name()); \
|
|
break;
|
|
#include "toolchain/semantics/semantics_node_kind.def"
|
|
}
|
|
out << ")";
|
|
}
|
|
|
|
} // namespace Carbon
|