Browse Source
Refactored some parts of expressions. In particular, visitors now can return anything they want by using boost::any.
Refactored some parts of expressions. In particular, visitors now can return anything they want by using boost::any.
Former-commit-id: 0f6af138ae
main
38 changed files with 404 additions and 878 deletions
-
199src/adapters/MathsatExpressionAdapter.h
-
210src/adapters/Z3ExpressionAdapter.h
-
2src/storage/expressions/BaseExpression.h
-
4src/storage/expressions/BinaryBooleanFunctionExpression.cpp
-
2src/storage/expressions/BinaryBooleanFunctionExpression.h
-
4src/storage/expressions/BinaryNumericalFunctionExpression.cpp
-
2src/storage/expressions/BinaryNumericalFunctionExpression.h
-
4src/storage/expressions/BinaryRelationExpression.cpp
-
2src/storage/expressions/BinaryRelationExpression.h
-
4src/storage/expressions/BooleanLiteralExpression.cpp
-
2src/storage/expressions/BooleanLiteralExpression.h
-
4src/storage/expressions/DoubleLiteralExpression.cpp
-
2src/storage/expressions/DoubleLiteralExpression.h
-
24src/storage/expressions/Expression.cpp
-
18src/storage/expressions/Expression.h
-
22src/storage/expressions/ExpressionVisitor.h
-
120src/storage/expressions/IdentifierSubstitutionVisitor.cpp
-
23src/storage/expressions/IdentifierSubstitutionVisitor.h
-
4src/storage/expressions/IfThenElseExpression.cpp
-
2src/storage/expressions/IfThenElseExpression.h
-
4src/storage/expressions/IntegerLiteralExpression.cpp
-
2src/storage/expressions/IntegerLiteralExpression.h
-
83src/storage/expressions/LinearCoefficientVisitor.cpp
-
23src/storage/expressions/LinearCoefficientVisitor.h
-
106src/storage/expressions/LinearityCheckVisitor.cpp
-
23src/storage/expressions/LinearityCheckVisitor.h
-
120src/storage/expressions/SubstitutionVisitor.cpp
-
23src/storage/expressions/SubstitutionVisitor.h
-
80src/storage/expressions/TypeCheckVisitor.cpp
-
47src/storage/expressions/TypeCheckVisitor.h
-
4src/storage/expressions/UnaryBooleanFunctionExpression.cpp
-
2src/storage/expressions/UnaryBooleanFunctionExpression.h
-
4src/storage/expressions/UnaryNumericalFunctionExpression.cpp
-
2src/storage/expressions/UnaryNumericalFunctionExpression.h
-
4src/storage/expressions/VariableExpression.cpp
-
2src/storage/expressions/VariableExpression.h
-
98src/storage/prism/Program.cpp
-
1test/functional/solver/GlpkLpSolverTest.cpp
@ -1,80 +0,0 @@ |
|||
#include "src/storage/expressions/TypeCheckVisitor.h"
|
|||
#include "src/storage/expressions/Expressions.h"
|
|||
|
|||
#include "src/utility/macros.h"
|
|||
#include "src/exceptions/InvalidTypeException.h"
|
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
template<typename MapType> |
|||
TypeCheckVisitor<MapType>::TypeCheckVisitor(MapType const& identifierToTypeMap) : identifierToTypeMap(identifierToTypeMap) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::check(Expression const& expression) { |
|||
expression.getBaseExpression().accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(IfThenElseExpression const* expression) { |
|||
expression->getCondition()->accept(this); |
|||
expression->getThenExpression()->accept(this); |
|||
expression->getElseExpression()->accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(BinaryBooleanFunctionExpression const* expression) { |
|||
expression->getFirstOperand()->accept(this); |
|||
expression->getSecondOperand()->accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(BinaryNumericalFunctionExpression const* expression) { |
|||
expression->getFirstOperand()->accept(this); |
|||
expression->getSecondOperand()->accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(BinaryRelationExpression const* expression) { |
|||
expression->getFirstOperand()->accept(this); |
|||
expression->getSecondOperand()->accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(VariableExpression const* expression) { |
|||
auto identifierTypePair = this->identifierToTypeMap.find(expression->getVariableName()); |
|||
STORM_LOG_THROW(identifierTypePair != this->identifierToTypeMap.end(), storm::exceptions::InvalidArgumentException, "No type available for identifier '" << expression->getVariableName() << "'."); |
|||
STORM_LOG_THROW(identifierTypePair->second == expression->getReturnType(), storm::exceptions::InvalidTypeException, "Type mismatch for variable '" << expression->getVariableName() << "': expected '" << identifierTypePair->first << "', but found '" << expression->getReturnType() << "'."); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(UnaryBooleanFunctionExpression const* expression) { |
|||
expression->getOperand()->accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(UnaryNumericalFunctionExpression const* expression) { |
|||
expression->getOperand()->accept(this); |
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(BooleanLiteralExpression const* expression) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(IntegerLiteralExpression const* expression) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
template<typename MapType> |
|||
void TypeCheckVisitor<MapType>::visit(DoubleLiteralExpression const* expression) { |
|||
// Intentionally left empty.
|
|||
} |
|||
|
|||
// Explicitly instantiate the class with map and unordered_map.
|
|||
template class TypeCheckVisitor<std::map<std::string, ExpressionReturnType>>; |
|||
template class TypeCheckVisitor<std::unordered_map<std::string, ExpressionReturnType>>; |
|||
} |
|||
} |
@ -1,47 +0,0 @@ |
|||
#ifndef STORM_STORAGE_EXPRESSIONS_TYPECHECKVISITOR_H_ |
|||
#define STORM_STORAGE_EXPRESSIONS_TYPECHECKVISITOR_H_ |
|||
|
|||
#include <stack> |
|||
|
|||
#include "src/storage/expressions/Expression.h" |
|||
#include "src/storage/expressions/ExpressionVisitor.h" |
|||
|
|||
namespace storm { |
|||
namespace expressions { |
|||
template<typename MapType> |
|||
class TypeCheckVisitor : public ExpressionVisitor { |
|||
public: |
|||
/*! |
|||
* Creates a new type check visitor that uses the given map to check the types of variables and constants. |
|||
* |
|||
* @param identifierToTypeMap A mapping from identifiers to expressions. |
|||
*/ |
|||
TypeCheckVisitor(MapType const& identifierToTypeMap); |
|||
|
|||
/*! |
|||
* Checks that the types of the identifiers in the given expression match the ones in the previously given |
|||
* map. |
|||
* |
|||
* @param expression The expression in which to check the types. |
|||
*/ |
|||
void check(Expression const& expression); |
|||
|
|||
virtual void visit(IfThenElseExpression const* expression) override; |
|||
virtual void visit(BinaryBooleanFunctionExpression const* expression) override; |
|||
virtual void visit(BinaryNumericalFunctionExpression const* expression) override; |
|||
virtual void visit(BinaryRelationExpression const* expression) override; |
|||
virtual void visit(VariableExpression const* expression) override; |
|||
virtual void visit(UnaryBooleanFunctionExpression const* expression) override; |
|||
virtual void visit(UnaryNumericalFunctionExpression const* expression) override; |
|||
virtual void visit(BooleanLiteralExpression const* expression) override; |
|||
virtual void visit(IntegerLiteralExpression const* expression) override; |
|||
virtual void visit(DoubleLiteralExpression const* expression) override; |
|||
|
|||
private: |
|||
// A mapping of identifier names to expressions with which they shall be replaced. |
|||
MapType const& identifierToTypeMap; |
|||
}; |
|||
} |
|||
} |
|||
|
|||
#endif /* STORM_STORAGE_EXPRESSIONS_TYPECHECKVISITOR_H_ */ |
Write
Preview
Loading…
Cancel
Save
Reference in new issue