Browse Source

Fixed renaming: Command names were not considered.

tempestpy_adaptions
gereon 12 years ago
parent
commit
ac86932785
  1. 11
      src/ir/Module.cpp
  2. 5
      src/ir/Module.h
  3. 7
      src/parser/PrismParser.cpp
  4. 4
      src/parser/PrismParser/PrismGrammar.cpp
  5. 33
      src/parser/PrismParser/VariableState.cpp
  6. 6
      src/parser/PrismParser/VariableState.h

11
src/ir/Module.cpp

@ -44,16 +44,7 @@ Module::Module(const Module& module, const std::string& moduleName, const std::m
LOG4CPLUS_DEBUG(logger, "Start renaming " << module.moduleName << " to " << moduleName);
// First step: Create new Variables via the adder.
for (BooleanVariable it: module.booleanVariables) {
if (renaming.count(it.getName()) > 0) {
adder->addBooleanVariable(renaming.at(it.getName()), it.getInitialValue());
} else LOG4CPLUS_ERROR(logger, moduleName << "." << it.getName() << " was not renamed!");
}
for (IntegerVariable it: module.integerVariables) {
if (renaming.count(it.getName()) > 0) {
adder->addIntegerVariable(renaming.at(it.getName()), it.getLowerBound(), it.getUpperBound(), it.getInitialValue());
} else LOG4CPLUS_ERROR(logger, moduleName << "." << it.getName() << " was not renamed!");
}
adder->performRenaming(renaming);
// Second step: Get all indices of variables that are produced by the renaming.
for (auto it: renaming) {

5
src/ir/Module.h

@ -24,9 +24,10 @@ namespace storm {
namespace ir {
struct VariableAdder {
virtual uint_fast64_t addIntegerVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> lower, const std::shared_ptr<storm::ir::expressions::BaseExpression> upper, const std::shared_ptr<storm::ir::expressions::BaseExpression> init) = 0;
virtual uint_fast64_t addBooleanVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> init) = 0;
virtual uint_fast64_t addIntegerVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> lower, const std::shared_ptr<storm::ir::expressions::BaseExpression> upper) = 0;
virtual uint_fast64_t addBooleanVariable(const std::string& name) = 0;
virtual std::shared_ptr<expressions::VariableExpression> getVariable(const std::string& name) = 0;
virtual void performRenaming(const std::map<std::string, std::string>& renaming) = 0;
};
/*!

7
src/parser/PrismParser.cpp

@ -42,7 +42,6 @@ storm::ir::Program PrismParser::parseFile(std::string const& filename) const {
try {
result = parse(inputFileStream, filename);
} catch(std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
// In case of an exception properly close the file before passing exception.
inputFileStream.close();
throw e;
@ -91,9 +90,6 @@ storm::ir::Program PrismParser::parse(std::istream& inputStream, std::string con
// Reset grammars.
grammar.resetGrammars();
} catch(const qi::expectation_failure<PositionIteratorType>& e) {
// Reset grammars in any case.
grammar.resetGrammars();
// If the parser expected content different than the one provided, display information
// about the location of the error.
const boost::spirit::classic::file_position_base<std::string>& pos = e.first.get_position();
@ -118,6 +114,9 @@ storm::ir::Program PrismParser::parse(std::istream& inputStream, std::string con
std::cerr << msg.str();
// Reset grammars in any case.
grammar.resetGrammars();
// Now propagate exception.
throw storm::exceptions::WrongFileFormatException() << msg.str();
}

4
src/parser/PrismParser/PrismGrammar.cpp

@ -84,14 +84,14 @@ Module PrismGrammar::createModule(const std::string name, std::vector<BooleanVar
void PrismGrammar::createIntegerVariable(const std::string name, std::shared_ptr<BaseExpression> lower, std::shared_ptr<BaseExpression> upper, std::shared_ptr<BaseExpression> init, std::vector<IntegerVariable>& vars, std::map<std::string, uint_fast64_t>& varids) {
//std::cout << "Creating int " << name << " = " << init << std::endl;
uint_fast64_t id = this->state->addIntegerVariable(name, lower, upper, init);
uint_fast64_t id = this->state->addIntegerVariable(name, lower, upper);
vars.emplace_back(id, name, lower, upper, init);
varids[name] = id;
this->state->localIntegerVariables_.add(name, name);
}
void PrismGrammar::createBooleanVariable(const std::string name, std::shared_ptr<BaseExpression> init, std::vector<BooleanVariable>& vars, std::map<std::string, uint_fast64_t>& varids) {
//std::cout << "Creating bool " << name << std::endl;
uint_fast64_t id = this->state->addBooleanVariable(name, init);
uint_fast64_t id = this->state->addBooleanVariable(name);
vars.emplace_back(id, name, init);
varids[name] = id;
this->state->localBooleanVariables_.add(name, name);

33
src/parser/PrismParser/VariableState.cpp

@ -23,13 +23,18 @@ std::ostream& operator<<(std::ostream& out, qi::symbols<char, T>& symbols) {
symbols.for_each(dump);
return out;
}
std::ostream& operator<<(std::ostream& out, VariableState::variableNamesStruct& symbols) {
SymbolDump<std::string> dump(out);
symbols.for_each(dump);
return out;
}
VariableState::VariableState(bool firstRun)
: firstRun(firstRun), keywords(), nextBooleanVariableIndex(0), nextIntegerVariableIndex(0) {
}
uint_fast64_t VariableState::addBooleanVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> init) {
uint_fast64_t VariableState::addBooleanVariable(const std::string& name) {
if (firstRun) {
std::shared_ptr<VariableExpression> varExpr = std::shared_ptr<VariableExpression>(new VariableExpression(storm::ir::expressions::BaseExpression::bool_, this->nextBooleanVariableIndex, name));
LOG4CPLUS_DEBUG(logger, "Adding boolean variable " << name << " with new id " << this->nextBooleanVariableIndex);
@ -48,7 +53,7 @@ uint_fast64_t VariableState::addBooleanVariable(const std::string& name, const s
}
}
uint_fast64_t VariableState::addIntegerVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> lower, const std::shared_ptr<storm::ir::expressions::BaseExpression> upper, const std::shared_ptr<storm::ir::expressions::BaseExpression> init) {
uint_fast64_t VariableState::addIntegerVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> lower, const std::shared_ptr<storm::ir::expressions::BaseExpression> upper) {
if (firstRun) {
std::shared_ptr<VariableExpression> varExpr = std::shared_ptr<VariableExpression>(new VariableExpression(storm::ir::expressions::BaseExpression::int_, this->nextIntegerVariableIndex, name, lower, upper));
LOG4CPLUS_DEBUG(logger, "Adding integer variable " << name << " with new id " << this->nextIntegerVariableIndex);
@ -106,12 +111,34 @@ std::shared_ptr<VariableExpression> VariableState::getVariable(const std::string
if (res != nullptr) {
return *res;
} else {
LOG4CPLUS_ERROR(logger, "Getting variable " << name << ", but was not found. This variable does not exist.");
return std::shared_ptr<VariableExpression>(nullptr);
}
}
}
void VariableState::performRenaming(const std::map<std::string, std::string>& renaming) {
for (auto it: renaming) {
std::shared_ptr<VariableExpression>* original = this->integerVariables_.find(it.first);
if (original != nullptr) {
std::shared_ptr<VariableExpression>* next = this->integerVariables_.find(it.second);
if (next == nullptr) {
this->addIntegerVariable(it.second, (*original)->getLowerBound(), (*original)->getUpperBound());
}
}
original = this->booleanVariables_.find(it.first);
if (original != nullptr) {
if (this->booleanVariables_.find(it.second) == nullptr) {
this->addBooleanVariable(it.second);
}
}
std::string* oldCmdName = this->commandNames_.find(it.first);
if (oldCmdName != nullptr) {
LOG4CPLUS_DEBUG(logger, "Adding new command name " << it.second << " due to module renaming.");
this->commandNames_.at(it.second) = it.second;
}
}
}
void VariableState::startModule() {
this->localBooleanVariables_.clear();
this->localIntegerVariables_.clear();

6
src/parser/PrismParser/VariableState.h

@ -46,13 +46,15 @@ public:
struct variableNamesStruct : qi::symbols<char, std::string> { } integerVariableNames_, booleanVariableNames_, commandNames_, labelNames_, allConstantNames_, moduleNames_,
localBooleanVariables_, localIntegerVariables_, assignedLocalBooleanVariables_, assignedLocalIntegerVariables_;
public:
uint_fast64_t addBooleanVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> init);
uint_fast64_t addIntegerVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> lower, const std::shared_ptr<storm::ir::expressions::BaseExpression> upper, const std::shared_ptr<storm::ir::expressions::BaseExpression> init);
uint_fast64_t addBooleanVariable(const std::string& name);
uint_fast64_t addIntegerVariable(const std::string& name, const std::shared_ptr<storm::ir::expressions::BaseExpression> lower, const std::shared_ptr<storm::ir::expressions::BaseExpression> upper);
std::shared_ptr<VariableExpression> getBooleanVariable(const std::string& name);
std::shared_ptr<VariableExpression> getIntegerVariable(const std::string& name);
std::shared_ptr<VariableExpression> getVariable(const std::string& name);
void performRenaming(const std::map<std::string, std::string>& renaming);
void startModule();
bool isFreeIdentifier(std::string& s) const;

Loading…
Cancel
Save