semantics_node.cpp 1.2 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 {
  6. static auto PrintArgs(llvm::raw_ostream& /*out*/,
  7. const SemanticsNodeArgs::None /*no_args*/) {}
  8. static auto PrintArgs(llvm::raw_ostream& out, SemanticsNodeId one_node) {
  9. out << one_node;
  10. }
  11. static auto PrintArgs(llvm::raw_ostream& out, SemanticsTwoNodeIds two_nodes) {
  12. out << two_nodes.nodes[0] << ", " << two_nodes.nodes[1];
  13. }
  14. static auto PrintArgs(llvm::raw_ostream& out,
  15. SemanticsIdentifierId identifier) {
  16. out << identifier;
  17. }
  18. static auto PrintArgs(llvm::raw_ostream& out,
  19. SemanticsIntegerLiteralId integer_literal) {
  20. out << integer_literal;
  21. }
  22. void SemanticsNode::Print(llvm::raw_ostream& out) const {
  23. out << kind_ << "(";
  24. switch (kind_) {
  25. #define CARBON_SEMANTICS_NODE_KIND(Name, Args) \
  26. case SemanticsNodeKind::Name(): \
  27. PrintArgs(out, one_of_args_.Args); \
  28. break;
  29. #include "toolchain/semantics/semantics_node_kind.def"
  30. }
  31. out << ")";
  32. }
  33. } // namespace Carbon