Browse Source

Further work on adapting classes that store a PRISM program to the new expressions. Commit to switch workplace.

Former-commit-id: 00c1b1324d
main
dehnert 11 years ago
parent
commit
0110758e3e
  1. 78
      src/storage/prism/Command.cpp
  2. 78
      src/storage/prism/Command.h

78
src/storage/prism/Command.cpp

@ -1,75 +1,39 @@
/*
* Command.cpp
*
* Created on: 12.01.2013
* Author: Christian Dehnert
*/
#include <sstream>
#include <iostream>
#include "Command.h" #include "Command.h"
#include "src/parser/prismparser/VariableState.h"
namespace storm { namespace storm {
namespace ir { namespace prism {
Command::Command(uint_fast64_t globalIndex, std::string const& actionName, storm::expressions::Expression const& guardExpression, std::vector<storm::prism::Update> const& updates) : actionName(actionName), guardExpression(guardExpression), updates(updates), globalIndex(globalIndex) {
Command::Command() : actionName(), guardExpression(), updates(), globalIndex() {
// Nothing to do here. // Nothing to do here.
} }
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) Command::Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming) : actionName(oldCommand.getActionName()), guardExpression(oldCommand.getGuardExpression().substitute<std::map>(renaming)), globalIndex(newGlobalIndex) {
: actionName(actionName), guardExpression(std::move(guardExpression)), updates(updates), globalIndex(globalIndex) { auto const& namePair = renaming.find(this->actionName);
// Nothing to do here. if (namePair != renaming.end()) {
} this->actionName = namePair->second;
Command::Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState& variableState)
: actionName(oldCommand.getActionName()), guardExpression(oldCommand.guardExpression->clone(renaming, variableState)), globalIndex(newGlobalIndex) {
auto renamingPair = renaming.find(this->actionName);
if (renamingPair != renaming.end()) {
this->actionName = renamingPair->second;
} }
this->updates.reserve(oldCommand.getNumberOfUpdates()); this->updates.reserve(oldCommand.getNumberOfUpdates());
for (Update const& update : oldCommand.updates) { for (Update const& update : oldCommand.getUpdates()) {
this->updates.emplace_back(update, variableState.getNextGlobalUpdateIndex(), renaming, variableState); this->updates.emplace_back(update, update.getGlobalIndex(), renaming);
variableState.nextGlobalUpdateIndex++;
}
} }
Command::Command(Command const& otherCommand) : actionName(otherCommand.actionName), guardExpression(), updates(otherCommand.updates), globalIndex(otherCommand.globalIndex) {
if (otherCommand.guardExpression != nullptr) {
guardExpression = otherCommand.guardExpression->clone();
}
}
Command& Command::operator=(Command const& otherCommand) {
if (this != &otherCommand) {
this->actionName = otherCommand.actionName;
this->guardExpression = otherCommand.guardExpression->clone();
this->updates = otherCommand.updates;
this->globalIndex = otherCommand.globalIndex;
}
return *this;
} }
std::string const& Command::getActionName() const { std::string const& Command::getActionName() const {
return this->actionName; return this->actionName;
} }
std::unique_ptr<storm::ir::expressions::BaseExpression> const& Command::getGuard() const { storm::expressions::Expression const& Command::getGuardExpression() const {
return guardExpression; return guardExpression;
} }
uint_fast64_t Command::getNumberOfUpdates() const { std::size_t Command::getNumberOfUpdates() const {
return this->updates.size(); return this->updates.size();
} }
storm::ir::Update const& Command::getUpdate(uint_fast64_t index) const { storm::prism::Update const& Command::getUpdate(uint_fast64_t index) const {
return this->updates[index]; return this->updates[index];
} }
std::vector<storm::ir::Update> const& Command::getUpdates() const { std::vector<storm::prism::Update> const& Command::getUpdates() const {
return this->updates; return this->updates;
} }
@ -77,18 +41,16 @@ namespace storm {
return this->globalIndex; return this->globalIndex;
} }
std::string Command::toString() const { std::ostream& operator<<(std::ostream& stream, Command const& command) {
std::stringstream result; stream << "[" << command.getActionName() << "] " << command.getGuardExpression() << " -> ";
result << "[" << actionName << "] " << guardExpression->toString() << " -> "; for (uint_fast64_t i = 0; i < command.getUpdates().size(); ++i) {
for (uint_fast64_t i = 0; i < updates.size(); ++i) { stream << command.getUpdate(i);
result << updates[i].toString(); if (i < command.getUpdates().size() - 1) {
if (i < updates.size() - 1) { stream << " + ";
result << " + ";
} }
} }
result << ";"; stream << ";";
return result.str(); return stream;
} }
} // namespace ir } // namespace ir
} // namespace storm } // namespace storm

78
src/storage/prism/Command.h

