semantics_node.cpp 967 B

12345678910111213141516171819202122232425262728293031323334
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/semantics/semantics_node.h"
  5. namespace Carbon {
  6. static auto PrintArgs(llvm::raw_ostream& /*out*/,
  7. const SemanticsNode::NoArgs /*no_args*/) {}
  8. template <typename T>
  9. static auto PrintArgs(llvm::raw_ostream& out, T arg) {
  10. out << arg;
  11. }
  12. template <typename T0, typename T1>
  13. static auto PrintArgs(llvm::raw_ostream& out, std::pair<T0, T1> args) {
  14. out << args.first << ", " << args.second;
  15. }
  16. void SemanticsNode::Print(llvm::raw_ostream& out) const {
  17. out << kind_ << "(";
  18. switch (kind_) {
  19. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  20. case SemanticsNodeKind::Name(): \
  21. PrintArgs(out, GetAs##Name()); \
  22. break;
  23. #include "toolchain/semantics/semantics_node_kind.def"
  24. }
  25. out << ")";
  26. }
  27. } // namespace Carbon