LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
visitor.hh
Go to the documentation of this file.
1 
6 #ifndef AST_VISITOR_HH
7 # define AST_VISITOR_HH
8 
9 # include <functional>
10 # include <ast/fwd.hh>
11 # include <misc/select-const.hh>
12 
13 namespace ast
14 {
15 
19  template <template <typename> class Const>
20  class GenVisitor : public std::unary_function<Ast, void>
21  {
24  public:
26  virtual ~GenVisitor();
29 
30  virtual void operator()(typename Const<Ast>::type& e);
31  virtual void operator()(typename Const<ArrayExp>::type&) = 0;
32  virtual void operator()(typename Const<ArrayTy>::type&) = 0;
33  virtual void operator()(typename Const<AssignExp>::type&) = 0;
34  virtual void operator()(typename Const<BreakExp>::type&) = 0;
35  virtual void operator()(typename Const<CallExp>::type&) = 0;
36  virtual void operator()(typename Const<CastExp>::type&) = 0;
37  virtual void operator()(typename Const<CastVar>::type&) = 0;
38  virtual void operator()(typename Const<ClassTy>::type&) = 0;
39  virtual void operator()(typename Const<DecsList>::type&) = 0;
40  virtual void operator()(typename Const<Field>::type&) = 0;
41  virtual void operator()(typename Const<FieldInit>::type&) = 0;
42  virtual void operator()(typename Const<FieldVar>::type&) = 0;
43  virtual void operator()(typename Const<ForExp>::type&) = 0;
44  virtual void operator()(typename Const<FunctionDec>::type&) = 0;
45  virtual void operator()(typename Const<IfExp>::type&) = 0;
46  virtual void operator()(typename Const<IntExp>::type&) = 0;
47  virtual void operator()(typename Const<LetExp>::type&) = 0;
48  virtual void operator()(typename Const<MethodCallExp>::type&) = 0;
49  virtual void operator()(typename Const<MethodDec>::type&) = 0;
50  virtual void operator()(typename Const<NameTy>::type&) = 0;
51  virtual void operator()(typename Const<NilExp>::type&) = 0;
52  virtual void operator()(typename Const<ObjectExp>::type&) = 0;
53  virtual void operator()(typename Const<OpExp>::type&) = 0;
54  virtual void operator()(typename Const<RecordExp>::type&) = 0;
55  virtual void operator()(typename Const<RecordTy>::type&) = 0;
56  virtual void operator()(typename Const<SeqExp>::type&) = 0;
57  virtual void operator()(typename Const<SimpleVar>::type&) = 0;
58  virtual void operator()(typename Const<StringExp>::type&) = 0;
59  virtual void operator()(typename Const<SubscriptVar>::type&) = 0;
60  virtual void operator()(typename Const<TypeDec>::type&) = 0;
61  virtual void operator()(typename Const<VarDec>::type&) = 0;
62  virtual void operator()(typename Const<WhileExp>::type&) = 0;
63 
64  virtual void operator()(typename Const<FunctionDecs>::type&) = 0;
65  virtual void operator()(typename Const<MethodDecs>::type&) = 0;
66  virtual void operator()(typename Const<TypeDecs>::type&) = 0;
67  virtual void operator()(typename Const<VarDecs>::type&) = 0;
68 
70  template <class E> void operator()(E* e);
71 
72  protected:
103  template <typename E>
104  void accept(E* e);
105  };
106 
107 # define VISITOR_VISIT_NODE_(Z, N, Array) \
108  virtual void operator()(ast::BOOST_PP_ARRAY_ELEM(N, Array)& e);
109 
110 # define VISITOR_VISIT_NODES(Nodes) \
111  BOOST_PP_REPEAT(BOOST_PP_ARRAY_SIZE(Nodes), \
112  VISITOR_VISIT_NODE_, \
113  Nodes)
114 
116  typedef GenVisitor<misc::constify_traits> ConstVisitor;
118  typedef GenVisitor<misc::id_traits> Visitor;
119 
120 } // namespace ast
121 
122 # include <ast/visitor.hxx>
123 
124 #endif // !AST_VISITOR_HH