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