summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/parse/tiger-factory.hxx
blob: 39d85310c127a0432969540587dd1e9f9735a305 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#pragma once
#include <parse/tiger-factory.hh>

namespace parse
{
  inline ast::IntExp* make_IntExp(const location& location, int num)
  {
    return new ast::IntExp(location, num);
  }

  inline ast::StringExp* make_StringExp(const location& location,
                                        std::string string)
  {
    // FIXME DONE: Some code was deleted here (Constructor of StringExp).
    return new ast::StringExp(location, string);
  }

  inline ast::ObjectExp* make_ObjectExp(const location& location,
                                        ast::NameTy* type_name)
  {
    // FIXME DONE: Some code was deleted here (Constructor of Object).
    return new ast::ObjectExp(location, type_name);
  }

  inline ast::CallExp* make_CallExp(const location& location,
                                    misc::symbol name,
                                    ast::exps_type* args)
  {
    // FIXME DONE: Some code was deleted here (Constructor of CallExp).
    return new ast::CallExp(location, name, args);
  }

  inline ast::MethodCallExp* make_MethodCallExp(const location& location,
                                                misc::symbol name,
                                                ast::exps_type* args,
                                                ast::Var* object)
  {
    // FIXME DONE: Some code was deleted here (Constructor of MethodCallExp).
    return new ast::MethodCallExp(location, name, args, object);
  }

  inline ast::RecordExp* make_RecordExp(const location& location,
                                        ast::NameTy* type_name,
                                        ast::fieldinits_type* fields)
  {
    // FIXME DONE: Some code was deleted here (Constructor of RecordExp).
    return new ast::RecordExp(location, type_name, fields);
  }

  inline ast::ArrayExp* make_ArrayExp(const location& location,
                                      ast::NameTy* type_name,
                                      ast::Exp* size,
                                      ast::Exp* init)
  {
    // FIXME DONE: Some code was deleted here (Constructor of ArrayExp).
    return new ast::ArrayExp(location, type_name, size, init);
  }

  inline ast::NilExp* make_NilExp(const location& location)
  {
    return new ast::NilExp(location);
  }

  inline ast::SeqExp* make_SeqExp(const location& location,
                                  ast::exps_type* exps)
  {
    // FIXME DONE: Some code was deleted here (Constructor of SeqExp).
    return new ast::SeqExp(location, exps);
  }

  inline ast::AssignExp*
  make_AssignExp(const location& location, ast::Var* var, ast::Exp* exp)
  {
    // FIXME DONE: Some code was deleted here (Constructor of AssignExp).
    return new ast::AssignExp(location, var, exp);
  }

  inline ast::IfExp* make_IfExp(const location& location,
                                ast::Exp* test,
                                ast::Exp* thenclause,
                                ast::Exp* elseclause)
  {
    // FIXME DONE: Some code was deleted here (Constructor of IfExp).
    return new ast::IfExp(location, test, thenclause, elseclause);
  }

  inline ast::IfExp*
  make_IfExp(const location& location, ast::Exp* test, ast::Exp* thenclause)
  {
    // FIXME DONE: Some code was deleted here (Constructor of IfExp).
    return new ast::IfExp(location, test, thenclause);
  }

  inline ast::WhileExp*
  make_WhileExp(const location& location, ast::Exp* test, ast::Exp* body)
  {
    return new ast::WhileExp(location, test, body);
  }

  inline ast::ForExp* make_ForExp(const location& location,
                                  ast::VarDec* vardec,
                                  ast::Exp* hi,
                                  ast::Exp* body)
  {
    return new ast::ForExp(location, vardec, hi, body);
  }

  inline ast::BreakExp* make_BreakExp(const location& location)
  {
    // FIXME DONE: Some code was deleted here (Constructor of BreakExp).
    return new ast::BreakExp(location);
  }

  inline ast::LetExp*
  make_LetExp(const location& location, ast::ChunkList* decs, ast::Exp* body)
  {
    // FIXME DONE: Some code was deleted here (Constructor of LetExp).
    return new ast::LetExp(location, decs, body);
  }

  inline ast::OpExp* make_OpExp(const location& location,
                                ast::Exp* left,
                                ast::OpExp::Oper oper,
                                ast::Exp* right)
  {
    return new ast::OpExp(location, left, oper, right);
  }

