Documentation of CSL
algo.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
90 #ifndef ALGO_H_INCLUDED
91 #define ALGO_H_INCLUDED
92 
93 #include "abstract.h"
94 #include <functional>
95 
96 namespace csl {
97 
111  Expr FindLeaf(Expr const& init,
112  Expr const& value,
113  size_t depth = -1);
114 
128  Expr FindNode(Expr const& init,
129  Expr const& node,
130  size_t depth = -1);
131 
146  Expr FindIfLeaf(Expr const& init,
147  std::function<bool(Expr const&)> const& f,
148  size_t depth = -1);
149 
164  Expr FindIfNode(Expr const& init,
165  std::function<bool(Expr const&)> const& f,
166  size_t depth = -1);
167 
183  bool AnyOfLeafs(Expr const& init,
184  std::function<bool(Expr const&)> const& f,
185  int depth = -1);
186  bool AnyOfLeafs(Expr_info init,
187  std::function<bool(Expr_info)> const& f,
188  int depth = -1);
189 
205  bool AllOfLeafs(Expr const& init,
206  std::function<bool(Expr const&)> const& f,
207  int depth = -1);
208  bool AllOfLeafs(Expr_info init,
209  std::function<bool(Expr_info)> const& f,
210  int depth = -1);
211 
227  bool AnyOfNodes(Expr const& init,
228  std::function<bool(Expr const&)> const& f,
229  int depth = -1);
230  bool AnyOfNodes(Expr_info init,
231  std::function<bool(Expr_info)> const& f,
232  int depth = -1);
233 
249  bool AllOfNodes(Expr const& init,
250  std::function<bool(Expr const&)> const& f,
251  int depth = -1);
252  bool AllOfNodes(Expr_info init,
253  std::function<bool(Expr_info)> const& f,
254  int depth = -1);
255 
268  void VisitEachNode(Expr const& init,
269  std::function<void(Expr const&)> const& f,
270  int depth = -1);
271  void VisitEachNodeReversed(Expr const &init,
272  std::function<void(Expr const&)> const& f,
273  int depth = -1);
274  void VisitEachNode(Expr_info init,
275  std::function<void(Expr_info)> const& f,
276  int depth = -1);
277 
290  void VisitEachLeaf(Expr const& init,
291  std::function<void(Expr const&)> const& f,
292  int depth = -1);
293  void VisitEachLeaf(Expr_info init,
294  std::function<void(Expr_info)> const& f,
295  int depth = -1);
296 
312  void VisitEachNodeCut(
313  Expr const& init,
314  std::function<bool(Expr const&)> const& f,
315  int depth = -1);
316  void VisitEachNodeCut(
317  Expr_info init,
318  std::function<bool(Expr_info)> const& f,
319  int depth = -1);
320 
321  bool isUnique(csl::Expr const &expr);
322 
323  size_t Count(csl::Expr const &expr, csl::Expr const &search);
324  size_t CountIf(
325  csl::Expr const &expr,
326  std::function<bool(csl::Expr const&)> const &f
327  );
328 
329  size_t CountNodes(Expr const &init);
330  size_t CountLeafs(Expr const &init);
331 
345  void ForEachNode(Expr & init,
346  std::function<void(Expr&)> const& f,
347  int depth = -1);
348  void ForEachNodeReversed(Expr & init,
349  std::function<void(Expr&)> const& f,
350  int depth = -1);
351 
365  void ForEachLeaf(Expr & init,
366  std::function<void(Expr&)> const& f,
367  int depth = -1);
368 
386  void ForEachNodeCut(Expr & init,
387  std::function<bool(Expr&)> const& f,
388  int depth = -1);
389 
406  bool FirstOfNode(Expr& init,
407  std::function<bool(Expr&)> const& f);
408 
425  bool FirstOfLeaf(Expr& init,
426  std::function<bool(Expr&)> const& f);
427 
428  bool VisitFirstOfNode(Expr const& init,
429  std::function<bool(Expr const&)> const& f);
430  bool VisitFirstOfLeaf(Expr const& init,
431  std::function<bool(Expr const&)> const& f);
432 
449  bool Transform(Expr & init,
450  std::function<bool(Expr&)> const& f,
451  int depth = -1);
452 
453 } // End of namespace csl
454 
455 #endif
Namespace for csl library.
Definition: abreviation.h:34
Expr FindIfLeaf(Expr const &init, std::function< bool(Expr const &)> const &f, size_t depth=-1)
Searches and returns an expression in another.
Definition: algo.cpp:55
void ForEachNode(Expr &init, std::function< void(Expr &)> const &f, int depth=-1)
Applies a user function on each node of an expression. The expression may be modified.
Definition: algo.cpp:336
void ForEachLeaf(Expr &init, std::function< void(Expr &)> const &f, int depth=-1)
Applies a user function on each leaf of an expression. The expression may be modified.
Definition: algo.cpp:370
bool AnyOfNodes(Expr const &init, std::function< bool(Expr const &)> const &f, int depth=-1)
Tells if any of the nodes of an expression respect a certain condition given by the user...
Definition: algo.cpp:158
void VisitEachNodeCut(Expr const &init, std::function< bool(Expr const &)> const &f, int depth=-1)
Visits all nodes of an expression, applying a function on it without modifying it. When the user function returns true on one node, the underlying branch (if there is) is not explored.
Definition: algo.cpp:255
void ForEachNodeCut(Expr &init, std::function< bool(Expr &)> const &f, int depth=-1)
Applies a user function on each node of an expression. The expression may be modified.
Definition: algo.cpp:358
bool AllOfLeafs(Expr const &init, std::function< bool(Expr const &)> const &f, int depth=-1)
Tells if all of the leafs of an expression respect a certain condition given by the user...
Definition: algo.cpp:130
Expr FindNode(Expr const &init, Expr const &node, size_t depth=-1)
Searches and returns an expression in another.
Definition: algo.cpp:40
void VisitEachNode(Expr const &init, std::function< void(Expr const &)> const &f, int depth=-1)
Visits all nodes of an expression, applying a function on it without modifying it.
Definition: algo.cpp:200
Base classes for all exprs in the program.
bool AllOfNodes(Expr const &init, std::function< bool(Expr const &)> const &f, int depth=-1)
Tells if all of the nodes of an expression respect a certain condition given by the user...
Definition: algo.cpp:172
Expr FindIfNode(Expr const &init, std::function< bool(Expr const &)> const &f, size_t depth=-1)
Searches and returns an expression in another.
Definition: algo.cpp:73
bool AnyOfLeafs(Expr const &init, std::function< bool(Expr const &)> const &f, int depth=-1)
Tells if any of the leafs of an expression respect a certain condition given by the user...
Definition: algo.cpp:102
bool Transform(Expr &init, std::function< bool(Expr &)> const &f, int depth=-1)
Applies a user function on each node of an expression. The expression may be modified. If it is, the expression is refreshed.
Definition: algo.cpp:445
Expr FindLeaf(Expr const &init, Expr const &value, size_t depth=-1)
Searches and returns an expression in another.
Definition: algo.cpp:22
bool FirstOfNode(Expr &init, std::function< bool(Expr &)> const &f)
Tells if any of the nodes of an expression respect a certain condition given by the user...
Definition: algo.cpp:400
bool FirstOfLeaf(Expr &init, std::function< bool(Expr &)> const &f)
Tells if any of the leafs of an expression respect a certain condition given by the user...
Definition: algo.cpp:411
Expression type/.
Definition: abstract.h:1573
void VisitEachLeaf(Expr const &init, std::function< void(Expr const &)> const &f, int depth=-1)
Visits all leafs of an expression, applying a function on it without modifying it.
Definition: algo.cpp:232