semantics_node.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include "toolchain/semantics/semantics_builtin_kind.h"
  6. namespace Carbon {
  7. static auto PrintArgs(llvm::raw_ostream& /*out*/,
  8. const SemanticsNode::NoArgs /*no_args*/) {}
  9. template <typename T>
  10. static auto PrintArgs(llvm::raw_ostream& out, T arg) {
  11. out << arg;
  12. }
  13. template <typename T0, typename T1>
  14. static auto PrintArgs(llvm::raw_ostream& out, std::pair<T0, T1> args) {
  15. out << args.first << ", " << args.second;
  16. }
  17. void SemanticsNode::Print(llvm::raw_ostream& out) const {
  18. out << kind_ << "(";
  19. switch (kind_) {
  20. #define CARBON_SEMANTICS_NODE_KIND(Name) \
  21. case SemanticsNodeKind::Name(): \
  22. PrintArgs(out, GetAs##Name()); \
  23. break;
  24. #include "toolchain/semantics/semantics_node_kind.def"
  25. }
  26. out << ")";
  27. if (type_.index != -1) {
  28. out << ": " << type_;
  29. }
  30. }
  31. } // namespace Carbon