  inline ast::CastExp*
  make_CastExp(const location& location, ast::Exp* exp, ast::Ty* ty)
  {
    return new ast::CastExp(location, exp, ty);
  }

  inline ast::SimpleVar* make_SimpleVar(const location& location,
                                        misc::symbol name)
  {
    return new ast::SimpleVar(location, name);
  }

  inline ast::FieldVar*
  make_FieldVar(const location& location, ast::Var* var, misc::symbol name)
  {
    // FIXME DONE: Some code was deleted here (Constructor of FieldVar).
    return new ast::FieldVar(location, var, name);
  }

  inline ast::SubscriptVar*
  make_SubscriptVar(const location& location, ast::Var* var, ast::Exp* index)
  {
    return new ast::SubscriptVar(location, var, index);
  }

  /* Use expansion parameter pack to handle one or empty arguments */
  template <class... T> inline ast::exps_type* make_exps_type(T... exps)
  {
    return new ast::exps_type{exps...};
  }

  inline ast::ChunkList* make_ChunkList(const location& location)
  {
    return new ast::ChunkList(location);
  }

  inline ast::TypeChunk* make_TypeChunk(const location& location)
  {
    return new ast::TypeChunk(location);
  }

  inline ast::TypeDec*
  make_TypeDec(const location& location, misc::symbol name, ast::Ty* ty)
  {
    return new ast::TypeDec(location, name, ty);
  }

  inline ast::RecordTy* make_RecordTy(const location& location,
                                      ast::fields_type* fields)
  {
    // FIXME DONE: Some code was deleted here (Constructor of RecordTy).
    return new ast::RecordTy(location, fields);
  }

  inline ast::ArrayTy* make_ArrayTy(const location& location,
                                    ast::NameTy* base_type)
  {
    return new ast::ArrayTy(location, base_type);
  }

  template <class... T> inline ast::fields_type* make_fields_type(T... types)
  {
    return new ast::fields_type{types...};
  }

  inline ast::Field* make_Field(const location& location,
                                misc::symbol name,
                                ast::NameTy* type_name)
  {
    return new ast::Field(location, name, type_name);
  }

  inline ast::NameTy* make_NameTy(const location& location, misc::symbol name)
  {
    return new ast::NameTy(location, name);
  }

  template <class... T>
  inline ast::fieldinits_type* make_fieldinits_type(T... inits_types)
  {
    return new ast::fieldinits_type{inits_types...};
  }

  inline ast::FieldInit*
  make_FieldInit(const location& location, misc::symbol name, ast::Exp* init)
  {
    return new ast::FieldInit(location, name, init);
  }

  inline ast::ClassTy* make_ClassTy(const location& location,
                                    ast::NameTy* super,
                                    ast::ChunkList* decs)
  {
    return new ast::ClassTy(location, super, decs);
  }

  inline ast::VarChunk* make_VarChunk(const location& location)
  {
    return new ast::VarChunk(location);
  }

  inline ast::VarDec* make_VarDec(const location& location,
                                  misc::symbol name,
                                  ast::NameTy* type_name,
                                  ast::Exp* init)
  {
    return new ast::VarDec(location, name, type_name, init);
  }

  inline ast::MethodChunk* make_MethodChunk(const location& location)
  {
    return new ast::MethodChunk(location);
  }

  inline ast::MethodDec* make_MethodDec(const location& location,
                                        misc::symbol name,
                                        ast::VarChunk* formals,
                                        ast::NameTy* result,
                                        ast::Exp* body)
  {
    return new ast::MethodDec(location, name, formals, result, body);
  }

  inline ast::FunctionDec* make_FunctionDec(const location& location,
                                            misc::symbol name,
                                            ast::VarChunk* formals,
                                            ast::NameTy* result,
                                            ast::Exp* body)
  {
    return new ast::FunctionDec(location, name, formals, result, body);
  }

  template <class... T> inline ast::FunctionChunk* make_FunctionChunk(T... args)
  {
    return new ast::FunctionChunk(args...);
  }

  // For the custom tiger extension
  inline ast::AssertExp* make_AssertExp(const location& location,
                                        ast::Exp* condition)
  {
    return new ast::AssertExp(location, condition);
  }
} // namespace parse