semantics_node.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. #include "toolchain/semantics/semantics_builtin_kind.h"
  6. namespace Carbon {
  7. static auto PrintArgs(llvm::raw_ostream& /*out*/,
  8. const SemanticsNode::NoArgs /*no_args*/) -> void {}
  9. template <typename T>
  10. static auto PrintArgs(llvm::raw_ostream& out, T arg) -> void {
  11. out << ", arg0: " << arg;
  12. }
  13. template <typename T0, typename T1>
  14. static auto PrintArgs(llvm::raw_ostream& out, std::pair<T0, T1> args) -> void {
  15. PrintArgs(out, args.first);
  16. out << ", arg1: " << args.second;
  17. }
  18. void SemanticsNode::Print(llvm::raw_ostream& out) const {
  19. out << "{kind: " << kind_;
  20. switch (kind_) {
  21. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  22. case SemanticsNodeKind::Name: \
  23. PrintArgs(out, GetAs##Name()); \
  24. break;
  25. #include "toolchain/semantics/semantics_node_kind.def"
  26. }
  27. if (type_.is_valid()) {
  28. out << ", type: " << type_;
  29. }
  30. out << "}";
  31. }
  32. } // namespace Carbon