ffi: fix support for generated calls with generic types (for Java FFI)
[nit.git] / contrib / pep8analysis / src / ast / rich_instructions.nit
1 # Pep/8 instructions are not reserved as keywords. It is common
2 # that the identifier of an instruction will be used for a label.
3 # For this reason, we cannot create precise instruction nodes with
4 # the parser.
5 #
6 # This module manually creates the expected subclass with an additionnal
7 # OOP hiearchy.
8
9 module rich_instructions
10
11 import backbone
12 intrude import parser
13 import ast_base
14
15 redef class AnalysisManager
16 redef fun build_ast(filename)
17 do
18 var ast = super
19 if ast != null then
20 #fun enrich_ast( ast : AListing ) do
21 for line in ast.n_lines do
22 if line isa AInstructionLine then
23 line.enrich
24 end
25 end
26 end
27 return ast
28 end
29 end
30
31 redef class AInstructionLine
32 # TODO move to AnalysisManager as private?
33 private fun enrich
34 do
35 var instr = n_instruction
36 var new_instr : AInstruction
37
38 var id = instr.n_id.text.to_upper
39 if instr isa ABinaryInstruction then
40 if id == "BR" then
41 new_instr = new ABrInstruction.from(instr)
42 else if id == "BRLE" then
43 new_instr = new ABrleInstruction.from(instr)
44 else if id == "BRLT" then
45 new_instr = new ABrltInstruction.from(instr)
46 else if id == "BREQ" then
47 new_instr = new ABreqInstruction.from(instr)
48 else if id == "BRNE" then
49 new_instr = new ABrneInstruction.from(instr)
50 else if id == "BRGE" then
51 new_instr = new ABrgeInstruction.from(instr)
52 else if id == "BRGT" then
53 new_instr = new ABrgtInstruction.from(instr)
54 else if id == "BRV" then
55 new_instr = new ABrvInstruction.from(instr)
56 else if id == "BRC" then
57 new_instr = new ABrcInstruction.from(instr)
58 else if id == "CALL" then
59 new_instr = new ACallInstruction.from(instr)
60 else if id == "NOP" then
61 new_instr = new ABinaryNopInstruction.from(instr)
62 else if id == "DECI" then
63 new_instr = new ADeciInstruction.from(instr)
64 else if id == "DECO" then
65 new_instr = new ADecoInstruction.from(instr)
66 else if id == "STRO" then
67 new_instr = new AStroInstruction.from(instr)
68 else if id == "CHARI" then
69 new_instr = new AChariInstruction.from(instr)
70 else if id == "CHARO" then
71 new_instr = new ACharoInstruction.from(instr)
72 else if id == "ADDSP" then
73 new_instr = new AAddspInstruction.from(instr)
74 else if id == "SUBSP" then
75 new_instr = new ASubspInstruction.from(instr)
76 else if id.has_prefix("ADD") then
77 new_instr = new AAddInstruction.from(instr)
78 else if id.has_prefix("SUB") then
79 new_instr = new ASubInstruction.from(instr)
80 else if id.has_prefix("AND") then
81 new_instr = new AAndInstruction.from(instr)
82 else if id.has_prefix("OR") then
83 new_instr = new AOrInstruction.from(instr)
84 else if id.has_prefix("CP") then
85 new_instr = new ACpInstruction.from(instr)
86 else if id.has_prefix("LDBYTE") then
87 new_instr = new ALdbyteInstruction.from(instr)
88 else if id.has_prefix("LD") then
89 new_instr = new ALdInstruction.from(instr)
90 else if id.has_prefix("STBYTE") then
91 new_instr = new AStbyteInstruction.from(instr)
92 else if id.has_prefix("ST") then
93 new_instr = new AStInstruction.from(instr)
94 else
95 # error
96 print "error {instr.location}: invalid instruction {id} with data access"
97 abort
98 end
99 else if instr isa AUnaryInstruction then
100 if id == "STOP" then
101 new_instr = new AStopInstruction.from(instr)
102 else if id == "RETTR" then
103 new_instr = new ARettrInstruction.from(instr)
104 else if id == "MOVSPA" then
105 new_instr = new AMovspaInstruction.from(instr)
106 else if id == "MOVFLGA" then
107 new_instr = new AMovflgaInstruction.from(instr)
108 else if id.has_prefix("NOT") then
109 new_instr = new ANotInstruction.from(instr)
110 else if id.has_prefix("NEG") then
111 new_instr = new ANegInstruction.from(instr)
112 else if id.has_prefix("ASL") then
113 new_instr = new AAslInstruction.from(instr)
114 else if id.has_prefix("ASR") then
115 new_instr = new AAsrInstruction.from(instr)
116 else if id.has_prefix("ROL") then
117 new_instr = new ARolInstruction.from(instr)
118 else if id.has_prefix("ROR") then
119 new_instr = new ARorInstruction.from(instr)
120 else if id.has_prefix("NOP") then
121 new_instr = new AUnaryNopInstruction.from(instr)
122 else if id.has_prefix("RET") then
123 new_instr = new ARetInstruction.from(instr)
124 else
125 # error
126 print "error {instr.location}: invalid instruction {id} without data access"
127 abort
128 end
129 else abort
130
131 # TODO check, one of those 2 might not be necessary
132 replace_child( instr, new_instr )
133 #n_instruction = new_instr
134 end
135 end
136
137 #
138 # Support classes
139 #
140 abstract class ARichBinaryInstruction
141 super ABinaryInstruction
142
143 init from( src: ABinaryInstruction ) do
144 _n_operand = src.n_operand
145 _n_id = src.n_id
146 parent = src.parent
147
148 init(src.location)
149 end
150 end
151
152 abstract class ARichUnaryInstruction
153 super AUnaryInstruction
154
155 init from( src: AUnaryInstruction ) do
156 _n_id = src.n_id
157 parent = src.parent
158
159 init(src.location)
160 end
161 end
162
163 #
164 # Categories
165 #
166 abstract class ABranchInstruction
167 super ARichBinaryInstruction
168 init from( src ) do super
169 end
170
171 class ABrInstruction
172 super ABranchInstruction
173 init from( src ) do super
174 end
175 class ABrleInstruction
176 super ABranchInstruction
177 init from( src ) do super
178 end
179 class ABrltInstruction
180 super ABranchInstruction
181 init from( src ) do super
182 end
183 class ABreqInstruction
184 super ABranchInstruction
185 init from( src ) do super
186 end
187 class ABrneInstruction
188 super ABranchInstruction
189 init from( src ) do super
190 end
191 class ABrgeInstruction
192 super ABranchInstruction
193 init from( src ) do super
194 end
195 class ABrgtInstruction
196 super ABranchInstruction
197 init from( src ) do super
198 end
199 class ABrvInstruction
200 super ABranchInstruction
201 init from( src ) do super
202 end
203 class ABrcInstruction
204 super ABranchInstruction
205 init from( src ) do super
206 end
207 class ACallInstruction
208 super ABranchInstruction
209 init from( src ) do super
210 end
211
212
213 abstract class ANopInstruction
214 super AInstruction
215 end
216 class ABinaryNopInstruction
217 super ANopInstruction
218 super ARichBinaryInstruction
219 init from( src ) do super
220 end
221 class AUnaryNopInstruction
222 super ANopInstruction
223 super ARichUnaryInstruction
224 init from( src ) do super
225 end
226
227
228 abstract class AOutputInstruction
229 super ARichBinaryInstruction
230 init from( src ) do super
231 end
232 abstract class AInputInstruction
233 super ARichBinaryInstruction
234 init from( src ) do super
235 end
236 # TODO add category for ADecInstruction?
237 class ADeciInstruction
238 super AInputInstruction
239 init from( src ) do super
240 end
241 class ADecoInstruction
242 super AOutputInstruction
243 init from( src ) do super
244 end
245
246 class AStroInstruction
247 super AOutputInstruction
248 init from( src ) do super
249 end
250
251 class AChariInstruction
252 super AInputInstruction
253 init from( src ) do super
254 end
255 class ACharoInstruction
256 super AOutputInstruction
257 init from( src ) do super
258 end
259
260
261 abstract class AStackInstruction
262 super ARichBinaryInstruction
263 init from( src ) do super
264 end
265 class AAddspInstruction
266 super AStackInstruction
267 init from( src ) do super
268 end
269 class ASubspInstruction
270 super AStackInstruction
271 init from( src ) do super
272 end
273
274 # Misc
275 class AStopInstruction
276 super ARichUnaryInstruction
277 init from( src ) do super
278 end
279
280 class ARettrInstruction
281 super ARichUnaryInstruction
282 init from( src ) do super
283 end
284
285 abstract class AMovInstruction
286 super ARichUnaryInstruction
287 init from( src ) do super
288 end
289 class AMovspaInstruction
290 super AMovInstruction
291 init from( src ) do super
292 end
293 class AMovflgaInstruction
294 super AMovInstruction
295 init from( src ) do super
296 end
297
298
299 class ANotInstruction
300 super ARichUnaryInstruction
301 init from( src ) do super
302 end
303
304 class ANegInstruction
305 super ARichUnaryInstruction
306 init from( src ) do super
307 end
308
309 abstract class AShiftInstruction
310 super ARichUnaryInstruction
311 init from( src ) do super
312 end
313 class AAslInstruction
314 super AShiftInstruction
315 init from( src ) do super
316 end
317 class AAsrInstruction
318 super AShiftInstruction
319 init from( src ) do super
320 end
321 class ARolInstruction
322 super AShiftInstruction
323 init from( src ) do super
324 end
325 class ARorInstruction
326 super AShiftInstruction
327 init from( src ) do super
328 end
329
330 class ARetInstruction
331 super ARichUnaryInstruction
332 init from( src ) do super
333 end
334
335
336 # TODO find a better name
337 abstract class AArithmeticInstruction
338 super ARichBinaryInstruction
339 init from( src ) do super
340 end
341 class AAddInstruction
342 super AArithmeticInstruction
343 init from( src ) do super
344 end
345 class ASubInstruction
346 super AArithmeticInstruction
347 init from( src ) do super
348 end
349 class AAndInstruction
350 super AArithmeticInstruction
351 init from( src ) do super
352 end
353 class AOrInstruction
354 super AArithmeticInstruction
355 init from( src ) do super
356 end
357
358 class ACpInstruction
359 super ARichBinaryInstruction
360 init from( src ) do super
361 end
362
363
364 abstract class ALoadInstruction
365 super ARichBinaryInstruction
366 init from( src ) do super
367 end
368 class ALdInstruction
369 super ALoadInstruction
370 init from( src ) do super
371 end
372 class ALdbyteInstruction
373 super ALoadInstruction
374 init from( src ) do super
375 end
376
377 abstract class AStoreInstruction
378 super ARichBinaryInstruction
379 init from( src ) do super
380 end
381 class AStInstruction
382 super AStoreInstruction
383 init from( src ) do super
384 end
385 class AStbyteInstruction
386 super AStoreInstruction
387 init from( src ) do super
388 end