LCOV - code coverage report
Current view: top level - bes/include/mcrl2/bes - simplify_rewriter.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 12 22 54.5 %
Date: 2020-10-20 00:45:57 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // Author(s): Wieger Wesselink
       2             : // Copyright: see the accompanying file COPYING or copy at
       3             : // https://github.com/mCRL2org/mCRL2/blob/master/COPYING
       4             : //
       5             : // Distributed under the Boost Software License, Version 1.0.
       6             : // (See accompanying file LICENSE_1_0.txt or copy at
       7             : // http://www.boost.org/LICENSE_1_0.txt)
       8             : //
       9             : /// \file mcrl2/pbes/rewriters/simplify_rewriter.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_BES_SIMPLIFY_REWRITER_H
      13             : #define MCRL2_BES_SIMPLIFY_REWRITER_H
      14             : 
      15             : #include "mcrl2/bes/builder.h"
      16             : #include "mcrl2/data/optimized_boolean_operators.h"
      17             : 
      18             : namespace mcrl2 {
      19             : 
      20             : namespace bes {
      21             : 
      22             : namespace detail {
      23             : 
      24             : template <template <class> class Builder, class Derived>
      25             : struct add_simplify: public Builder<Derived>
      26             : {
      27             :   typedef Builder<Derived> super;
      28             :   using super::apply;
      29             : 
      30           0 :   boolean_expression apply(const not_& x)
      31             :   {
      32           0 :     return data::optimized_not(apply(x.operand()));
      33             :   }
      34             : 
      35           1 :   boolean_expression apply(const and_& x)
      36             :   {
      37           2 :     auto left = apply(x.left());
      38           1 :     if (is_false(left))
      39             :     {
      40           0 :       return false_();
      41             :     }
      42           2 :     auto right = apply(x.right());
      43           1 :     return data::optimized_and(left, right);
      44             :   }
      45             : 
      46           3 :   boolean_expression apply(const or_& x)
      47             :   {
      48           6 :     auto left = apply(x.left());
      49           3 :     if (is_true(left))
      50             :     {
      51           0 :       return true_();
      52             :     }
      53           6 :     auto right = apply(x.right());
      54           3 :     return data::optimized_or(left, right);
      55             :   }
      56             : 
      57           0 :   boolean_expression apply(const imp& x)
      58             :   {
      59           0 :     auto left = apply(x.left());
      60           0 :     if (is_false(left))
      61             :     {
      62           0 :       return true_();
      63             :     }
      64           0 :     auto right = apply(x.right());
      65           0 :     return data::optimized_imp(left, right);
      66             :   }
      67             : };
      68             : 
      69             : template <typename Derived>
      70             : struct simplify_builder: public add_simplify<bes::boolean_expression_builder, Derived>
      71             : { };
      72             : 
      73             : } // namespace detail
      74             : 
      75             : /// \brief A rewriter that simplifies boolean expressions in a term.
      76             : struct simplify_rewriter
      77             : {
      78             :   typedef boolean_expression term_type;
      79             :   typedef boolean_variable variable_type;
      80             : 
      81          13 :   boolean_expression operator()(const boolean_expression& x) const
      82             :   {
      83          13 :     return core::make_apply_builder<detail::simplify_builder>().apply(x);
      84             :   }
      85             : };
      86             : 
      87             : } // namespace bes
      88             : 
      89             : } // namespace mcrl2
      90             : 
      91             : #endif // MCRL2_BES_SIMPLIFY_REWRITER_H

Generated by: LCOV version 1.13