semantics_ir.cpp 1.3 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/semantics/semantics_ir.h"
  5. #include "common/check.h"
  6. #include "llvm/Support/FormatVariadic.h"
  7. #include "toolchain/lexer/tokenized_buffer.h"
  8. namespace Carbon {
  9. void SemanticsIR::Print(llvm::raw_ostream& out,
  10. Semantics::NodeRef node_ref) const {
  11. switch (node_ref.kind()) {
  12. case Semantics::NodeKind::BinaryOperator:
  13. nodes_.Get<Semantics::BinaryOperator>(node_ref).Print(out);
  14. return;
  15. case Semantics::NodeKind::Function:
  16. nodes_.Get<Semantics::Function>(node_ref).Print(
  17. out, [&](Semantics::NodeRef other) { Print(out, other); });
  18. return;
  19. case Semantics::NodeKind::IntegerLiteral:
  20. nodes_.Get<Semantics::IntegerLiteral>(node_ref).Print(out);
  21. return;
  22. case Semantics::NodeKind::Return:
  23. nodes_.Get<Semantics::Return>(node_ref).Print(out);
  24. return;
  25. case Semantics::NodeKind::SetName:
  26. nodes_.Get<Semantics::SetName>(node_ref).Print(out);
  27. return;
  28. case Semantics::NodeKind::Invalid:
  29. CARBON_FATAL() << "Invalid NodeRef kind";
  30. }
  31. }
  32. } // namespace Carbon