@ -1,69 +1,42 @@
/* #ifndef STORM_STORAGE_PRISM_COMMAND_H_
* Command.h #define STORM_STORAGE_PRISM_COMMAND_H_
*
* Created on: 06.01.2013
* Author: Christian Dehnert
*/
#ifndef STORM_IR_COMMAND_H_
#define STORM_IR_COMMAND_H_
#include <vector> #include <vector>
#include <string> #include <string>
#include <map> #include <map>
#include "expressions/BaseExpression.h" #include "src/storage/expressions/Expression.h"
#include "Update.h" #include "src/storage/prism/Update.h"
namespace storm { namespace storm {
namespace parser {
namespace prism { namespace prism {
class VariableState;
} // namespace prismparser
} // namespace parser
namespace ir {
/*!
* A class representing a command.
*/
class Command { class Command {
public: public:
/*! /*!
* Default constructor. Creates a a command without name, guard and updates. * Creates a command with the given action name, guard and updates.
*/
Command();
/*!
* Creates a command with the given name, guard and updates.
* *
* @param globalIndex The global index of the command. * @param globalIndex The global index of the command.
* @param actionName The action name of the command. * @param actionName The action name of the command.
* @param guardExpression the expression that defines the guard of the command. * @param guardExpression the expression that defines the guard of the command.
* @param updates A list of updates that is associated with this command. * @param updates A list of updates that is associated with this 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); Command(uint_fast64_t globalIndex, std::string const& actionName, storm::expressions::Expression const& guardExpression, std::vector<storm::prism::Update> const& updates);
/*! /*!
* Creates a copy of the given command and performs the provided renaming. * Creates a copy of the given command and performs the provided renaming.
* *
* @param oldCommand The command to copy. * @param oldCommand The command to copy.
* @param newGlobalIndex The global index of the copy of the command. * @param newGlobalIndex The global index of the copy of the command.
* @param renaming A mapping from names that are to be renamed to the names they are to be * @param renaming A mapping from names that are to be renamed to the names they are to be replaced with.
* replaced with.
* @param variableState An object knowing about the variables in the system.
*/ */
Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming, storm::parser::prism::VariableState& variableState); Command(Command const& oldCommand, uint_fast64_t newGlobalIndex, std::map<std::string, std::string> const& renaming);
/*! // Create default implementations of constructors/assignment.
* Performs a deep-copy of the given command. Command() = default;
* Command(Command const& otherVariable) = default;
* @param otherCommand The command to copy. Command& operator=(Command const& otherVariable)= default;
*/ Command(Command&& otherVariable) = default;
Command(Command const& otherCommand); Command& operator=(Command&& otherVariable) = default;
Command& operator=(Command const& otherCommand);
/*! /*!
* Retrieves the action name of this command. * Retrieves the action name of this command.
@ -77,28 +50,28 @@ namespace storm {
* *
* @return A reference to the guard of the command. * @return A reference to the guard of the command.
*/ */
std::unique_ptr<storm::ir::expressions::BaseExpression> const& getGuard() const; storm::expressions::Expression const& getGuardExpression() const;
/*! /*!
* Retrieves the number of updates associated with this command. * Retrieves the number of updates associated with this command.
* *
* @return The number of updates associated with this command. * @return The number of updates associated with this command.
*/ */
uint_fast64_t getNumberOfUpdates() const; std::size_t getNumberOfUpdates() const;
/*! /*!
* Retrieves a reference to the update with the given index. * Retrieves a reference to the update with the given index.
* *
* @return A reference to the update with the given index. * @return A reference to the update with the given index.
*/ */
storm::ir::Update const& getUpdate(uint_fast64_t index) const; storm::prism::Update const& getUpdate(uint_fast64_t index) const;
/*! /*!
* Retrieves a vector of all updates associated with this command. * Retrieves a vector of all updates associated with this command.
* *
* @return A vector of updates associated with this command. * @return A vector of updates associated with this command.
*/ */
std::vector<storm::ir::Update> const& getUpdates() const; std::vector<storm::prism::Update> const& getUpdates() const;
/*! /*!
* Retrieves the global index of the command, that is, a unique index over all modules. * Retrieves the global index of the command, that is, a unique index over all modules.
@ -107,28 +80,23 @@ namespace storm {
*/ */
uint_fast64_t getGlobalIndex() const; uint_fast64_t getGlobalIndex() const;
/*! friend std::ostream& operator<<(std::ostream& stream, Command const& command);
* Retrieves a string representation of this command.
*
* @return A string representation of this command.
*/
std::string toString() const;
private: private:
// The name of the command. // The name of the command.
std::string actionName; std::string actionName;
// The expression that defines the guard of the command. // The expression that defines the guard of the command.
std::unique_ptr<storm::ir::expressions::BaseExpression> guardExpression; storm::expressions::Expression guardExpression;
// The list of updates of the command. // The list of updates of the command.
std::vector<storm::ir::Update> updates; std::vector<storm::prism::Update> updates;
// The global index of the command. // The global index of the command.
uint_fast64_t globalIndex; uint_fast64_t globalIndex;
}; };
} // namespace ir } // namespace prism
} // namespace storm } // namespace storm
#endif /* STORM_IR_COMMAND_H_ */ #endif /* STORM_STORAGE_PRISM_COMMAND_H_ */
|||||||
100:0
Loading…
Cancel
Save