LRDE Tiger Compiler  1.34a $Id: 7fef12e1f5fa43449d667a0eec1d837c40fc1202 $
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
translator.hh
Go to the documentation of this file.
1 
6 #ifndef TRANSLATE_TRANSLATOR_HH
7 # define TRANSLATE_TRANSLATOR_HH
8 
9 # include <list>
10 # include <map>
11 # include <stack>
12 
13 # include <ast/default-visitor.hh>
14 # include <ast/non-object-visitor.hh>
15 
16 # include <temp/fwd.hh>
17 # include <tree/fwd.hh>
18 # include <translate/fwd.hh>
19 
20 namespace translate
21 {
22 
24  class Translator
27  {
28  public:
32  using super_type::operator();
33 
34  Translator();
35 
43  Translator(const Translator&) = delete;
44  Translator& operator= (const Translator&) = delete;
46 
47  virtual ~Translator();
48 
50  virtual void operator()(const ast::Ast& e) override;
51 
55 
60  rExp translate(const ast::Ast& node);
61 
63  template <typename T>
64  std::list<rExp> translate(const std::list<T*>& es);
65 
68  virtual void operator()(const ast::SimpleVar& e) override;
69  virtual void operator()(const ast::FieldVar& e) override;
70  virtual void operator()(const ast::SubscriptVar& e) override;
71  virtual void operator()(const ast::CastVar& e) override;
73 
74 
77  // Literals.
78  virtual void operator()(const ast::NilExp&) override;
79  virtual void operator()(const ast::IntExp& e) override;
80  // Literal string: insert its definition in fragments_, and return
81  // an exp which refers to this fragment.
82  virtual void operator()(const ast::StringExp& e) override;
83  virtual void operator()(const ast::RecordExp& e) override;
84  virtual void operator()(const ast::CallExp& e) override;
85  virtual void operator()(const ast::OpExp& e) override;
86  virtual void operator()(const ast::SeqExp& e) override;
87  virtual void operator()(const ast::AssignExp& e) override;
88  virtual void operator()(const ast::IfExp& e) override;
89  virtual void operator()(const ast::WhileExp& e) override;
90 
91  // Translating a ForExp is an EPITA. It would be more pleasant to
92  // build a pseudo AST which maps a for-loop into a while-loop.
93  virtual void operator()(const ast::ForExp& e) override;
94  virtual void operator()(const ast::BreakExp&) override;
95  virtual void operator()(const ast::LetExp& e) override;
96  virtual void operator()(const ast::ArrayExp& e) override;
97  virtual void operator()(const ast::CastExp& e) override;
99 
102  virtual void operator()(const ast::VarDecs& e) override;
103  virtual void operator()(const ast::TypeDecs&) override;
104  virtual void operator()(const ast::FunctionDecs& e) override;
106 
109  virtual void operator()(const ast::FunctionDec&) override;
113 
114  virtual void operator()(const ast::VarDec& e) override;
115 
116  protected:
119 
121  std::stack<std::list<rExp>> exps_;
122 
125 
128 
130  std::map<const ast::Exp*, temp::Label> loop_end_label_;
131 
133  std::map<const ast::Ast*, const Access*> var_access_;
134 
136  std::map<const ast::Ast*, const Level*> fun_level_;
137 
139  std::map<const ast::Ast*, temp::Label> fun_label_;
140 
141 
142  };
143 
144 }
145 
146 #endif // !TRANSLATE_TRANSLATOR_HH