From 9613d099bb8d02d6fd538383bc0ed5e2ca8d2955 Mon Sep 17 00:00:00 2001 From: gereon Date: Tue, 23 Apr 2013 18:20:05 +0200 Subject: [PATCH] Removed shared_ptr for module, program and rewardmodel objects. --- src/adapters/ExplicitModelAdapter.cpp | 58 +++++++++++++------------- src/adapters/ExplicitModelAdapter.h | 8 ++-- src/ir/Program.cpp | 22 +++++----- src/ir/Program.h | 16 +++---- src/ir/RewardModel.cpp | 10 ++--- src/ir/RewardModel.h | 10 ++--- src/parser/PrismParser.cpp | 46 ++++++++++---------- src/parser/PrismParser.h | 43 +++++++++++-------- src/parser/PrismParser/VariableState.h | 2 +- 9 files changed, 112 insertions(+), 103 deletions(-) diff --git a/src/adapters/ExplicitModelAdapter.cpp b/src/adapters/ExplicitModelAdapter.cpp index 39d7bfe8b..d5f9be117 100644 --- a/src/adapters/ExplicitModelAdapter.cpp +++ b/src/adapters/ExplicitModelAdapter.cpp @@ -24,7 +24,7 @@ namespace storm { namespace adapters { -ExplicitModelAdapter::ExplicitModelAdapter(std::shared_ptr program) : program(program), +ExplicitModelAdapter::ExplicitModelAdapter(storm::ir::Program program) : program(program), booleanVariables(), integerVariables(), booleanVariableToIndexMap(), integerVariableToIndexMap(), allStates(), stateToIndexMap(), numberOfTransitions(0), numberOfChoices(0), transitionRewards(nullptr), transitionMap() { this->initializeVariables(); @@ -39,12 +39,12 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { this->buildTransitionMap(); - std::shared_ptr stateLabeling = this->getStateLabeling(this->program->getLabels()); + std::shared_ptr stateLabeling = this->getStateLabeling(this->program.getLabels()); std::shared_ptr> stateRewards = nullptr; this->rewardModel = nullptr; if (rewardModelName != "") { - this->rewardModel = this->program->getRewardModel(rewardModelName); + this->rewardModel = std::unique_ptr(new storm::ir::RewardModel(this->program.getRewardModel(rewardModelName)));; if (this->rewardModel != nullptr) { if (this->rewardModel->hasStateRewards()) { stateRewards = this->getStateRewards(this->rewardModel->getStateRewards()); @@ -52,7 +52,7 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { } } - switch (this->program->getModelType()) + switch (this->program.getModelType()) { case storm::ir::Program::DTMC: { @@ -93,11 +93,11 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { std::get<1>(*state)[index] = value; } - std::shared_ptr> ExplicitModelAdapter::getStateRewards(std::vector> const & rewards) { + std::shared_ptr> ExplicitModelAdapter::getStateRewards(std::vector const & rewards) { std::shared_ptr> results(new std::vector(this->allStates.size())); for (uint_fast64_t index = 0; index < this->allStates.size(); index++) { for (auto reward: rewards) { - (*results)[index] = reward->getReward(this->allStates[index]); + (*results)[index] = reward.getReward(this->allStates[index]); } } return results; @@ -121,9 +121,9 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { void ExplicitModelAdapter::initializeVariables() { uint_fast64_t numberOfIntegerVariables = 0; uint_fast64_t numberOfBooleanVariables = 0; - for (uint_fast64_t i = 0; i < program->getNumberOfModules(); ++i) { - numberOfIntegerVariables += program->getModule(i)->getNumberOfIntegerVariables(); - numberOfBooleanVariables += program->getModule(i)->getNumberOfBooleanVariables(); + for (uint_fast64_t i = 0; i < program.getNumberOfModules(); ++i) { + numberOfIntegerVariables += program.getModule(i).getNumberOfIntegerVariables(); + numberOfBooleanVariables += program.getModule(i).getNumberOfBooleanVariables(); } this->booleanVariables.resize(numberOfBooleanVariables); @@ -131,17 +131,17 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { uint_fast64_t nextBooleanVariableIndex = 0; uint_fast64_t nextIntegerVariableIndex = 0; - for (uint_fast64_t i = 0; i < program->getNumberOfModules(); ++i) { - std::shared_ptr const module = program->getModule(i); + for (uint_fast64_t i = 0; i < program.getNumberOfModules(); ++i) { + storm::ir::Module const& module = program.getModule(i); - for (uint_fast64_t j = 0; j < module->getNumberOfBooleanVariables(); ++j) { - this->booleanVariables[nextBooleanVariableIndex] = module->getBooleanVariable(j); - this->booleanVariableToIndexMap[module->getBooleanVariable(j).getName()] = nextBooleanVariableIndex; + for (uint_fast64_t j = 0; j < module.getNumberOfBooleanVariables(); ++j) { + this->booleanVariables[nextBooleanVariableIndex] = module.getBooleanVariable(j); + this->booleanVariableToIndexMap[module.getBooleanVariable(j).getName()] = nextBooleanVariableIndex; ++nextBooleanVariableIndex; } - for (uint_fast64_t j = 0; j < module->getNumberOfIntegerVariables(); ++j) { - this->integerVariables[nextIntegerVariableIndex] = module->getIntegerVariable(j); - this->integerVariableToIndexMap[module->getIntegerVariable(j).getName()] = nextIntegerVariableIndex; + for (uint_fast64_t j = 0; j < module.getNumberOfIntegerVariables(); ++j) { + this->integerVariables[nextIntegerVariableIndex] = module.getIntegerVariable(j); + this->integerVariableToIndexMap[module.getIntegerVariable(j).getName()] = nextIntegerVariableIndex; ++nextIntegerVariableIndex; } } @@ -164,17 +164,17 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { std::unique_ptr>> res = std::unique_ptr>>(new std::list>()); // Iterate over all modules. - for (uint_fast64_t i = 0; i < this->program->getNumberOfModules(); ++i) { - std::shared_ptr const module = this->program->getModule(i); + for (uint_fast64_t i = 0; i < this->program.getNumberOfModules(); ++i) { + storm::ir::Module const& module = this->program.getModule(i); - std::shared_ptr> ids = module->getCommandsByAction(action); + std::shared_ptr> ids = module.getCommandsByAction(action); std::list commands; // Look up commands by their id. Add, if guard holds. for (uint_fast64_t id : *ids) { - storm::ir::Command cmd = module->getCommand(id); + storm::ir::Command cmd = module.getCommand(id); if (cmd.getGuard()->getValueAsBool(state)) { - commands.push_back(module->getCommand(id)); + commands.push_back(module.getCommand(id)); } } res->push_back(commands); @@ -293,11 +293,11 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { void ExplicitModelAdapter::addUnlabeledTransitions(const uint_fast64_t stateID, std::list>>& res) { const StateType* state = this->allStates[stateID]; // Iterate over all modules. - for (uint_fast64_t i = 0; i < program->getNumberOfModules(); ++i) { - std::shared_ptr const module = program->getModule(i); + for (uint_fast64_t i = 0; i < program.getNumberOfModules(); ++i) { + storm::ir::Module const& module = program.getModule(i); // Iterate over all commands. - for (uint_fast64_t j = 0; j < module->getNumberOfCommands(); ++j) { - storm::ir::Command const& command = module->getCommand(j); + for (uint_fast64_t j = 0; j < module.getNumberOfCommands(); ++j) { + storm::ir::Command const& command = module.getCommand(j); // Only consider unlabeled commands. if (command.getActionName() != "") continue; // Omit, if command is not active. @@ -334,7 +334,7 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { */ void ExplicitModelAdapter::addLabeledTransitions(const uint_fast64_t stateID, std::list>>& res) { // Create a copy of the current state, as we will free intermediate states... - for (std::string action : this->program->getActions()) { + for (std::string action : this->program.getActions()) { StateType* state = new StateType(*this->allStates[stateID]); std::unique_ptr>> cmds = this->getActiveCommandsByAction(state, action); @@ -432,7 +432,7 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { map[elem.first] += elem.second; if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) { for (auto reward : this->rewardModel->getTransitionRewards()) { - rewardMap[elem.first] += reward->getReward(choice.first, this->allStates[state]); + rewardMap[elem.first] += reward.getReward(choice.first, this->allStates[state]); } } } @@ -474,7 +474,7 @@ ExplicitModelAdapter::~ExplicitModelAdapter() { if ((this->rewardModel != nullptr) && (this->rewardModel->hasTransitionRewards())) { double rewardValue = 0; for (auto reward : this->rewardModel->getTransitionRewards()) { - rewardValue = reward->getReward(choice.first, this->allStates[state]); + rewardValue = reward.getReward(choice.first, this->allStates[state]); } this->transitionRewards->addNextValue(nextRow, it.first, rewardValue); } diff --git a/src/adapters/ExplicitModelAdapter.h b/src/adapters/ExplicitModelAdapter.h index 73a705e33..f97f76c5e 100644 --- a/src/adapters/ExplicitModelAdapter.h +++ b/src/adapters/ExplicitModelAdapter.h @@ -53,7 +53,7 @@ public: class ExplicitModelAdapter { public: - ExplicitModelAdapter(std::shared_ptr program); + ExplicitModelAdapter(storm::ir::Program program); ~ExplicitModelAdapter(); std::shared_ptr getModel(std::string const & rewardModelName = ""); @@ -91,7 +91,7 @@ private: */ void initializeVariables(); - std::shared_ptr> getStateRewards(std::vector> const & rewards); + std::shared_ptr> getStateRewards(std::vector const & rewards); std::shared_ptr getStateLabeling(std::map> labels); /*! @@ -166,14 +166,14 @@ private: void clearInternalState(); // Program that should be converted. - std::shared_ptr program; + storm::ir::Program program; std::vector booleanVariables; std::vector integerVariables; std::map booleanVariableToIndexMap; std::map integerVariableToIndexMap; // Members that are filled during the conversion. - std::shared_ptr rewardModel; + std::unique_ptr rewardModel; std::vector allStates; std::unordered_map stateToIndexMap; uint_fast64_t numberOfTransitions; diff --git a/src/ir/Program.cpp b/src/ir/Program.cpp index d153a1bc6..fd75d9b3e 100644 --- a/src/ir/Program.cpp +++ b/src/ir/Program.cpp @@ -25,15 +25,15 @@ Program::Program() : modelType(UNDEFINED), booleanUndefinedConstantExpressions() } // Initializes all members according to the given values. -Program::Program(ModelType modelType, std::map> booleanUndefinedConstantExpressions, std::map> integerUndefinedConstantExpressions, std::map> doubleUndefinedConstantExpressions, std::vector> modules, std::map> rewards, std::map> labels) +Program::Program(ModelType modelType, std::map> booleanUndefinedConstantExpressions, std::map> integerUndefinedConstantExpressions, std::map> doubleUndefinedConstantExpressions, std::vector modules, std::map rewards, std::map> labels) : modelType(modelType), booleanUndefinedConstantExpressions(booleanUndefinedConstantExpressions), integerUndefinedConstantExpressions(integerUndefinedConstantExpressions), doubleUndefinedConstantExpressions(doubleUndefinedConstantExpressions), modules(modules), rewards(rewards), labels(labels), actionsToModuleIndexMap() { // Build actionsToModuleIndexMap for (unsigned int id = 0; id < this->modules.size(); id++) { - for (auto action : this->modules[id]->getActions()) { + for (auto action : this->modules[id].getActions()) { if (this->actionsToModuleIndexMap.count(action) == 0) { - this->actionsToModuleIndexMap[action] = std::shared_ptr>(new std::set()); + this->actionsToModuleIndexMap[action] = std::set(); } - this->actionsToModuleIndexMap[action]->insert(id); + this->actionsToModuleIndexMap[action].insert(id); this->actions.insert(action); } } @@ -67,11 +67,11 @@ std::string Program::toString() const { result << std::endl; for (auto module : modules) { - result << module->toString() << std::endl; + result << module.toString() << std::endl; } for (auto rewardModel : rewards) { - result << rewardModel.first << ": " << rewardModel.second->toString() << std::endl; + result << rewardModel.first << ": " << rewardModel.second.toString() << std::endl; } for (auto label : labels) { @@ -85,7 +85,7 @@ uint_fast64_t Program::getNumberOfModules() const { return this->modules.size(); } -std::shared_ptr const& Program::getModule(uint_fast64_t index) const { +storm::ir::Module const& Program::getModule(uint_fast64_t index) const { return this->modules[index]; } @@ -95,20 +95,20 @@ std::set const& Program::getActions() const { } // Return modules with given action. -std::shared_ptr> const Program::getModulesByAction(std::string const& action) const { +std::set const Program::getModulesByAction(std::string const& action) const { auto res = this->actionsToModuleIndexMap.find(action); if (res == this->actionsToModuleIndexMap.end()) { - return std::shared_ptr>(new std::set()); + return std::set(); } else { return res->second; } } -std::shared_ptr Program::getRewardModel(std::string const & name) const { +storm::ir::RewardModel Program::getRewardModel(std::string const & name) const { auto it = this->rewards.find(name); if (it == this->rewards.end()) { LOG4CPLUS_ERROR(logger, "The given reward model \"" << name << "\" does not exist. We will proceed without rewards."); - return nullptr; + throw "Rewardmodel does not exist."; } else { return it->second; } diff --git a/src/ir/Program.h b/src/ir/Program.h index d51ebeb0e..a181bbcc3 100644 --- a/src/ir/Program.h +++ b/src/ir/Program.h @@ -58,8 +58,8 @@ public: std::map> booleanUndefinedConstantExpressions, std::map> integerUndefinedConstantExpressions, std::map> doubleUndefinedConstantExpressions, - std::vector> modules, - std::map> rewards, + std::vector modules, + std::map rewards, std::map> labels); /*! @@ -72,7 +72,7 @@ public: * Retrieves a reference to the module with the given index. * @param index the index of the module to retrieve. */ - std::shared_ptr const& getModule(uint_fast64_t index) const; + storm::ir::Module const& getModule(uint_fast64_t index) const; /*! * Retrieves the model type of the model. @@ -98,14 +98,14 @@ public: * @param action Name of the action. * @returns Indices of all matching modules. */ - std::shared_ptr> const getModulesByAction(std::string const& action) const; + std::set const getModulesByAction(std::string const& action) const; /*! * Retrieve reward model with given name. * @param name Name of the reward model. * @return Reward model with given name. */ - std::shared_ptr getRewardModel(std::string const & name) const; + storm::ir::RewardModel getRewardModel(std::string const & name) const; /*! * Retrieves all labels. @@ -127,10 +127,10 @@ private: std::map> doubleUndefinedConstantExpressions; // The modules associated with the program. - std::vector> modules; + std::vector modules; // The reward models associated with the program. - std::map> rewards; + std::map rewards; // The labels that are defined for this model. std::map> labels; @@ -139,7 +139,7 @@ private: std::set actions; // A map of actions to the set of modules containing commands labelled with this action. - std::map>> actionsToModuleIndexMap; + std::map> actionsToModuleIndexMap; }; } // namespace ir diff --git a/src/ir/RewardModel.cpp b/src/ir/RewardModel.cpp index 352c8614c..d6611e4ec 100644 --- a/src/ir/RewardModel.cpp +++ b/src/ir/RewardModel.cpp @@ -19,7 +19,7 @@ RewardModel::RewardModel() : rewardModelName(), stateRewards(), transitionReward } // Initializes all members according to the given values. -RewardModel::RewardModel(std::string rewardModelName, std::vector> stateRewards, std::vector> transitionRewards) : rewardModelName(rewardModelName), stateRewards(stateRewards), transitionRewards(transitionRewards) { +RewardModel::RewardModel(std::string rewardModelName, std::vector stateRewards, std::vector transitionRewards) : rewardModelName(rewardModelName), stateRewards(stateRewards), transitionRewards(transitionRewards) { // Nothing to do here. } @@ -28,10 +28,10 @@ std::string RewardModel::toString() const { std::stringstream result; result << "rewards \"" << rewardModelName << "\"" << std::endl; for (auto reward : stateRewards) { - result << reward->toString() << std::endl; + result << reward.toString() << std::endl; } for (auto reward : transitionRewards) { - result << reward->toString() << std::endl; + result << reward.toString() << std::endl; } result << "endrewards" << std::endl; return result.str(); @@ -41,7 +41,7 @@ bool RewardModel::hasStateRewards() const { return this->stateRewards.size() > 0; } -std::vector> RewardModel::getStateRewards() const { +std::vector RewardModel::getStateRewards() const { return this->stateRewards; } @@ -49,7 +49,7 @@ bool RewardModel::hasTransitionRewards() const { return this->transitionRewards.size() > 0; } -std::vector> RewardModel::getTransitionRewards() const { +std::vector RewardModel::getTransitionRewards() const { return this->transitionRewards; } diff --git a/src/ir/RewardModel.h b/src/ir/RewardModel.h index 29029a4db..cb538f173 100644 --- a/src/ir/RewardModel.h +++ b/src/ir/RewardModel.h @@ -34,7 +34,7 @@ public: * @param stateRewards A vector of state-based reward. * @param transitionRewards A vector of transition-based reward. */ - RewardModel(std::string rewardModelName, std::vector> stateRewards, std::vector> transitionRewards); + RewardModel(std::string rewardModelName, std::vector stateRewards, std::vector transitionRewards); /*! * Retrieves a string representation of this variable. @@ -52,7 +52,7 @@ public: * Retrieve state rewards. * @return State rewards. */ - std::vector> getStateRewards() const; + std::vector getStateRewards() const; /*! * Check, if there are any transition rewards. @@ -64,17 +64,17 @@ public: * Retrieve transition rewards. * @return Transition rewards. */ - std::vector> getTransitionRewards() const; + std::vector getTransitionRewards() const; private: // The name of the reward model. std::string rewardModelName; // The state-based rewards associated with this reward model. - std::vector> stateRewards; + std::vector stateRewards; // The transition-based rewards associated with this reward model. - std::vector> transitionRewards; + std::vector transitionRewards; }; } // namespace ir diff --git a/src/parser/PrismParser.cpp b/src/parser/PrismParser.cpp index 7340d9d3a..980853300 100644 --- a/src/parser/PrismParser.cpp +++ b/src/parser/PrismParser.cpp @@ -58,32 +58,32 @@ namespace parser { this->state->assignedLocalBooleanVariables_.add(variable, variable); mapping[variable] = Assignment(variable, value); } - std::shared_ptr PrismParser::PrismGrammar::renameModule(const std::string& name, const std::string& oldname, std::map& mapping) { + Module PrismParser::PrismGrammar::renameModule(const std::string& name, const std::string& oldname, std::map& mapping) { this->state->moduleNames_.add(name, name); - std::shared_ptr old = this->state->moduleMap_.at(oldname); + Module* old = this->state->moduleMap_.find(oldname); if (old == nullptr) { std::cerr << "Renaming module failed: module " << oldname << " does not exist!" << std::endl; - return nullptr; + throw "Renaming module failed"; } - std::shared_ptr res = std::shared_ptr(new Module(*old, name, mapping, this->state)); + Module res(*old, name, mapping, this->state); this->state->moduleMap_.add(name, res); return res; } - std::shared_ptr PrismParser::PrismGrammar::createModule(const std::string name, std::vector& bools, std::vector& ints, std::map& boolids, std::map intids, std::vector commands) { + Module PrismParser::PrismGrammar::createModule(const std::string name, std::vector& bools, std::vector& ints, std::map& boolids, std::map intids, std::vector commands) { this->state->moduleNames_.add(name, name); - std::shared_ptr res = std::shared_ptr(new Module(name, bools, ints, boolids, intids, commands)); + Module res(name, bools, ints, boolids, intids, commands); this->state->moduleMap_.add(name, res); return res; } - std::shared_ptr createStateReward(std::shared_ptr guard, std::shared_ptr reward) { - return std::shared_ptr(new StateReward(guard, reward)); + StateReward createStateReward(std::shared_ptr guard, std::shared_ptr reward) { + return StateReward(guard, reward); } - std::shared_ptr createTransitionReward(std::string label, std::shared_ptr guard, std::shared_ptr reward) { - return std::shared_ptr(new TransitionReward(label, guard, reward)); + TransitionReward createTransitionReward(std::string label, std::shared_ptr guard, std::shared_ptr reward) { + return TransitionReward(label, guard, reward); } - void createRewardModel(std::string name, std::vector>& stateRewards, std::vector>& transitionRewards, std::map>& mapping) { - mapping[name] = std::shared_ptr(new RewardModel(name, stateRewards, transitionRewards)); + void createRewardModel(std::string name, std::vector& stateRewards, std::vector& transitionRewards, std::map& mapping) { + mapping[name] = RewardModel(name, stateRewards, transitionRewards); } Update createUpdate(std::shared_ptr likelihood, std::map& bools, std::map ints) { return Update(likelihood, bools, ints); @@ -91,15 +91,15 @@ namespace parser { Command createCommand(std::string& label, std::shared_ptr guard, std::vector& updates) { return Command(label, guard, updates); } - std::shared_ptr createProgram( + Program createProgram( Program::ModelType modelType, std::map> undefBoolConst, std::map> undefIntConst, std::map> undefDoubleConst, - std::vector> modules, - std::map> rewards, + std::vector modules, + std::map rewards, std::map> labels) { - return std::shared_ptr(new Program(modelType, undefBoolConst, undefIntConst, undefDoubleConst, modules, rewards, labels)); + return Program(modelType, undefBoolConst, undefIntConst, undefDoubleConst, modules, rewards, labels); } PrismParser::PrismGrammar::PrismGrammar() : PrismParser::PrismGrammar::base_type(start), state(new storm::parser::prism::VariableState()) { @@ -230,14 +230,14 @@ PrismParser::PrismGrammar::PrismGrammar() : PrismParser::PrismGrammar::base_type * closes the file properly, even if an exception is thrown in the parser. In this case, the * exception is passed on to the caller. */ -std::shared_ptr PrismParser::parseFile(std::string const& filename) const { +storm::ir::Program PrismParser::parseFile(std::string const& filename) const { // Open file and initialize result. std::ifstream inputFileStream(filename, std::ios::in); - std::shared_ptr result(nullptr); + storm::ir::Program result; // Now try to parse the contents of the file. try { - result = std::shared_ptr(parse(inputFileStream, filename)); + result = parse(inputFileStream, filename); } catch(std::exception& e) { // In case of an exception properly close the file before passing exception. inputFileStream.close(); @@ -254,7 +254,7 @@ std::shared_ptr PrismParser::parseFile(std::string const& fi * If the parser throws an expectation failure exception, i.e. expected input different than the one * provided, this is caught and displayed properly before the exception is passed on. */ -std::shared_ptr PrismParser::parse(std::istream& inputStream, std::string const& filename) const { +storm::ir::Program PrismParser::parse(std::istream& inputStream, std::string const& filename) const { // Prepare iterators to input. // TODO: Right now, this parses the whole contents of the file into a string first. // While this is usually not necessary, because there exist adapters that make an input stream @@ -268,7 +268,7 @@ std::shared_ptr PrismParser::parse(std::istream& inputStream PositionIteratorType positionIteratorEnd; // Prepare resulting intermediate representation of input. - std::shared_ptr result(new storm::ir::Program()); + storm::ir::Program result; // In order to instantiate the grammar, we have to pass the type of the skipping parser. // As this is more complex, we let Boost figure out the actual type for us. @@ -278,11 +278,11 @@ std::shared_ptr PrismParser::parse(std::istream& inputStream // First run. qi::phrase_parse(positionIteratorBegin, positionIteratorEnd, grammar, boost::spirit::ascii::space | qi::lit("//") >> *(qi::char_ - qi::eol) >> qi::eol, result); grammar.prepareForSecondRun(); - result = std::shared_ptr(new storm::ir::Program()); + result = storm::ir::Program(); std::cout << "Now we start the second run..." << std::endl; // Second run. qi::phrase_parse(positionIteratorBegin2, positionIteratorEnd, grammar, boost::spirit::ascii::space | qi::lit("//") >> *(qi::char_ - qi::eol) >> qi::eol, result); - std::cout << "Here is the parsed grammar: " << std::endl << result->toString() << std::endl; + std::cout << "Here is the parsed grammar: " << std::endl << result.toString() << std::endl; } catch(const qi::expectation_failure& e) { // If the parser expected content different than the one provided, display information // about the location of the error. diff --git a/src/parser/PrismParser.h b/src/parser/PrismParser.h index 0da0e0821..10cdeb895 100644 --- a/src/parser/PrismParser.h +++ b/src/parser/PrismParser.h @@ -1,5 +1,4 @@ -/* - * PrismParser.h +/* * PrismParser.h * * Created on: Jan 3, 2013 * Author: Christian Dehnert @@ -42,7 +41,7 @@ public: * @param filename the name of the file to parse. * @return a shared pointer to the intermediate representation of the PRISM file. */ - std::shared_ptr parseFile(std::string const& filename) const; + storm::ir::Program parseFile(std::string const& filename) const; /*! * The Boost spirit grammar for the PRISM language. Returns the intermediate representation of @@ -50,11 +49,15 @@ public: */ class PrismGrammar : public qi::grammar< Iterator, - std::shared_ptr(), + Program(), qi::locals< std::map>, std::map>, - std::map>, std::map>, std::map>>, Skipper> { + std::map>, + std::map, + std::map> + >, + Skipper> { public: PrismGrammar(); void prepareForSecondRun(); @@ -66,16 +69,22 @@ public: // The starting point of the grammar. qi::rule< Iterator, - std::shared_ptr(), - qi::locals>, std::map>, std::map>, std::map>, std::map>>, + Program(), + qi::locals< + std::map>, + std::map>, + std::map>, + std::map, + std::map> + >, Skipper> start; qi::rule modelTypeDefinition; qi::rule>&, std::map>&, std::map>&), Skipper> constantDefinitionList; - qi::rule>(), Skipper> moduleDefinitionList; + qi::rule(), Skipper> moduleDefinitionList; // Rules for module definition. - qi::rule(), qi::locals, std::vector, std::map, std::map>, Skipper> moduleDefinition; - qi::rule(), qi::locals>, Skipper> moduleRenaming; + qi::rule, std::vector, std::map, std::map>, Skipper> moduleDefinition; + qi::rule>, Skipper> moduleRenaming; // Rules for variable definitions. qi::rule(), Skipper> integerLiteralExpression; @@ -96,10 +105,10 @@ public: qi::rule unassignedLocalIntegerVariableName; // Rules for reward definitions. - qi::rule>&), Skipper> rewardDefinitionList; - qi::rule>&), qi::locals>, std::vector>>, Skipper> rewardDefinition; - qi::rule(), Skipper> stateRewardDefinition; - qi::rule(), qi::locals, Skipper> transitionRewardDefinition; + qi::rule&), Skipper> rewardDefinitionList; + qi::rule&), qi::locals, std::vector>, Skipper> rewardDefinition; + qi::rule stateRewardDefinition; + qi::rule, Skipper> transitionRewardDefinition; // Rules for label definitions. qi::rule>&), Skipper> labelDefinitionList; @@ -128,8 +137,8 @@ public: void addLabel(const std::string& name, std::shared_ptr value, std::map>& mapping); void addBoolAssignment(const std::string& variable, std::shared_ptr value, std::map& mapping); void addIntAssignment(const std::string& variable, std::shared_ptr value, std::map& mapping); - std::shared_ptr renameModule(const std::string& name, const std::string& oldname, std::map& mapping); - std::shared_ptr createModule(const std::string name, std::vector& bools, std::vector& ints, std::map& boolids, std::map intids, std::vector commands); + Module renameModule(const std::string& name, const std::string& oldname, std::map& mapping); + Module createModule(const std::string name, std::vector& bools, std::vector& ints, std::map& boolids, std::map intids, std::vector commands); }; @@ -141,7 +150,7 @@ private: * @param filename the name of the file the input stream belongs to. Used for diagnostics. * @return a shared pointer to the intermediate representation of the PRISM file. */ - std::shared_ptr parse(std::istream& inputStream, std::string const& filename) const; + storm::ir::Program parse(std::istream& inputStream, std::string const& filename) const; }; } // namespace parser diff --git a/src/parser/PrismParser/VariableState.h b/src/parser/PrismParser/VariableState.h index 6b2c9a9b3..58a716fd1 100644 --- a/src/parser/PrismParser/VariableState.h +++ b/src/parser/PrismParser/VariableState.h @@ -38,7 +38,7 @@ public: // the intermediate representation. struct qi::symbols> integerVariables_, booleanVariables_; struct qi::symbols> integerConstants_, booleanConstants_, doubleConstants_; - struct qi::symbols> moduleMap_; + struct qi::symbols moduleMap_; // A structure representing the identity function over identifier names. struct variableNamesStruct : qi::symbols { } integerVariableNames_, booleanVariableNames_, commandNames_, labelNames_, allConstantNames_, moduleNames_,