diff --git a/src/ir/Assignment.h b/src/ir/Assignment.h index a552bb750..308d1f27f 100644 --- a/src/ir/Assignment.h +++ b/src/ir/Assignment.h @@ -8,8 +8,7 @@ #ifndef ASSIGNMENT_H_ #define ASSIGNMENT_H_ -#include "expressions/Expressions.h" -#include +#include "expressions/BaseExpression.h" namespace storm { @@ -18,6 +17,28 @@ namespace ir { class Assignment { public: + Assignment() : variableName(""), expression(nullptr) { + + } + + Assignment(std::string variableName, std::shared_ptr expression) + : variableName(variableName), expression(expression) { + + } + + std::string getVariableName() { + return variableName; + } + + std::shared_ptr getExpression() { + return expression; + } + + std::string toString() { + return variableName + "' = " + expression->toString(); + } + +private: std::string variableName; std::shared_ptr expression; }; @@ -26,10 +47,4 @@ public: } -BOOST_FUSION_ADAPT_STRUCT( - storm::ir::Assignment, - (std::string, variableName) - (std::shared_ptr, expression) -) - #endif /* ASSIGNMENT_H_ */ diff --git a/src/ir/BooleanVariable.h b/src/ir/BooleanVariable.h index 71e09e4ea..051982316 100644 --- a/src/ir/BooleanVariable.h +++ b/src/ir/BooleanVariable.h @@ -27,7 +27,7 @@ public: } virtual std::string toString() { - return variableName + ": bool;"; + return getVariableName() + ": bool;"; } }; @@ -35,9 +35,4 @@ public: } -BOOST_FUSION_ADAPT_STRUCT( - storm::ir::BooleanVariable, - (std::string, variableName) -) - #endif /* BOOLEANVARIABLE_H_ */ diff --git a/src/ir/Command.h b/src/ir/Command.h index 92fd673f1..9a687eab6 100644 --- a/src/ir/Command.h +++ b/src/ir/Command.h @@ -16,25 +16,37 @@ namespace ir { class Command { public: - std::string commandName; - std::shared_ptr guardExpression; - std::vector updates; + + Command() : commandName(""), guardExpression(nullptr), updates() { + + } + + Command(std::string commandName, std::shared_ptr guardExpression, std::vector updates) + : commandName(commandName), guardExpression(guardExpression), updates(updates) { + + } std::string toString() { - return "command!"; + std::string result = "[" + commandName + "] " + guardExpression->toString() + " -> "; + for (uint_fast64_t i = 0; i < updates.size(); ++i) { + result += updates[i].toString(); + if (i < updates.size() - 1) { + result += " + "; + } + } + result += ";"; + return result; } +private: + std::string commandName; + std::shared_ptr guardExpression; + std::vector updates; + }; } } -BOOST_FUSION_ADAPT_STRUCT( - storm::ir::Command, - (std::string, commandName) - (std::shared_ptr, guardExpression) - (std::vector, updates) -) - #endif /* COMMAND_H_ */ diff --git a/src/ir/IntegerVariable.h b/src/ir/IntegerVariable.h index 58a6e8f52..0e8ab9521 100644 --- a/src/ir/IntegerVariable.h +++ b/src/ir/IntegerVariable.h @@ -29,17 +29,10 @@ public: } virtual std::string toString() { - return variableName + ": int[];"; - } - - void setLowerBound(std::shared_ptr& lowerBound) { - this->lowerBound = lowerBound; - } - - void setUpperBound(std::shared_ptr& upperBound) { - this->upperBound = upperBound; + return getVariableName() + ": int[" + lowerBound->toString() + ".." + upperBound->toString() + "];"; } +private: std::shared_ptr lowerBound; std::shared_ptr upperBound; }; diff --git a/src/ir/Module.h b/src/ir/Module.h index d68503f78..02966a5a1 100644 --- a/src/ir/Module.h +++ b/src/ir/Module.h @@ -16,7 +16,16 @@ namespace ir { class Module { public: - Module() { + Module() : moduleName(""), booleanVariables(), integerVariables(), commands() { + + } + + Module(std::string moduleName, std::vector booleanVariables, std::vector integerVariables, std::vector commands) + : moduleName(moduleName), booleanVariables(booleanVariables), integerVariables(integerVariables), commands(commands) { + + } + + Module(std::string moduleName, std::vector commands) : moduleName(moduleName), booleanVariables(), integerVariables(), commands(commands) { } @@ -44,6 +53,7 @@ public: integerVariables.push_back(variable); } +private: std::string moduleName; std::vector booleanVariables; @@ -56,10 +66,4 @@ public: } -BOOST_FUSION_ADAPT_STRUCT( - storm::ir::Module, - (std::string, moduleName) - (std::vector, commands) -) - #endif /* MODULE_H_ */ diff --git a/src/ir/Program.h b/src/ir/Program.h index 98b13e9de..16e213cab 100644 --- a/src/ir/Program.h +++ b/src/ir/Program.h @@ -18,15 +18,30 @@ namespace ir { class Program { public: - enum ModelType {DTMC, CTMC, MDP, CTMDP} modelType; - std::map> booleanUndefinedConstantExpressions; - std::map> integerUndefinedConstantExpressions; - std::map> doubleUndefinedConstantExpressions; - std::vector modules; - std::map rewards; + + enum ModelType {DTMC, CTMC, MDP, CTMDP}; + + Program() : modelType(DTMC), booleanUndefinedConstantExpressions(), integerUndefinedConstantExpressions(), doubleUndefinedConstantExpressions(), modules(), rewards() { + + } + + Program(ModelType modelType, std::map> booleanUndefinedConstantExpressions, std::map> integerUndefinedConstantExpressions, std::map> doubleUndefinedConstantExpressions, std::vector modules, std::map rewards) + : modelType(modelType), booleanUndefinedConstantExpressions(booleanUndefinedConstantExpressions), integerUndefinedConstantExpressions(integerUndefinedConstantExpressions), doubleUndefinedConstantExpressions(doubleUndefinedConstantExpressions), modules(modules), rewards(rewards) { + + } + + Program(ModelType modelType, std::vector modules) : modelType(modelType), booleanUndefinedConstantExpressions(), integerUndefinedConstantExpressions(), doubleUndefinedConstantExpressions(), modules(modules), rewards() { + + } std::string toString() { std::string result = ""; + switch (modelType) { + case DTMC: result += "dtmc\n"; break; + case CTMC: result += "ctmc\n"; break; + case MDP: result += "mdp\n"; break; + case CTMDP: result += "ctmdp\n"; break; + } for (auto element : booleanUndefinedConstantExpressions) { result += "const bool " + element.first + ";\n"; } @@ -55,18 +70,17 @@ public: doubleUndefinedConstantExpressions[constantName] = constantExpression; } - void setModules(std::vector modules) { - this->modules = modules; - } +private: + ModelType modelType; + std::map> booleanUndefinedConstantExpressions; + std::map> integerUndefinedConstantExpressions; + std::map> doubleUndefinedConstantExpressions; + std::vector modules; + std::map rewards; }; } } -BOOST_FUSION_ADAPT_STRUCT( - storm::ir::Program, - (std::vector, modules) -) - #endif /* PROGRAM_H_ */ diff --git a/src/ir/RewardModel.h b/src/ir/RewardModel.h index b53194668..16cb70f62 100644 --- a/src/ir/RewardModel.h +++ b/src/ir/RewardModel.h @@ -20,5 +20,4 @@ class RewardModel { } - #endif /* REWARDMODEL_H_ */ diff --git a/src/ir/Update.h b/src/ir/Update.h index 9cc1648a7..e2751703a 100644 --- a/src/ir/Update.h +++ b/src/ir/Update.h @@ -16,6 +16,27 @@ namespace ir { class Update { public: + Update() : likelihoodExpression(nullptr), assignments() { + + } + + Update(std::shared_ptr likelihoodExpression, std::vector assignments) + : likelihoodExpression(likelihoodExpression), assignments(assignments) { + + } + + std::string toString() { + std::string result = likelihoodExpression->toString() + " : "; + for (uint_fast64_t i = 0; i < assignments.size(); ++i) { + result += assignments[i].toString(); + if (i < assignments.size() - 1) { + result += " & "; + } + } + return result; + } + +private: std::shared_ptr likelihoodExpression; std::vector assignments; }; @@ -24,10 +45,4 @@ public: } -BOOST_FUSION_ADAPT_STRUCT( - storm::ir::Update, - (std::shared_ptr, likelihoodExpression) - (std::vector, assignments) -) - #endif /* UPDATE_H_ */ diff --git a/src/ir/Variable.h b/src/ir/Variable.h index 4456ae8f1..abb62df35 100644 --- a/src/ir/Variable.h +++ b/src/ir/Variable.h @@ -14,8 +14,6 @@ namespace ir { class Variable { public: - std::string variableName; - Variable() { } @@ -32,9 +30,12 @@ public: return variableName; } - void setVariableName(std::string variableName) { - this->variableName = variableName; + std::string getVariableName() { + return variableName; } + +private: + std::string variableName; }; } diff --git a/src/ir/expressions/BaseExpression.h b/src/ir/expressions/BaseExpression.h index aea967901..9d6c93db2 100644 --- a/src/ir/expressions/BaseExpression.h +++ b/src/ir/expressions/BaseExpression.h @@ -21,7 +21,9 @@ public: } - virtual std::string toString() const = 0; + virtual std::string toString() const { + return "expr here!"; + } }; } diff --git a/src/parser/PrismParser.h b/src/parser/PrismParser.h index 6a6a39476..14ca7fba3 100644 --- a/src/parser/PrismParser.h +++ b/src/parser/PrismParser.h @@ -98,7 +98,7 @@ private: expression %= (booleanExpression | integerExpression | doubleExpression); booleanVariableDefinition = (freeIdentifierName >> qi::lit(":") >> qi::lit("bool") >> qi::lit(";"))[qi::_val = phoenix::construct(qi::_1), qi::_a = phoenix::construct>(phoenix::new_(qi::_1)), phoenix::bind(booleanVariables_.add, qi::_1, qi::_a), phoenix::bind(booleanVariableNames_.add, qi::_1, qi::_1), phoenix::bind(allVariables_.add, qi::_1, qi::_a)]; - integerVariableDefinition = (freeIdentifierName >> qi::lit(":") >> qi::lit("[") >> integerConstantExpression >> qi::lit("..") >> integerConstantExpression >> qi::lit("]") >> qi::lit(";"))[qi::_val = phoenix::construct(qi::_1, qi::_2, qi::_3), qi::_a = phoenix::construct>(phoenix::new_(qi::_1)), phoenix::bind(integerVariables_.add, qi::_1, qi::_a), phoenix::bind(integerVariableNames_.add, qi::_1, qi::_1), phoenix::bind(allVariables_.add, qi::_1, qi::_a), phoenix::bind(&storm::ir::IntegerVariable::setVariableName, qi::_val, qi::_1), phoenix::bind(&storm::ir::IntegerVariable::setLowerBound, qi::_val, qi::_2), phoenix::bind(&storm::ir::IntegerVariable::setUpperBound, qi::_val, qi::_3)]; + integerVariableDefinition = (freeIdentifierName >> qi::lit(":") >> qi::lit("[") >> integerConstantExpression >> qi::lit("..") >> integerConstantExpression >> qi::lit("]") >> qi::lit(";"))[qi::_val = phoenix::construct(qi::_1, qi::_2, qi::_3), qi::_a = phoenix::construct>(phoenix::new_(qi::_1)), phoenix::bind(integerVariables_.add, qi::_1, qi::_a), phoenix::bind(integerVariableNames_.add, qi::_1, qi::_1), phoenix::bind(allVariables_.add, qi::_1, qi::_a)]; variableDefinition = (booleanVariableDefinition[phoenix::bind(&storm::ir::Module::addBooleanVariable, qi::_r1, qi::_1)] | integerVariableDefinition[phoenix::bind(&storm::ir::Module::addIntegerVariable, qi::_r1, qi::_1)]); definedBooleanConstantDefinition = (qi::lit("const") >> qi::lit("bool") >> freeIdentifierName >> qi::lit("=") >> booleanLiteralExpression >> qi::lit(";"))[phoenix::bind(booleanConstants_.add, qi::_1, qi::_2), phoenix::bind(allConstants_.add, qi::_1, qi::_2), qi::_val = qi::_2]; @@ -116,17 +116,17 @@ private: integerVariableName %= integerVariableNames_; booleanVariableName %= booleanVariableNames_; - assignmentDefinition = qi::lit("(") >> integerVariableName >> qi::lit("'") >> integerExpression >> qi::lit(")") | qi::lit("(") >> booleanVariableName >> qi::lit("'") >> booleanExpression >> qi::lit(")"); + assignmentDefinition = (qi::lit("(") >> integerVariableName >> qi::lit("'") >> integerExpression >> qi::lit(")"))[qi::_val = phoenix::construct(qi::_1, qi::_2)] | (qi::lit("(") >> booleanVariableName >> qi::lit("'") >> booleanExpression >> qi::lit(")"))[qi::_val = phoenix::construct(qi::_1, qi::_2)]; assignmentDefinitionList %= assignmentDefinition % "&"; - updateDefinition %= doubleConstantExpression >> qi::lit(":") >> assignmentDefinitionList; + updateDefinition = (doubleConstantExpression >> qi::lit(":") >> assignmentDefinitionList)[qi::_val = phoenix::construct(qi::_1, qi::_2)]; updateListDefinition = +updateDefinition; - commandDefinition %= qi::lit("[") >> freeIdentifierName >> qi::lit("]") >> booleanExpression >> qi::lit("->") >> updateListDefinition >> qi::lit(";"); + commandDefinition = (qi::lit("[") >> freeIdentifierName >> qi::lit("]") >> booleanExpression >> qi::lit("->") >> updateListDefinition >> qi::lit(";"))[qi::_val = phoenix::construct(qi::_1, qi::_2, qi::_3)]; - moduleDefinition %= qi::lit("module") >> freeIdentifierName >> *variableDefinition(qi::_val) >> *commandDefinition >> qi::lit("endmodule"); + moduleDefinition = (qi::lit("module") >> freeIdentifierName >> *variableDefinition(qi::_val) >> *commandDefinition >> qi::lit("endmodule"))[qi::_val = phoenix::construct(qi::_1, qi::_2)]; moduleDefinitionList = +moduleDefinition; - start = constantDefinitionList >> moduleDefinitionList; + start = (constantDefinitionList >> moduleDefinitionList)[qi::_val = phoenix::construct(storm::ir::Program::ModelType::DTMC, qi::_1)]; } // The starting point of the grammar.