LCOV - code coverage report
Current view: top level - pbes/include/mcrl2/pbes/rewriters - data_rewriter.h (source / functions) Hit Total Coverage
Test: mcrl2_coverage.info.cleaned Lines: 31 31 100.0 %
Date: 2019-06-26 00:32:26 Functions: 59 69 85.5 %
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/data_rewriter.h
      10             : /// \brief add your file description here.
      11             : 
      12             : #ifndef MCRL2_PBES_REWRITERS_DATA_REWRITER_H
      13             : #define MCRL2_PBES_REWRITERS_DATA_REWRITER_H
      14             : 
      15             : #include "mcrl2/data/substitutions/no_substitution.h"
      16             : #include "mcrl2/pbes/builder.h"
      17             : 
      18             : namespace mcrl2 {
      19             : 
      20             : namespace pbes_system {
      21             : 
      22             : namespace detail {
      23             : 
      24             : template <typename DataRewriter, typename SubstitutionFunction>
      25      117560 : data::data_expression data_rewrite(const data::data_expression& x, const DataRewriter& R, SubstitutionFunction& sigma)
      26             : {
      27      117560 :   mCRL2log(log::debug2) << "data_rewrite " << x << sigma << " -> " << R(x, sigma) << std::endl;
      28      117560 :   return R(x, sigma);
      29             : }
      30             : 
      31             : template <typename DataRewriter>
      32       13635 : data::data_expression data_rewrite(const data::data_expression& x, const DataRewriter& R, data::no_substitution&)
      33             : {
      34       13635 :   mCRL2log(log::debug2) << "data_rewrite " << x << "[]" << " -> " << R(x) << std::endl;
      35       13635 :   return R(x);
      36             : }
      37             : 
      38             : template <template <class> class Builder, class Derived, class DataRewriter, class SubstitutionFunction = data::no_substitution>
      39             : struct add_data_rewriter: public Builder<Derived>
      40             : {
      41             :   typedef Builder<Derived> super;
      42             :   using super::apply;
      43             : 
      44             :   const DataRewriter& R;
      45             :   SubstitutionFunction& sigma;
      46             : 
      47        6740 :   add_data_rewriter(const DataRewriter& R_, SubstitutionFunction& sigma_)
      48        6740 :     : R(R_), sigma(sigma_)
      49        6740 :   {}
      50             : 
      51       31144 :   pbes_expression apply(const data::data_expression& x)
      52             :   {
      53       31144 :     return data_rewrite(x, R, sigma);
      54             :   }
      55             : 
      56       12179 :   pbes_expression apply(const propositional_variable_instantiation& x)
      57             :   {
      58       24358 :     std::vector<data::data_expression> d;
      59      112230 :     for (const data::data_expression& e: x.parameters())
      60             :     {
      61      100051 :       d.push_back(data_rewrite(e, R, sigma));
      62             :     }
      63       24358 :     return propositional_variable_instantiation(x.name(), data::data_expression_list(d.begin(), d.end()));
      64             :   }
      65             : };
      66             : 
      67             : template <typename Derived, typename DataRewriter, typename SubstitutionFunction>
      68             : struct data_rewriter_builder: public add_data_rewriter<pbes_system::pbes_expression_builder, Derived, DataRewriter, SubstitutionFunction>
      69             : {
      70             :   typedef add_data_rewriter<pbes_system::pbes_expression_builder, Derived, DataRewriter, SubstitutionFunction> super;
      71             :   using super::enter;
      72             :   using super::leave;
      73             : 
      74         139 :   data_rewriter_builder(const DataRewriter& R, SubstitutionFunction& sigma)
      75         139 :     : super(R, sigma)
      76         139 :   {}
      77             : };
      78             : 
      79             : template <template <class, class, class> class Builder, class DataRewriter, class SubstitutionFunction>
      80             : struct apply_rewriter_builder: public Builder<apply_rewriter_builder<Builder, DataRewriter, SubstitutionFunction>, DataRewriter, SubstitutionFunction>
      81             : {
      82             :   typedef Builder<apply_rewriter_builder<Builder, DataRewriter, SubstitutionFunction>, DataRewriter, SubstitutionFunction> super;
      83             :   using super::enter;
      84             :   using super::leave;
      85             : 
      86         932 :   apply_rewriter_builder(const DataRewriter& datar, SubstitutionFunction& sigma)
      87         932 :     : super(datar, sigma)
      88         932 :   {}
      89             : };
      90             : 
      91             : template <template <class, class, class> class Builder, class DataRewriter, class SubstitutionFunction>
      92             : apply_rewriter_builder<Builder, DataRewriter, SubstitutionFunction>
      93         932 : make_apply_rewriter_builder(const DataRewriter& datar, SubstitutionFunction& sigma)
      94             : {
      95         932 :   return apply_rewriter_builder<Builder, DataRewriter, SubstitutionFunction>(datar, sigma);
      96             : }
      97             : 
      98             : } // namespace detail
      99             : 
     100             : /// \brief A rewriter that applies a data rewriter to data expressions in a term.
     101             : template <typename DataRewriter>
     102             : struct data_rewriter
     103             : {
     104             :   typedef pbes_expression term_type;
     105             :   typedef data::variable variable_type;
     106             : 
     107             :   const DataRewriter& R;
     108             : 
     109          15 :   data_rewriter(const DataRewriter& R_)
     110          15 :     : R(R_)
     111          15 :   {}
     112             : 
     113          85 :   pbes_expression operator()(const pbes_expression& x) const
     114             :   {
     115             :     data::no_substitution sigma;
     116          85 :     return detail::make_apply_rewriter_builder<detail::data_rewriter_builder>(R, sigma).apply(x);
     117             :   }
     118             : 
     119             :   template <typename SubstitutionFunction>
     120          14 :   pbes_expression operator()(const pbes_expression& x, SubstitutionFunction& sigma) const
     121             :   {
     122          14 :     return detail::make_apply_rewriter_builder<detail::data_rewriter_builder>(R, sigma).apply(x);
     123             :   }
     124             : };
     125             : 
     126             : } // namespace pbes_system
     127             : 
     128             : } // namespace mcrl2
     129             : 
     130             : #endif // MCRL2_PBES_REWRITERS_DATA_REWRITER_H

Generated by: LCOV version 1.12