You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.5 KiB

  1. /*
  2. * Command.cpp
  3. *
  4. * Created on: 12.01.2013
  5. * Author: Christian Dehnert
  6. */
  7. #include <sstream>
  8. #include <iostream>
  9. #include "Command.h"
  10. #include "src/parser/prismparser/VariableState.h"
  11. namespace storm {
  12. namespace ir {
  13. Command::Command() : actionName(), guardExpression(), updates(), globalIndex() {
  14. // Nothing to do here.
  15. }
  16. Command::Command(uint_fast64_t globalIndex, std::string const& actionName, std::unique_ptr<storm::ir::expressions::BaseExpression>&& guardExpression, std::vector<storm::ir::Update> const& updates)
  17. : actionName(actionName), guardExpression(std::move(guardExpression)), updates(updates), globalIndex(globalIndex) {
  18. // Nothing to do here.
  19. }
  20. Command::Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState& variableState)
  21. : actionName(oldCommand.getActionName()), guardExpression(oldCommand.guardExpression->clone(renaming, variableState)), globalIndex(newGlobalIndex) {
  22. auto renamingPair = renaming.find(this->actionName);
  23. if (renamingPair != renaming.end()) {
  24. this->actionName = renamingPair->first;
  25. }
  26. this->updates.reserve(oldCommand.getNumberOfUpdates());
  27. for (Update const& update : oldCommand.updates) {
  28. this->updates.emplace_back(update, variableState.getNextGlobalUpdateIndex(), renaming, variableState);
  29. variableState.nextGlobalUpdateIndex++;
  30. }
  31. }
  32. Command::Command(Command const& otherCommand) : actionName(otherCommand.actionName), guardExpression(), updates(otherCommand.updates), globalIndex(otherCommand.globalIndex) {
  33. if (otherCommand.guardExpression != nullptr) {
  34. guardExpression = otherCommand.guardExpression->clone();
  35. }
  36. }
  37. Command& Command::operator=(Command const& otherCommand) {
  38. if (this != &otherCommand) {
  39. this->actionName = otherCommand.actionName;
  40. this->guardExpression = otherCommand.guardExpression->clone();
  41. this->updates = otherCommand.updates;
  42. this->globalIndex = otherCommand.globalIndex;
  43. }
  44. return *this;
  45. }
  46. std::string const& Command::getActionName() const {
  47. return this->actionName;
  48. }
  49. std::unique_ptr<storm::ir::expressions::BaseExpression> const& Command::getGuard() const {
  50. return guardExpression;
  51. }
  52. uint_fast64_t Command::getNumberOfUpdates() const {
  53. return this->updates.size();
  54. }
  55. storm::ir::Update const& Command::getUpdate(uint_fast64_t index) const {
  56. return this->updates[index];
  57. }
  58. uint_fast64_t Command::getGlobalIndex() const {
  59. return this->globalIndex;
  60. }
  61. std::string Command::toString() const {
  62. std::stringstream result;
  63. result << "[" << actionName << "] " << guardExpression->toString() << " -> ";
  64. for (uint_fast64_t i = 0; i < updates.size(); ++i) {
  65. result << updates[i].toString();
  66. if (i < updates.size() - 1) {
  67. result << " + ";
  68. }
  69. }
  70. result << ";";
  71. return result.str();
  72. }
  73. } // namespace ir
  74. } // namespace storm