action.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "executable_semantics/interpreter/action.h"
  5. #include <iterator>
  6. #include <map>
  7. #include <optional>
  8. #include <utility>
  9. #include <vector>
  10. #include "executable_semantics/ast/expression.h"
  11. #include "executable_semantics/ast/function_definition.h"
  12. #include "executable_semantics/common/arena.h"
  13. #include "executable_semantics/interpreter/stack.h"
  14. #include "llvm/ADT/StringExtras.h"
  15. #include "llvm/Support/Casting.h"
  16. namespace Carbon {
  17. using llvm::cast;
  18. void Action::Print(llvm::raw_ostream& out) const {
  19. switch (Tag()) {
  20. case Action::Kind::LValAction:
  21. out << *cast<LValAction>(*this).Exp();
  22. break;
  23. case Action::Kind::ExpressionAction:
  24. out << *cast<ExpressionAction>(*this).Exp();
  25. break;
  26. case Action::Kind::PatternAction:
  27. out << *cast<PatternAction>(*this).Pat();
  28. break;
  29. case Action::Kind::StatementAction:
  30. cast<StatementAction>(*this).Stmt()->PrintDepth(1, out);
  31. break;
  32. case Action::Kind::ValAction:
  33. out << *cast<ValAction>(*this).Val();
  34. break;
  35. }
  36. out << "<" << pos << ">";
  37. if (results.size() > 0) {
  38. out << "(";
  39. llvm::ListSeparator sep;
  40. for (auto& result : results) {
  41. out << sep;
  42. if (result) {
  43. out << *result;
  44. }
  45. }
  46. out << ")";
  47. }
  48. }
  49. void Action::PrintList(const Stack<Action*>& ls, llvm::raw_ostream& out) {
  50. llvm::ListSeparator sep(" :: ");
  51. for (const auto& action : ls) {
  52. out << sep << *action;
  53. }
  54. }
  55. } // namespace Carbon