Files
carbon-lang/toolchain/semantics/semantics_node.cpp
T
Richard Smith 62205763a5 Add support for & operator. (#3055)
Refactor type canonicalization so that we can reuse the same code for
building a `T*` expression and for forming the type of an `&x`
expression.

Add basic computation of expression category in order to check that we
only take the address of durable reference expressions. This is
currently computed on demand rather than being tracked as part of the
semantics node, but in most cases can be determined by looking at only a
single expression, so caching it in the node doesn't seem worthwhile
yet. This decision should be revisited if we start doing more complex
category calculations.

Also add trivial lowering support, but it doesn't work properly yet
because lowering doesn't yet take the expression category into account.
2023-08-08 20:53:50 +00:00

39 lines
1.1 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 SemanticsNode::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 SemanticsNode::Print(llvm::raw_ostream& out) const -> void {
out << "{kind: " << kind_;
switch (kind_) {
#define CARBON_SEMANTICS_NODE_KIND(Name) \
case SemanticsNodeKind::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