Browse Source

Somewhat works now. Still has at least one bug and segfaults afterwards :-)

tempestpy_adaptions
gereon 12 years ago
parent
commit
840a9b6e07
  1. 3
      src/ir/BooleanVariable.cpp
  2. 2
      src/ir/BooleanVariable.h
  3. 8
      src/ir/IntegerVariable.cpp
  4. 2
      src/ir/IntegerVariable.h
  5. 20
      src/ir/Module.cpp
  6. 6
      src/ir/Variable.cpp
  7. 2
      src/ir/Variable.h
  8. 2
      src/ir/expressions/BinaryRelationExpression.h
  9. 1
      src/ir/expressions/VariableExpression.h
  10. 21
      src/parser/PrismParser.cpp

3
src/ir/BooleanVariable.cpp

@ -25,7 +25,8 @@ BooleanVariable::BooleanVariable(uint_fast64_t index, std::string variableName,
// Nothing to do here.
}
BooleanVariable::BooleanVariable(const BooleanVariable& var, const std::string& newName) : Variable(var, newName) {
BooleanVariable::BooleanVariable(const BooleanVariable& var, const std::string& newName, const std::map<std::string, std::string>& renaming, const std::map<std::string,uint_fast64_t>& bools, const std::map<std::string,uint_fast64_t>& ints)
: Variable(var, newName, renaming, bools, ints) {
}
// Build a string representation of the variable.

2
src/ir/BooleanVariable.h

@ -35,7 +35,7 @@ public:
BooleanVariable(uint_fast64_t index, std::string variableName, std::shared_ptr<storm::ir::expressions::BaseExpression> initialValue = std::shared_ptr<storm::ir::expressions::BaseExpression>(nullptr));
BooleanVariable(const BooleanVariable& var, const std::string& newName);
BooleanVariable(const BooleanVariable& var, const std::string& newName, const std::map<std::string, std::string>& renaming, const std::map<std::string,uint_fast64_t>& bools, const std::map<std::string,uint_fast64_t>& ints);
/*!
* Retrieves a string representation of this variable.

8
src/ir/IntegerVariable.cpp

@ -21,13 +21,15 @@ IntegerVariable::IntegerVariable() : lowerBound(), upperBound() {
}
// Initializes all members according to the given values.
IntegerVariable::IntegerVariable(uint_fast64_t index, std::string variableName, std::shared_ptr<storm::ir::expressions::BaseExpression> lowerBound, std::shared_ptr<storm::ir::expressions::BaseExpression> upperBound, std::shared_ptr<storm::ir::expressions::BaseExpression> initialValue) : Variable(index, variableName, initialValue), lowerBound(lowerBound), upperBound(upperBound) {
IntegerVariable::IntegerVariable(uint_fast64_t index, std::string variableName, std::shared_ptr<storm::ir::expressions::BaseExpression> lowerBound, std::shared_ptr<storm::ir::expressions::BaseExpression> upperBound, std::shared_ptr<storm::ir::expressions::BaseExpression> initialValue)
: Variable(index, variableName, initialValue), lowerBound(lowerBound), upperBound(upperBound) {
if (this->getInitialValue() == nullptr) {
this->setInitialValue(lowerBound);
}
}
IntegerVariable::IntegerVariable(const IntegerVariable& var, const std::string& newName) : Variable(var, newName) {
IntegerVariable::IntegerVariable(const IntegerVariable& var, const std::string& newName, const std::map<std::string, std::string>& renaming, const std::map<std::string,uint_fast64_t>& bools, const std::map<std::string,uint_fast64_t>& ints)
: Variable(var, newName, renaming, bools, ints), lowerBound(var.lowerBound->clone(renaming, bools, ints)), upperBound(var.upperBound->clone(renaming, bools, ints)) {
}
// Return lower bound for variable.
@ -44,7 +46,7 @@ std::shared_ptr<storm::ir::expressions::BaseExpression> IntegerVariable::getUppe
// Build a string representation of the variable.
std::string IntegerVariable::toString() const {
std::stringstream result;
result << this->getName() << ": [" << lowerBound->toString() << ".." << upperBound->toString() << "]";
result << "int_" << this->getName() << ": [" << lowerBound->toString() << ".." << upperBound->toString() << "]";
if (this->getInitialValue() != nullptr) {
result << " init " + this->getInitialValue()->toString();
}

2
src/ir/IntegerVariable.h

@ -37,7 +37,7 @@ public:
*/
IntegerVariable(uint_fast64_t index, std::string variableName, std::shared_ptr<storm::ir::expressions::BaseExpression> lowerBound, std::shared_ptr<storm::ir::expressions::BaseExpression> upperBound, std::shared_ptr<storm::ir::expressions::BaseExpression> initialValue = std::shared_ptr<storm::ir::expressions::BaseExpression>(nullptr));
IntegerVariable(const IntegerVariable& var, const std::string& newName);
IntegerVariable(const IntegerVariable& var, const std::string& newName, const std::map<std::string, std::string>& renaming, const std::map<std::string,uint_fast64_t>& bools, const std::map<std::string,uint_fast64_t>& ints);
/*!
* Retrieves the lower bound for this integer variable.

20
src/ir/Module.cpp

@ -36,22 +36,34 @@ Module::Module(std::string moduleName, std::vector<storm::ir::BooleanVariable> b
Module::Module(const Module& module, const std::string& moduleName, const std::map<std::string, std::string>& renaming, const VariableAdder& adder)
: moduleName(moduleName) {
std::cout << "Renaming module " << module.moduleName << " to " << moduleName << " with " << renaming.size() << " renamings:" << std::endl;
for (auto it: renaming) {
std::cout << "\t" << it.first << " -> " << it.second << std::endl;
}
this->booleanVariables.reserve(module.booleanVariables.size());
for (BooleanVariable it: module.booleanVariables) {
if (renaming.count(it.getName()) > 0) {
this->booleanVariables.emplace_back(it, renaming.at(it.getName()));
//this->booleanVariablesToIndexMap[renaming.at(it.getName())] = (*boolAdder)(it.getName(), it.getInitialValue());
this->booleanVariablesToIndexMap[renaming.at(it.getName())] = adder.addBooleanVariable(it.getName(), it.getInitialValue());
} else std::cerr << "ERROR: " << moduleName << "." << it.getName() << " was not renamed!" << std::endl;
}
this->integerVariables.reserve(module.integerVariables.size());
for (IntegerVariable it: module.integerVariables) {
if (renaming.count(it.getName()) > 0) {
this->integerVariables.emplace_back(it, renaming.at(it.getName()));
//this->integerVariablesToIndexMap[renaming.at(it.getName())] = (*intAdder)(it.getName(), it.getLowerBound(), it.getUpperBound(), it.getInitialValue());
this->integerVariablesToIndexMap[renaming.at(it.getName())] = adder.addIntegerVariable(it.getName(), it.getLowerBound(), it.getUpperBound(), it.getInitialValue());
} else std::cerr << "ERROR: " << moduleName << "." << it.getName() << " was not renamed!" << std::endl;
}
this->booleanVariables.reserve(module.booleanVariables.size());
for (BooleanVariable it: module.booleanVariables) {
if (renaming.count(it.getName()) > 0) {
this->booleanVariables.emplace_back(it, renaming.at(it.getName()), renaming, this->booleanVariablesToIndexMap, this->integerVariablesToIndexMap);
} else std::cerr << "ERROR: " << moduleName << "." << it.getName() << " was not renamed!" << std::endl;
}
this->integerVariables.reserve(module.integerVariables.size());
for (IntegerVariable it: module.integerVariables) {
if (renaming.count(it.getName()) > 0) {
this->integerVariables.emplace_back(it, renaming.at(it.getName()), renaming, this->booleanVariablesToIndexMap, this->integerVariablesToIndexMap);
} else std::cerr << "ERROR: " << moduleName << "." << it.getName() << " was not renamed!" << std::endl;
}
this->commands.reserve(module.commands.size());
for (Command cmd: module.commands) {

6
src/ir/Variable.cpp

@ -9,6 +9,7 @@
#include <sstream>
#include <map>
#include <iostream>
namespace storm {
@ -24,8 +25,9 @@ Variable::Variable(uint_fast64_t index, std::string variableName, std::shared_pt
// Nothing to do here.
}
Variable::Variable(const Variable& var, const std::string& newName) : Variable(var.index, newName, var.initialValue) {
// Nothing to do here
Variable::Variable(const Variable& var, const std::string& newName, const std::map<std::string, std::string>& renaming, const std::map<std::string,uint_fast64_t>& bools, const std::map<std::string,uint_fast64_t>& ints)
: Variable(var.index, newName, var.initialValue->clone(renaming, bools, ints)) {
std::cout << "Cloning Variable " << var.variableName << " to " << newName << std::endl;
}
// Return the name of the variable.

2
src/ir/Variable.h

@ -40,7 +40,7 @@ public:
* @param var Variable to copy.
* @param newName New name of this variable.
*/
Variable(const Variable& var, const std::string& newName);
Variable(const Variable& var, const std::string& newName, const std::map<std::string, std::string>& renaming, const std::map<std::string,uint_fast64_t>& bools, const std::map<std::string,uint_fast64_t>& ints);
/*!
* Retrieves the name of the variable.

2
src/ir/expressions/BinaryRelationExpression.h

@ -9,6 +9,7 @@
#define BINARYRELATIONEXPRESSION_H_
#include "src/ir/expressions/BinaryExpression.h"
#include <iostream>
namespace storm {
@ -29,6 +30,7 @@ public:
}
virtual std::shared_ptr<BaseExpression> clone(const std::map<std::string, std::string>& renaming, const std::map<std::string, uint_fast64_t>& bools, const std::map<std::string, uint_fast64_t>& ints) {
std::cout << "Cloning " << this->getLeft()->toString() << " ~ " << this->getRight()->toString() << std::endl;
return std::shared_ptr<BaseExpression>(new BinaryRelationExpression(this->getLeft()->clone(renaming, bools, ints), this->getRight()->clone(renaming, bools, ints), this->relationType));
}

1
src/ir/expressions/VariableExpression.h

@ -34,6 +34,7 @@ public:
}
virtual std::shared_ptr<BaseExpression> clone(const std::map<std::string, std::string>& renaming, const std::map<std::string, uint_fast64_t>& bools, const std::map<std::string, uint_fast64_t>& ints) {
std::cout << "Cloning VarExpr " << this->variableName << std::endl;
if (renaming.count(this->variableName) > 0) {
std::string newName = renaming.at(this->variableName);
if (this->getType() == bool_) {

21
src/parser/PrismParser.cpp

@ -222,9 +222,9 @@ struct PrismParser::PrismGrammar : qi::grammar<Iterator, Program(), qi::locals<s
variableDefinition.name("variable declaration");
// This block defines all entities that are needed for parsing a module.
moduleDefinition = (qi::lit("module")
moduleDefinition = (qi::lit("module") >> freeIdentifierName
[phoenix::clear(phoenix::ref(localBooleanVariables_)), phoenix::clear(phoenix::ref(localIntegerVariables_))]
>> freeIdentifierName >> *(variableDefinition(qi::_a, qi::_b, qi::_c, qi::_d)) > +commandDefinition > qi::lit("endmodule"))
>> *(variableDefinition(qi::_a, qi::_b, qi::_c, qi::_d)) >> +commandDefinition > qi::lit("endmodule"))
[
phoenix::bind(moduleNames_.add, qi::_1, qi::_1),
qi::_val = phoenix::construct<Module>(qi::_1, qi::_a, qi::_b, qi::_c, qi::_d, qi::_2),
@ -233,18 +233,18 @@ struct PrismParser::PrismGrammar : qi::grammar<Iterator, Program(), qi::locals<s
Module const * (qi::symbols<char, Module>::*moduleFinder)(const std::string&) const = &qi::symbols<char, Module>::find;
moduleDefinition.name("module");
moduleRenaming = (qi::lit("module")
[phoenix::clear(phoenix::ref(localRenamings_))]
>> freeIdentifierName >> qi::lit("=") > moduleNames_ > qi::lit("[") > *(
(identifierName > qi::lit("=") > identifierName)[phoenix::insert(phoenix::ref(localRenamings_), phoenix::construct<std::pair<std::string,std::string>>(qi::_1, qi::_2))]
moduleRenaming = (qi::lit("module") >> freeIdentifierName >> qi::lit("=")
> moduleNames_ > qi::lit("[") > *(
(identifierName > qi::lit("=") > identifierName >> -qi::lit(","))[phoenix::insert(qi::_a, phoenix::construct<std::pair<std::string,std::string>>(qi::_1, qi::_2))]
) > qi::lit("]") > qi::lit("endmodule"))
[
phoenix::bind(moduleNames_.add, qi::_1, qi::_1),
qi::_val = phoenix::construct<Module>(*phoenix::bind(moduleFinder, moduleMap_, qi::_2), qi::_1, localRenamings_, VariableAdder(this)),
qi::_val = phoenix::construct<Module>(*phoenix::bind(moduleFinder, moduleMap_, qi::_2), qi::_1, qi::_a, VariableAdder(this)),
phoenix::bind(moduleMap_.add, qi::_1, qi::_val)
];
moduleDefinitionList %= +moduleDefinition;
moduleRenaming.name("renamed module");
moduleDefinitionList %= +(moduleDefinition | moduleRenaming);
moduleDefinitionList.name("module list");
// This block defines all entities that are needed for parsing constant definitions.
@ -357,7 +357,7 @@ struct PrismParser::PrismGrammar : qi::grammar<Iterator, Program(), qi::locals<s
// Rules for module definition.
qi::rule<Iterator, Module(), qi::locals<std::vector<BooleanVariable>, std::vector<IntegerVariable>, std::map<std::string, uint_fast64_t>, std::map<std::string, uint_fast64_t>>, Skipper> moduleDefinition;
qi::rule<Iterator, Module(), qi::locals<std::vector<BooleanVariable>, std::vector<IntegerVariable>, std::map<std::string, uint_fast64_t>, std::map<std::string, uint_fast64_t>>, Skipper> moduleRenaming;
qi::rule<Iterator, Module(), qi::locals<std::map<std::string, std::string>>, Skipper> moduleRenaming;
// Rules for variable definitions.
qi::rule<Iterator, qi::unused_type(std::vector<BooleanVariable>&, std::vector<IntegerVariable>&, std::map<std::string, uint_fast64_t>&, std::map<std::string, uint_fast64_t>&), Skipper> variableDefinition;
@ -512,8 +512,6 @@ struct PrismParser::PrismGrammar : qi::grammar<Iterator, Program(), qi::locals<s
struct qi::symbols<char, std::shared_ptr<BaseExpression>> integerConstants_, booleanConstants_, doubleConstants_;
struct qi::symbols<char, Module> moduleMap_;
std::map<std::string, std::string> localRenamings_;
// A structure representing the identity function over identifier names.
struct variableNamesStruct : qi::symbols<char, std::string> { } integerVariableNames_, booleanVariableNames_, commandNames_, labelNames_, allConstantNames_, moduleNames_,
localBooleanVariables_, localIntegerVariables_, assignedLocalBooleanVariables_, assignedLocalIntegerVariables_;
@ -575,6 +573,7 @@ std::shared_ptr<storm::ir::Program> PrismParser::parse(std::istream& inputStream
result = std::shared_ptr<storm::ir::Program>(new storm::ir::Program());
// 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;
} catch(const qi::expectation_failure<PositionIteratorType>& e) {
// If the parser expected content different than the one provided, display information
// about the location of the error.

Loading…
Cancel
Save