semantics_node.cpp 1.2 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 Node::Print(llvm::raw_ostream& out) const -> void {
  18. out << "{kind: " << kind_;
  19. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  20. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  21. switch (kind_) {
  22. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  23. case NodeKind::Name: \
  24. PrintArgs(out, GetAs##Name()); \
  25. break;
  26. #include "toolchain/semantics/semantics_node_kind.def"
  27. }
  28. if (type_id_.is_valid()) {
  29. out << ", type: " << type_id_;
  30. }
  31. out << "}";
  32. }
  33. } // namespace Carbon::SemIR