mCRL2
Loading...
Searching...
No Matches
data_rewriter.h
Go to the documentation of this file.
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/data/rewriters/data_rewriter.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_DATA_REWRITERS_DATA_REWRITER_H
13#define MCRL2_DATA_REWRITERS_DATA_REWRITER_H
14
15#include "mcrl2/data/concepts.h"
16#include "mcrl2/data/builder.h"
17#include "mcrl2/data/substitutions/no_substitution.h"
18
19namespace mcrl2::data {
20
21namespace detail {
22
23template <typename DataRewriter, IsSubstitution SubstitutionFunction>
24void data_rewrite(data_expression& result, const data_expression& x, const DataRewriter& R, SubstitutionFunction& sigma)
25{
26 R(result, x, sigma);
27}
28
29template <typename DataRewriter>
30void data_rewrite(data_expression& result, const data_expression& x, const DataRewriter& R, no_substitution&)
31{
32 R(result, x);
33}
34
35/// \brief Applies a data rewriter to data expressions appearing in a term. It works both with and without a substitution.
36template <template <class> class Builder, class Derived, class DataRewriter, IsSubstitution SubstitutionFunction = no_substitution>
37struct add_data_rewriter: public Builder<Derived>
38{
39 using super = Builder<Derived>;
40 using super::enter;
41 using super::leave;
42
43 const DataRewriter& m_R;
44 SubstitutionFunction& m_sigma;
45
46 add_data_rewriter(const DataRewriter& R, SubstitutionFunction& sigma)
47 : m_R(R), m_sigma(sigma)
48 {}
49
51 {
52 data_expression result;
53 data_rewrite(result, x, m_R, m_sigma);
54 return result;
55 }
56
57 template <class T>
58 void apply(T& result, const data_expression& x)
59 {
60 data_rewrite(atermpp::assign_cast<data_expression>(result), x, m_R, m_sigma);
61 }
62
63};
64
65template <typename Derived, typename DataRewriter, IsSubstitution SubstitutionFunction>
67{
69 using super::enter;
70 using super::leave;
71 using super::operator();
72
73 data_rewriter_builder(const DataRewriter& R, SubstitutionFunction& sigma)
74 : super(R, sigma)
75 {}
76};
77
78template <template <class, class, class> class Builder, class DataRewriter, IsSubstitution SubstitutionFunction>
80{
84 using super::enter;
85 using super::leave;
86 using super::operator();
87
88 apply_rewriter_builder(const DataRewriter& datar, SubstitutionFunction& sigma)
89 : super(datar, sigma)
90 {}
91
92#ifdef BOOST_MSVC
93#include "mcrl2/core/detail/builder_msvc.inc.h"
94#endif
95};
96
97template <template <class, class, class> class Builder, class DataRewriter, IsSubstitution SubstitutionFunction>
100{
101 return apply_rewriter_builder<Builder, DataRewriter, SubstitutionFunction>(datar, sigma);
102}
103
104} // namespace detail
105
106/// \brief A rewriter that applies a data rewriter to data expressions in a term.
107template <typename DataRewriter>
109{
110 using term_type = data_expression;
111 using variable_type = data::variable;
112
113 const DataRewriter& R;
114
115 data_rewriter(const DataRewriter& R_)
116 : R(R_)
117 {}
118
120 {
121 data::no_substitution sigma;
122 return detail::make_apply_rewriter_builder<detail::data_rewriter_builder>(R, sigma)(x);
123 }
124
125 template <IsSubstitution SubstitutionFunction>
126 data_expression operator()(const data_expression& x, SubstitutionFunction& sigma) const
127 {
128 return detail::make_apply_rewriter_builder<detail::data_rewriter_builder>(R, sigma)(x);
129 }
130};
131
132} // namespace mcrl2::data
133
134
135
136#endif // MCRL2_DATA_REWRITERS_DATA_REWRITER_H
\brief A data variable
Definition variable.h:25
void data_rewrite(data_expression &result, const data_expression &x, const DataRewriter &R, SubstitutionFunction &sigma)
apply_rewriter_builder< Builder, DataRewriter, SubstitutionFunction > make_apply_rewriter_builder(const DataRewriter &datar, SubstitutionFunction &sigma)
void data_rewrite(data_expression &result, const data_expression &x, const DataRewriter &R, no_substitution &)
A rewriter that applies a data rewriter to data expressions in a term.
data_rewriter(const DataRewriter &R_)
data_expression operator()(const data_expression &x, SubstitutionFunction &sigma) const
const DataRewriter & R
data_expression operator()(const data_expression &x) const
Applies a data rewriter to data expressions appearing in a term. It works both with and without a sub...
data_expression operator()(const data_expression &x)
void apply(T &result, const data_expression &x)
add_data_rewriter(const DataRewriter &R, SubstitutionFunction &sigma)
apply_rewriter_builder(const DataRewriter &datar, SubstitutionFunction &sigma)
data_rewriter_builder(const DataRewriter &R, SubstitutionFunction &sigma)
An empty struct that is used to denote the absence of a substitution. Used for rewriters.