action.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #ifndef EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_
  5. #define EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_
  6. #include <iostream>
  7. #include <vector>
  8. #include "executable_semantics/ast/expression.h"
  9. #include "executable_semantics/ast/statement.h"
  10. #include "executable_semantics/interpreter/stack.h"
  11. #include "executable_semantics/interpreter/value.h"
  12. namespace Carbon {
  13. enum class ActionKind {
  14. LValAction,
  15. ExpressionAction,
  16. StatementAction,
  17. ValAction,
  18. ExpToLValAction,
  19. DeleteTmpAction
  20. };
  21. struct Action {
  22. ActionKind tag;
  23. union {
  24. const Expression* exp; // for LValAction and ExpressionAction
  25. const Statement* stmt;
  26. const Value* val; // for finished actions with a value (ValAction)
  27. Address delete_tmp;
  28. } u;
  29. int pos; // position or state of the action
  30. std::vector<const Value*> results; // results from subexpression
  31. };
  32. void PrintAct(Action* act, std::ostream& out);
  33. void PrintActList(Stack<Action*> ls, std::ostream& out);
  34. auto MakeExpAct(const Expression* e) -> Action*;
  35. auto MakeLvalAct(const Expression* e) -> Action*;
  36. auto MakeStmtAct(const Statement* s) -> Action*;
  37. auto MakeValAct(const Value* v) -> Action*;
  38. auto MakeExpToLvalAct() -> Action*;
  39. auto MakeDeleteAct(Address a) -> Action*;
  40. } // namespace Carbon
  41. #endif // EXECUTABLE_SEMANTICS_INTERPRETER_ACTION_H_