action.cpp 1.6 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/declaration.h"
  11. #include "executable_semantics/ast/expression.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 (kind()) {
  20. case Action::Kind::LValAction:
  21. out << cast<LValAction>(*this).expression();
  22. break;
  23. case Action::Kind::ExpressionAction:
  24. out << cast<ExpressionAction>(*this).expression();
  25. break;
  26. case Action::Kind::PatternAction:
  27. out << cast<PatternAction>(*this).pattern();
  28. break;
  29. case Action::Kind::StatementAction:
  30. cast<StatementAction>(*this).statement().PrintDepth(1, out);
  31. break;
  32. case Action::Kind::ScopeAction:
  33. out << "ScopeAction";
  34. }
  35. out << "<" << pos_ << ">";
  36. if (results_.size() > 0) {
  37. out << "(";
  38. llvm::ListSeparator sep;
  39. for (auto& result : results_) {
  40. out << sep << *result;
  41. }
  42. out << ")";
  43. }
  44. }
  45. void Action::PrintList(const Stack<Nonnull<Action*>>& ls,
  46. llvm::raw_ostream& out) {
  47. llvm::ListSeparator sep(" :: ");
  48. for (const auto& action : ls) {
  49. out << sep << *action;
  50. }
  51. }
  52. } // namespace Carbon