mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
This rewrites semantics towards a more pure instruction model, in pursuit of the simple instruction-style output. I think I can get this approach to type-check as it goes along, but obviously this change doesn't prove that yet. I'm separating it out because it's a large rewrite of the semantics structure, tossing out a lot of what was there before. But I think it does help towards several requests, like setting up a clear path for consolidating duplicate identifiers and making the node style more standardized. I expect to need to pass multiple args to function calls, that'd probably be storing vectors of args similar to how I'm showing identifiers and integer literals stored. This removes the semantics namespace because (a) it was getting annoying writing the `::` everywhere, and (b) I think the leaning with Carbon is to avoid namespaces (@chandlerc asked not to put SemanticsIR/SemanticsFactory in a namespace, which is the crux of the issue). But, it's still necessary to avoid name conflicts so I just prefix everything with "Semantics" (still a lot of typing, but no `::`).
43 lines
1.2 KiB
C++
43 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 {
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& /*out*/,
|
|
const SemanticsNodeArgs::None /*no_args*/) {}
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& out, SemanticsNodeId one_node) {
|
|
out << one_node;
|
|
}
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& out, SemanticsTwoNodeIds two_nodes) {
|
|
out << two_nodes.nodes[0] << ", " << two_nodes.nodes[1];
|
|
}
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& out,
|
|
SemanticsIdentifierId identifier) {
|
|
out << identifier;
|
|
}
|
|
|
|
static auto PrintArgs(llvm::raw_ostream& out,
|
|
SemanticsIntegerLiteralId integer_literal) {
|
|
out << integer_literal;
|
|
}
|
|
|
|
void SemanticsNode::Print(llvm::raw_ostream& out) const {
|
|
out << kind_ << "(";
|
|
switch (kind_) {
|
|
#define CARBON_SEMANTICS_NODE_KIND(Name, Args) \
|
|
case SemanticsNodeKind::Name(): \
|
|
PrintArgs(out, one_of_args_.Args); \
|
|
break;
|
|
#include "toolchain/semantics/semantics_node_kind.def"
|
|
}
|
|
out << ")";
|
|
}
|
|
|
|
} // namespace Carbon
|