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
SeExpr2::Examiner::examine
virtual bool examine(T_NODE *examinee)=0
SeExpr2::Walker::_examiner
T_EXAMINER * _examiner
Definition: ExprWalker.h:60
SeExpr2::ADD_CONST< T, true >::TYPE
const T TYPE
Definition: ExprWalker.h:29
SeExpr2::ExprNode
Definition: ExprNode.h:72
SeExpr2::Walker::Walker
Walker(T_EXAMINER *examiner)
Definition: ExprWalker.h:48
SeExpr2::ADD_CONST::TYPE
T TYPE
Definition: ExprWalker.h:25
SeExpr2::Examiner::reset
virtual void reset()=0
SeExpr2::Walker::T_EXAMINER
Examiner< constnode > T_EXAMINER
Definition: ExprWalker.h:45
SeExpr2::Examiner::T_NODE
ADD_CONST< ExprNode, constnode >::TYPE T_NODE
Definition: ExprWalker.h:35
SeExpr2::Walker::internalWalk
void internalWalk(T_NODE *examinee)
Definition: ExprWalker.cpp:36
SeExpr2::Examiner
Definition: ExprWalker.h:33
SeExpr2::Examiner::post
virtual void post(T_NODE *examinee)
Definition: ExprWalker.h:38
SeExpr2::Walker::walkChildren
void walkChildren(T_NODE *parent)
Definition: ExprWalker.cpp:43
SeExpr2
Definition: Context.h:22
SeExpr2::ADD_CONST
Definition: ExprWalker.h:24
SeExpr2::ConstWalker
Walker< true > ConstWalker
Definition: ExprWalker.h:64
SeExpr2::ConstExaminer
Examiner< true > ConstExaminer
Definition: ExprWalker.h:63
SeExpr2::Walker::T_NODE
T_EXAMINER::T_NODE T_NODE
Definition: ExprWalker.h:46
SeExpr2::Walker
Definition: ExprWalker.h:43
SeExpr2::Walker::walk
void walk(T_NODE *examinee)
Preorder walk.
Definition: ExprWalker.cpp:30