action.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }
  33. out << "<" << pos << ">";
  34. if (results.size() > 0) {
  35. out << "(";
  36. llvm::ListSeparator sep;
  37. for (auto& result : results) {
  38. out << sep;
  39. if (result) {
  40. out << *result;
  41. }
  42. }
  43. out << ")";
  44. }
  45. }
  46. void Action::PrintList(const Stack<Ptr<Action>>& ls, llvm::raw_ostream& out) {
  47. llvm::ListSeparator sep(" :: ");
  48. for (const auto& action : ls) {
  49. out << sep << *action;
  50. }
  51. }
  52. } // namespace Carbon