KSeExpr  4.0.4.0
ExprWalker.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2 // SPDX-License-Identifier: LicenseRef-Apache-2.0
3 // SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4 // SPDX-License-Identifier: GPL-3.0-or-later
5 
6 #pragma once
7 
8 #include <type_traits>
9 
10 #include "ExprNode.h"
11 
12 namespace KSeExpr {
13 template<class T, bool constnode> struct conditional_const {
14  using type = typename std::conditional<constnode, typename std::add_const<T>::type, T>::type;
15 };
16 
17 template <bool constnode = false>
18 class Examiner {
19  public:
21 
22  virtual bool examine(T_NODE *examinee) = 0;
23  virtual void post(T_NODE *examinee) = 0;
24  virtual void reset() = 0;
25 };
26 
27 template <bool constnode = false>
28 class Walker {
29  public:
31  using T_NODE = typename T_EXAMINER::T_NODE;
32 
33  Walker(T_EXAMINER* examiner) : _examiner(examiner) {
34  _examiner->reset();
35  };
36 
38  void walk(T_NODE* examinee);
39 
40  protected:
41  void internalWalk(T_NODE* examinee);
42  void walkChildren(T_NODE* parent);
43 
44  private:
46 };
47 
50 } // namespace KSeExpr
virtual void post(T_NODE *examinee)=0
virtual void reset()=0
typename conditional_const< ExprNode, constnode >::type T_NODE
Definition: ExprWalker.h:20
virtual bool examine(T_NODE *examinee)=0
typename T_EXAMINER::T_NODE T_NODE
Definition: ExprWalker.h:31
Walker(T_EXAMINER *examiner)
Definition: ExprWalker.h:33
void walk(T_NODE *examinee)
Preorder walk.
Definition: ExprWalker.cpp:15
void internalWalk(T_NODE *examinee)
Definition: ExprWalker.cpp:21
void walkChildren(T_NODE *parent)
Definition: ExprWalker.cpp:28
T_EXAMINER * _examiner
Definition: ExprWalker.h:45
typename std::conditional< constnode, typename std::add_const< T >::type, T >::type type
Definition: ExprWalker.h:14