SeExpr
ExprWalker.h
Go to the documentation of this file.
1 /*
2  Copyright Disney Enterprises, Inc. All rights reserved.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License
6  and the following modification to it: Section 6 Trademarks.
7  deleted and replaced with:
8 
9  6. Trademarks. This License does not grant permission to use the
10  trade names, trademarks, service marks, or product names of the
11  Licensor and its affiliates, except as required for reproducing
12  the content of the NOTICE file.
13 
14  You may obtain a copy of the License at
15  http://www.apache.org/licenses/LICENSE-2.0
16 */
17 
18 #ifndef ExprWalker_h
19 #define ExprWalker_h
20 
21 namespace SeExpr2 {
22 
23 template <class T, bool constnode>
24 struct ADD_CONST {
25  typedef T TYPE;
26 };
27 template <class T>
28 struct ADD_CONST<T, true> {
29  typedef const T TYPE;
30 };
31 
32 template <bool constnode = false>
33 class Examiner {
34  public:
36 
37  virtual bool examine(T_NODE* examinee) = 0;
38  virtual void post(T_NODE* examinee) {}; // TODO: make this pure virt
39  virtual void reset() = 0;
40 };
41 
42 template <bool constnode = false>
43 class Walker {
44  public:
46  typedef typename T_EXAMINER::T_NODE T_NODE;
47 
48  Walker(T_EXAMINER* examiner) : _examiner(examiner) {
49  _examiner->reset();
50  };
51 
53  void walk(T_NODE* examinee);
54 
55  protected:
56  void internalWalk(T_NODE* examinee);
57  void walkChildren(T_NODE* parent);
58 
59  private:
61 };
62 
65 }
66 #endif
virtual bool examine(T_NODE *examinee)=0
virtual void reset()=0
void walk(T_NODE *examinee)
Preorder walk.
Definition: ExprWalker.cpp:30
Examiner< constnode > T_EXAMINER
Definition: ExprWalker.h:45
Walker(T_EXAMINER *examiner)
Definition: ExprWalker.h:48
Walker< true > ConstWalker
Definition: ExprWalker.h:64
T_EXAMINER::T_NODE T_NODE
Definition: ExprWalker.h:46
virtual void post(T_NODE *examinee)
Definition: ExprWalker.h:38
void walkChildren(T_NODE *parent)
Definition: ExprWalker.cpp:43
Examiner< true > ConstExaminer
Definition: ExprWalker.h:63
void internalWalk(T_NODE *examinee)
Definition: ExprWalker.cpp:36
ADD_CONST< ExprNode, constnode >::TYPE T_NODE
Definition: ExprWalker.h:35
T_EXAMINER * _examiner
Definition: ExprWalker.h:60