semantics_node.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  21. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  22. switch (node.kind_) {
  23. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  24. case NodeKind::Name: \
  25. PrintArgs(out, node.GetAs##Name()); \
  26. break;
  27. #include "toolchain/semantics/semantics_node_kind.def"
  28. }
  29. if (node.type_id_.is_valid()) {
  30. out << ", type: " << node.type_id_;
  31. }
  32. out << "}";
  33. return out;
  34. }
  35. } // namespace Carbon::SemIR