mCRL2
Loading...
Searching...
No Matches
replace_subterm.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/pbes/replace_subterm.h
10/// \brief add your file description here.
11
12#ifndef MCRL2_PBES_REPLACE_SUBTERM_H
13#define MCRL2_PBES_REPLACE_SUBTERM_H
14
15#include "mcrl2/pbes/builder.h"
16#include "mcrl2/pbes/detail/position_count_traverser.h"
17
18namespace mcrl2::pbes_system
19{
20
21namespace detail {
22
24{
26 using super::enter;
27 using super::leave;
28 using super::apply;
29
30 utilities::detail::position_counter counter;
32 std::size_t ypos; // depth
34
35 find_subterm_traverser(std::size_t xpos_, std::size_t ypos_)
36 : xpos(xpos_), ypos(ypos_)
37 {}
38
39 template <typename T>
40 void visit(const T& x)
41 {
42 counter.increase();
43 if (counter.at(xpos, ypos))
44 {
45 result = atermpp::down_cast<pbes_expression>(x);
46 }
47 super::apply(x);
48 counter.decrease();
49 }
50
51 void apply(const and_& x)
52 {
53 visit(x);
54 }
55
56 void apply(const or_& x)
57 {
58 visit(x);
59 }
60
61 void apply(const imp& x)
62 {
63 visit(x);
64 }
65
66 void apply(const exists& x)
67 {
68 visit(x);
69 }
70
71 void apply(const forall& x)
72 {
73 visit(x);
74 }
75
77 {
78 visit(x);
79 }
80
81 void apply(const data::data_expression& x)
82 {
83 visit(x);
84 }
85};
86
88{
90 using super::apply;
91 using super::update;
92
94 std::size_t ypos; // depth
96 bool ready = false;
97 utilities::detail::position_counter counter;
98
99 replace_subterm_builder(std::size_t xpos_, std::size_t ypos_, const pbes_expression& replacement_)
100 : xpos(xpos_), ypos(ypos_), replacement(replacement_)
101 {}
102
103 template <typename T>
105 {
106 counter.increase();
107 bool arrived = counter.at(xpos, ypos);
108 pbes_expression result;
109 if (counter.y > ypos)
110 {
111 result = atermpp::down_cast<pbes_expression>(x);
112 }
113 else if (arrived)
114 {
115 result = replacement;
116 }
117 else
118 {
119 super::apply(result, x);
120 }
121 counter.decrease();
122 return result;
123 }
124
125 template <class T>
126 void apply(T& result, const data::data_expression& x)
127 {
128 result = visit(x);
129 }
130
131 template <class T>
133 {
134 result = visit(x);
135 }
136
137 template <class T>
138 void apply(T& result, const pbes_system::forall& x)
139 {
140 result = visit(x);
141 }
142
143 template <class T>
144 void apply(T& result, const pbes_system::exists& x)
145 {
146 result = visit(x);
147 }
148
149 template <class T>
150 void apply(T& result, const pbes_system::and_& x)
151 {
152 result = visit(x);
153 }
154
155 template <class T>
156 void apply(T& result, const pbes_system::or_& x)
157 {
158 result = visit(x);
159 }
160
161 template <class T>
162 void apply(T& result, const pbes_system::imp& x)
163 {
164 result = visit(x);
165 }
166};
167
168} // namespace detail
169
170/// \brief Replace the subterm at position (x, y) with a given term
171inline
172pbes_expression replace_subterm(const pbes_expression& expr, std::size_t x, std::size_t y, const pbes_expression& replacement)
173{
174 detail::replace_subterm_builder f(x, y, replacement);
175 pbes_expression result;
176 f.apply(result, expr);
177 return result;
178}
179
180/// \brief Replace the subterm at position (x, y) with a given term
181inline
182pbes replace_subterm(const pbes& p, std::size_t x, std::size_t y, const pbes_expression& replacement)
183{
184 pbes result = p;
185 detail::replace_subterm_builder f(x, y, replacement);
186 f.update(result);
187 return result;
188}
189
190inline
191pbes_expression find_subterm(const pbes& pbesspec, std::size_t x, std::size_t y)
192{
194 f.apply(pbesspec);
195 return f.result;
196}
197
198} // namespace mcrl2::pbes_system
199
200#endif // MCRL2_PBES_REPLACE_SUBTERM_H
\brief The and operator for pbes expressions
\brief The existential quantification operator for pbes expressions
\brief The universal quantification operator for pbes expressions
\brief The implication operator for pbes expressions
\brief The or operator for pbes expressions
pbes_expression & operator=(const pbes_expression &) noexcept=default
pbes_expression(const pbes_expression &) noexcept=default
Move semantics.
parameterized boolean equation system
Definition pbes.h:54
\brief A propositional variable instantiation
pbes_expression replace_subterm(const pbes_expression &expr, std::size_t x, std::size_t y, const pbes_expression &replacement)
Replace the subterm at position (x, y) with a given term.
pbes_expression find_subterm(const pbes &pbesspec, std::size_t x, std::size_t y)
pbes replace_subterm(const pbes &p, std::size_t x, std::size_t y, const pbes_expression &replacement)
Replace the subterm at position (x, y) with a given term.
utilities::detail::position_counter counter
void apply(const data::data_expression &x)
void apply(const propositional_variable_instantiation &x)
find_subterm_traverser(std::size_t xpos_, std::size_t ypos_)
void apply(T &result, const pbes_system::forall &x)
void apply(T &result, const pbes_system::or_ &x)
void apply(T &result, const data::data_expression &x)
void apply(T &result, const pbes_system::and_ &x)
utilities::detail::position_counter counter
void apply(T &result, const propositional_variable_instantiation &x)
void apply(T &result, const pbes_system::exists &x)
void apply(T &result, const pbes_system::imp &x)
replace_subterm_builder(std::size_t xpos_, std::size_t ypos_, const pbes_expression &replacement_)