You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.1 KiB

  1. /*
  2. * UnaryBooleanFunctionExpression.h
  3. *
  4. * Created on: 03.01.2013
  5. * Author: chris
  6. */
  7. #ifndef UNARYBOOLEANFUNCTIONEXPRESSION_H_
  8. #define UNARYBOOLEANFUNCTIONEXPRESSION_H_
  9. #include "src/ir/expressions/UnaryExpression.h"
  10. namespace storm {
  11. namespace ir {
  12. namespace expressions {
  13. class UnaryBooleanFunctionExpression : public UnaryExpression {
  14. public:
  15. enum FunctionType {NOT};
  16. UnaryBooleanFunctionExpression(std::shared_ptr<BaseExpression> child, FunctionType functionType) : UnaryExpression(bool_, child), functionType(functionType) {
  17. }
  18. virtual ~UnaryBooleanFunctionExpression() {
  19. }
  20. 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) {
  21. return std::shared_ptr<BaseExpression>(new UnaryBooleanFunctionExpression(this->getChild()->clone(renaming, bools, ints), this->functionType));
  22. }
  23. FunctionType getFunctionType() const {
  24. return functionType;
  25. }
  26. virtual bool getValueAsBool(std::pair<std::vector<bool>, std::vector<int_fast64_t>> const* variableValues) const {
  27. bool resultChild = this->getChild()->getValueAsBool(variableValues);
  28. switch(functionType) {
  29. case NOT: return !resultChild; break;
  30. default: throw storm::exceptions::ExpressionEvaluationException() << "Cannot evaluate expression: "
  31. << "Unknown boolean unary operator: '" << functionType << "'.";
  32. }
  33. }
  34. virtual void accept(ExpressionVisitor* visitor) {
  35. visitor->visit(this);
  36. }
  37. virtual std::string toString() const {
  38. std::string result = "";
  39. switch (functionType) {
  40. case NOT: result += "!"; break;
  41. }
  42. result += "(" + this->getChild()->toString() + ")";
  43. return result;
  44. }
  45. virtual std::string dump(std::string prefix) const {
  46. std::stringstream result;
  47. result << prefix << "UnaryBooleanFunctionExpression" << std::endl;
  48. switch (functionType) {
  49. case NOT: result << prefix << "!" << std::endl; break;
  50. }
  51. result << this->getChild()->dump(prefix + "\t");
  52. return result.str();
  53. }
  54. private:
  55. FunctionType functionType;
  56. };
  57. }
  58. }
  59. }
  60. #endif /* UNARYBOOLEANFUNCTIONEXPRESSION_H_ */