node.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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/sem_ir/node.h"
  5. namespace Carbon::SemIR {
  6. auto Node::Print(llvm::raw_ostream& out) const -> void {
  7. out << "{kind: " << kind_;
  8. auto print_args = [&](auto info) {
  9. using Info = decltype(info);
  10. if constexpr (Info::NumArgs > 0) {
  11. out << ", arg0: " << FromRaw<typename Info::template ArgType<0>>(arg0_);
  12. }
  13. if constexpr (Info::NumArgs > 1) {
  14. out << ", arg1: " << FromRaw<typename Info::template ArgType<1>>(arg1_);
  15. }
  16. };
  17. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  18. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  19. switch (kind_) {
  20. #define CARBON_SEM_IR_NODE_KIND(Name) \
  21. case Name::Kind: \
  22. print_args(TypedNodeArgsInfo<Name>()); \
  23. break;
  24. #include "toolchain/sem_ir/node_kind.def"
  25. }
  26. if (type_id_.is_valid()) {
  27. out << ", type: " << type_id_;
  28. }
  29. out << "}";
  30. }
  31. } // namespace Carbon::SemIR