node.cpp 964 B

1234567891011121314151617181920212223242526272829303132
  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... args) {
  9. int n = 0;
  10. ((out << ", arg" << n++ << ": " << args), ...);
  11. };
  12. // clang warns on unhandled enum values; clang-tidy is incorrect here.
  13. // NOLINTNEXTLINE(bugprone-switch-missing-default-case)
  14. switch (kind_) {
  15. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  16. case NodeKind::Name: \
  17. std::apply(print_args, As<SemIR::Name>().args_tuple()); \
  18. break;
  19. #include "toolchain/sem_ir/node_kind.def"
  20. }
  21. if (type_id_.is_valid()) {
  22. out << ", type: " << type_id_;
  23. }
  24. out << "}";
  25. }
  26. } // namespace Carbon::SemIR