Browse Source
more work on jit-based model builder
more work on jit-based model builder
Former-commit-id:main150ac22d6b
[formerly85061a73c7
] Former-commit-id:cd18eec45b
11 changed files with 1067 additions and 80 deletions
-
735src/builder/ExplicitJitJaniModelBuilder.cpp
-
41src/builder/ExplicitJitJaniModelBuilder.h
-
8src/builder/JitModelBuilderInterface.h
-
3src/cli/entrypoints.h
-
6src/settings/modules/IOSettings.cpp
-
8src/settings/modules/IOSettings.h
-
7src/storage/SparseMatrix.h
-
2src/storage/bisimulation/BisimulationDecomposition.h
-
268src/storage/expressions/ToCppVisitor.cpp
-
46src/storage/expressions/ToCppVisitor.h
-
23src/utility/storm.h
@ -0,0 +1,268 @@ |
|||||
|
#include "src/storage/expressions/ToCppVisitor.h"
|
||||
|
|
||||
|
#include "src/storage/expressions/Expressions.h"
|
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
|
||||
|
ToCppTranslationOptions::ToCppTranslationOptions(std::string const& prefix, std::string const& valueTypeCast) : valueTypeCast(valueTypeCast), prefix(prefix) { |
||||
|
// Intentionally left empty.
|
||||
|
} |
||||
|
|
||||
|
std::string const& ToCppTranslationOptions::getPrefix() const { |
||||
|
return prefix; |
||||
|
} |
||||
|
|
||||
|
bool ToCppTranslationOptions::hasValueTypeCast() const { |
||||
|
return !valueTypeCast.empty(); |
||||
|
} |
||||
|
|
||||
|
std::string const& ToCppTranslationOptions::getValueTypeCast() const { |
||||
|
return valueTypeCast; |
||||
|
} |
||||
|
|
||||
|
void ToCppTranslationOptions::clearValueTypeCast() { |
||||
|
valueTypeCast = ""; |
||||
|
} |
||||
|
|
||||
|
std::string ToCppVisitor::translate(storm::expressions::Expression const& expression, ToCppTranslationOptions const& options) { |
||||
|
expression.accept(*this, options); |
||||
|
std::string result = stream.str(); |
||||
|
stream.str(""); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(IfThenElseExpression const& expression, boost::any const& data) { |
||||
|
ToCppTranslationOptions conditionOptions = boost::any_cast<ToCppTranslationOptions>(data); |
||||
|
conditionOptions.clearValueTypeCast(); |
||||
|
stream << "("; |
||||
|
expression.getCondition()->accept(*this, conditionOptions); |
||||
|
stream << " ? "; |
||||
|
expression.getThenExpression()->accept(*this, data); |
||||
|
stream << " : "; |
||||
|
expression.getElseExpression()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(BinaryBooleanFunctionExpression const& expression, boost::any const& data) { |
||||
|
ToCppTranslationOptions newOptions = boost::any_cast<ToCppTranslationOptions>(data); |
||||
|
newOptions.clearValueTypeCast(); |
||||
|
|
||||
|
switch (expression.getOperatorType()) { |
||||
|
case BinaryBooleanFunctionExpression::OperatorType::And: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " && "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryBooleanFunctionExpression::OperatorType::Or: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " || "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryBooleanFunctionExpression::OperatorType::Xor: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " ^ "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryBooleanFunctionExpression::OperatorType::Implies: |
||||
|
stream << "(!"; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " || "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryBooleanFunctionExpression::OperatorType::Iff: |
||||
|
stream << "!("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " ^ "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(BinaryNumericalFunctionExpression const& expression, boost::any const& data) { |
||||
|
switch (expression.getOperatorType()) { |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Plus: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << " + "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Minus: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << " - "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Times: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << " * "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Divide: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << " / "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Min: |
||||
|
stream << "std::min("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << ", "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Max: |
||||
|
stream << "std::max("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << ", "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryNumericalFunctionExpression::OperatorType::Power: |
||||
|
stream << "std::pow("; |
||||
|
expression.getFirstOperand()->accept(*this, data); |
||||
|
stream << ", "; |
||||
|
expression.getSecondOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(BinaryRelationExpression const& expression, boost::any const& data) { |
||||
|
ToCppTranslationOptions newOptions = boost::any_cast<ToCppTranslationOptions>(data); |
||||
|
newOptions.clearValueTypeCast(); |
||||
|
|
||||
|
switch (expression.getRelationType()) { |
||||
|
case BinaryRelationExpression::RelationType::Equal: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " == "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryRelationExpression::RelationType::NotEqual: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " != "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryRelationExpression::RelationType::Less: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " < "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryRelationExpression::RelationType::LessOrEqual: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " <= "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryRelationExpression::RelationType::Greater: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " > "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case BinaryRelationExpression::RelationType::GreaterOrEqual: |
||||
|
stream << "("; |
||||
|
expression.getFirstOperand()->accept(*this, newOptions); |
||||
|
stream << " >= "; |
||||
|
expression.getSecondOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(VariableExpression const& expression, boost::any const& data) { |
||||
|
ToCppTranslationOptions const& options = boost::any_cast<ToCppTranslationOptions const&>(data); |
||||
|
if (options.hasValueTypeCast()) { |
||||
|
stream << "static_cast<" << options.getValueTypeCast() << ">("; |
||||
|
} |
||||
|
stream << options.getPrefix() << expression.getVariableName(); |
||||
|
if (options.hasValueTypeCast()) { |
||||
|
stream << ")"; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(UnaryBooleanFunctionExpression const& expression, boost::any const& data) { |
||||
|
ToCppTranslationOptions newOptions = boost::any_cast<ToCppTranslationOptions>(data); |
||||
|
newOptions.clearValueTypeCast(); |
||||
|
|
||||
|
switch (expression.getOperatorType()) { |
||||
|
case UnaryBooleanFunctionExpression::OperatorType::Not: |
||||
|
stream << "!("; |
||||
|
expression.getOperand()->accept(*this, newOptions); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) { |
||||
|
switch (expression.getOperatorType()) { |
||||
|
case UnaryNumericalFunctionExpression::OperatorType::Minus: |
||||
|
stream << "-("; |
||||
|
expression.getOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case UnaryNumericalFunctionExpression::OperatorType::Floor: |
||||
|
stream << "std::floor("; |
||||
|
expression.getOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
case UnaryNumericalFunctionExpression::OperatorType::Ceil: |
||||
|
stream << "std::ceil("; |
||||
|
expression.getOperand()->accept(*this, data); |
||||
|
stream << ")"; |
||||
|
break; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(BooleanLiteralExpression const& expression, boost::any const& data) { |
||||
|
stream << std::boolalpha << expression.getValue(); |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(IntegerLiteralExpression const& expression, boost::any const& data) { |
||||
|
ToCppTranslationOptions const& options = boost::any_cast<ToCppTranslationOptions const&>(data); |
||||
|
if (options.hasValueTypeCast()) { |
||||
|
stream << "static_cast<" << options.getValueTypeCast() << ">("; |
||||
|
} |
||||
|
stream << expression.getValue(); |
||||
|
if (options.hasValueTypeCast()) { |
||||
|
stream << ")"; |
||||
|
} |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
boost::any ToCppVisitor::visit(RationalLiteralExpression const& expression, boost::any const& data) { |
||||
|
stream << expression.getValueAsDouble(); |
||||
|
return boost::none; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <sstream> |
||||
|
|
||||
|
#include "src/storage/expressions/ExpressionVisitor.h" |
||||
|
|
||||
|
namespace storm { |
||||
|
namespace expressions { |
||||
|
class Expression; |
||||
|
|
||||
|
class ToCppTranslationOptions { |
||||
|
public: |
||||
|
ToCppTranslationOptions(std::string const& prefix = "", std::string const& valueTypeCast = ""); |
||||
|
|
||||
|
std::string const& getPrefix() const; |
||||
|
|
||||
|
bool hasValueTypeCast() const; |
||||
|
std::string const& getValueTypeCast() const; |
||||
|
void clearValueTypeCast(); |
||||
|
|
||||
|
private: |
||||
|
std::string valueTypeCast; |
||||
|
std::string prefix; |
||||
|
}; |
||||
|
|
||||
|
class ToCppVisitor : public ExpressionVisitor { |
||||
|
public: |
||||
|
std::string translate(storm::expressions::Expression const& expression, ToCppTranslationOptions const& options = ToCppTranslationOptions()); |
||||
|
|
||||
|
virtual boost::any visit(IfThenElseExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BinaryBooleanFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BinaryNumericalFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BinaryRelationExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(VariableExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(UnaryBooleanFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(UnaryNumericalFunctionExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(BooleanLiteralExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(IntegerLiteralExpression const& expression, boost::any const& data) override; |
||||
|
virtual boost::any visit(RationalLiteralExpression const& expression, boost::any const& data) override; |
||||
|
|
||||
|
private: |
||||
|
std::stringstream stream; |
||||
|
}; |
||||
|
|
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue