1 | n/a | /* File automatically generated by Parser/asdl_c.py. */ |
---|
2 | n/a | |
---|
3 | n/a | #include <stddef.h> |
---|
4 | n/a | |
---|
5 | n/a | #include "Python.h" |
---|
6 | n/a | #include "Python-ast.h" |
---|
7 | n/a | |
---|
8 | n/a | static PyTypeObject AST_type; |
---|
9 | n/a | static PyTypeObject *mod_type; |
---|
10 | n/a | static PyObject* ast2obj_mod(void*); |
---|
11 | n/a | static PyTypeObject *Module_type; |
---|
12 | n/a | _Py_IDENTIFIER(body); |
---|
13 | n/a | static char *Module_fields[]={ |
---|
14 | n/a | "body", |
---|
15 | n/a | }; |
---|
16 | n/a | static PyTypeObject *Interactive_type; |
---|
17 | n/a | static char *Interactive_fields[]={ |
---|
18 | n/a | "body", |
---|
19 | n/a | }; |
---|
20 | n/a | static PyTypeObject *Expression_type; |
---|
21 | n/a | static char *Expression_fields[]={ |
---|
22 | n/a | "body", |
---|
23 | n/a | }; |
---|
24 | n/a | static PyTypeObject *Suite_type; |
---|
25 | n/a | static char *Suite_fields[]={ |
---|
26 | n/a | "body", |
---|
27 | n/a | }; |
---|
28 | n/a | static PyTypeObject *stmt_type; |
---|
29 | n/a | _Py_IDENTIFIER(lineno); |
---|
30 | n/a | _Py_IDENTIFIER(col_offset); |
---|
31 | n/a | static char *stmt_attributes[] = { |
---|
32 | n/a | "lineno", |
---|
33 | n/a | "col_offset", |
---|
34 | n/a | }; |
---|
35 | n/a | static PyObject* ast2obj_stmt(void*); |
---|
36 | n/a | static PyTypeObject *FunctionDef_type; |
---|
37 | n/a | _Py_IDENTIFIER(name); |
---|
38 | n/a | _Py_IDENTIFIER(args); |
---|
39 | n/a | _Py_IDENTIFIER(decorator_list); |
---|
40 | n/a | _Py_IDENTIFIER(returns); |
---|
41 | n/a | static char *FunctionDef_fields[]={ |
---|
42 | n/a | "name", |
---|
43 | n/a | "args", |
---|
44 | n/a | "body", |
---|
45 | n/a | "decorator_list", |
---|
46 | n/a | "returns", |
---|
47 | n/a | }; |
---|
48 | n/a | static PyTypeObject *AsyncFunctionDef_type; |
---|
49 | n/a | static char *AsyncFunctionDef_fields[]={ |
---|
50 | n/a | "name", |
---|
51 | n/a | "args", |
---|
52 | n/a | "body", |
---|
53 | n/a | "decorator_list", |
---|
54 | n/a | "returns", |
---|
55 | n/a | }; |
---|
56 | n/a | static PyTypeObject *ClassDef_type; |
---|
57 | n/a | _Py_IDENTIFIER(bases); |
---|
58 | n/a | _Py_IDENTIFIER(keywords); |
---|
59 | n/a | static char *ClassDef_fields[]={ |
---|
60 | n/a | "name", |
---|
61 | n/a | "bases", |
---|
62 | n/a | "keywords", |
---|
63 | n/a | "body", |
---|
64 | n/a | "decorator_list", |
---|
65 | n/a | }; |
---|
66 | n/a | static PyTypeObject *Return_type; |
---|
67 | n/a | _Py_IDENTIFIER(value); |
---|
68 | n/a | static char *Return_fields[]={ |
---|
69 | n/a | "value", |
---|
70 | n/a | }; |
---|
71 | n/a | static PyTypeObject *Delete_type; |
---|
72 | n/a | _Py_IDENTIFIER(targets); |
---|
73 | n/a | static char *Delete_fields[]={ |
---|
74 | n/a | "targets", |
---|
75 | n/a | }; |
---|
76 | n/a | static PyTypeObject *Assign_type; |
---|
77 | n/a | static char *Assign_fields[]={ |
---|
78 | n/a | "targets", |
---|
79 | n/a | "value", |
---|
80 | n/a | }; |
---|
81 | n/a | static PyTypeObject *AugAssign_type; |
---|
82 | n/a | _Py_IDENTIFIER(target); |
---|
83 | n/a | _Py_IDENTIFIER(op); |
---|
84 | n/a | static char *AugAssign_fields[]={ |
---|
85 | n/a | "target", |
---|
86 | n/a | "op", |
---|
87 | n/a | "value", |
---|
88 | n/a | }; |
---|
89 | n/a | static PyTypeObject *AnnAssign_type; |
---|
90 | n/a | _Py_IDENTIFIER(annotation); |
---|
91 | n/a | _Py_IDENTIFIER(simple); |
---|
92 | n/a | static char *AnnAssign_fields[]={ |
---|
93 | n/a | "target", |
---|
94 | n/a | "annotation", |
---|
95 | n/a | "value", |
---|
96 | n/a | "simple", |
---|
97 | n/a | }; |
---|
98 | n/a | static PyTypeObject *For_type; |
---|
99 | n/a | _Py_IDENTIFIER(iter); |
---|
100 | n/a | _Py_IDENTIFIER(orelse); |
---|
101 | n/a | static char *For_fields[]={ |
---|
102 | n/a | "target", |
---|
103 | n/a | "iter", |
---|
104 | n/a | "body", |
---|
105 | n/a | "orelse", |
---|
106 | n/a | }; |
---|
107 | n/a | static PyTypeObject *AsyncFor_type; |
---|
108 | n/a | static char *AsyncFor_fields[]={ |
---|
109 | n/a | "target", |
---|
110 | n/a | "iter", |
---|
111 | n/a | "body", |
---|
112 | n/a | "orelse", |
---|
113 | n/a | }; |
---|
114 | n/a | static PyTypeObject *While_type; |
---|
115 | n/a | _Py_IDENTIFIER(test); |
---|
116 | n/a | static char *While_fields[]={ |
---|
117 | n/a | "test", |
---|
118 | n/a | "body", |
---|
119 | n/a | "orelse", |
---|
120 | n/a | }; |
---|
121 | n/a | static PyTypeObject *If_type; |
---|
122 | n/a | static char *If_fields[]={ |
---|
123 | n/a | "test", |
---|
124 | n/a | "body", |
---|
125 | n/a | "orelse", |
---|
126 | n/a | }; |
---|
127 | n/a | static PyTypeObject *With_type; |
---|
128 | n/a | _Py_IDENTIFIER(items); |
---|
129 | n/a | static char *With_fields[]={ |
---|
130 | n/a | "items", |
---|
131 | n/a | "body", |
---|
132 | n/a | }; |
---|
133 | n/a | static PyTypeObject *AsyncWith_type; |
---|
134 | n/a | static char *AsyncWith_fields[]={ |
---|
135 | n/a | "items", |
---|
136 | n/a | "body", |
---|
137 | n/a | }; |
---|
138 | n/a | static PyTypeObject *Raise_type; |
---|
139 | n/a | _Py_IDENTIFIER(exc); |
---|
140 | n/a | _Py_IDENTIFIER(cause); |
---|
141 | n/a | static char *Raise_fields[]={ |
---|
142 | n/a | "exc", |
---|
143 | n/a | "cause", |
---|
144 | n/a | }; |
---|
145 | n/a | static PyTypeObject *Try_type; |
---|
146 | n/a | _Py_IDENTIFIER(handlers); |
---|
147 | n/a | _Py_IDENTIFIER(finalbody); |
---|
148 | n/a | static char *Try_fields[]={ |
---|
149 | n/a | "body", |
---|
150 | n/a | "handlers", |
---|
151 | n/a | "orelse", |
---|
152 | n/a | "finalbody", |
---|
153 | n/a | }; |
---|
154 | n/a | static PyTypeObject *Assert_type; |
---|
155 | n/a | _Py_IDENTIFIER(msg); |
---|
156 | n/a | static char *Assert_fields[]={ |
---|
157 | n/a | "test", |
---|
158 | n/a | "msg", |
---|
159 | n/a | }; |
---|
160 | n/a | static PyTypeObject *Import_type; |
---|
161 | n/a | _Py_IDENTIFIER(names); |
---|
162 | n/a | static char *Import_fields[]={ |
---|
163 | n/a | "names", |
---|
164 | n/a | }; |
---|
165 | n/a | static PyTypeObject *ImportFrom_type; |
---|
166 | n/a | _Py_IDENTIFIER(module); |
---|
167 | n/a | _Py_IDENTIFIER(level); |
---|
168 | n/a | static char *ImportFrom_fields[]={ |
---|
169 | n/a | "module", |
---|
170 | n/a | "names", |
---|
171 | n/a | "level", |
---|
172 | n/a | }; |
---|
173 | n/a | static PyTypeObject *Global_type; |
---|
174 | n/a | static char *Global_fields[]={ |
---|
175 | n/a | "names", |
---|
176 | n/a | }; |
---|
177 | n/a | static PyTypeObject *Nonlocal_type; |
---|
178 | n/a | static char *Nonlocal_fields[]={ |
---|
179 | n/a | "names", |
---|
180 | n/a | }; |
---|
181 | n/a | static PyTypeObject *Expr_type; |
---|
182 | n/a | static char *Expr_fields[]={ |
---|
183 | n/a | "value", |
---|
184 | n/a | }; |
---|
185 | n/a | static PyTypeObject *Pass_type; |
---|
186 | n/a | static PyTypeObject *Break_type; |
---|
187 | n/a | static PyTypeObject *Continue_type; |
---|
188 | n/a | static PyTypeObject *expr_type; |
---|
189 | n/a | static char *expr_attributes[] = { |
---|
190 | n/a | "lineno", |
---|
191 | n/a | "col_offset", |
---|
192 | n/a | }; |
---|
193 | n/a | static PyObject* ast2obj_expr(void*); |
---|
194 | n/a | static PyTypeObject *BoolOp_type; |
---|
195 | n/a | _Py_IDENTIFIER(values); |
---|
196 | n/a | static char *BoolOp_fields[]={ |
---|
197 | n/a | "op", |
---|
198 | n/a | "values", |
---|
199 | n/a | }; |
---|
200 | n/a | static PyTypeObject *BinOp_type; |
---|
201 | n/a | _Py_IDENTIFIER(left); |
---|
202 | n/a | _Py_IDENTIFIER(right); |
---|
203 | n/a | static char *BinOp_fields[]={ |
---|
204 | n/a | "left", |
---|
205 | n/a | "op", |
---|
206 | n/a | "right", |
---|
207 | n/a | }; |
---|
208 | n/a | static PyTypeObject *UnaryOp_type; |
---|
209 | n/a | _Py_IDENTIFIER(operand); |
---|
210 | n/a | static char *UnaryOp_fields[]={ |
---|
211 | n/a | "op", |
---|
212 | n/a | "operand", |
---|
213 | n/a | }; |
---|
214 | n/a | static PyTypeObject *Lambda_type; |
---|
215 | n/a | static char *Lambda_fields[]={ |
---|
216 | n/a | "args", |
---|
217 | n/a | "body", |
---|
218 | n/a | }; |
---|
219 | n/a | static PyTypeObject *IfExp_type; |
---|
220 | n/a | static char *IfExp_fields[]={ |
---|
221 | n/a | "test", |
---|
222 | n/a | "body", |
---|
223 | n/a | "orelse", |
---|
224 | n/a | }; |
---|
225 | n/a | static PyTypeObject *Dict_type; |
---|
226 | n/a | _Py_IDENTIFIER(keys); |
---|
227 | n/a | static char *Dict_fields[]={ |
---|
228 | n/a | "keys", |
---|
229 | n/a | "values", |
---|
230 | n/a | }; |
---|
231 | n/a | static PyTypeObject *Set_type; |
---|
232 | n/a | _Py_IDENTIFIER(elts); |
---|
233 | n/a | static char *Set_fields[]={ |
---|
234 | n/a | "elts", |
---|
235 | n/a | }; |
---|
236 | n/a | static PyTypeObject *ListComp_type; |
---|
237 | n/a | _Py_IDENTIFIER(elt); |
---|
238 | n/a | _Py_IDENTIFIER(generators); |
---|
239 | n/a | static char *ListComp_fields[]={ |
---|
240 | n/a | "elt", |
---|
241 | n/a | "generators", |
---|
242 | n/a | }; |
---|
243 | n/a | static PyTypeObject *SetComp_type; |
---|
244 | n/a | static char *SetComp_fields[]={ |
---|
245 | n/a | "elt", |
---|
246 | n/a | "generators", |
---|
247 | n/a | }; |
---|
248 | n/a | static PyTypeObject *DictComp_type; |
---|
249 | n/a | _Py_IDENTIFIER(key); |
---|
250 | n/a | static char *DictComp_fields[]={ |
---|
251 | n/a | "key", |
---|
252 | n/a | "value", |
---|
253 | n/a | "generators", |
---|
254 | n/a | }; |
---|
255 | n/a | static PyTypeObject *GeneratorExp_type; |
---|
256 | n/a | static char *GeneratorExp_fields[]={ |
---|
257 | n/a | "elt", |
---|
258 | n/a | "generators", |
---|
259 | n/a | }; |
---|
260 | n/a | static PyTypeObject *Await_type; |
---|
261 | n/a | static char *Await_fields[]={ |
---|
262 | n/a | "value", |
---|
263 | n/a | }; |
---|
264 | n/a | static PyTypeObject *Yield_type; |
---|
265 | n/a | static char *Yield_fields[]={ |
---|
266 | n/a | "value", |
---|
267 | n/a | }; |
---|
268 | n/a | static PyTypeObject *YieldFrom_type; |
---|
269 | n/a | static char *YieldFrom_fields[]={ |
---|
270 | n/a | "value", |
---|
271 | n/a | }; |
---|
272 | n/a | static PyTypeObject *Compare_type; |
---|
273 | n/a | _Py_IDENTIFIER(ops); |
---|
274 | n/a | _Py_IDENTIFIER(comparators); |
---|
275 | n/a | static char *Compare_fields[]={ |
---|
276 | n/a | "left", |
---|
277 | n/a | "ops", |
---|
278 | n/a | "comparators", |
---|
279 | n/a | }; |
---|
280 | n/a | static PyTypeObject *Call_type; |
---|
281 | n/a | _Py_IDENTIFIER(func); |
---|
282 | n/a | static char *Call_fields[]={ |
---|
283 | n/a | "func", |
---|
284 | n/a | "args", |
---|
285 | n/a | "keywords", |
---|
286 | n/a | }; |
---|
287 | n/a | static PyTypeObject *Num_type; |
---|
288 | n/a | _Py_IDENTIFIER(n); |
---|
289 | n/a | static char *Num_fields[]={ |
---|
290 | n/a | "n", |
---|
291 | n/a | }; |
---|
292 | n/a | static PyTypeObject *Str_type; |
---|
293 | n/a | _Py_IDENTIFIER(s); |
---|
294 | n/a | static char *Str_fields[]={ |
---|
295 | n/a | "s", |
---|
296 | n/a | }; |
---|
297 | n/a | static PyTypeObject *FormattedValue_type; |
---|
298 | n/a | _Py_IDENTIFIER(conversion); |
---|
299 | n/a | _Py_IDENTIFIER(format_spec); |
---|
300 | n/a | static char *FormattedValue_fields[]={ |
---|
301 | n/a | "value", |
---|
302 | n/a | "conversion", |
---|
303 | n/a | "format_spec", |
---|
304 | n/a | }; |
---|
305 | n/a | static PyTypeObject *JoinedStr_type; |
---|
306 | n/a | static char *JoinedStr_fields[]={ |
---|
307 | n/a | "values", |
---|
308 | n/a | }; |
---|
309 | n/a | static PyTypeObject *Bytes_type; |
---|
310 | n/a | static char *Bytes_fields[]={ |
---|
311 | n/a | "s", |
---|
312 | n/a | }; |
---|
313 | n/a | static PyTypeObject *NameConstant_type; |
---|
314 | n/a | static char *NameConstant_fields[]={ |
---|
315 | n/a | "value", |
---|
316 | n/a | }; |
---|
317 | n/a | static PyTypeObject *Ellipsis_type; |
---|
318 | n/a | static PyTypeObject *Constant_type; |
---|
319 | n/a | static char *Constant_fields[]={ |
---|
320 | n/a | "value", |
---|
321 | n/a | }; |
---|
322 | n/a | static PyTypeObject *Attribute_type; |
---|
323 | n/a | _Py_IDENTIFIER(attr); |
---|
324 | n/a | _Py_IDENTIFIER(ctx); |
---|
325 | n/a | static char *Attribute_fields[]={ |
---|
326 | n/a | "value", |
---|
327 | n/a | "attr", |
---|
328 | n/a | "ctx", |
---|
329 | n/a | }; |
---|
330 | n/a | static PyTypeObject *Subscript_type; |
---|
331 | n/a | _Py_IDENTIFIER(slice); |
---|
332 | n/a | static char *Subscript_fields[]={ |
---|
333 | n/a | "value", |
---|
334 | n/a | "slice", |
---|
335 | n/a | "ctx", |
---|
336 | n/a | }; |
---|
337 | n/a | static PyTypeObject *Starred_type; |
---|
338 | n/a | static char *Starred_fields[]={ |
---|
339 | n/a | "value", |
---|
340 | n/a | "ctx", |
---|
341 | n/a | }; |
---|
342 | n/a | static PyTypeObject *Name_type; |
---|
343 | n/a | _Py_IDENTIFIER(id); |
---|
344 | n/a | static char *Name_fields[]={ |
---|
345 | n/a | "id", |
---|
346 | n/a | "ctx", |
---|
347 | n/a | }; |
---|
348 | n/a | static PyTypeObject *List_type; |
---|
349 | n/a | static char *List_fields[]={ |
---|
350 | n/a | "elts", |
---|
351 | n/a | "ctx", |
---|
352 | n/a | }; |
---|
353 | n/a | static PyTypeObject *Tuple_type; |
---|
354 | n/a | static char *Tuple_fields[]={ |
---|
355 | n/a | "elts", |
---|
356 | n/a | "ctx", |
---|
357 | n/a | }; |
---|
358 | n/a | static PyTypeObject *expr_context_type; |
---|
359 | n/a | static PyObject *Load_singleton, *Store_singleton, *Del_singleton, |
---|
360 | n/a | *AugLoad_singleton, *AugStore_singleton, *Param_singleton; |
---|
361 | n/a | static PyObject* ast2obj_expr_context(expr_context_ty); |
---|
362 | n/a | static PyTypeObject *Load_type; |
---|
363 | n/a | static PyTypeObject *Store_type; |
---|
364 | n/a | static PyTypeObject *Del_type; |
---|
365 | n/a | static PyTypeObject *AugLoad_type; |
---|
366 | n/a | static PyTypeObject *AugStore_type; |
---|
367 | n/a | static PyTypeObject *Param_type; |
---|
368 | n/a | static PyTypeObject *slice_type; |
---|
369 | n/a | static PyObject* ast2obj_slice(void*); |
---|
370 | n/a | static PyTypeObject *Slice_type; |
---|
371 | n/a | _Py_IDENTIFIER(lower); |
---|
372 | n/a | _Py_IDENTIFIER(upper); |
---|
373 | n/a | _Py_IDENTIFIER(step); |
---|
374 | n/a | static char *Slice_fields[]={ |
---|
375 | n/a | "lower", |
---|
376 | n/a | "upper", |
---|
377 | n/a | "step", |
---|
378 | n/a | }; |
---|
379 | n/a | static PyTypeObject *ExtSlice_type; |
---|
380 | n/a | _Py_IDENTIFIER(dims); |
---|
381 | n/a | static char *ExtSlice_fields[]={ |
---|
382 | n/a | "dims", |
---|
383 | n/a | }; |
---|
384 | n/a | static PyTypeObject *Index_type; |
---|
385 | n/a | static char *Index_fields[]={ |
---|
386 | n/a | "value", |
---|
387 | n/a | }; |
---|
388 | n/a | static PyTypeObject *boolop_type; |
---|
389 | n/a | static PyObject *And_singleton, *Or_singleton; |
---|
390 | n/a | static PyObject* ast2obj_boolop(boolop_ty); |
---|
391 | n/a | static PyTypeObject *And_type; |
---|
392 | n/a | static PyTypeObject *Or_type; |
---|
393 | n/a | static PyTypeObject *operator_type; |
---|
394 | n/a | static PyObject *Add_singleton, *Sub_singleton, *Mult_singleton, |
---|
395 | n/a | *MatMult_singleton, *Div_singleton, *Mod_singleton, *Pow_singleton, |
---|
396 | n/a | *LShift_singleton, *RShift_singleton, *BitOr_singleton, *BitXor_singleton, |
---|
397 | n/a | *BitAnd_singleton, *FloorDiv_singleton; |
---|
398 | n/a | static PyObject* ast2obj_operator(operator_ty); |
---|
399 | n/a | static PyTypeObject *Add_type; |
---|
400 | n/a | static PyTypeObject *Sub_type; |
---|
401 | n/a | static PyTypeObject *Mult_type; |
---|
402 | n/a | static PyTypeObject *MatMult_type; |
---|
403 | n/a | static PyTypeObject *Div_type; |
---|
404 | n/a | static PyTypeObject *Mod_type; |
---|
405 | n/a | static PyTypeObject *Pow_type; |
---|
406 | n/a | static PyTypeObject *LShift_type; |
---|
407 | n/a | static PyTypeObject *RShift_type; |
---|
408 | n/a | static PyTypeObject *BitOr_type; |
---|
409 | n/a | static PyTypeObject *BitXor_type; |
---|
410 | n/a | static PyTypeObject *BitAnd_type; |
---|
411 | n/a | static PyTypeObject *FloorDiv_type; |
---|
412 | n/a | static PyTypeObject *unaryop_type; |
---|
413 | n/a | static PyObject *Invert_singleton, *Not_singleton, *UAdd_singleton, |
---|
414 | n/a | *USub_singleton; |
---|
415 | n/a | static PyObject* ast2obj_unaryop(unaryop_ty); |
---|
416 | n/a | static PyTypeObject *Invert_type; |
---|
417 | n/a | static PyTypeObject *Not_type; |
---|
418 | n/a | static PyTypeObject *UAdd_type; |
---|
419 | n/a | static PyTypeObject *USub_type; |
---|
420 | n/a | static PyTypeObject *cmpop_type; |
---|
421 | n/a | static PyObject *Eq_singleton, *NotEq_singleton, *Lt_singleton, *LtE_singleton, |
---|
422 | n/a | *Gt_singleton, *GtE_singleton, *Is_singleton, *IsNot_singleton, *In_singleton, |
---|
423 | n/a | *NotIn_singleton; |
---|
424 | n/a | static PyObject* ast2obj_cmpop(cmpop_ty); |
---|
425 | n/a | static PyTypeObject *Eq_type; |
---|
426 | n/a | static PyTypeObject *NotEq_type; |
---|
427 | n/a | static PyTypeObject *Lt_type; |
---|
428 | n/a | static PyTypeObject *LtE_type; |
---|
429 | n/a | static PyTypeObject *Gt_type; |
---|
430 | n/a | static PyTypeObject *GtE_type; |
---|
431 | n/a | static PyTypeObject *Is_type; |
---|
432 | n/a | static PyTypeObject *IsNot_type; |
---|
433 | n/a | static PyTypeObject *In_type; |
---|
434 | n/a | static PyTypeObject *NotIn_type; |
---|
435 | n/a | static PyTypeObject *comprehension_type; |
---|
436 | n/a | static PyObject* ast2obj_comprehension(void*); |
---|
437 | n/a | _Py_IDENTIFIER(ifs); |
---|
438 | n/a | _Py_IDENTIFIER(is_async); |
---|
439 | n/a | static char *comprehension_fields[]={ |
---|
440 | n/a | "target", |
---|
441 | n/a | "iter", |
---|
442 | n/a | "ifs", |
---|
443 | n/a | "is_async", |
---|
444 | n/a | }; |
---|
445 | n/a | static PyTypeObject *excepthandler_type; |
---|
446 | n/a | static char *excepthandler_attributes[] = { |
---|
447 | n/a | "lineno", |
---|
448 | n/a | "col_offset", |
---|
449 | n/a | }; |
---|
450 | n/a | static PyObject* ast2obj_excepthandler(void*); |
---|
451 | n/a | static PyTypeObject *ExceptHandler_type; |
---|
452 | n/a | _Py_IDENTIFIER(type); |
---|
453 | n/a | static char *ExceptHandler_fields[]={ |
---|
454 | n/a | "type", |
---|
455 | n/a | "name", |
---|
456 | n/a | "body", |
---|
457 | n/a | }; |
---|
458 | n/a | static PyTypeObject *arguments_type; |
---|
459 | n/a | static PyObject* ast2obj_arguments(void*); |
---|
460 | n/a | _Py_IDENTIFIER(vararg); |
---|
461 | n/a | _Py_IDENTIFIER(kwonlyargs); |
---|
462 | n/a | _Py_IDENTIFIER(kw_defaults); |
---|
463 | n/a | _Py_IDENTIFIER(kwarg); |
---|
464 | n/a | _Py_IDENTIFIER(defaults); |
---|
465 | n/a | static char *arguments_fields[]={ |
---|
466 | n/a | "args", |
---|
467 | n/a | "vararg", |
---|
468 | n/a | "kwonlyargs", |
---|
469 | n/a | "kw_defaults", |
---|
470 | n/a | "kwarg", |
---|
471 | n/a | "defaults", |
---|
472 | n/a | }; |
---|
473 | n/a | static PyTypeObject *arg_type; |
---|
474 | n/a | static PyObject* ast2obj_arg(void*); |
---|
475 | n/a | static char *arg_attributes[] = { |
---|
476 | n/a | "lineno", |
---|
477 | n/a | "col_offset", |
---|
478 | n/a | }; |
---|
479 | n/a | _Py_IDENTIFIER(arg); |
---|
480 | n/a | static char *arg_fields[]={ |
---|
481 | n/a | "arg", |
---|
482 | n/a | "annotation", |
---|
483 | n/a | }; |
---|
484 | n/a | static PyTypeObject *keyword_type; |
---|
485 | n/a | static PyObject* ast2obj_keyword(void*); |
---|
486 | n/a | static char *keyword_fields[]={ |
---|
487 | n/a | "arg", |
---|
488 | n/a | "value", |
---|
489 | n/a | }; |
---|
490 | n/a | static PyTypeObject *alias_type; |
---|
491 | n/a | static PyObject* ast2obj_alias(void*); |
---|
492 | n/a | _Py_IDENTIFIER(asname); |
---|
493 | n/a | static char *alias_fields[]={ |
---|
494 | n/a | "name", |
---|
495 | n/a | "asname", |
---|
496 | n/a | }; |
---|
497 | n/a | static PyTypeObject *withitem_type; |
---|
498 | n/a | static PyObject* ast2obj_withitem(void*); |
---|
499 | n/a | _Py_IDENTIFIER(context_expr); |
---|
500 | n/a | _Py_IDENTIFIER(optional_vars); |
---|
501 | n/a | static char *withitem_fields[]={ |
---|
502 | n/a | "context_expr", |
---|
503 | n/a | "optional_vars", |
---|
504 | n/a | }; |
---|
505 | n/a | |
---|
506 | n/a | |
---|
507 | n/a | _Py_IDENTIFIER(_fields); |
---|
508 | n/a | _Py_IDENTIFIER(_attributes); |
---|
509 | n/a | |
---|
510 | n/a | typedef struct { |
---|
511 | n/a | PyObject_HEAD |
---|
512 | n/a | PyObject *dict; |
---|
513 | n/a | } AST_object; |
---|
514 | n/a | |
---|
515 | n/a | static void |
---|
516 | n/a | ast_dealloc(AST_object *self) |
---|
517 | n/a | { |
---|
518 | n/a | Py_CLEAR(self->dict); |
---|
519 | n/a | Py_TYPE(self)->tp_free(self); |
---|
520 | n/a | } |
---|
521 | n/a | |
---|
522 | n/a | static int |
---|
523 | n/a | ast_traverse(AST_object *self, visitproc visit, void *arg) |
---|
524 | n/a | { |
---|
525 | n/a | Py_VISIT(self->dict); |
---|
526 | n/a | return 0; |
---|
527 | n/a | } |
---|
528 | n/a | |
---|
529 | n/a | static void |
---|
530 | n/a | ast_clear(AST_object *self) |
---|
531 | n/a | { |
---|
532 | n/a | Py_CLEAR(self->dict); |
---|
533 | n/a | } |
---|
534 | n/a | |
---|
535 | n/a | static int |
---|
536 | n/a | ast_type_init(PyObject *self, PyObject *args, PyObject *kw) |
---|
537 | n/a | { |
---|
538 | n/a | Py_ssize_t i, numfields = 0; |
---|
539 | n/a | int res = -1; |
---|
540 | n/a | PyObject *key, *value, *fields; |
---|
541 | n/a | fields = _PyObject_GetAttrId((PyObject*)Py_TYPE(self), &PyId__fields); |
---|
542 | n/a | if (!fields) |
---|
543 | n/a | PyErr_Clear(); |
---|
544 | n/a | if (fields) { |
---|
545 | n/a | numfields = PySequence_Size(fields); |
---|
546 | n/a | if (numfields == -1) |
---|
547 | n/a | goto cleanup; |
---|
548 | n/a | } |
---|
549 | n/a | res = 0; /* if no error occurs, this stays 0 to the end */ |
---|
550 | n/a | if (PyTuple_GET_SIZE(args) > 0) { |
---|
551 | n/a | if (numfields != PyTuple_GET_SIZE(args)) { |
---|
552 | n/a | PyErr_Format(PyExc_TypeError, "%.400s constructor takes %s" |
---|
553 | n/a | "%zd positional argument%s", |
---|
554 | n/a | Py_TYPE(self)->tp_name, |
---|
555 | n/a | numfields == 0 ? "" : "either 0 or ", |
---|
556 | n/a | numfields, numfields == 1 ? "" : "s"); |
---|
557 | n/a | res = -1; |
---|
558 | n/a | goto cleanup; |
---|
559 | n/a | } |
---|
560 | n/a | for (i = 0; i < PyTuple_GET_SIZE(args); i++) { |
---|
561 | n/a | /* cannot be reached when fields is NULL */ |
---|
562 | n/a | PyObject *name = PySequence_GetItem(fields, i); |
---|
563 | n/a | if (!name) { |
---|
564 | n/a | res = -1; |
---|
565 | n/a | goto cleanup; |
---|
566 | n/a | } |
---|
567 | n/a | res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i)); |
---|
568 | n/a | Py_DECREF(name); |
---|
569 | n/a | if (res < 0) |
---|
570 | n/a | goto cleanup; |
---|
571 | n/a | } |
---|
572 | n/a | } |
---|
573 | n/a | if (kw) { |
---|
574 | n/a | i = 0; /* needed by PyDict_Next */ |
---|
575 | n/a | while (PyDict_Next(kw, &i, &key, &value)) { |
---|
576 | n/a | res = PyObject_SetAttr(self, key, value); |
---|
577 | n/a | if (res < 0) |
---|
578 | n/a | goto cleanup; |
---|
579 | n/a | } |
---|
580 | n/a | } |
---|
581 | n/a | cleanup: |
---|
582 | n/a | Py_XDECREF(fields); |
---|
583 | n/a | return res; |
---|
584 | n/a | } |
---|
585 | n/a | |
---|
586 | n/a | /* Pickling support */ |
---|
587 | n/a | static PyObject * |
---|
588 | n/a | ast_type_reduce(PyObject *self, PyObject *unused) |
---|
589 | n/a | { |
---|
590 | n/a | PyObject *res; |
---|
591 | n/a | _Py_IDENTIFIER(__dict__); |
---|
592 | n/a | PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); |
---|
593 | n/a | if (dict == NULL) { |
---|
594 | n/a | if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
---|
595 | n/a | PyErr_Clear(); |
---|
596 | n/a | else |
---|
597 | n/a | return NULL; |
---|
598 | n/a | } |
---|
599 | n/a | if (dict) { |
---|
600 | n/a | res = Py_BuildValue("O()O", Py_TYPE(self), dict); |
---|
601 | n/a | Py_DECREF(dict); |
---|
602 | n/a | return res; |
---|
603 | n/a | } |
---|
604 | n/a | return Py_BuildValue("O()", Py_TYPE(self)); |
---|
605 | n/a | } |
---|
606 | n/a | |
---|
607 | n/a | static PyMethodDef ast_type_methods[] = { |
---|
608 | n/a | {"__reduce__", ast_type_reduce, METH_NOARGS, NULL}, |
---|
609 | n/a | {NULL} |
---|
610 | n/a | }; |
---|
611 | n/a | |
---|
612 | n/a | static PyGetSetDef ast_type_getsets[] = { |
---|
613 | n/a | {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict}, |
---|
614 | n/a | {NULL} |
---|
615 | n/a | }; |
---|
616 | n/a | |
---|
617 | n/a | static PyTypeObject AST_type = { |
---|
618 | n/a | PyVarObject_HEAD_INIT(&PyType_Type, 0) |
---|
619 | n/a | "_ast.AST", |
---|
620 | n/a | sizeof(AST_object), |
---|
621 | n/a | 0, |
---|
622 | n/a | (destructor)ast_dealloc, /* tp_dealloc */ |
---|
623 | n/a | 0, /* tp_print */ |
---|
624 | n/a | 0, /* tp_getattr */ |
---|
625 | n/a | 0, /* tp_setattr */ |
---|
626 | n/a | 0, /* tp_reserved */ |
---|
627 | n/a | 0, /* tp_repr */ |
---|
628 | n/a | 0, /* tp_as_number */ |
---|
629 | n/a | 0, /* tp_as_sequence */ |
---|
630 | n/a | 0, /* tp_as_mapping */ |
---|
631 | n/a | 0, /* tp_hash */ |
---|
632 | n/a | 0, /* tp_call */ |
---|
633 | n/a | 0, /* tp_str */ |
---|
634 | n/a | PyObject_GenericGetAttr, /* tp_getattro */ |
---|
635 | n/a | PyObject_GenericSetAttr, /* tp_setattro */ |
---|
636 | n/a | 0, /* tp_as_buffer */ |
---|
637 | n/a | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
---|
638 | n/a | 0, /* tp_doc */ |
---|
639 | n/a | (traverseproc)ast_traverse, /* tp_traverse */ |
---|
640 | n/a | (inquiry)ast_clear, /* tp_clear */ |
---|
641 | n/a | 0, /* tp_richcompare */ |
---|
642 | n/a | 0, /* tp_weaklistoffset */ |
---|
643 | n/a | 0, /* tp_iter */ |
---|
644 | n/a | 0, /* tp_iternext */ |
---|
645 | n/a | ast_type_methods, /* tp_methods */ |
---|
646 | n/a | 0, /* tp_members */ |
---|
647 | n/a | ast_type_getsets, /* tp_getset */ |
---|
648 | n/a | 0, /* tp_base */ |
---|
649 | n/a | 0, /* tp_dict */ |
---|
650 | n/a | 0, /* tp_descr_get */ |
---|
651 | n/a | 0, /* tp_descr_set */ |
---|
652 | n/a | offsetof(AST_object, dict),/* tp_dictoffset */ |
---|
653 | n/a | (initproc)ast_type_init, /* tp_init */ |
---|
654 | n/a | PyType_GenericAlloc, /* tp_alloc */ |
---|
655 | n/a | PyType_GenericNew, /* tp_new */ |
---|
656 | n/a | PyObject_GC_Del, /* tp_free */ |
---|
657 | n/a | }; |
---|
658 | n/a | |
---|
659 | n/a | |
---|
660 | n/a | static PyTypeObject* make_type(char *type, PyTypeObject* base, char**fields, int num_fields) |
---|
661 | n/a | { |
---|
662 | n/a | _Py_IDENTIFIER(__module__); |
---|
663 | n/a | _Py_IDENTIFIER(_ast); |
---|
664 | n/a | PyObject *fnames, *result; |
---|
665 | n/a | int i; |
---|
666 | n/a | fnames = PyTuple_New(num_fields); |
---|
667 | n/a | if (!fnames) return NULL; |
---|
668 | n/a | for (i = 0; i < num_fields; i++) { |
---|
669 | n/a | PyObject *field = PyUnicode_FromString(fields[i]); |
---|
670 | n/a | if (!field) { |
---|
671 | n/a | Py_DECREF(fnames); |
---|
672 | n/a | return NULL; |
---|
673 | n/a | } |
---|
674 | n/a | PyTuple_SET_ITEM(fnames, i, field); |
---|
675 | n/a | } |
---|
676 | n/a | result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}", |
---|
677 | n/a | type, base, |
---|
678 | n/a | _PyUnicode_FromId(&PyId__fields), fnames, |
---|
679 | n/a | _PyUnicode_FromId(&PyId___module__), |
---|
680 | n/a | _PyUnicode_FromId(&PyId__ast)); |
---|
681 | n/a | Py_DECREF(fnames); |
---|
682 | n/a | return (PyTypeObject*)result; |
---|
683 | n/a | } |
---|
684 | n/a | |
---|
685 | n/a | static int add_attributes(PyTypeObject* type, char**attrs, int num_fields) |
---|
686 | n/a | { |
---|
687 | n/a | int i, result; |
---|
688 | n/a | PyObject *s, *l = PyTuple_New(num_fields); |
---|
689 | n/a | if (!l) |
---|
690 | n/a | return 0; |
---|
691 | n/a | for (i = 0; i < num_fields; i++) { |
---|
692 | n/a | s = PyUnicode_FromString(attrs[i]); |
---|
693 | n/a | if (!s) { |
---|
694 | n/a | Py_DECREF(l); |
---|
695 | n/a | return 0; |
---|
696 | n/a | } |
---|
697 | n/a | PyTuple_SET_ITEM(l, i, s); |
---|
698 | n/a | } |
---|
699 | n/a | result = _PyObject_SetAttrId((PyObject*)type, &PyId__attributes, l) >= 0; |
---|
700 | n/a | Py_DECREF(l); |
---|
701 | n/a | return result; |
---|
702 | n/a | } |
---|
703 | n/a | |
---|
704 | n/a | /* Conversion AST -> Python */ |
---|
705 | n/a | |
---|
706 | n/a | static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*)) |
---|
707 | n/a | { |
---|
708 | n/a | Py_ssize_t i, n = asdl_seq_LEN(seq); |
---|
709 | n/a | PyObject *result = PyList_New(n); |
---|
710 | n/a | PyObject *value; |
---|
711 | n/a | if (!result) |
---|
712 | n/a | return NULL; |
---|
713 | n/a | for (i = 0; i < n; i++) { |
---|
714 | n/a | value = func(asdl_seq_GET(seq, i)); |
---|
715 | n/a | if (!value) { |
---|
716 | n/a | Py_DECREF(result); |
---|
717 | n/a | return NULL; |
---|
718 | n/a | } |
---|
719 | n/a | PyList_SET_ITEM(result, i, value); |
---|
720 | n/a | } |
---|
721 | n/a | return result; |
---|
722 | n/a | } |
---|
723 | n/a | |
---|
724 | n/a | static PyObject* ast2obj_object(void *o) |
---|
725 | n/a | { |
---|
726 | n/a | if (!o) |
---|
727 | n/a | o = Py_None; |
---|
728 | n/a | Py_INCREF((PyObject*)o); |
---|
729 | n/a | return (PyObject*)o; |
---|
730 | n/a | } |
---|
731 | n/a | #define ast2obj_singleton ast2obj_object |
---|
732 | n/a | #define ast2obj_constant ast2obj_object |
---|
733 | n/a | #define ast2obj_identifier ast2obj_object |
---|
734 | n/a | #define ast2obj_string ast2obj_object |
---|
735 | n/a | #define ast2obj_bytes ast2obj_object |
---|
736 | n/a | |
---|
737 | n/a | static PyObject* ast2obj_int(long b) |
---|
738 | n/a | { |
---|
739 | n/a | return PyLong_FromLong(b); |
---|
740 | n/a | } |
---|
741 | n/a | |
---|
742 | n/a | /* Conversion Python -> AST */ |
---|
743 | n/a | |
---|
744 | n/a | static int obj2ast_singleton(PyObject *obj, PyObject** out, PyArena* arena) |
---|
745 | n/a | { |
---|
746 | n/a | if (obj != Py_None && obj != Py_True && obj != Py_False) { |
---|
747 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
748 | n/a | "AST singleton must be True, False, or None"); |
---|
749 | n/a | return 1; |
---|
750 | n/a | } |
---|
751 | n/a | *out = obj; |
---|
752 | n/a | return 0; |
---|
753 | n/a | } |
---|
754 | n/a | |
---|
755 | n/a | static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena) |
---|
756 | n/a | { |
---|
757 | n/a | if (obj == Py_None) |
---|
758 | n/a | obj = NULL; |
---|
759 | n/a | if (obj) { |
---|
760 | n/a | if (PyArena_AddPyObject(arena, obj) < 0) { |
---|
761 | n/a | *out = NULL; |
---|
762 | n/a | return -1; |
---|
763 | n/a | } |
---|
764 | n/a | Py_INCREF(obj); |
---|
765 | n/a | } |
---|
766 | n/a | *out = obj; |
---|
767 | n/a | return 0; |
---|
768 | n/a | } |
---|
769 | n/a | |
---|
770 | n/a | static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena) |
---|
771 | n/a | { |
---|
772 | n/a | if (obj) { |
---|
773 | n/a | if (PyArena_AddPyObject(arena, obj) < 0) { |
---|
774 | n/a | *out = NULL; |
---|
775 | n/a | return -1; |
---|
776 | n/a | } |
---|
777 | n/a | Py_INCREF(obj); |
---|
778 | n/a | } |
---|
779 | n/a | *out = obj; |
---|
780 | n/a | return 0; |
---|
781 | n/a | } |
---|
782 | n/a | |
---|
783 | n/a | static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena) |
---|
784 | n/a | { |
---|
785 | n/a | if (!PyUnicode_CheckExact(obj) && obj != Py_None) { |
---|
786 | n/a | PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str"); |
---|
787 | n/a | return 1; |
---|
788 | n/a | } |
---|
789 | n/a | return obj2ast_object(obj, out, arena); |
---|
790 | n/a | } |
---|
791 | n/a | |
---|
792 | n/a | static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena) |
---|
793 | n/a | { |
---|
794 | n/a | if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) { |
---|
795 | n/a | PyErr_SetString(PyExc_TypeError, "AST string must be of type str"); |
---|
796 | n/a | return 1; |
---|
797 | n/a | } |
---|
798 | n/a | return obj2ast_object(obj, out, arena); |
---|
799 | n/a | } |
---|
800 | n/a | |
---|
801 | n/a | static int obj2ast_bytes(PyObject* obj, PyObject** out, PyArena* arena) |
---|
802 | n/a | { |
---|
803 | n/a | if (!PyBytes_CheckExact(obj)) { |
---|
804 | n/a | PyErr_SetString(PyExc_TypeError, "AST bytes must be of type bytes"); |
---|
805 | n/a | return 1; |
---|
806 | n/a | } |
---|
807 | n/a | return obj2ast_object(obj, out, arena); |
---|
808 | n/a | } |
---|
809 | n/a | |
---|
810 | n/a | static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) |
---|
811 | n/a | { |
---|
812 | n/a | int i; |
---|
813 | n/a | if (!PyLong_Check(obj)) { |
---|
814 | n/a | PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); |
---|
815 | n/a | return 1; |
---|
816 | n/a | } |
---|
817 | n/a | |
---|
818 | n/a | i = _PyLong_AsInt(obj); |
---|
819 | n/a | if (i == -1 && PyErr_Occurred()) |
---|
820 | n/a | return 1; |
---|
821 | n/a | *out = i; |
---|
822 | n/a | return 0; |
---|
823 | n/a | } |
---|
824 | n/a | |
---|
825 | n/a | static int add_ast_fields(void) |
---|
826 | n/a | { |
---|
827 | n/a | PyObject *empty_tuple, *d; |
---|
828 | n/a | if (PyType_Ready(&AST_type) < 0) |
---|
829 | n/a | return -1; |
---|
830 | n/a | d = AST_type.tp_dict; |
---|
831 | n/a | empty_tuple = PyTuple_New(0); |
---|
832 | n/a | if (!empty_tuple || |
---|
833 | n/a | _PyDict_SetItemId(d, &PyId__fields, empty_tuple) < 0 || |
---|
834 | n/a | _PyDict_SetItemId(d, &PyId__attributes, empty_tuple) < 0) { |
---|
835 | n/a | Py_XDECREF(empty_tuple); |
---|
836 | n/a | return -1; |
---|
837 | n/a | } |
---|
838 | n/a | Py_DECREF(empty_tuple); |
---|
839 | n/a | return 0; |
---|
840 | n/a | } |
---|
841 | n/a | |
---|
842 | n/a | static int exists_not_none(PyObject *obj, _Py_Identifier *id) |
---|
843 | n/a | { |
---|
844 | n/a | int isnone; |
---|
845 | n/a | PyObject *attr = _PyObject_GetAttrId(obj, id); |
---|
846 | n/a | if (!attr) { |
---|
847 | n/a | PyErr_Clear(); |
---|
848 | n/a | return 0; |
---|
849 | n/a | } |
---|
850 | n/a | isnone = attr == Py_None; |
---|
851 | n/a | Py_DECREF(attr); |
---|
852 | n/a | return !isnone; |
---|
853 | n/a | } |
---|
854 | n/a | |
---|
855 | n/a | |
---|
856 | n/a | static int init_types(void) |
---|
857 | n/a | { |
---|
858 | n/a | static int initialized; |
---|
859 | n/a | if (initialized) return 1; |
---|
860 | n/a | if (add_ast_fields() < 0) return 0; |
---|
861 | n/a | mod_type = make_type("mod", &AST_type, NULL, 0); |
---|
862 | n/a | if (!mod_type) return 0; |
---|
863 | n/a | if (!add_attributes(mod_type, NULL, 0)) return 0; |
---|
864 | n/a | Module_type = make_type("Module", mod_type, Module_fields, 1); |
---|
865 | n/a | if (!Module_type) return 0; |
---|
866 | n/a | Interactive_type = make_type("Interactive", mod_type, Interactive_fields, |
---|
867 | n/a | 1); |
---|
868 | n/a | if (!Interactive_type) return 0; |
---|
869 | n/a | Expression_type = make_type("Expression", mod_type, Expression_fields, 1); |
---|
870 | n/a | if (!Expression_type) return 0; |
---|
871 | n/a | Suite_type = make_type("Suite", mod_type, Suite_fields, 1); |
---|
872 | n/a | if (!Suite_type) return 0; |
---|
873 | n/a | stmt_type = make_type("stmt", &AST_type, NULL, 0); |
---|
874 | n/a | if (!stmt_type) return 0; |
---|
875 | n/a | if (!add_attributes(stmt_type, stmt_attributes, 2)) return 0; |
---|
876 | n/a | FunctionDef_type = make_type("FunctionDef", stmt_type, FunctionDef_fields, |
---|
877 | n/a | 5); |
---|
878 | n/a | if (!FunctionDef_type) return 0; |
---|
879 | n/a | AsyncFunctionDef_type = make_type("AsyncFunctionDef", stmt_type, |
---|
880 | n/a | AsyncFunctionDef_fields, 5); |
---|
881 | n/a | if (!AsyncFunctionDef_type) return 0; |
---|
882 | n/a | ClassDef_type = make_type("ClassDef", stmt_type, ClassDef_fields, 5); |
---|
883 | n/a | if (!ClassDef_type) return 0; |
---|
884 | n/a | Return_type = make_type("Return", stmt_type, Return_fields, 1); |
---|
885 | n/a | if (!Return_type) return 0; |
---|
886 | n/a | Delete_type = make_type("Delete", stmt_type, Delete_fields, 1); |
---|
887 | n/a | if (!Delete_type) return 0; |
---|
888 | n/a | Assign_type = make_type("Assign", stmt_type, Assign_fields, 2); |
---|
889 | n/a | if (!Assign_type) return 0; |
---|
890 | n/a | AugAssign_type = make_type("AugAssign", stmt_type, AugAssign_fields, 3); |
---|
891 | n/a | if (!AugAssign_type) return 0; |
---|
892 | n/a | AnnAssign_type = make_type("AnnAssign", stmt_type, AnnAssign_fields, 4); |
---|
893 | n/a | if (!AnnAssign_type) return 0; |
---|
894 | n/a | For_type = make_type("For", stmt_type, For_fields, 4); |
---|
895 | n/a | if (!For_type) return 0; |
---|
896 | n/a | AsyncFor_type = make_type("AsyncFor", stmt_type, AsyncFor_fields, 4); |
---|
897 | n/a | if (!AsyncFor_type) return 0; |
---|
898 | n/a | While_type = make_type("While", stmt_type, While_fields, 3); |
---|
899 | n/a | if (!While_type) return 0; |
---|
900 | n/a | If_type = make_type("If", stmt_type, If_fields, 3); |
---|
901 | n/a | if (!If_type) return 0; |
---|
902 | n/a | With_type = make_type("With", stmt_type, With_fields, 2); |
---|
903 | n/a | if (!With_type) return 0; |
---|
904 | n/a | AsyncWith_type = make_type("AsyncWith", stmt_type, AsyncWith_fields, 2); |
---|
905 | n/a | if (!AsyncWith_type) return 0; |
---|
906 | n/a | Raise_type = make_type("Raise", stmt_type, Raise_fields, 2); |
---|
907 | n/a | if (!Raise_type) return 0; |
---|
908 | n/a | Try_type = make_type("Try", stmt_type, Try_fields, 4); |
---|
909 | n/a | if (!Try_type) return 0; |
---|
910 | n/a | Assert_type = make_type("Assert", stmt_type, Assert_fields, 2); |
---|
911 | n/a | if (!Assert_type) return 0; |
---|
912 | n/a | Import_type = make_type("Import", stmt_type, Import_fields, 1); |
---|
913 | n/a | if (!Import_type) return 0; |
---|
914 | n/a | ImportFrom_type = make_type("ImportFrom", stmt_type, ImportFrom_fields, 3); |
---|
915 | n/a | if (!ImportFrom_type) return 0; |
---|
916 | n/a | Global_type = make_type("Global", stmt_type, Global_fields, 1); |
---|
917 | n/a | if (!Global_type) return 0; |
---|
918 | n/a | Nonlocal_type = make_type("Nonlocal", stmt_type, Nonlocal_fields, 1); |
---|
919 | n/a | if (!Nonlocal_type) return 0; |
---|
920 | n/a | Expr_type = make_type("Expr", stmt_type, Expr_fields, 1); |
---|
921 | n/a | if (!Expr_type) return 0; |
---|
922 | n/a | Pass_type = make_type("Pass", stmt_type, NULL, 0); |
---|
923 | n/a | if (!Pass_type) return 0; |
---|
924 | n/a | Break_type = make_type("Break", stmt_type, NULL, 0); |
---|
925 | n/a | if (!Break_type) return 0; |
---|
926 | n/a | Continue_type = make_type("Continue", stmt_type, NULL, 0); |
---|
927 | n/a | if (!Continue_type) return 0; |
---|
928 | n/a | expr_type = make_type("expr", &AST_type, NULL, 0); |
---|
929 | n/a | if (!expr_type) return 0; |
---|
930 | n/a | if (!add_attributes(expr_type, expr_attributes, 2)) return 0; |
---|
931 | n/a | BoolOp_type = make_type("BoolOp", expr_type, BoolOp_fields, 2); |
---|
932 | n/a | if (!BoolOp_type) return 0; |
---|
933 | n/a | BinOp_type = make_type("BinOp", expr_type, BinOp_fields, 3); |
---|
934 | n/a | if (!BinOp_type) return 0; |
---|
935 | n/a | UnaryOp_type = make_type("UnaryOp", expr_type, UnaryOp_fields, 2); |
---|
936 | n/a | if (!UnaryOp_type) return 0; |
---|
937 | n/a | Lambda_type = make_type("Lambda", expr_type, Lambda_fields, 2); |
---|
938 | n/a | if (!Lambda_type) return 0; |
---|
939 | n/a | IfExp_type = make_type("IfExp", expr_type, IfExp_fields, 3); |
---|
940 | n/a | if (!IfExp_type) return 0; |
---|
941 | n/a | Dict_type = make_type("Dict", expr_type, Dict_fields, 2); |
---|
942 | n/a | if (!Dict_type) return 0; |
---|
943 | n/a | Set_type = make_type("Set", expr_type, Set_fields, 1); |
---|
944 | n/a | if (!Set_type) return 0; |
---|
945 | n/a | ListComp_type = make_type("ListComp", expr_type, ListComp_fields, 2); |
---|
946 | n/a | if (!ListComp_type) return 0; |
---|
947 | n/a | SetComp_type = make_type("SetComp", expr_type, SetComp_fields, 2); |
---|
948 | n/a | if (!SetComp_type) return 0; |
---|
949 | n/a | DictComp_type = make_type("DictComp", expr_type, DictComp_fields, 3); |
---|
950 | n/a | if (!DictComp_type) return 0; |
---|
951 | n/a | GeneratorExp_type = make_type("GeneratorExp", expr_type, |
---|
952 | n/a | GeneratorExp_fields, 2); |
---|
953 | n/a | if (!GeneratorExp_type) return 0; |
---|
954 | n/a | Await_type = make_type("Await", expr_type, Await_fields, 1); |
---|
955 | n/a | if (!Await_type) return 0; |
---|
956 | n/a | Yield_type = make_type("Yield", expr_type, Yield_fields, 1); |
---|
957 | n/a | if (!Yield_type) return 0; |
---|
958 | n/a | YieldFrom_type = make_type("YieldFrom", expr_type, YieldFrom_fields, 1); |
---|
959 | n/a | if (!YieldFrom_type) return 0; |
---|
960 | n/a | Compare_type = make_type("Compare", expr_type, Compare_fields, 3); |
---|
961 | n/a | if (!Compare_type) return 0; |
---|
962 | n/a | Call_type = make_type("Call", expr_type, Call_fields, 3); |
---|
963 | n/a | if (!Call_type) return 0; |
---|
964 | n/a | Num_type = make_type("Num", expr_type, Num_fields, 1); |
---|
965 | n/a | if (!Num_type) return 0; |
---|
966 | n/a | Str_type = make_type("Str", expr_type, Str_fields, 1); |
---|
967 | n/a | if (!Str_type) return 0; |
---|
968 | n/a | FormattedValue_type = make_type("FormattedValue", expr_type, |
---|
969 | n/a | FormattedValue_fields, 3); |
---|
970 | n/a | if (!FormattedValue_type) return 0; |
---|
971 | n/a | JoinedStr_type = make_type("JoinedStr", expr_type, JoinedStr_fields, 1); |
---|
972 | n/a | if (!JoinedStr_type) return 0; |
---|
973 | n/a | Bytes_type = make_type("Bytes", expr_type, Bytes_fields, 1); |
---|
974 | n/a | if (!Bytes_type) return 0; |
---|
975 | n/a | NameConstant_type = make_type("NameConstant", expr_type, |
---|
976 | n/a | NameConstant_fields, 1); |
---|
977 | n/a | if (!NameConstant_type) return 0; |
---|
978 | n/a | Ellipsis_type = make_type("Ellipsis", expr_type, NULL, 0); |
---|
979 | n/a | if (!Ellipsis_type) return 0; |
---|
980 | n/a | Constant_type = make_type("Constant", expr_type, Constant_fields, 1); |
---|
981 | n/a | if (!Constant_type) return 0; |
---|
982 | n/a | Attribute_type = make_type("Attribute", expr_type, Attribute_fields, 3); |
---|
983 | n/a | if (!Attribute_type) return 0; |
---|
984 | n/a | Subscript_type = make_type("Subscript", expr_type, Subscript_fields, 3); |
---|
985 | n/a | if (!Subscript_type) return 0; |
---|
986 | n/a | Starred_type = make_type("Starred", expr_type, Starred_fields, 2); |
---|
987 | n/a | if (!Starred_type) return 0; |
---|
988 | n/a | Name_type = make_type("Name", expr_type, Name_fields, 2); |
---|
989 | n/a | if (!Name_type) return 0; |
---|
990 | n/a | List_type = make_type("List", expr_type, List_fields, 2); |
---|
991 | n/a | if (!List_type) return 0; |
---|
992 | n/a | Tuple_type = make_type("Tuple", expr_type, Tuple_fields, 2); |
---|
993 | n/a | if (!Tuple_type) return 0; |
---|
994 | n/a | expr_context_type = make_type("expr_context", &AST_type, NULL, 0); |
---|
995 | n/a | if (!expr_context_type) return 0; |
---|
996 | n/a | if (!add_attributes(expr_context_type, NULL, 0)) return 0; |
---|
997 | n/a | Load_type = make_type("Load", expr_context_type, NULL, 0); |
---|
998 | n/a | if (!Load_type) return 0; |
---|
999 | n/a | Load_singleton = PyType_GenericNew(Load_type, NULL, NULL); |
---|
1000 | n/a | if (!Load_singleton) return 0; |
---|
1001 | n/a | Store_type = make_type("Store", expr_context_type, NULL, 0); |
---|
1002 | n/a | if (!Store_type) return 0; |
---|
1003 | n/a | Store_singleton = PyType_GenericNew(Store_type, NULL, NULL); |
---|
1004 | n/a | if (!Store_singleton) return 0; |
---|
1005 | n/a | Del_type = make_type("Del", expr_context_type, NULL, 0); |
---|
1006 | n/a | if (!Del_type) return 0; |
---|
1007 | n/a | Del_singleton = PyType_GenericNew(Del_type, NULL, NULL); |
---|
1008 | n/a | if (!Del_singleton) return 0; |
---|
1009 | n/a | AugLoad_type = make_type("AugLoad", expr_context_type, NULL, 0); |
---|
1010 | n/a | if (!AugLoad_type) return 0; |
---|
1011 | n/a | AugLoad_singleton = PyType_GenericNew(AugLoad_type, NULL, NULL); |
---|
1012 | n/a | if (!AugLoad_singleton) return 0; |
---|
1013 | n/a | AugStore_type = make_type("AugStore", expr_context_type, NULL, 0); |
---|
1014 | n/a | if (!AugStore_type) return 0; |
---|
1015 | n/a | AugStore_singleton = PyType_GenericNew(AugStore_type, NULL, NULL); |
---|
1016 | n/a | if (!AugStore_singleton) return 0; |
---|
1017 | n/a | Param_type = make_type("Param", expr_context_type, NULL, 0); |
---|
1018 | n/a | if (!Param_type) return 0; |
---|
1019 | n/a | Param_singleton = PyType_GenericNew(Param_type, NULL, NULL); |
---|
1020 | n/a | if (!Param_singleton) return 0; |
---|
1021 | n/a | slice_type = make_type("slice", &AST_type, NULL, 0); |
---|
1022 | n/a | if (!slice_type) return 0; |
---|
1023 | n/a | if (!add_attributes(slice_type, NULL, 0)) return 0; |
---|
1024 | n/a | Slice_type = make_type("Slice", slice_type, Slice_fields, 3); |
---|
1025 | n/a | if (!Slice_type) return 0; |
---|
1026 | n/a | ExtSlice_type = make_type("ExtSlice", slice_type, ExtSlice_fields, 1); |
---|
1027 | n/a | if (!ExtSlice_type) return 0; |
---|
1028 | n/a | Index_type = make_type("Index", slice_type, Index_fields, 1); |
---|
1029 | n/a | if (!Index_type) return 0; |
---|
1030 | n/a | boolop_type = make_type("boolop", &AST_type, NULL, 0); |
---|
1031 | n/a | if (!boolop_type) return 0; |
---|
1032 | n/a | if (!add_attributes(boolop_type, NULL, 0)) return 0; |
---|
1033 | n/a | And_type = make_type("And", boolop_type, NULL, 0); |
---|
1034 | n/a | if (!And_type) return 0; |
---|
1035 | n/a | And_singleton = PyType_GenericNew(And_type, NULL, NULL); |
---|
1036 | n/a | if (!And_singleton) return 0; |
---|
1037 | n/a | Or_type = make_type("Or", boolop_type, NULL, 0); |
---|
1038 | n/a | if (!Or_type) return 0; |
---|
1039 | n/a | Or_singleton = PyType_GenericNew(Or_type, NULL, NULL); |
---|
1040 | n/a | if (!Or_singleton) return 0; |
---|
1041 | n/a | operator_type = make_type("operator", &AST_type, NULL, 0); |
---|
1042 | n/a | if (!operator_type) return 0; |
---|
1043 | n/a | if (!add_attributes(operator_type, NULL, 0)) return 0; |
---|
1044 | n/a | Add_type = make_type("Add", operator_type, NULL, 0); |
---|
1045 | n/a | if (!Add_type) return 0; |
---|
1046 | n/a | Add_singleton = PyType_GenericNew(Add_type, NULL, NULL); |
---|
1047 | n/a | if (!Add_singleton) return 0; |
---|
1048 | n/a | Sub_type = make_type("Sub", operator_type, NULL, 0); |
---|
1049 | n/a | if (!Sub_type) return 0; |
---|
1050 | n/a | Sub_singleton = PyType_GenericNew(Sub_type, NULL, NULL); |
---|
1051 | n/a | if (!Sub_singleton) return 0; |
---|
1052 | n/a | Mult_type = make_type("Mult", operator_type, NULL, 0); |
---|
1053 | n/a | if (!Mult_type) return 0; |
---|
1054 | n/a | Mult_singleton = PyType_GenericNew(Mult_type, NULL, NULL); |
---|
1055 | n/a | if (!Mult_singleton) return 0; |
---|
1056 | n/a | MatMult_type = make_type("MatMult", operator_type, NULL, 0); |
---|
1057 | n/a | if (!MatMult_type) return 0; |
---|
1058 | n/a | MatMult_singleton = PyType_GenericNew(MatMult_type, NULL, NULL); |
---|
1059 | n/a | if (!MatMult_singleton) return 0; |
---|
1060 | n/a | Div_type = make_type("Div", operator_type, NULL, 0); |
---|
1061 | n/a | if (!Div_type) return 0; |
---|
1062 | n/a | Div_singleton = PyType_GenericNew(Div_type, NULL, NULL); |
---|
1063 | n/a | if (!Div_singleton) return 0; |
---|
1064 | n/a | Mod_type = make_type("Mod", operator_type, NULL, 0); |
---|
1065 | n/a | if (!Mod_type) return 0; |
---|
1066 | n/a | Mod_singleton = PyType_GenericNew(Mod_type, NULL, NULL); |
---|
1067 | n/a | if (!Mod_singleton) return 0; |
---|
1068 | n/a | Pow_type = make_type("Pow", operator_type, NULL, 0); |
---|
1069 | n/a | if (!Pow_type) return 0; |
---|
1070 | n/a | Pow_singleton = PyType_GenericNew(Pow_type, NULL, NULL); |
---|
1071 | n/a | if (!Pow_singleton) return 0; |
---|
1072 | n/a | LShift_type = make_type("LShift", operator_type, NULL, 0); |
---|
1073 | n/a | if (!LShift_type) return 0; |
---|
1074 | n/a | LShift_singleton = PyType_GenericNew(LShift_type, NULL, NULL); |
---|
1075 | n/a | if (!LShift_singleton) return 0; |
---|
1076 | n/a | RShift_type = make_type("RShift", operator_type, NULL, 0); |
---|
1077 | n/a | if (!RShift_type) return 0; |
---|
1078 | n/a | RShift_singleton = PyType_GenericNew(RShift_type, NULL, NULL); |
---|
1079 | n/a | if (!RShift_singleton) return 0; |
---|
1080 | n/a | BitOr_type = make_type("BitOr", operator_type, NULL, 0); |
---|
1081 | n/a | if (!BitOr_type) return 0; |
---|
1082 | n/a | BitOr_singleton = PyType_GenericNew(BitOr_type, NULL, NULL); |
---|
1083 | n/a | if (!BitOr_singleton) return 0; |
---|
1084 | n/a | BitXor_type = make_type("BitXor", operator_type, NULL, 0); |
---|
1085 | n/a | if (!BitXor_type) return 0; |
---|
1086 | n/a | BitXor_singleton = PyType_GenericNew(BitXor_type, NULL, NULL); |
---|
1087 | n/a | if (!BitXor_singleton) return 0; |
---|
1088 | n/a | BitAnd_type = make_type("BitAnd", operator_type, NULL, 0); |
---|
1089 | n/a | if (!BitAnd_type) return 0; |
---|
1090 | n/a | BitAnd_singleton = PyType_GenericNew(BitAnd_type, NULL, NULL); |
---|
1091 | n/a | if (!BitAnd_singleton) return 0; |
---|
1092 | n/a | FloorDiv_type = make_type("FloorDiv", operator_type, NULL, 0); |
---|
1093 | n/a | if (!FloorDiv_type) return 0; |
---|
1094 | n/a | FloorDiv_singleton = PyType_GenericNew(FloorDiv_type, NULL, NULL); |
---|
1095 | n/a | if (!FloorDiv_singleton) return 0; |
---|
1096 | n/a | unaryop_type = make_type("unaryop", &AST_type, NULL, 0); |
---|
1097 | n/a | if (!unaryop_type) return 0; |
---|
1098 | n/a | if (!add_attributes(unaryop_type, NULL, 0)) return 0; |
---|
1099 | n/a | Invert_type = make_type("Invert", unaryop_type, NULL, 0); |
---|
1100 | n/a | if (!Invert_type) return 0; |
---|
1101 | n/a | Invert_singleton = PyType_GenericNew(Invert_type, NULL, NULL); |
---|
1102 | n/a | if (!Invert_singleton) return 0; |
---|
1103 | n/a | Not_type = make_type("Not", unaryop_type, NULL, 0); |
---|
1104 | n/a | if (!Not_type) return 0; |
---|
1105 | n/a | Not_singleton = PyType_GenericNew(Not_type, NULL, NULL); |
---|
1106 | n/a | if (!Not_singleton) return 0; |
---|
1107 | n/a | UAdd_type = make_type("UAdd", unaryop_type, NULL, 0); |
---|
1108 | n/a | if (!UAdd_type) return 0; |
---|
1109 | n/a | UAdd_singleton = PyType_GenericNew(UAdd_type, NULL, NULL); |
---|
1110 | n/a | if (!UAdd_singleton) return 0; |
---|
1111 | n/a | USub_type = make_type("USub", unaryop_type, NULL, 0); |
---|
1112 | n/a | if (!USub_type) return 0; |
---|
1113 | n/a | USub_singleton = PyType_GenericNew(USub_type, NULL, NULL); |
---|
1114 | n/a | if (!USub_singleton) return 0; |
---|
1115 | n/a | cmpop_type = make_type("cmpop", &AST_type, NULL, 0); |
---|
1116 | n/a | if (!cmpop_type) return 0; |
---|
1117 | n/a | if (!add_attributes(cmpop_type, NULL, 0)) return 0; |
---|
1118 | n/a | Eq_type = make_type("Eq", cmpop_type, NULL, 0); |
---|
1119 | n/a | if (!Eq_type) return 0; |
---|
1120 | n/a | Eq_singleton = PyType_GenericNew(Eq_type, NULL, NULL); |
---|
1121 | n/a | if (!Eq_singleton) return 0; |
---|
1122 | n/a | NotEq_type = make_type("NotEq", cmpop_type, NULL, 0); |
---|
1123 | n/a | if (!NotEq_type) return 0; |
---|
1124 | n/a | NotEq_singleton = PyType_GenericNew(NotEq_type, NULL, NULL); |
---|
1125 | n/a | if (!NotEq_singleton) return 0; |
---|
1126 | n/a | Lt_type = make_type("Lt", cmpop_type, NULL, 0); |
---|
1127 | n/a | if (!Lt_type) return 0; |
---|
1128 | n/a | Lt_singleton = PyType_GenericNew(Lt_type, NULL, NULL); |
---|
1129 | n/a | if (!Lt_singleton) return 0; |
---|
1130 | n/a | LtE_type = make_type("LtE", cmpop_type, NULL, 0); |
---|
1131 | n/a | if (!LtE_type) return 0; |
---|
1132 | n/a | LtE_singleton = PyType_GenericNew(LtE_type, NULL, NULL); |
---|
1133 | n/a | if (!LtE_singleton) return 0; |
---|
1134 | n/a | Gt_type = make_type("Gt", cmpop_type, NULL, 0); |
---|
1135 | n/a | if (!Gt_type) return 0; |
---|
1136 | n/a | Gt_singleton = PyType_GenericNew(Gt_type, NULL, NULL); |
---|
1137 | n/a | if (!Gt_singleton) return 0; |
---|
1138 | n/a | GtE_type = make_type("GtE", cmpop_type, NULL, 0); |
---|
1139 | n/a | if (!GtE_type) return 0; |
---|
1140 | n/a | GtE_singleton = PyType_GenericNew(GtE_type, NULL, NULL); |
---|
1141 | n/a | if (!GtE_singleton) return 0; |
---|
1142 | n/a | Is_type = make_type("Is", cmpop_type, NULL, 0); |
---|
1143 | n/a | if (!Is_type) return 0; |
---|
1144 | n/a | Is_singleton = PyType_GenericNew(Is_type, NULL, NULL); |
---|
1145 | n/a | if (!Is_singleton) return 0; |
---|
1146 | n/a | IsNot_type = make_type("IsNot", cmpop_type, NULL, 0); |
---|
1147 | n/a | if (!IsNot_type) return 0; |
---|
1148 | n/a | IsNot_singleton = PyType_GenericNew(IsNot_type, NULL, NULL); |
---|
1149 | n/a | if (!IsNot_singleton) return 0; |
---|
1150 | n/a | In_type = make_type("In", cmpop_type, NULL, 0); |
---|
1151 | n/a | if (!In_type) return 0; |
---|
1152 | n/a | In_singleton = PyType_GenericNew(In_type, NULL, NULL); |
---|
1153 | n/a | if (!In_singleton) return 0; |
---|
1154 | n/a | NotIn_type = make_type("NotIn", cmpop_type, NULL, 0); |
---|
1155 | n/a | if (!NotIn_type) return 0; |
---|
1156 | n/a | NotIn_singleton = PyType_GenericNew(NotIn_type, NULL, NULL); |
---|
1157 | n/a | if (!NotIn_singleton) return 0; |
---|
1158 | n/a | comprehension_type = make_type("comprehension", &AST_type, |
---|
1159 | n/a | comprehension_fields, 4); |
---|
1160 | n/a | if (!comprehension_type) return 0; |
---|
1161 | n/a | if (!add_attributes(comprehension_type, NULL, 0)) return 0; |
---|
1162 | n/a | excepthandler_type = make_type("excepthandler", &AST_type, NULL, 0); |
---|
1163 | n/a | if (!excepthandler_type) return 0; |
---|
1164 | n/a | if (!add_attributes(excepthandler_type, excepthandler_attributes, 2)) |
---|
1165 | n/a | return 0; |
---|
1166 | n/a | ExceptHandler_type = make_type("ExceptHandler", excepthandler_type, |
---|
1167 | n/a | ExceptHandler_fields, 3); |
---|
1168 | n/a | if (!ExceptHandler_type) return 0; |
---|
1169 | n/a | arguments_type = make_type("arguments", &AST_type, arguments_fields, 6); |
---|
1170 | n/a | if (!arguments_type) return 0; |
---|
1171 | n/a | if (!add_attributes(arguments_type, NULL, 0)) return 0; |
---|
1172 | n/a | arg_type = make_type("arg", &AST_type, arg_fields, 2); |
---|
1173 | n/a | if (!arg_type) return 0; |
---|
1174 | n/a | if (!add_attributes(arg_type, arg_attributes, 2)) return 0; |
---|
1175 | n/a | keyword_type = make_type("keyword", &AST_type, keyword_fields, 2); |
---|
1176 | n/a | if (!keyword_type) return 0; |
---|
1177 | n/a | if (!add_attributes(keyword_type, NULL, 0)) return 0; |
---|
1178 | n/a | alias_type = make_type("alias", &AST_type, alias_fields, 2); |
---|
1179 | n/a | if (!alias_type) return 0; |
---|
1180 | n/a | if (!add_attributes(alias_type, NULL, 0)) return 0; |
---|
1181 | n/a | withitem_type = make_type("withitem", &AST_type, withitem_fields, 2); |
---|
1182 | n/a | if (!withitem_type) return 0; |
---|
1183 | n/a | if (!add_attributes(withitem_type, NULL, 0)) return 0; |
---|
1184 | n/a | initialized = 1; |
---|
1185 | n/a | return 1; |
---|
1186 | n/a | } |
---|
1187 | n/a | |
---|
1188 | n/a | static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena); |
---|
1189 | n/a | static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena); |
---|
1190 | n/a | static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena); |
---|
1191 | n/a | static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* |
---|
1192 | n/a | arena); |
---|
1193 | n/a | static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena); |
---|
1194 | n/a | static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena); |
---|
1195 | n/a | static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena); |
---|
1196 | n/a | static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena); |
---|
1197 | n/a | static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena); |
---|
1198 | n/a | static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* |
---|
1199 | n/a | arena); |
---|
1200 | n/a | static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* |
---|
1201 | n/a | arena); |
---|
1202 | n/a | static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena); |
---|
1203 | n/a | static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena); |
---|
1204 | n/a | static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena); |
---|
1205 | n/a | static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena); |
---|
1206 | n/a | static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena); |
---|
1207 | n/a | |
---|
1208 | n/a | mod_ty |
---|
1209 | n/a | Module(asdl_seq * body, PyArena *arena) |
---|
1210 | n/a | { |
---|
1211 | n/a | mod_ty p; |
---|
1212 | n/a | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1213 | n/a | if (!p) |
---|
1214 | n/a | return NULL; |
---|
1215 | n/a | p->kind = Module_kind; |
---|
1216 | n/a | p->v.Module.body = body; |
---|
1217 | n/a | return p; |
---|
1218 | n/a | } |
---|
1219 | n/a | |
---|
1220 | n/a | mod_ty |
---|
1221 | n/a | Interactive(asdl_seq * body, PyArena *arena) |
---|
1222 | n/a | { |
---|
1223 | n/a | mod_ty p; |
---|
1224 | n/a | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1225 | n/a | if (!p) |
---|
1226 | n/a | return NULL; |
---|
1227 | n/a | p->kind = Interactive_kind; |
---|
1228 | n/a | p->v.Interactive.body = body; |
---|
1229 | n/a | return p; |
---|
1230 | n/a | } |
---|
1231 | n/a | |
---|
1232 | n/a | mod_ty |
---|
1233 | n/a | Expression(expr_ty body, PyArena *arena) |
---|
1234 | n/a | { |
---|
1235 | n/a | mod_ty p; |
---|
1236 | n/a | if (!body) { |
---|
1237 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1238 | n/a | "field body is required for Expression"); |
---|
1239 | n/a | return NULL; |
---|
1240 | n/a | } |
---|
1241 | n/a | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1242 | n/a | if (!p) |
---|
1243 | n/a | return NULL; |
---|
1244 | n/a | p->kind = Expression_kind; |
---|
1245 | n/a | p->v.Expression.body = body; |
---|
1246 | n/a | return p; |
---|
1247 | n/a | } |
---|
1248 | n/a | |
---|
1249 | n/a | mod_ty |
---|
1250 | n/a | Suite(asdl_seq * body, PyArena *arena) |
---|
1251 | n/a | { |
---|
1252 | n/a | mod_ty p; |
---|
1253 | n/a | p = (mod_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1254 | n/a | if (!p) |
---|
1255 | n/a | return NULL; |
---|
1256 | n/a | p->kind = Suite_kind; |
---|
1257 | n/a | p->v.Suite.body = body; |
---|
1258 | n/a | return p; |
---|
1259 | n/a | } |
---|
1260 | n/a | |
---|
1261 | n/a | stmt_ty |
---|
1262 | n/a | FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * |
---|
1263 | n/a | decorator_list, expr_ty returns, int lineno, int col_offset, |
---|
1264 | n/a | PyArena *arena) |
---|
1265 | n/a | { |
---|
1266 | n/a | stmt_ty p; |
---|
1267 | n/a | if (!name) { |
---|
1268 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1269 | n/a | "field name is required for FunctionDef"); |
---|
1270 | n/a | return NULL; |
---|
1271 | n/a | } |
---|
1272 | n/a | if (!args) { |
---|
1273 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1274 | n/a | "field args is required for FunctionDef"); |
---|
1275 | n/a | return NULL; |
---|
1276 | n/a | } |
---|
1277 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1278 | n/a | if (!p) |
---|
1279 | n/a | return NULL; |
---|
1280 | n/a | p->kind = FunctionDef_kind; |
---|
1281 | n/a | p->v.FunctionDef.name = name; |
---|
1282 | n/a | p->v.FunctionDef.args = args; |
---|
1283 | n/a | p->v.FunctionDef.body = body; |
---|
1284 | n/a | p->v.FunctionDef.decorator_list = decorator_list; |
---|
1285 | n/a | p->v.FunctionDef.returns = returns; |
---|
1286 | n/a | p->lineno = lineno; |
---|
1287 | n/a | p->col_offset = col_offset; |
---|
1288 | n/a | return p; |
---|
1289 | n/a | } |
---|
1290 | n/a | |
---|
1291 | n/a | stmt_ty |
---|
1292 | n/a | AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq |
---|
1293 | n/a | * decorator_list, expr_ty returns, int lineno, int col_offset, |
---|
1294 | n/a | PyArena *arena) |
---|
1295 | n/a | { |
---|
1296 | n/a | stmt_ty p; |
---|
1297 | n/a | if (!name) { |
---|
1298 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1299 | n/a | "field name is required for AsyncFunctionDef"); |
---|
1300 | n/a | return NULL; |
---|
1301 | n/a | } |
---|
1302 | n/a | if (!args) { |
---|
1303 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1304 | n/a | "field args is required for AsyncFunctionDef"); |
---|
1305 | n/a | return NULL; |
---|
1306 | n/a | } |
---|
1307 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1308 | n/a | if (!p) |
---|
1309 | n/a | return NULL; |
---|
1310 | n/a | p->kind = AsyncFunctionDef_kind; |
---|
1311 | n/a | p->v.AsyncFunctionDef.name = name; |
---|
1312 | n/a | p->v.AsyncFunctionDef.args = args; |
---|
1313 | n/a | p->v.AsyncFunctionDef.body = body; |
---|
1314 | n/a | p->v.AsyncFunctionDef.decorator_list = decorator_list; |
---|
1315 | n/a | p->v.AsyncFunctionDef.returns = returns; |
---|
1316 | n/a | p->lineno = lineno; |
---|
1317 | n/a | p->col_offset = col_offset; |
---|
1318 | n/a | return p; |
---|
1319 | n/a | } |
---|
1320 | n/a | |
---|
1321 | n/a | stmt_ty |
---|
1322 | n/a | ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq * |
---|
1323 | n/a | body, asdl_seq * decorator_list, int lineno, int col_offset, PyArena |
---|
1324 | n/a | *arena) |
---|
1325 | n/a | { |
---|
1326 | n/a | stmt_ty p; |
---|
1327 | n/a | if (!name) { |
---|
1328 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1329 | n/a | "field name is required for ClassDef"); |
---|
1330 | n/a | return NULL; |
---|
1331 | n/a | } |
---|
1332 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1333 | n/a | if (!p) |
---|
1334 | n/a | return NULL; |
---|
1335 | n/a | p->kind = ClassDef_kind; |
---|
1336 | n/a | p->v.ClassDef.name = name; |
---|
1337 | n/a | p->v.ClassDef.bases = bases; |
---|
1338 | n/a | p->v.ClassDef.keywords = keywords; |
---|
1339 | n/a | p->v.ClassDef.body = body; |
---|
1340 | n/a | p->v.ClassDef.decorator_list = decorator_list; |
---|
1341 | n/a | p->lineno = lineno; |
---|
1342 | n/a | p->col_offset = col_offset; |
---|
1343 | n/a | return p; |
---|
1344 | n/a | } |
---|
1345 | n/a | |
---|
1346 | n/a | stmt_ty |
---|
1347 | n/a | Return(expr_ty value, int lineno, int col_offset, PyArena *arena) |
---|
1348 | n/a | { |
---|
1349 | n/a | stmt_ty p; |
---|
1350 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1351 | n/a | if (!p) |
---|
1352 | n/a | return NULL; |
---|
1353 | n/a | p->kind = Return_kind; |
---|
1354 | n/a | p->v.Return.value = value; |
---|
1355 | n/a | p->lineno = lineno; |
---|
1356 | n/a | p->col_offset = col_offset; |
---|
1357 | n/a | return p; |
---|
1358 | n/a | } |
---|
1359 | n/a | |
---|
1360 | n/a | stmt_ty |
---|
1361 | n/a | Delete(asdl_seq * targets, int lineno, int col_offset, PyArena *arena) |
---|
1362 | n/a | { |
---|
1363 | n/a | stmt_ty p; |
---|
1364 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1365 | n/a | if (!p) |
---|
1366 | n/a | return NULL; |
---|
1367 | n/a | p->kind = Delete_kind; |
---|
1368 | n/a | p->v.Delete.targets = targets; |
---|
1369 | n/a | p->lineno = lineno; |
---|
1370 | n/a | p->col_offset = col_offset; |
---|
1371 | n/a | return p; |
---|
1372 | n/a | } |
---|
1373 | n/a | |
---|
1374 | n/a | stmt_ty |
---|
1375 | n/a | Assign(asdl_seq * targets, expr_ty value, int lineno, int col_offset, PyArena |
---|
1376 | n/a | *arena) |
---|
1377 | n/a | { |
---|
1378 | n/a | stmt_ty p; |
---|
1379 | n/a | if (!value) { |
---|
1380 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1381 | n/a | "field value is required for Assign"); |
---|
1382 | n/a | return NULL; |
---|
1383 | n/a | } |
---|
1384 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1385 | n/a | if (!p) |
---|
1386 | n/a | return NULL; |
---|
1387 | n/a | p->kind = Assign_kind; |
---|
1388 | n/a | p->v.Assign.targets = targets; |
---|
1389 | n/a | p->v.Assign.value = value; |
---|
1390 | n/a | p->lineno = lineno; |
---|
1391 | n/a | p->col_offset = col_offset; |
---|
1392 | n/a | return p; |
---|
1393 | n/a | } |
---|
1394 | n/a | |
---|
1395 | n/a | stmt_ty |
---|
1396 | n/a | AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int |
---|
1397 | n/a | col_offset, PyArena *arena) |
---|
1398 | n/a | { |
---|
1399 | n/a | stmt_ty p; |
---|
1400 | n/a | if (!target) { |
---|
1401 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1402 | n/a | "field target is required for AugAssign"); |
---|
1403 | n/a | return NULL; |
---|
1404 | n/a | } |
---|
1405 | n/a | if (!op) { |
---|
1406 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1407 | n/a | "field op is required for AugAssign"); |
---|
1408 | n/a | return NULL; |
---|
1409 | n/a | } |
---|
1410 | n/a | if (!value) { |
---|
1411 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1412 | n/a | "field value is required for AugAssign"); |
---|
1413 | n/a | return NULL; |
---|
1414 | n/a | } |
---|
1415 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1416 | n/a | if (!p) |
---|
1417 | n/a | return NULL; |
---|
1418 | n/a | p->kind = AugAssign_kind; |
---|
1419 | n/a | p->v.AugAssign.target = target; |
---|
1420 | n/a | p->v.AugAssign.op = op; |
---|
1421 | n/a | p->v.AugAssign.value = value; |
---|
1422 | n/a | p->lineno = lineno; |
---|
1423 | n/a | p->col_offset = col_offset; |
---|
1424 | n/a | return p; |
---|
1425 | n/a | } |
---|
1426 | n/a | |
---|
1427 | n/a | stmt_ty |
---|
1428 | n/a | AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int |
---|
1429 | n/a | lineno, int col_offset, PyArena *arena) |
---|
1430 | n/a | { |
---|
1431 | n/a | stmt_ty p; |
---|
1432 | n/a | if (!target) { |
---|
1433 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1434 | n/a | "field target is required for AnnAssign"); |
---|
1435 | n/a | return NULL; |
---|
1436 | n/a | } |
---|
1437 | n/a | if (!annotation) { |
---|
1438 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1439 | n/a | "field annotation is required for AnnAssign"); |
---|
1440 | n/a | return NULL; |
---|
1441 | n/a | } |
---|
1442 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1443 | n/a | if (!p) |
---|
1444 | n/a | return NULL; |
---|
1445 | n/a | p->kind = AnnAssign_kind; |
---|
1446 | n/a | p->v.AnnAssign.target = target; |
---|
1447 | n/a | p->v.AnnAssign.annotation = annotation; |
---|
1448 | n/a | p->v.AnnAssign.value = value; |
---|
1449 | n/a | p->v.AnnAssign.simple = simple; |
---|
1450 | n/a | p->lineno = lineno; |
---|
1451 | n/a | p->col_offset = col_offset; |
---|
1452 | n/a | return p; |
---|
1453 | n/a | } |
---|
1454 | n/a | |
---|
1455 | n/a | stmt_ty |
---|
1456 | n/a | For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
---|
1457 | n/a | lineno, int col_offset, PyArena *arena) |
---|
1458 | n/a | { |
---|
1459 | n/a | stmt_ty p; |
---|
1460 | n/a | if (!target) { |
---|
1461 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1462 | n/a | "field target is required for For"); |
---|
1463 | n/a | return NULL; |
---|
1464 | n/a | } |
---|
1465 | n/a | if (!iter) { |
---|
1466 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1467 | n/a | "field iter is required for For"); |
---|
1468 | n/a | return NULL; |
---|
1469 | n/a | } |
---|
1470 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1471 | n/a | if (!p) |
---|
1472 | n/a | return NULL; |
---|
1473 | n/a | p->kind = For_kind; |
---|
1474 | n/a | p->v.For.target = target; |
---|
1475 | n/a | p->v.For.iter = iter; |
---|
1476 | n/a | p->v.For.body = body; |
---|
1477 | n/a | p->v.For.orelse = orelse; |
---|
1478 | n/a | p->lineno = lineno; |
---|
1479 | n/a | p->col_offset = col_offset; |
---|
1480 | n/a | return p; |
---|
1481 | n/a | } |
---|
1482 | n/a | |
---|
1483 | n/a | stmt_ty |
---|
1484 | n/a | AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, int |
---|
1485 | n/a | lineno, int col_offset, PyArena *arena) |
---|
1486 | n/a | { |
---|
1487 | n/a | stmt_ty p; |
---|
1488 | n/a | if (!target) { |
---|
1489 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1490 | n/a | "field target is required for AsyncFor"); |
---|
1491 | n/a | return NULL; |
---|
1492 | n/a | } |
---|
1493 | n/a | if (!iter) { |
---|
1494 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1495 | n/a | "field iter is required for AsyncFor"); |
---|
1496 | n/a | return NULL; |
---|
1497 | n/a | } |
---|
1498 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1499 | n/a | if (!p) |
---|
1500 | n/a | return NULL; |
---|
1501 | n/a | p->kind = AsyncFor_kind; |
---|
1502 | n/a | p->v.AsyncFor.target = target; |
---|
1503 | n/a | p->v.AsyncFor.iter = iter; |
---|
1504 | n/a | p->v.AsyncFor.body = body; |
---|
1505 | n/a | p->v.AsyncFor.orelse = orelse; |
---|
1506 | n/a | p->lineno = lineno; |
---|
1507 | n/a | p->col_offset = col_offset; |
---|
1508 | n/a | return p; |
---|
1509 | n/a | } |
---|
1510 | n/a | |
---|
1511 | n/a | stmt_ty |
---|
1512 | n/a | While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
---|
1513 | n/a | col_offset, PyArena *arena) |
---|
1514 | n/a | { |
---|
1515 | n/a | stmt_ty p; |
---|
1516 | n/a | if (!test) { |
---|
1517 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1518 | n/a | "field test is required for While"); |
---|
1519 | n/a | return NULL; |
---|
1520 | n/a | } |
---|
1521 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1522 | n/a | if (!p) |
---|
1523 | n/a | return NULL; |
---|
1524 | n/a | p->kind = While_kind; |
---|
1525 | n/a | p->v.While.test = test; |
---|
1526 | n/a | p->v.While.body = body; |
---|
1527 | n/a | p->v.While.orelse = orelse; |
---|
1528 | n/a | p->lineno = lineno; |
---|
1529 | n/a | p->col_offset = col_offset; |
---|
1530 | n/a | return p; |
---|
1531 | n/a | } |
---|
1532 | n/a | |
---|
1533 | n/a | stmt_ty |
---|
1534 | n/a | If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int |
---|
1535 | n/a | col_offset, PyArena *arena) |
---|
1536 | n/a | { |
---|
1537 | n/a | stmt_ty p; |
---|
1538 | n/a | if (!test) { |
---|
1539 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1540 | n/a | "field test is required for If"); |
---|
1541 | n/a | return NULL; |
---|
1542 | n/a | } |
---|
1543 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1544 | n/a | if (!p) |
---|
1545 | n/a | return NULL; |
---|
1546 | n/a | p->kind = If_kind; |
---|
1547 | n/a | p->v.If.test = test; |
---|
1548 | n/a | p->v.If.body = body; |
---|
1549 | n/a | p->v.If.orelse = orelse; |
---|
1550 | n/a | p->lineno = lineno; |
---|
1551 | n/a | p->col_offset = col_offset; |
---|
1552 | n/a | return p; |
---|
1553 | n/a | } |
---|
1554 | n/a | |
---|
1555 | n/a | stmt_ty |
---|
1556 | n/a | With(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, PyArena |
---|
1557 | n/a | *arena) |
---|
1558 | n/a | { |
---|
1559 | n/a | stmt_ty p; |
---|
1560 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1561 | n/a | if (!p) |
---|
1562 | n/a | return NULL; |
---|
1563 | n/a | p->kind = With_kind; |
---|
1564 | n/a | p->v.With.items = items; |
---|
1565 | n/a | p->v.With.body = body; |
---|
1566 | n/a | p->lineno = lineno; |
---|
1567 | n/a | p->col_offset = col_offset; |
---|
1568 | n/a | return p; |
---|
1569 | n/a | } |
---|
1570 | n/a | |
---|
1571 | n/a | stmt_ty |
---|
1572 | n/a | AsyncWith(asdl_seq * items, asdl_seq * body, int lineno, int col_offset, |
---|
1573 | n/a | PyArena *arena) |
---|
1574 | n/a | { |
---|
1575 | n/a | stmt_ty p; |
---|
1576 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1577 | n/a | if (!p) |
---|
1578 | n/a | return NULL; |
---|
1579 | n/a | p->kind = AsyncWith_kind; |
---|
1580 | n/a | p->v.AsyncWith.items = items; |
---|
1581 | n/a | p->v.AsyncWith.body = body; |
---|
1582 | n/a | p->lineno = lineno; |
---|
1583 | n/a | p->col_offset = col_offset; |
---|
1584 | n/a | return p; |
---|
1585 | n/a | } |
---|
1586 | n/a | |
---|
1587 | n/a | stmt_ty |
---|
1588 | n/a | Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, PyArena *arena) |
---|
1589 | n/a | { |
---|
1590 | n/a | stmt_ty p; |
---|
1591 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1592 | n/a | if (!p) |
---|
1593 | n/a | return NULL; |
---|
1594 | n/a | p->kind = Raise_kind; |
---|
1595 | n/a | p->v.Raise.exc = exc; |
---|
1596 | n/a | p->v.Raise.cause = cause; |
---|
1597 | n/a | p->lineno = lineno; |
---|
1598 | n/a | p->col_offset = col_offset; |
---|
1599 | n/a | return p; |
---|
1600 | n/a | } |
---|
1601 | n/a | |
---|
1602 | n/a | stmt_ty |
---|
1603 | n/a | Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq * |
---|
1604 | n/a | finalbody, int lineno, int col_offset, PyArena *arena) |
---|
1605 | n/a | { |
---|
1606 | n/a | stmt_ty p; |
---|
1607 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1608 | n/a | if (!p) |
---|
1609 | n/a | return NULL; |
---|
1610 | n/a | p->kind = Try_kind; |
---|
1611 | n/a | p->v.Try.body = body; |
---|
1612 | n/a | p->v.Try.handlers = handlers; |
---|
1613 | n/a | p->v.Try.orelse = orelse; |
---|
1614 | n/a | p->v.Try.finalbody = finalbody; |
---|
1615 | n/a | p->lineno = lineno; |
---|
1616 | n/a | p->col_offset = col_offset; |
---|
1617 | n/a | return p; |
---|
1618 | n/a | } |
---|
1619 | n/a | |
---|
1620 | n/a | stmt_ty |
---|
1621 | n/a | Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, PyArena *arena) |
---|
1622 | n/a | { |
---|
1623 | n/a | stmt_ty p; |
---|
1624 | n/a | if (!test) { |
---|
1625 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1626 | n/a | "field test is required for Assert"); |
---|
1627 | n/a | return NULL; |
---|
1628 | n/a | } |
---|
1629 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1630 | n/a | if (!p) |
---|
1631 | n/a | return NULL; |
---|
1632 | n/a | p->kind = Assert_kind; |
---|
1633 | n/a | p->v.Assert.test = test; |
---|
1634 | n/a | p->v.Assert.msg = msg; |
---|
1635 | n/a | p->lineno = lineno; |
---|
1636 | n/a | p->col_offset = col_offset; |
---|
1637 | n/a | return p; |
---|
1638 | n/a | } |
---|
1639 | n/a | |
---|
1640 | n/a | stmt_ty |
---|
1641 | n/a | Import(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
---|
1642 | n/a | { |
---|
1643 | n/a | stmt_ty p; |
---|
1644 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1645 | n/a | if (!p) |
---|
1646 | n/a | return NULL; |
---|
1647 | n/a | p->kind = Import_kind; |
---|
1648 | n/a | p->v.Import.names = names; |
---|
1649 | n/a | p->lineno = lineno; |
---|
1650 | n/a | p->col_offset = col_offset; |
---|
1651 | n/a | return p; |
---|
1652 | n/a | } |
---|
1653 | n/a | |
---|
1654 | n/a | stmt_ty |
---|
1655 | n/a | ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int |
---|
1656 | n/a | col_offset, PyArena *arena) |
---|
1657 | n/a | { |
---|
1658 | n/a | stmt_ty p; |
---|
1659 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1660 | n/a | if (!p) |
---|
1661 | n/a | return NULL; |
---|
1662 | n/a | p->kind = ImportFrom_kind; |
---|
1663 | n/a | p->v.ImportFrom.module = module; |
---|
1664 | n/a | p->v.ImportFrom.names = names; |
---|
1665 | n/a | p->v.ImportFrom.level = level; |
---|
1666 | n/a | p->lineno = lineno; |
---|
1667 | n/a | p->col_offset = col_offset; |
---|
1668 | n/a | return p; |
---|
1669 | n/a | } |
---|
1670 | n/a | |
---|
1671 | n/a | stmt_ty |
---|
1672 | n/a | Global(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
---|
1673 | n/a | { |
---|
1674 | n/a | stmt_ty p; |
---|
1675 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1676 | n/a | if (!p) |
---|
1677 | n/a | return NULL; |
---|
1678 | n/a | p->kind = Global_kind; |
---|
1679 | n/a | p->v.Global.names = names; |
---|
1680 | n/a | p->lineno = lineno; |
---|
1681 | n/a | p->col_offset = col_offset; |
---|
1682 | n/a | return p; |
---|
1683 | n/a | } |
---|
1684 | n/a | |
---|
1685 | n/a | stmt_ty |
---|
1686 | n/a | Nonlocal(asdl_seq * names, int lineno, int col_offset, PyArena *arena) |
---|
1687 | n/a | { |
---|
1688 | n/a | stmt_ty p; |
---|
1689 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1690 | n/a | if (!p) |
---|
1691 | n/a | return NULL; |
---|
1692 | n/a | p->kind = Nonlocal_kind; |
---|
1693 | n/a | p->v.Nonlocal.names = names; |
---|
1694 | n/a | p->lineno = lineno; |
---|
1695 | n/a | p->col_offset = col_offset; |
---|
1696 | n/a | return p; |
---|
1697 | n/a | } |
---|
1698 | n/a | |
---|
1699 | n/a | stmt_ty |
---|
1700 | n/a | Expr(expr_ty value, int lineno, int col_offset, PyArena *arena) |
---|
1701 | n/a | { |
---|
1702 | n/a | stmt_ty p; |
---|
1703 | n/a | if (!value) { |
---|
1704 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1705 | n/a | "field value is required for Expr"); |
---|
1706 | n/a | return NULL; |
---|
1707 | n/a | } |
---|
1708 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1709 | n/a | if (!p) |
---|
1710 | n/a | return NULL; |
---|
1711 | n/a | p->kind = Expr_kind; |
---|
1712 | n/a | p->v.Expr.value = value; |
---|
1713 | n/a | p->lineno = lineno; |
---|
1714 | n/a | p->col_offset = col_offset; |
---|
1715 | n/a | return p; |
---|
1716 | n/a | } |
---|
1717 | n/a | |
---|
1718 | n/a | stmt_ty |
---|
1719 | n/a | Pass(int lineno, int col_offset, PyArena *arena) |
---|
1720 | n/a | { |
---|
1721 | n/a | stmt_ty p; |
---|
1722 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1723 | n/a | if (!p) |
---|
1724 | n/a | return NULL; |
---|
1725 | n/a | p->kind = Pass_kind; |
---|
1726 | n/a | p->lineno = lineno; |
---|
1727 | n/a | p->col_offset = col_offset; |
---|
1728 | n/a | return p; |
---|
1729 | n/a | } |
---|
1730 | n/a | |
---|
1731 | n/a | stmt_ty |
---|
1732 | n/a | Break(int lineno, int col_offset, PyArena *arena) |
---|
1733 | n/a | { |
---|
1734 | n/a | stmt_ty p; |
---|
1735 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1736 | n/a | if (!p) |
---|
1737 | n/a | return NULL; |
---|
1738 | n/a | p->kind = Break_kind; |
---|
1739 | n/a | p->lineno = lineno; |
---|
1740 | n/a | p->col_offset = col_offset; |
---|
1741 | n/a | return p; |
---|
1742 | n/a | } |
---|
1743 | n/a | |
---|
1744 | n/a | stmt_ty |
---|
1745 | n/a | Continue(int lineno, int col_offset, PyArena *arena) |
---|
1746 | n/a | { |
---|
1747 | n/a | stmt_ty p; |
---|
1748 | n/a | p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1749 | n/a | if (!p) |
---|
1750 | n/a | return NULL; |
---|
1751 | n/a | p->kind = Continue_kind; |
---|
1752 | n/a | p->lineno = lineno; |
---|
1753 | n/a | p->col_offset = col_offset; |
---|
1754 | n/a | return p; |
---|
1755 | n/a | } |
---|
1756 | n/a | |
---|
1757 | n/a | expr_ty |
---|
1758 | n/a | BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, PyArena |
---|
1759 | n/a | *arena) |
---|
1760 | n/a | { |
---|
1761 | n/a | expr_ty p; |
---|
1762 | n/a | if (!op) { |
---|
1763 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1764 | n/a | "field op is required for BoolOp"); |
---|
1765 | n/a | return NULL; |
---|
1766 | n/a | } |
---|
1767 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1768 | n/a | if (!p) |
---|
1769 | n/a | return NULL; |
---|
1770 | n/a | p->kind = BoolOp_kind; |
---|
1771 | n/a | p->v.BoolOp.op = op; |
---|
1772 | n/a | p->v.BoolOp.values = values; |
---|
1773 | n/a | p->lineno = lineno; |
---|
1774 | n/a | p->col_offset = col_offset; |
---|
1775 | n/a | return p; |
---|
1776 | n/a | } |
---|
1777 | n/a | |
---|
1778 | n/a | expr_ty |
---|
1779 | n/a | BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset, |
---|
1780 | n/a | PyArena *arena) |
---|
1781 | n/a | { |
---|
1782 | n/a | expr_ty p; |
---|
1783 | n/a | if (!left) { |
---|
1784 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1785 | n/a | "field left is required for BinOp"); |
---|
1786 | n/a | return NULL; |
---|
1787 | n/a | } |
---|
1788 | n/a | if (!op) { |
---|
1789 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1790 | n/a | "field op is required for BinOp"); |
---|
1791 | n/a | return NULL; |
---|
1792 | n/a | } |
---|
1793 | n/a | if (!right) { |
---|
1794 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1795 | n/a | "field right is required for BinOp"); |
---|
1796 | n/a | return NULL; |
---|
1797 | n/a | } |
---|
1798 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1799 | n/a | if (!p) |
---|
1800 | n/a | return NULL; |
---|
1801 | n/a | p->kind = BinOp_kind; |
---|
1802 | n/a | p->v.BinOp.left = left; |
---|
1803 | n/a | p->v.BinOp.op = op; |
---|
1804 | n/a | p->v.BinOp.right = right; |
---|
1805 | n/a | p->lineno = lineno; |
---|
1806 | n/a | p->col_offset = col_offset; |
---|
1807 | n/a | return p; |
---|
1808 | n/a | } |
---|
1809 | n/a | |
---|
1810 | n/a | expr_ty |
---|
1811 | n/a | UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, PyArena |
---|
1812 | n/a | *arena) |
---|
1813 | n/a | { |
---|
1814 | n/a | expr_ty p; |
---|
1815 | n/a | if (!op) { |
---|
1816 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1817 | n/a | "field op is required for UnaryOp"); |
---|
1818 | n/a | return NULL; |
---|
1819 | n/a | } |
---|
1820 | n/a | if (!operand) { |
---|
1821 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1822 | n/a | "field operand is required for UnaryOp"); |
---|
1823 | n/a | return NULL; |
---|
1824 | n/a | } |
---|
1825 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1826 | n/a | if (!p) |
---|
1827 | n/a | return NULL; |
---|
1828 | n/a | p->kind = UnaryOp_kind; |
---|
1829 | n/a | p->v.UnaryOp.op = op; |
---|
1830 | n/a | p->v.UnaryOp.operand = operand; |
---|
1831 | n/a | p->lineno = lineno; |
---|
1832 | n/a | p->col_offset = col_offset; |
---|
1833 | n/a | return p; |
---|
1834 | n/a | } |
---|
1835 | n/a | |
---|
1836 | n/a | expr_ty |
---|
1837 | n/a | Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, PyArena |
---|
1838 | n/a | *arena) |
---|
1839 | n/a | { |
---|
1840 | n/a | expr_ty p; |
---|
1841 | n/a | if (!args) { |
---|
1842 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1843 | n/a | "field args is required for Lambda"); |
---|
1844 | n/a | return NULL; |
---|
1845 | n/a | } |
---|
1846 | n/a | if (!body) { |
---|
1847 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1848 | n/a | "field body is required for Lambda"); |
---|
1849 | n/a | return NULL; |
---|
1850 | n/a | } |
---|
1851 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1852 | n/a | if (!p) |
---|
1853 | n/a | return NULL; |
---|
1854 | n/a | p->kind = Lambda_kind; |
---|
1855 | n/a | p->v.Lambda.args = args; |
---|
1856 | n/a | p->v.Lambda.body = body; |
---|
1857 | n/a | p->lineno = lineno; |
---|
1858 | n/a | p->col_offset = col_offset; |
---|
1859 | n/a | return p; |
---|
1860 | n/a | } |
---|
1861 | n/a | |
---|
1862 | n/a | expr_ty |
---|
1863 | n/a | IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset, |
---|
1864 | n/a | PyArena *arena) |
---|
1865 | n/a | { |
---|
1866 | n/a | expr_ty p; |
---|
1867 | n/a | if (!test) { |
---|
1868 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1869 | n/a | "field test is required for IfExp"); |
---|
1870 | n/a | return NULL; |
---|
1871 | n/a | } |
---|
1872 | n/a | if (!body) { |
---|
1873 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1874 | n/a | "field body is required for IfExp"); |
---|
1875 | n/a | return NULL; |
---|
1876 | n/a | } |
---|
1877 | n/a | if (!orelse) { |
---|
1878 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1879 | n/a | "field orelse is required for IfExp"); |
---|
1880 | n/a | return NULL; |
---|
1881 | n/a | } |
---|
1882 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1883 | n/a | if (!p) |
---|
1884 | n/a | return NULL; |
---|
1885 | n/a | p->kind = IfExp_kind; |
---|
1886 | n/a | p->v.IfExp.test = test; |
---|
1887 | n/a | p->v.IfExp.body = body; |
---|
1888 | n/a | p->v.IfExp.orelse = orelse; |
---|
1889 | n/a | p->lineno = lineno; |
---|
1890 | n/a | p->col_offset = col_offset; |
---|
1891 | n/a | return p; |
---|
1892 | n/a | } |
---|
1893 | n/a | |
---|
1894 | n/a | expr_ty |
---|
1895 | n/a | Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, PyArena |
---|
1896 | n/a | *arena) |
---|
1897 | n/a | { |
---|
1898 | n/a | expr_ty p; |
---|
1899 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1900 | n/a | if (!p) |
---|
1901 | n/a | return NULL; |
---|
1902 | n/a | p->kind = Dict_kind; |
---|
1903 | n/a | p->v.Dict.keys = keys; |
---|
1904 | n/a | p->v.Dict.values = values; |
---|
1905 | n/a | p->lineno = lineno; |
---|
1906 | n/a | p->col_offset = col_offset; |
---|
1907 | n/a | return p; |
---|
1908 | n/a | } |
---|
1909 | n/a | |
---|
1910 | n/a | expr_ty |
---|
1911 | n/a | Set(asdl_seq * elts, int lineno, int col_offset, PyArena *arena) |
---|
1912 | n/a | { |
---|
1913 | n/a | expr_ty p; |
---|
1914 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1915 | n/a | if (!p) |
---|
1916 | n/a | return NULL; |
---|
1917 | n/a | p->kind = Set_kind; |
---|
1918 | n/a | p->v.Set.elts = elts; |
---|
1919 | n/a | p->lineno = lineno; |
---|
1920 | n/a | p->col_offset = col_offset; |
---|
1921 | n/a | return p; |
---|
1922 | n/a | } |
---|
1923 | n/a | |
---|
1924 | n/a | expr_ty |
---|
1925 | n/a | ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
---|
1926 | n/a | PyArena *arena) |
---|
1927 | n/a | { |
---|
1928 | n/a | expr_ty p; |
---|
1929 | n/a | if (!elt) { |
---|
1930 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1931 | n/a | "field elt is required for ListComp"); |
---|
1932 | n/a | return NULL; |
---|
1933 | n/a | } |
---|
1934 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1935 | n/a | if (!p) |
---|
1936 | n/a | return NULL; |
---|
1937 | n/a | p->kind = ListComp_kind; |
---|
1938 | n/a | p->v.ListComp.elt = elt; |
---|
1939 | n/a | p->v.ListComp.generators = generators; |
---|
1940 | n/a | p->lineno = lineno; |
---|
1941 | n/a | p->col_offset = col_offset; |
---|
1942 | n/a | return p; |
---|
1943 | n/a | } |
---|
1944 | n/a | |
---|
1945 | n/a | expr_ty |
---|
1946 | n/a | SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, PyArena |
---|
1947 | n/a | *arena) |
---|
1948 | n/a | { |
---|
1949 | n/a | expr_ty p; |
---|
1950 | n/a | if (!elt) { |
---|
1951 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1952 | n/a | "field elt is required for SetComp"); |
---|
1953 | n/a | return NULL; |
---|
1954 | n/a | } |
---|
1955 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1956 | n/a | if (!p) |
---|
1957 | n/a | return NULL; |
---|
1958 | n/a | p->kind = SetComp_kind; |
---|
1959 | n/a | p->v.SetComp.elt = elt; |
---|
1960 | n/a | p->v.SetComp.generators = generators; |
---|
1961 | n/a | p->lineno = lineno; |
---|
1962 | n/a | p->col_offset = col_offset; |
---|
1963 | n/a | return p; |
---|
1964 | n/a | } |
---|
1965 | n/a | |
---|
1966 | n/a | expr_ty |
---|
1967 | n/a | DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int |
---|
1968 | n/a | col_offset, PyArena *arena) |
---|
1969 | n/a | { |
---|
1970 | n/a | expr_ty p; |
---|
1971 | n/a | if (!key) { |
---|
1972 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1973 | n/a | "field key is required for DictComp"); |
---|
1974 | n/a | return NULL; |
---|
1975 | n/a | } |
---|
1976 | n/a | if (!value) { |
---|
1977 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
1978 | n/a | "field value is required for DictComp"); |
---|
1979 | n/a | return NULL; |
---|
1980 | n/a | } |
---|
1981 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
1982 | n/a | if (!p) |
---|
1983 | n/a | return NULL; |
---|
1984 | n/a | p->kind = DictComp_kind; |
---|
1985 | n/a | p->v.DictComp.key = key; |
---|
1986 | n/a | p->v.DictComp.value = value; |
---|
1987 | n/a | p->v.DictComp.generators = generators; |
---|
1988 | n/a | p->lineno = lineno; |
---|
1989 | n/a | p->col_offset = col_offset; |
---|
1990 | n/a | return p; |
---|
1991 | n/a | } |
---|
1992 | n/a | |
---|
1993 | n/a | expr_ty |
---|
1994 | n/a | GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, |
---|
1995 | n/a | PyArena *arena) |
---|
1996 | n/a | { |
---|
1997 | n/a | expr_ty p; |
---|
1998 | n/a | if (!elt) { |
---|
1999 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2000 | n/a | "field elt is required for GeneratorExp"); |
---|
2001 | n/a | return NULL; |
---|
2002 | n/a | } |
---|
2003 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2004 | n/a | if (!p) |
---|
2005 | n/a | return NULL; |
---|
2006 | n/a | p->kind = GeneratorExp_kind; |
---|
2007 | n/a | p->v.GeneratorExp.elt = elt; |
---|
2008 | n/a | p->v.GeneratorExp.generators = generators; |
---|
2009 | n/a | p->lineno = lineno; |
---|
2010 | n/a | p->col_offset = col_offset; |
---|
2011 | n/a | return p; |
---|
2012 | n/a | } |
---|
2013 | n/a | |
---|
2014 | n/a | expr_ty |
---|
2015 | n/a | Await(expr_ty value, int lineno, int col_offset, PyArena *arena) |
---|
2016 | n/a | { |
---|
2017 | n/a | expr_ty p; |
---|
2018 | n/a | if (!value) { |
---|
2019 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2020 | n/a | "field value is required for Await"); |
---|
2021 | n/a | return NULL; |
---|
2022 | n/a | } |
---|
2023 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2024 | n/a | if (!p) |
---|
2025 | n/a | return NULL; |
---|
2026 | n/a | p->kind = Await_kind; |
---|
2027 | n/a | p->v.Await.value = value; |
---|
2028 | n/a | p->lineno = lineno; |
---|
2029 | n/a | p->col_offset = col_offset; |
---|
2030 | n/a | return p; |
---|
2031 | n/a | } |
---|
2032 | n/a | |
---|
2033 | n/a | expr_ty |
---|
2034 | n/a | Yield(expr_ty value, int lineno, int col_offset, PyArena *arena) |
---|
2035 | n/a | { |
---|
2036 | n/a | expr_ty p; |
---|
2037 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2038 | n/a | if (!p) |
---|
2039 | n/a | return NULL; |
---|
2040 | n/a | p->kind = Yield_kind; |
---|
2041 | n/a | p->v.Yield.value = value; |
---|
2042 | n/a | p->lineno = lineno; |
---|
2043 | n/a | p->col_offset = col_offset; |
---|
2044 | n/a | return p; |
---|
2045 | n/a | } |
---|
2046 | n/a | |
---|
2047 | n/a | expr_ty |
---|
2048 | n/a | YieldFrom(expr_ty value, int lineno, int col_offset, PyArena *arena) |
---|
2049 | n/a | { |
---|
2050 | n/a | expr_ty p; |
---|
2051 | n/a | if (!value) { |
---|
2052 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2053 | n/a | "field value is required for YieldFrom"); |
---|
2054 | n/a | return NULL; |
---|
2055 | n/a | } |
---|
2056 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2057 | n/a | if (!p) |
---|
2058 | n/a | return NULL; |
---|
2059 | n/a | p->kind = YieldFrom_kind; |
---|
2060 | n/a | p->v.YieldFrom.value = value; |
---|
2061 | n/a | p->lineno = lineno; |
---|
2062 | n/a | p->col_offset = col_offset; |
---|
2063 | n/a | return p; |
---|
2064 | n/a | } |
---|
2065 | n/a | |
---|
2066 | n/a | expr_ty |
---|
2067 | n/a | Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno, |
---|
2068 | n/a | int col_offset, PyArena *arena) |
---|
2069 | n/a | { |
---|
2070 | n/a | expr_ty p; |
---|
2071 | n/a | if (!left) { |
---|
2072 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2073 | n/a | "field left is required for Compare"); |
---|
2074 | n/a | return NULL; |
---|
2075 | n/a | } |
---|
2076 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2077 | n/a | if (!p) |
---|
2078 | n/a | return NULL; |
---|
2079 | n/a | p->kind = Compare_kind; |
---|
2080 | n/a | p->v.Compare.left = left; |
---|
2081 | n/a | p->v.Compare.ops = ops; |
---|
2082 | n/a | p->v.Compare.comparators = comparators; |
---|
2083 | n/a | p->lineno = lineno; |
---|
2084 | n/a | p->col_offset = col_offset; |
---|
2085 | n/a | return p; |
---|
2086 | n/a | } |
---|
2087 | n/a | |
---|
2088 | n/a | expr_ty |
---|
2089 | n/a | Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int |
---|
2090 | n/a | col_offset, PyArena *arena) |
---|
2091 | n/a | { |
---|
2092 | n/a | expr_ty p; |
---|
2093 | n/a | if (!func) { |
---|
2094 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2095 | n/a | "field func is required for Call"); |
---|
2096 | n/a | return NULL; |
---|
2097 | n/a | } |
---|
2098 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2099 | n/a | if (!p) |
---|
2100 | n/a | return NULL; |
---|
2101 | n/a | p->kind = Call_kind; |
---|
2102 | n/a | p->v.Call.func = func; |
---|
2103 | n/a | p->v.Call.args = args; |
---|
2104 | n/a | p->v.Call.keywords = keywords; |
---|
2105 | n/a | p->lineno = lineno; |
---|
2106 | n/a | p->col_offset = col_offset; |
---|
2107 | n/a | return p; |
---|
2108 | n/a | } |
---|
2109 | n/a | |
---|
2110 | n/a | expr_ty |
---|
2111 | n/a | Num(object n, int lineno, int col_offset, PyArena *arena) |
---|
2112 | n/a | { |
---|
2113 | n/a | expr_ty p; |
---|
2114 | n/a | if (!n) { |
---|
2115 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2116 | n/a | "field n is required for Num"); |
---|
2117 | n/a | return NULL; |
---|
2118 | n/a | } |
---|
2119 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2120 | n/a | if (!p) |
---|
2121 | n/a | return NULL; |
---|
2122 | n/a | p->kind = Num_kind; |
---|
2123 | n/a | p->v.Num.n = n; |
---|
2124 | n/a | p->lineno = lineno; |
---|
2125 | n/a | p->col_offset = col_offset; |
---|
2126 | n/a | return p; |
---|
2127 | n/a | } |
---|
2128 | n/a | |
---|
2129 | n/a | expr_ty |
---|
2130 | n/a | Str(string s, int lineno, int col_offset, PyArena *arena) |
---|
2131 | n/a | { |
---|
2132 | n/a | expr_ty p; |
---|
2133 | n/a | if (!s) { |
---|
2134 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2135 | n/a | "field s is required for Str"); |
---|
2136 | n/a | return NULL; |
---|
2137 | n/a | } |
---|
2138 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2139 | n/a | if (!p) |
---|
2140 | n/a | return NULL; |
---|
2141 | n/a | p->kind = Str_kind; |
---|
2142 | n/a | p->v.Str.s = s; |
---|
2143 | n/a | p->lineno = lineno; |
---|
2144 | n/a | p->col_offset = col_offset; |
---|
2145 | n/a | return p; |
---|
2146 | n/a | } |
---|
2147 | n/a | |
---|
2148 | n/a | expr_ty |
---|
2149 | n/a | FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno, |
---|
2150 | n/a | int col_offset, PyArena *arena) |
---|
2151 | n/a | { |
---|
2152 | n/a | expr_ty p; |
---|
2153 | n/a | if (!value) { |
---|
2154 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2155 | n/a | "field value is required for FormattedValue"); |
---|
2156 | n/a | return NULL; |
---|
2157 | n/a | } |
---|
2158 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2159 | n/a | if (!p) |
---|
2160 | n/a | return NULL; |
---|
2161 | n/a | p->kind = FormattedValue_kind; |
---|
2162 | n/a | p->v.FormattedValue.value = value; |
---|
2163 | n/a | p->v.FormattedValue.conversion = conversion; |
---|
2164 | n/a | p->v.FormattedValue.format_spec = format_spec; |
---|
2165 | n/a | p->lineno = lineno; |
---|
2166 | n/a | p->col_offset = col_offset; |
---|
2167 | n/a | return p; |
---|
2168 | n/a | } |
---|
2169 | n/a | |
---|
2170 | n/a | expr_ty |
---|
2171 | n/a | JoinedStr(asdl_seq * values, int lineno, int col_offset, PyArena *arena) |
---|
2172 | n/a | { |
---|
2173 | n/a | expr_ty p; |
---|
2174 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2175 | n/a | if (!p) |
---|
2176 | n/a | return NULL; |
---|
2177 | n/a | p->kind = JoinedStr_kind; |
---|
2178 | n/a | p->v.JoinedStr.values = values; |
---|
2179 | n/a | p->lineno = lineno; |
---|
2180 | n/a | p->col_offset = col_offset; |
---|
2181 | n/a | return p; |
---|
2182 | n/a | } |
---|
2183 | n/a | |
---|
2184 | n/a | expr_ty |
---|
2185 | n/a | Bytes(bytes s, int lineno, int col_offset, PyArena *arena) |
---|
2186 | n/a | { |
---|
2187 | n/a | expr_ty p; |
---|
2188 | n/a | if (!s) { |
---|
2189 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2190 | n/a | "field s is required for Bytes"); |
---|
2191 | n/a | return NULL; |
---|
2192 | n/a | } |
---|
2193 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2194 | n/a | if (!p) |
---|
2195 | n/a | return NULL; |
---|
2196 | n/a | p->kind = Bytes_kind; |
---|
2197 | n/a | p->v.Bytes.s = s; |
---|
2198 | n/a | p->lineno = lineno; |
---|
2199 | n/a | p->col_offset = col_offset; |
---|
2200 | n/a | return p; |
---|
2201 | n/a | } |
---|
2202 | n/a | |
---|
2203 | n/a | expr_ty |
---|
2204 | n/a | NameConstant(singleton value, int lineno, int col_offset, PyArena *arena) |
---|
2205 | n/a | { |
---|
2206 | n/a | expr_ty p; |
---|
2207 | n/a | if (!value) { |
---|
2208 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2209 | n/a | "field value is required for NameConstant"); |
---|
2210 | n/a | return NULL; |
---|
2211 | n/a | } |
---|
2212 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2213 | n/a | if (!p) |
---|
2214 | n/a | return NULL; |
---|
2215 | n/a | p->kind = NameConstant_kind; |
---|
2216 | n/a | p->v.NameConstant.value = value; |
---|
2217 | n/a | p->lineno = lineno; |
---|
2218 | n/a | p->col_offset = col_offset; |
---|
2219 | n/a | return p; |
---|
2220 | n/a | } |
---|
2221 | n/a | |
---|
2222 | n/a | expr_ty |
---|
2223 | n/a | Ellipsis(int lineno, int col_offset, PyArena *arena) |
---|
2224 | n/a | { |
---|
2225 | n/a | expr_ty p; |
---|
2226 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2227 | n/a | if (!p) |
---|
2228 | n/a | return NULL; |
---|
2229 | n/a | p->kind = Ellipsis_kind; |
---|
2230 | n/a | p->lineno = lineno; |
---|
2231 | n/a | p->col_offset = col_offset; |
---|
2232 | n/a | return p; |
---|
2233 | n/a | } |
---|
2234 | n/a | |
---|
2235 | n/a | expr_ty |
---|
2236 | n/a | Constant(constant value, int lineno, int col_offset, PyArena *arena) |
---|
2237 | n/a | { |
---|
2238 | n/a | expr_ty p; |
---|
2239 | n/a | if (!value) { |
---|
2240 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2241 | n/a | "field value is required for Constant"); |
---|
2242 | n/a | return NULL; |
---|
2243 | n/a | } |
---|
2244 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2245 | n/a | if (!p) |
---|
2246 | n/a | return NULL; |
---|
2247 | n/a | p->kind = Constant_kind; |
---|
2248 | n/a | p->v.Constant.value = value; |
---|
2249 | n/a | p->lineno = lineno; |
---|
2250 | n/a | p->col_offset = col_offset; |
---|
2251 | n/a | return p; |
---|
2252 | n/a | } |
---|
2253 | n/a | |
---|
2254 | n/a | expr_ty |
---|
2255 | n/a | Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int |
---|
2256 | n/a | col_offset, PyArena *arena) |
---|
2257 | n/a | { |
---|
2258 | n/a | expr_ty p; |
---|
2259 | n/a | if (!value) { |
---|
2260 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2261 | n/a | "field value is required for Attribute"); |
---|
2262 | n/a | return NULL; |
---|
2263 | n/a | } |
---|
2264 | n/a | if (!attr) { |
---|
2265 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2266 | n/a | "field attr is required for Attribute"); |
---|
2267 | n/a | return NULL; |
---|
2268 | n/a | } |
---|
2269 | n/a | if (!ctx) { |
---|
2270 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2271 | n/a | "field ctx is required for Attribute"); |
---|
2272 | n/a | return NULL; |
---|
2273 | n/a | } |
---|
2274 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2275 | n/a | if (!p) |
---|
2276 | n/a | return NULL; |
---|
2277 | n/a | p->kind = Attribute_kind; |
---|
2278 | n/a | p->v.Attribute.value = value; |
---|
2279 | n/a | p->v.Attribute.attr = attr; |
---|
2280 | n/a | p->v.Attribute.ctx = ctx; |
---|
2281 | n/a | p->lineno = lineno; |
---|
2282 | n/a | p->col_offset = col_offset; |
---|
2283 | n/a | return p; |
---|
2284 | n/a | } |
---|
2285 | n/a | |
---|
2286 | n/a | expr_ty |
---|
2287 | n/a | Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int |
---|
2288 | n/a | col_offset, PyArena *arena) |
---|
2289 | n/a | { |
---|
2290 | n/a | expr_ty p; |
---|
2291 | n/a | if (!value) { |
---|
2292 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2293 | n/a | "field value is required for Subscript"); |
---|
2294 | n/a | return NULL; |
---|
2295 | n/a | } |
---|
2296 | n/a | if (!slice) { |
---|
2297 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2298 | n/a | "field slice is required for Subscript"); |
---|
2299 | n/a | return NULL; |
---|
2300 | n/a | } |
---|
2301 | n/a | if (!ctx) { |
---|
2302 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2303 | n/a | "field ctx is required for Subscript"); |
---|
2304 | n/a | return NULL; |
---|
2305 | n/a | } |
---|
2306 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2307 | n/a | if (!p) |
---|
2308 | n/a | return NULL; |
---|
2309 | n/a | p->kind = Subscript_kind; |
---|
2310 | n/a | p->v.Subscript.value = value; |
---|
2311 | n/a | p->v.Subscript.slice = slice; |
---|
2312 | n/a | p->v.Subscript.ctx = ctx; |
---|
2313 | n/a | p->lineno = lineno; |
---|
2314 | n/a | p->col_offset = col_offset; |
---|
2315 | n/a | return p; |
---|
2316 | n/a | } |
---|
2317 | n/a | |
---|
2318 | n/a | expr_ty |
---|
2319 | n/a | Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, PyArena |
---|
2320 | n/a | *arena) |
---|
2321 | n/a | { |
---|
2322 | n/a | expr_ty p; |
---|
2323 | n/a | if (!value) { |
---|
2324 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2325 | n/a | "field value is required for Starred"); |
---|
2326 | n/a | return NULL; |
---|
2327 | n/a | } |
---|
2328 | n/a | if (!ctx) { |
---|
2329 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2330 | n/a | "field ctx is required for Starred"); |
---|
2331 | n/a | return NULL; |
---|
2332 | n/a | } |
---|
2333 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2334 | n/a | if (!p) |
---|
2335 | n/a | return NULL; |
---|
2336 | n/a | p->kind = Starred_kind; |
---|
2337 | n/a | p->v.Starred.value = value; |
---|
2338 | n/a | p->v.Starred.ctx = ctx; |
---|
2339 | n/a | p->lineno = lineno; |
---|
2340 | n/a | p->col_offset = col_offset; |
---|
2341 | n/a | return p; |
---|
2342 | n/a | } |
---|
2343 | n/a | |
---|
2344 | n/a | expr_ty |
---|
2345 | n/a | Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, PyArena |
---|
2346 | n/a | *arena) |
---|
2347 | n/a | { |
---|
2348 | n/a | expr_ty p; |
---|
2349 | n/a | if (!id) { |
---|
2350 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2351 | n/a | "field id is required for Name"); |
---|
2352 | n/a | return NULL; |
---|
2353 | n/a | } |
---|
2354 | n/a | if (!ctx) { |
---|
2355 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2356 | n/a | "field ctx is required for Name"); |
---|
2357 | n/a | return NULL; |
---|
2358 | n/a | } |
---|
2359 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2360 | n/a | if (!p) |
---|
2361 | n/a | return NULL; |
---|
2362 | n/a | p->kind = Name_kind; |
---|
2363 | n/a | p->v.Name.id = id; |
---|
2364 | n/a | p->v.Name.ctx = ctx; |
---|
2365 | n/a | p->lineno = lineno; |
---|
2366 | n/a | p->col_offset = col_offset; |
---|
2367 | n/a | return p; |
---|
2368 | n/a | } |
---|
2369 | n/a | |
---|
2370 | n/a | expr_ty |
---|
2371 | n/a | List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
---|
2372 | n/a | *arena) |
---|
2373 | n/a | { |
---|
2374 | n/a | expr_ty p; |
---|
2375 | n/a | if (!ctx) { |
---|
2376 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2377 | n/a | "field ctx is required for List"); |
---|
2378 | n/a | return NULL; |
---|
2379 | n/a | } |
---|
2380 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2381 | n/a | if (!p) |
---|
2382 | n/a | return NULL; |
---|
2383 | n/a | p->kind = List_kind; |
---|
2384 | n/a | p->v.List.elts = elts; |
---|
2385 | n/a | p->v.List.ctx = ctx; |
---|
2386 | n/a | p->lineno = lineno; |
---|
2387 | n/a | p->col_offset = col_offset; |
---|
2388 | n/a | return p; |
---|
2389 | n/a | } |
---|
2390 | n/a | |
---|
2391 | n/a | expr_ty |
---|
2392 | n/a | Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, PyArena |
---|
2393 | n/a | *arena) |
---|
2394 | n/a | { |
---|
2395 | n/a | expr_ty p; |
---|
2396 | n/a | if (!ctx) { |
---|
2397 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2398 | n/a | "field ctx is required for Tuple"); |
---|
2399 | n/a | return NULL; |
---|
2400 | n/a | } |
---|
2401 | n/a | p = (expr_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2402 | n/a | if (!p) |
---|
2403 | n/a | return NULL; |
---|
2404 | n/a | p->kind = Tuple_kind; |
---|
2405 | n/a | p->v.Tuple.elts = elts; |
---|
2406 | n/a | p->v.Tuple.ctx = ctx; |
---|
2407 | n/a | p->lineno = lineno; |
---|
2408 | n/a | p->col_offset = col_offset; |
---|
2409 | n/a | return p; |
---|
2410 | n/a | } |
---|
2411 | n/a | |
---|
2412 | n/a | slice_ty |
---|
2413 | n/a | Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena) |
---|
2414 | n/a | { |
---|
2415 | n/a | slice_ty p; |
---|
2416 | n/a | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2417 | n/a | if (!p) |
---|
2418 | n/a | return NULL; |
---|
2419 | n/a | p->kind = Slice_kind; |
---|
2420 | n/a | p->v.Slice.lower = lower; |
---|
2421 | n/a | p->v.Slice.upper = upper; |
---|
2422 | n/a | p->v.Slice.step = step; |
---|
2423 | n/a | return p; |
---|
2424 | n/a | } |
---|
2425 | n/a | |
---|
2426 | n/a | slice_ty |
---|
2427 | n/a | ExtSlice(asdl_seq * dims, PyArena *arena) |
---|
2428 | n/a | { |
---|
2429 | n/a | slice_ty p; |
---|
2430 | n/a | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2431 | n/a | if (!p) |
---|
2432 | n/a | return NULL; |
---|
2433 | n/a | p->kind = ExtSlice_kind; |
---|
2434 | n/a | p->v.ExtSlice.dims = dims; |
---|
2435 | n/a | return p; |
---|
2436 | n/a | } |
---|
2437 | n/a | |
---|
2438 | n/a | slice_ty |
---|
2439 | n/a | Index(expr_ty value, PyArena *arena) |
---|
2440 | n/a | { |
---|
2441 | n/a | slice_ty p; |
---|
2442 | n/a | if (!value) { |
---|
2443 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2444 | n/a | "field value is required for Index"); |
---|
2445 | n/a | return NULL; |
---|
2446 | n/a | } |
---|
2447 | n/a | p = (slice_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2448 | n/a | if (!p) |
---|
2449 | n/a | return NULL; |
---|
2450 | n/a | p->kind = Index_kind; |
---|
2451 | n/a | p->v.Index.value = value; |
---|
2452 | n/a | return p; |
---|
2453 | n/a | } |
---|
2454 | n/a | |
---|
2455 | n/a | comprehension_ty |
---|
2456 | n/a | comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async, |
---|
2457 | n/a | PyArena *arena) |
---|
2458 | n/a | { |
---|
2459 | n/a | comprehension_ty p; |
---|
2460 | n/a | if (!target) { |
---|
2461 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2462 | n/a | "field target is required for comprehension"); |
---|
2463 | n/a | return NULL; |
---|
2464 | n/a | } |
---|
2465 | n/a | if (!iter) { |
---|
2466 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2467 | n/a | "field iter is required for comprehension"); |
---|
2468 | n/a | return NULL; |
---|
2469 | n/a | } |
---|
2470 | n/a | p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2471 | n/a | if (!p) |
---|
2472 | n/a | return NULL; |
---|
2473 | n/a | p->target = target; |
---|
2474 | n/a | p->iter = iter; |
---|
2475 | n/a | p->ifs = ifs; |
---|
2476 | n/a | p->is_async = is_async; |
---|
2477 | n/a | return p; |
---|
2478 | n/a | } |
---|
2479 | n/a | |
---|
2480 | n/a | excepthandler_ty |
---|
2481 | n/a | ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int |
---|
2482 | n/a | col_offset, PyArena *arena) |
---|
2483 | n/a | { |
---|
2484 | n/a | excepthandler_ty p; |
---|
2485 | n/a | p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2486 | n/a | if (!p) |
---|
2487 | n/a | return NULL; |
---|
2488 | n/a | p->kind = ExceptHandler_kind; |
---|
2489 | n/a | p->v.ExceptHandler.type = type; |
---|
2490 | n/a | p->v.ExceptHandler.name = name; |
---|
2491 | n/a | p->v.ExceptHandler.body = body; |
---|
2492 | n/a | p->lineno = lineno; |
---|
2493 | n/a | p->col_offset = col_offset; |
---|
2494 | n/a | return p; |
---|
2495 | n/a | } |
---|
2496 | n/a | |
---|
2497 | n/a | arguments_ty |
---|
2498 | n/a | arguments(asdl_seq * args, arg_ty vararg, asdl_seq * kwonlyargs, asdl_seq * |
---|
2499 | n/a | kw_defaults, arg_ty kwarg, asdl_seq * defaults, PyArena *arena) |
---|
2500 | n/a | { |
---|
2501 | n/a | arguments_ty p; |
---|
2502 | n/a | p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2503 | n/a | if (!p) |
---|
2504 | n/a | return NULL; |
---|
2505 | n/a | p->args = args; |
---|
2506 | n/a | p->vararg = vararg; |
---|
2507 | n/a | p->kwonlyargs = kwonlyargs; |
---|
2508 | n/a | p->kw_defaults = kw_defaults; |
---|
2509 | n/a | p->kwarg = kwarg; |
---|
2510 | n/a | p->defaults = defaults; |
---|
2511 | n/a | return p; |
---|
2512 | n/a | } |
---|
2513 | n/a | |
---|
2514 | n/a | arg_ty |
---|
2515 | n/a | arg(identifier arg, expr_ty annotation, int lineno, int col_offset, PyArena |
---|
2516 | n/a | *arena) |
---|
2517 | n/a | { |
---|
2518 | n/a | arg_ty p; |
---|
2519 | n/a | if (!arg) { |
---|
2520 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2521 | n/a | "field arg is required for arg"); |
---|
2522 | n/a | return NULL; |
---|
2523 | n/a | } |
---|
2524 | n/a | p = (arg_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2525 | n/a | if (!p) |
---|
2526 | n/a | return NULL; |
---|
2527 | n/a | p->arg = arg; |
---|
2528 | n/a | p->annotation = annotation; |
---|
2529 | n/a | p->lineno = lineno; |
---|
2530 | n/a | p->col_offset = col_offset; |
---|
2531 | n/a | return p; |
---|
2532 | n/a | } |
---|
2533 | n/a | |
---|
2534 | n/a | keyword_ty |
---|
2535 | n/a | keyword(identifier arg, expr_ty value, PyArena *arena) |
---|
2536 | n/a | { |
---|
2537 | n/a | keyword_ty p; |
---|
2538 | n/a | if (!value) { |
---|
2539 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2540 | n/a | "field value is required for keyword"); |
---|
2541 | n/a | return NULL; |
---|
2542 | n/a | } |
---|
2543 | n/a | p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2544 | n/a | if (!p) |
---|
2545 | n/a | return NULL; |
---|
2546 | n/a | p->arg = arg; |
---|
2547 | n/a | p->value = value; |
---|
2548 | n/a | return p; |
---|
2549 | n/a | } |
---|
2550 | n/a | |
---|
2551 | n/a | alias_ty |
---|
2552 | n/a | alias(identifier name, identifier asname, PyArena *arena) |
---|
2553 | n/a | { |
---|
2554 | n/a | alias_ty p; |
---|
2555 | n/a | if (!name) { |
---|
2556 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2557 | n/a | "field name is required for alias"); |
---|
2558 | n/a | return NULL; |
---|
2559 | n/a | } |
---|
2560 | n/a | p = (alias_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2561 | n/a | if (!p) |
---|
2562 | n/a | return NULL; |
---|
2563 | n/a | p->name = name; |
---|
2564 | n/a | p->asname = asname; |
---|
2565 | n/a | return p; |
---|
2566 | n/a | } |
---|
2567 | n/a | |
---|
2568 | n/a | withitem_ty |
---|
2569 | n/a | withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena) |
---|
2570 | n/a | { |
---|
2571 | n/a | withitem_ty p; |
---|
2572 | n/a | if (!context_expr) { |
---|
2573 | n/a | PyErr_SetString(PyExc_ValueError, |
---|
2574 | n/a | "field context_expr is required for withitem"); |
---|
2575 | n/a | return NULL; |
---|
2576 | n/a | } |
---|
2577 | n/a | p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p)); |
---|
2578 | n/a | if (!p) |
---|
2579 | n/a | return NULL; |
---|
2580 | n/a | p->context_expr = context_expr; |
---|
2581 | n/a | p->optional_vars = optional_vars; |
---|
2582 | n/a | return p; |
---|
2583 | n/a | } |
---|
2584 | n/a | |
---|
2585 | n/a | |
---|
2586 | n/a | PyObject* |
---|
2587 | n/a | ast2obj_mod(void* _o) |
---|
2588 | n/a | { |
---|
2589 | n/a | mod_ty o = (mod_ty)_o; |
---|
2590 | n/a | PyObject *result = NULL, *value = NULL; |
---|
2591 | n/a | if (!o) { |
---|
2592 | n/a | Py_RETURN_NONE; |
---|
2593 | n/a | } |
---|
2594 | n/a | |
---|
2595 | n/a | switch (o->kind) { |
---|
2596 | n/a | case Module_kind: |
---|
2597 | n/a | result = PyType_GenericNew(Module_type, NULL, NULL); |
---|
2598 | n/a | if (!result) goto failed; |
---|
2599 | n/a | value = ast2obj_list(o->v.Module.body, ast2obj_stmt); |
---|
2600 | n/a | if (!value) goto failed; |
---|
2601 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2602 | n/a | goto failed; |
---|
2603 | n/a | Py_DECREF(value); |
---|
2604 | n/a | break; |
---|
2605 | n/a | case Interactive_kind: |
---|
2606 | n/a | result = PyType_GenericNew(Interactive_type, NULL, NULL); |
---|
2607 | n/a | if (!result) goto failed; |
---|
2608 | n/a | value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt); |
---|
2609 | n/a | if (!value) goto failed; |
---|
2610 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2611 | n/a | goto failed; |
---|
2612 | n/a | Py_DECREF(value); |
---|
2613 | n/a | break; |
---|
2614 | n/a | case Expression_kind: |
---|
2615 | n/a | result = PyType_GenericNew(Expression_type, NULL, NULL); |
---|
2616 | n/a | if (!result) goto failed; |
---|
2617 | n/a | value = ast2obj_expr(o->v.Expression.body); |
---|
2618 | n/a | if (!value) goto failed; |
---|
2619 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2620 | n/a | goto failed; |
---|
2621 | n/a | Py_DECREF(value); |
---|
2622 | n/a | break; |
---|
2623 | n/a | case Suite_kind: |
---|
2624 | n/a | result = PyType_GenericNew(Suite_type, NULL, NULL); |
---|
2625 | n/a | if (!result) goto failed; |
---|
2626 | n/a | value = ast2obj_list(o->v.Suite.body, ast2obj_stmt); |
---|
2627 | n/a | if (!value) goto failed; |
---|
2628 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2629 | n/a | goto failed; |
---|
2630 | n/a | Py_DECREF(value); |
---|
2631 | n/a | break; |
---|
2632 | n/a | } |
---|
2633 | n/a | return result; |
---|
2634 | n/a | failed: |
---|
2635 | n/a | Py_XDECREF(value); |
---|
2636 | n/a | Py_XDECREF(result); |
---|
2637 | n/a | return NULL; |
---|
2638 | n/a | } |
---|
2639 | n/a | |
---|
2640 | n/a | PyObject* |
---|
2641 | n/a | ast2obj_stmt(void* _o) |
---|
2642 | n/a | { |
---|
2643 | n/a | stmt_ty o = (stmt_ty)_o; |
---|
2644 | n/a | PyObject *result = NULL, *value = NULL; |
---|
2645 | n/a | if (!o) { |
---|
2646 | n/a | Py_RETURN_NONE; |
---|
2647 | n/a | } |
---|
2648 | n/a | |
---|
2649 | n/a | switch (o->kind) { |
---|
2650 | n/a | case FunctionDef_kind: |
---|
2651 | n/a | result = PyType_GenericNew(FunctionDef_type, NULL, NULL); |
---|
2652 | n/a | if (!result) goto failed; |
---|
2653 | n/a | value = ast2obj_identifier(o->v.FunctionDef.name); |
---|
2654 | n/a | if (!value) goto failed; |
---|
2655 | n/a | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
---|
2656 | n/a | goto failed; |
---|
2657 | n/a | Py_DECREF(value); |
---|
2658 | n/a | value = ast2obj_arguments(o->v.FunctionDef.args); |
---|
2659 | n/a | if (!value) goto failed; |
---|
2660 | n/a | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
---|
2661 | n/a | goto failed; |
---|
2662 | n/a | Py_DECREF(value); |
---|
2663 | n/a | value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt); |
---|
2664 | n/a | if (!value) goto failed; |
---|
2665 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2666 | n/a | goto failed; |
---|
2667 | n/a | Py_DECREF(value); |
---|
2668 | n/a | value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr); |
---|
2669 | n/a | if (!value) goto failed; |
---|
2670 | n/a | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
---|
2671 | n/a | goto failed; |
---|
2672 | n/a | Py_DECREF(value); |
---|
2673 | n/a | value = ast2obj_expr(o->v.FunctionDef.returns); |
---|
2674 | n/a | if (!value) goto failed; |
---|
2675 | n/a | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
---|
2676 | n/a | goto failed; |
---|
2677 | n/a | Py_DECREF(value); |
---|
2678 | n/a | break; |
---|
2679 | n/a | case AsyncFunctionDef_kind: |
---|
2680 | n/a | result = PyType_GenericNew(AsyncFunctionDef_type, NULL, NULL); |
---|
2681 | n/a | if (!result) goto failed; |
---|
2682 | n/a | value = ast2obj_identifier(o->v.AsyncFunctionDef.name); |
---|
2683 | n/a | if (!value) goto failed; |
---|
2684 | n/a | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
---|
2685 | n/a | goto failed; |
---|
2686 | n/a | Py_DECREF(value); |
---|
2687 | n/a | value = ast2obj_arguments(o->v.AsyncFunctionDef.args); |
---|
2688 | n/a | if (!value) goto failed; |
---|
2689 | n/a | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
---|
2690 | n/a | goto failed; |
---|
2691 | n/a | Py_DECREF(value); |
---|
2692 | n/a | value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt); |
---|
2693 | n/a | if (!value) goto failed; |
---|
2694 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2695 | n/a | goto failed; |
---|
2696 | n/a | Py_DECREF(value); |
---|
2697 | n/a | value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list, |
---|
2698 | n/a | ast2obj_expr); |
---|
2699 | n/a | if (!value) goto failed; |
---|
2700 | n/a | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
---|
2701 | n/a | goto failed; |
---|
2702 | n/a | Py_DECREF(value); |
---|
2703 | n/a | value = ast2obj_expr(o->v.AsyncFunctionDef.returns); |
---|
2704 | n/a | if (!value) goto failed; |
---|
2705 | n/a | if (_PyObject_SetAttrId(result, &PyId_returns, value) == -1) |
---|
2706 | n/a | goto failed; |
---|
2707 | n/a | Py_DECREF(value); |
---|
2708 | n/a | break; |
---|
2709 | n/a | case ClassDef_kind: |
---|
2710 | n/a | result = PyType_GenericNew(ClassDef_type, NULL, NULL); |
---|
2711 | n/a | if (!result) goto failed; |
---|
2712 | n/a | value = ast2obj_identifier(o->v.ClassDef.name); |
---|
2713 | n/a | if (!value) goto failed; |
---|
2714 | n/a | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
---|
2715 | n/a | goto failed; |
---|
2716 | n/a | Py_DECREF(value); |
---|
2717 | n/a | value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr); |
---|
2718 | n/a | if (!value) goto failed; |
---|
2719 | n/a | if (_PyObject_SetAttrId(result, &PyId_bases, value) == -1) |
---|
2720 | n/a | goto failed; |
---|
2721 | n/a | Py_DECREF(value); |
---|
2722 | n/a | value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword); |
---|
2723 | n/a | if (!value) goto failed; |
---|
2724 | n/a | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
---|
2725 | n/a | goto failed; |
---|
2726 | n/a | Py_DECREF(value); |
---|
2727 | n/a | value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt); |
---|
2728 | n/a | if (!value) goto failed; |
---|
2729 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2730 | n/a | goto failed; |
---|
2731 | n/a | Py_DECREF(value); |
---|
2732 | n/a | value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr); |
---|
2733 | n/a | if (!value) goto failed; |
---|
2734 | n/a | if (_PyObject_SetAttrId(result, &PyId_decorator_list, value) == -1) |
---|
2735 | n/a | goto failed; |
---|
2736 | n/a | Py_DECREF(value); |
---|
2737 | n/a | break; |
---|
2738 | n/a | case Return_kind: |
---|
2739 | n/a | result = PyType_GenericNew(Return_type, NULL, NULL); |
---|
2740 | n/a | if (!result) goto failed; |
---|
2741 | n/a | value = ast2obj_expr(o->v.Return.value); |
---|
2742 | n/a | if (!value) goto failed; |
---|
2743 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
2744 | n/a | goto failed; |
---|
2745 | n/a | Py_DECREF(value); |
---|
2746 | n/a | break; |
---|
2747 | n/a | case Delete_kind: |
---|
2748 | n/a | result = PyType_GenericNew(Delete_type, NULL, NULL); |
---|
2749 | n/a | if (!result) goto failed; |
---|
2750 | n/a | value = ast2obj_list(o->v.Delete.targets, ast2obj_expr); |
---|
2751 | n/a | if (!value) goto failed; |
---|
2752 | n/a | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
---|
2753 | n/a | goto failed; |
---|
2754 | n/a | Py_DECREF(value); |
---|
2755 | n/a | break; |
---|
2756 | n/a | case Assign_kind: |
---|
2757 | n/a | result = PyType_GenericNew(Assign_type, NULL, NULL); |
---|
2758 | n/a | if (!result) goto failed; |
---|
2759 | n/a | value = ast2obj_list(o->v.Assign.targets, ast2obj_expr); |
---|
2760 | n/a | if (!value) goto failed; |
---|
2761 | n/a | if (_PyObject_SetAttrId(result, &PyId_targets, value) == -1) |
---|
2762 | n/a | goto failed; |
---|
2763 | n/a | Py_DECREF(value); |
---|
2764 | n/a | value = ast2obj_expr(o->v.Assign.value); |
---|
2765 | n/a | if (!value) goto failed; |
---|
2766 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
2767 | n/a | goto failed; |
---|
2768 | n/a | Py_DECREF(value); |
---|
2769 | n/a | break; |
---|
2770 | n/a | case AugAssign_kind: |
---|
2771 | n/a | result = PyType_GenericNew(AugAssign_type, NULL, NULL); |
---|
2772 | n/a | if (!result) goto failed; |
---|
2773 | n/a | value = ast2obj_expr(o->v.AugAssign.target); |
---|
2774 | n/a | if (!value) goto failed; |
---|
2775 | n/a | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
---|
2776 | n/a | goto failed; |
---|
2777 | n/a | Py_DECREF(value); |
---|
2778 | n/a | value = ast2obj_operator(o->v.AugAssign.op); |
---|
2779 | n/a | if (!value) goto failed; |
---|
2780 | n/a | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
---|
2781 | n/a | goto failed; |
---|
2782 | n/a | Py_DECREF(value); |
---|
2783 | n/a | value = ast2obj_expr(o->v.AugAssign.value); |
---|
2784 | n/a | if (!value) goto failed; |
---|
2785 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
2786 | n/a | goto failed; |
---|
2787 | n/a | Py_DECREF(value); |
---|
2788 | n/a | break; |
---|
2789 | n/a | case AnnAssign_kind: |
---|
2790 | n/a | result = PyType_GenericNew(AnnAssign_type, NULL, NULL); |
---|
2791 | n/a | if (!result) goto failed; |
---|
2792 | n/a | value = ast2obj_expr(o->v.AnnAssign.target); |
---|
2793 | n/a | if (!value) goto failed; |
---|
2794 | n/a | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
---|
2795 | n/a | goto failed; |
---|
2796 | n/a | Py_DECREF(value); |
---|
2797 | n/a | value = ast2obj_expr(o->v.AnnAssign.annotation); |
---|
2798 | n/a | if (!value) goto failed; |
---|
2799 | n/a | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
---|
2800 | n/a | goto failed; |
---|
2801 | n/a | Py_DECREF(value); |
---|
2802 | n/a | value = ast2obj_expr(o->v.AnnAssign.value); |
---|
2803 | n/a | if (!value) goto failed; |
---|
2804 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
2805 | n/a | goto failed; |
---|
2806 | n/a | Py_DECREF(value); |
---|
2807 | n/a | value = ast2obj_int(o->v.AnnAssign.simple); |
---|
2808 | n/a | if (!value) goto failed; |
---|
2809 | n/a | if (_PyObject_SetAttrId(result, &PyId_simple, value) == -1) |
---|
2810 | n/a | goto failed; |
---|
2811 | n/a | Py_DECREF(value); |
---|
2812 | n/a | break; |
---|
2813 | n/a | case For_kind: |
---|
2814 | n/a | result = PyType_GenericNew(For_type, NULL, NULL); |
---|
2815 | n/a | if (!result) goto failed; |
---|
2816 | n/a | value = ast2obj_expr(o->v.For.target); |
---|
2817 | n/a | if (!value) goto failed; |
---|
2818 | n/a | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
---|
2819 | n/a | goto failed; |
---|
2820 | n/a | Py_DECREF(value); |
---|
2821 | n/a | value = ast2obj_expr(o->v.For.iter); |
---|
2822 | n/a | if (!value) goto failed; |
---|
2823 | n/a | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
---|
2824 | n/a | goto failed; |
---|
2825 | n/a | Py_DECREF(value); |
---|
2826 | n/a | value = ast2obj_list(o->v.For.body, ast2obj_stmt); |
---|
2827 | n/a | if (!value) goto failed; |
---|
2828 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2829 | n/a | goto failed; |
---|
2830 | n/a | Py_DECREF(value); |
---|
2831 | n/a | value = ast2obj_list(o->v.For.orelse, ast2obj_stmt); |
---|
2832 | n/a | if (!value) goto failed; |
---|
2833 | n/a | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
---|
2834 | n/a | goto failed; |
---|
2835 | n/a | Py_DECREF(value); |
---|
2836 | n/a | break; |
---|
2837 | n/a | case AsyncFor_kind: |
---|
2838 | n/a | result = PyType_GenericNew(AsyncFor_type, NULL, NULL); |
---|
2839 | n/a | if (!result) goto failed; |
---|
2840 | n/a | value = ast2obj_expr(o->v.AsyncFor.target); |
---|
2841 | n/a | if (!value) goto failed; |
---|
2842 | n/a | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
---|
2843 | n/a | goto failed; |
---|
2844 | n/a | Py_DECREF(value); |
---|
2845 | n/a | value = ast2obj_expr(o->v.AsyncFor.iter); |
---|
2846 | n/a | if (!value) goto failed; |
---|
2847 | n/a | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
---|
2848 | n/a | goto failed; |
---|
2849 | n/a | Py_DECREF(value); |
---|
2850 | n/a | value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt); |
---|
2851 | n/a | if (!value) goto failed; |
---|
2852 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2853 | n/a | goto failed; |
---|
2854 | n/a | Py_DECREF(value); |
---|
2855 | n/a | value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt); |
---|
2856 | n/a | if (!value) goto failed; |
---|
2857 | n/a | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
---|
2858 | n/a | goto failed; |
---|
2859 | n/a | Py_DECREF(value); |
---|
2860 | n/a | break; |
---|
2861 | n/a | case While_kind: |
---|
2862 | n/a | result = PyType_GenericNew(While_type, NULL, NULL); |
---|
2863 | n/a | if (!result) goto failed; |
---|
2864 | n/a | value = ast2obj_expr(o->v.While.test); |
---|
2865 | n/a | if (!value) goto failed; |
---|
2866 | n/a | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
---|
2867 | n/a | goto failed; |
---|
2868 | n/a | Py_DECREF(value); |
---|
2869 | n/a | value = ast2obj_list(o->v.While.body, ast2obj_stmt); |
---|
2870 | n/a | if (!value) goto failed; |
---|
2871 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2872 | n/a | goto failed; |
---|
2873 | n/a | Py_DECREF(value); |
---|
2874 | n/a | value = ast2obj_list(o->v.While.orelse, ast2obj_stmt); |
---|
2875 | n/a | if (!value) goto failed; |
---|
2876 | n/a | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
---|
2877 | n/a | goto failed; |
---|
2878 | n/a | Py_DECREF(value); |
---|
2879 | n/a | break; |
---|
2880 | n/a | case If_kind: |
---|
2881 | n/a | result = PyType_GenericNew(If_type, NULL, NULL); |
---|
2882 | n/a | if (!result) goto failed; |
---|
2883 | n/a | value = ast2obj_expr(o->v.If.test); |
---|
2884 | n/a | if (!value) goto failed; |
---|
2885 | n/a | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
---|
2886 | n/a | goto failed; |
---|
2887 | n/a | Py_DECREF(value); |
---|
2888 | n/a | value = ast2obj_list(o->v.If.body, ast2obj_stmt); |
---|
2889 | n/a | if (!value) goto failed; |
---|
2890 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2891 | n/a | goto failed; |
---|
2892 | n/a | Py_DECREF(value); |
---|
2893 | n/a | value = ast2obj_list(o->v.If.orelse, ast2obj_stmt); |
---|
2894 | n/a | if (!value) goto failed; |
---|
2895 | n/a | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
---|
2896 | n/a | goto failed; |
---|
2897 | n/a | Py_DECREF(value); |
---|
2898 | n/a | break; |
---|
2899 | n/a | case With_kind: |
---|
2900 | n/a | result = PyType_GenericNew(With_type, NULL, NULL); |
---|
2901 | n/a | if (!result) goto failed; |
---|
2902 | n/a | value = ast2obj_list(o->v.With.items, ast2obj_withitem); |
---|
2903 | n/a | if (!value) goto failed; |
---|
2904 | n/a | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
---|
2905 | n/a | goto failed; |
---|
2906 | n/a | Py_DECREF(value); |
---|
2907 | n/a | value = ast2obj_list(o->v.With.body, ast2obj_stmt); |
---|
2908 | n/a | if (!value) goto failed; |
---|
2909 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2910 | n/a | goto failed; |
---|
2911 | n/a | Py_DECREF(value); |
---|
2912 | n/a | break; |
---|
2913 | n/a | case AsyncWith_kind: |
---|
2914 | n/a | result = PyType_GenericNew(AsyncWith_type, NULL, NULL); |
---|
2915 | n/a | if (!result) goto failed; |
---|
2916 | n/a | value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem); |
---|
2917 | n/a | if (!value) goto failed; |
---|
2918 | n/a | if (_PyObject_SetAttrId(result, &PyId_items, value) == -1) |
---|
2919 | n/a | goto failed; |
---|
2920 | n/a | Py_DECREF(value); |
---|
2921 | n/a | value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt); |
---|
2922 | n/a | if (!value) goto failed; |
---|
2923 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2924 | n/a | goto failed; |
---|
2925 | n/a | Py_DECREF(value); |
---|
2926 | n/a | break; |
---|
2927 | n/a | case Raise_kind: |
---|
2928 | n/a | result = PyType_GenericNew(Raise_type, NULL, NULL); |
---|
2929 | n/a | if (!result) goto failed; |
---|
2930 | n/a | value = ast2obj_expr(o->v.Raise.exc); |
---|
2931 | n/a | if (!value) goto failed; |
---|
2932 | n/a | if (_PyObject_SetAttrId(result, &PyId_exc, value) == -1) |
---|
2933 | n/a | goto failed; |
---|
2934 | n/a | Py_DECREF(value); |
---|
2935 | n/a | value = ast2obj_expr(o->v.Raise.cause); |
---|
2936 | n/a | if (!value) goto failed; |
---|
2937 | n/a | if (_PyObject_SetAttrId(result, &PyId_cause, value) == -1) |
---|
2938 | n/a | goto failed; |
---|
2939 | n/a | Py_DECREF(value); |
---|
2940 | n/a | break; |
---|
2941 | n/a | case Try_kind: |
---|
2942 | n/a | result = PyType_GenericNew(Try_type, NULL, NULL); |
---|
2943 | n/a | if (!result) goto failed; |
---|
2944 | n/a | value = ast2obj_list(o->v.Try.body, ast2obj_stmt); |
---|
2945 | n/a | if (!value) goto failed; |
---|
2946 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
2947 | n/a | goto failed; |
---|
2948 | n/a | Py_DECREF(value); |
---|
2949 | n/a | value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler); |
---|
2950 | n/a | if (!value) goto failed; |
---|
2951 | n/a | if (_PyObject_SetAttrId(result, &PyId_handlers, value) == -1) |
---|
2952 | n/a | goto failed; |
---|
2953 | n/a | Py_DECREF(value); |
---|
2954 | n/a | value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt); |
---|
2955 | n/a | if (!value) goto failed; |
---|
2956 | n/a | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
---|
2957 | n/a | goto failed; |
---|
2958 | n/a | Py_DECREF(value); |
---|
2959 | n/a | value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt); |
---|
2960 | n/a | if (!value) goto failed; |
---|
2961 | n/a | if (_PyObject_SetAttrId(result, &PyId_finalbody, value) == -1) |
---|
2962 | n/a | goto failed; |
---|
2963 | n/a | Py_DECREF(value); |
---|
2964 | n/a | break; |
---|
2965 | n/a | case Assert_kind: |
---|
2966 | n/a | result = PyType_GenericNew(Assert_type, NULL, NULL); |
---|
2967 | n/a | if (!result) goto failed; |
---|
2968 | n/a | value = ast2obj_expr(o->v.Assert.test); |
---|
2969 | n/a | if (!value) goto failed; |
---|
2970 | n/a | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
---|
2971 | n/a | goto failed; |
---|
2972 | n/a | Py_DECREF(value); |
---|
2973 | n/a | value = ast2obj_expr(o->v.Assert.msg); |
---|
2974 | n/a | if (!value) goto failed; |
---|
2975 | n/a | if (_PyObject_SetAttrId(result, &PyId_msg, value) == -1) |
---|
2976 | n/a | goto failed; |
---|
2977 | n/a | Py_DECREF(value); |
---|
2978 | n/a | break; |
---|
2979 | n/a | case Import_kind: |
---|
2980 | n/a | result = PyType_GenericNew(Import_type, NULL, NULL); |
---|
2981 | n/a | if (!result) goto failed; |
---|
2982 | n/a | value = ast2obj_list(o->v.Import.names, ast2obj_alias); |
---|
2983 | n/a | if (!value) goto failed; |
---|
2984 | n/a | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
---|
2985 | n/a | goto failed; |
---|
2986 | n/a | Py_DECREF(value); |
---|
2987 | n/a | break; |
---|
2988 | n/a | case ImportFrom_kind: |
---|
2989 | n/a | result = PyType_GenericNew(ImportFrom_type, NULL, NULL); |
---|
2990 | n/a | if (!result) goto failed; |
---|
2991 | n/a | value = ast2obj_identifier(o->v.ImportFrom.module); |
---|
2992 | n/a | if (!value) goto failed; |
---|
2993 | n/a | if (_PyObject_SetAttrId(result, &PyId_module, value) == -1) |
---|
2994 | n/a | goto failed; |
---|
2995 | n/a | Py_DECREF(value); |
---|
2996 | n/a | value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias); |
---|
2997 | n/a | if (!value) goto failed; |
---|
2998 | n/a | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
---|
2999 | n/a | goto failed; |
---|
3000 | n/a | Py_DECREF(value); |
---|
3001 | n/a | value = ast2obj_int(o->v.ImportFrom.level); |
---|
3002 | n/a | if (!value) goto failed; |
---|
3003 | n/a | if (_PyObject_SetAttrId(result, &PyId_level, value) == -1) |
---|
3004 | n/a | goto failed; |
---|
3005 | n/a | Py_DECREF(value); |
---|
3006 | n/a | break; |
---|
3007 | n/a | case Global_kind: |
---|
3008 | n/a | result = PyType_GenericNew(Global_type, NULL, NULL); |
---|
3009 | n/a | if (!result) goto failed; |
---|
3010 | n/a | value = ast2obj_list(o->v.Global.names, ast2obj_identifier); |
---|
3011 | n/a | if (!value) goto failed; |
---|
3012 | n/a | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
---|
3013 | n/a | goto failed; |
---|
3014 | n/a | Py_DECREF(value); |
---|
3015 | n/a | break; |
---|
3016 | n/a | case Nonlocal_kind: |
---|
3017 | n/a | result = PyType_GenericNew(Nonlocal_type, NULL, NULL); |
---|
3018 | n/a | if (!result) goto failed; |
---|
3019 | n/a | value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier); |
---|
3020 | n/a | if (!value) goto failed; |
---|
3021 | n/a | if (_PyObject_SetAttrId(result, &PyId_names, value) == -1) |
---|
3022 | n/a | goto failed; |
---|
3023 | n/a | Py_DECREF(value); |
---|
3024 | n/a | break; |
---|
3025 | n/a | case Expr_kind: |
---|
3026 | n/a | result = PyType_GenericNew(Expr_type, NULL, NULL); |
---|
3027 | n/a | if (!result) goto failed; |
---|
3028 | n/a | value = ast2obj_expr(o->v.Expr.value); |
---|
3029 | n/a | if (!value) goto failed; |
---|
3030 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3031 | n/a | goto failed; |
---|
3032 | n/a | Py_DECREF(value); |
---|
3033 | n/a | break; |
---|
3034 | n/a | case Pass_kind: |
---|
3035 | n/a | result = PyType_GenericNew(Pass_type, NULL, NULL); |
---|
3036 | n/a | if (!result) goto failed; |
---|
3037 | n/a | break; |
---|
3038 | n/a | case Break_kind: |
---|
3039 | n/a | result = PyType_GenericNew(Break_type, NULL, NULL); |
---|
3040 | n/a | if (!result) goto failed; |
---|
3041 | n/a | break; |
---|
3042 | n/a | case Continue_kind: |
---|
3043 | n/a | result = PyType_GenericNew(Continue_type, NULL, NULL); |
---|
3044 | n/a | if (!result) goto failed; |
---|
3045 | n/a | break; |
---|
3046 | n/a | } |
---|
3047 | n/a | value = ast2obj_int(o->lineno); |
---|
3048 | n/a | if (!value) goto failed; |
---|
3049 | n/a | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
---|
3050 | n/a | goto failed; |
---|
3051 | n/a | Py_DECREF(value); |
---|
3052 | n/a | value = ast2obj_int(o->col_offset); |
---|
3053 | n/a | if (!value) goto failed; |
---|
3054 | n/a | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
---|
3055 | n/a | goto failed; |
---|
3056 | n/a | Py_DECREF(value); |
---|
3057 | n/a | return result; |
---|
3058 | n/a | failed: |
---|
3059 | n/a | Py_XDECREF(value); |
---|
3060 | n/a | Py_XDECREF(result); |
---|
3061 | n/a | return NULL; |
---|
3062 | n/a | } |
---|
3063 | n/a | |
---|
3064 | n/a | PyObject* |
---|
3065 | n/a | ast2obj_expr(void* _o) |
---|
3066 | n/a | { |
---|
3067 | n/a | expr_ty o = (expr_ty)_o; |
---|
3068 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3069 | n/a | if (!o) { |
---|
3070 | n/a | Py_RETURN_NONE; |
---|
3071 | n/a | } |
---|
3072 | n/a | |
---|
3073 | n/a | switch (o->kind) { |
---|
3074 | n/a | case BoolOp_kind: |
---|
3075 | n/a | result = PyType_GenericNew(BoolOp_type, NULL, NULL); |
---|
3076 | n/a | if (!result) goto failed; |
---|
3077 | n/a | value = ast2obj_boolop(o->v.BoolOp.op); |
---|
3078 | n/a | if (!value) goto failed; |
---|
3079 | n/a | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
---|
3080 | n/a | goto failed; |
---|
3081 | n/a | Py_DECREF(value); |
---|
3082 | n/a | value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr); |
---|
3083 | n/a | if (!value) goto failed; |
---|
3084 | n/a | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
---|
3085 | n/a | goto failed; |
---|
3086 | n/a | Py_DECREF(value); |
---|
3087 | n/a | break; |
---|
3088 | n/a | case BinOp_kind: |
---|
3089 | n/a | result = PyType_GenericNew(BinOp_type, NULL, NULL); |
---|
3090 | n/a | if (!result) goto failed; |
---|
3091 | n/a | value = ast2obj_expr(o->v.BinOp.left); |
---|
3092 | n/a | if (!value) goto failed; |
---|
3093 | n/a | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
---|
3094 | n/a | goto failed; |
---|
3095 | n/a | Py_DECREF(value); |
---|
3096 | n/a | value = ast2obj_operator(o->v.BinOp.op); |
---|
3097 | n/a | if (!value) goto failed; |
---|
3098 | n/a | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
---|
3099 | n/a | goto failed; |
---|
3100 | n/a | Py_DECREF(value); |
---|
3101 | n/a | value = ast2obj_expr(o->v.BinOp.right); |
---|
3102 | n/a | if (!value) goto failed; |
---|
3103 | n/a | if (_PyObject_SetAttrId(result, &PyId_right, value) == -1) |
---|
3104 | n/a | goto failed; |
---|
3105 | n/a | Py_DECREF(value); |
---|
3106 | n/a | break; |
---|
3107 | n/a | case UnaryOp_kind: |
---|
3108 | n/a | result = PyType_GenericNew(UnaryOp_type, NULL, NULL); |
---|
3109 | n/a | if (!result) goto failed; |
---|
3110 | n/a | value = ast2obj_unaryop(o->v.UnaryOp.op); |
---|
3111 | n/a | if (!value) goto failed; |
---|
3112 | n/a | if (_PyObject_SetAttrId(result, &PyId_op, value) == -1) |
---|
3113 | n/a | goto failed; |
---|
3114 | n/a | Py_DECREF(value); |
---|
3115 | n/a | value = ast2obj_expr(o->v.UnaryOp.operand); |
---|
3116 | n/a | if (!value) goto failed; |
---|
3117 | n/a | if (_PyObject_SetAttrId(result, &PyId_operand, value) == -1) |
---|
3118 | n/a | goto failed; |
---|
3119 | n/a | Py_DECREF(value); |
---|
3120 | n/a | break; |
---|
3121 | n/a | case Lambda_kind: |
---|
3122 | n/a | result = PyType_GenericNew(Lambda_type, NULL, NULL); |
---|
3123 | n/a | if (!result) goto failed; |
---|
3124 | n/a | value = ast2obj_arguments(o->v.Lambda.args); |
---|
3125 | n/a | if (!value) goto failed; |
---|
3126 | n/a | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
---|
3127 | n/a | goto failed; |
---|
3128 | n/a | Py_DECREF(value); |
---|
3129 | n/a | value = ast2obj_expr(o->v.Lambda.body); |
---|
3130 | n/a | if (!value) goto failed; |
---|
3131 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
3132 | n/a | goto failed; |
---|
3133 | n/a | Py_DECREF(value); |
---|
3134 | n/a | break; |
---|
3135 | n/a | case IfExp_kind: |
---|
3136 | n/a | result = PyType_GenericNew(IfExp_type, NULL, NULL); |
---|
3137 | n/a | if (!result) goto failed; |
---|
3138 | n/a | value = ast2obj_expr(o->v.IfExp.test); |
---|
3139 | n/a | if (!value) goto failed; |
---|
3140 | n/a | if (_PyObject_SetAttrId(result, &PyId_test, value) == -1) |
---|
3141 | n/a | goto failed; |
---|
3142 | n/a | Py_DECREF(value); |
---|
3143 | n/a | value = ast2obj_expr(o->v.IfExp.body); |
---|
3144 | n/a | if (!value) goto failed; |
---|
3145 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
3146 | n/a | goto failed; |
---|
3147 | n/a | Py_DECREF(value); |
---|
3148 | n/a | value = ast2obj_expr(o->v.IfExp.orelse); |
---|
3149 | n/a | if (!value) goto failed; |
---|
3150 | n/a | if (_PyObject_SetAttrId(result, &PyId_orelse, value) == -1) |
---|
3151 | n/a | goto failed; |
---|
3152 | n/a | Py_DECREF(value); |
---|
3153 | n/a | break; |
---|
3154 | n/a | case Dict_kind: |
---|
3155 | n/a | result = PyType_GenericNew(Dict_type, NULL, NULL); |
---|
3156 | n/a | if (!result) goto failed; |
---|
3157 | n/a | value = ast2obj_list(o->v.Dict.keys, ast2obj_expr); |
---|
3158 | n/a | if (!value) goto failed; |
---|
3159 | n/a | if (_PyObject_SetAttrId(result, &PyId_keys, value) == -1) |
---|
3160 | n/a | goto failed; |
---|
3161 | n/a | Py_DECREF(value); |
---|
3162 | n/a | value = ast2obj_list(o->v.Dict.values, ast2obj_expr); |
---|
3163 | n/a | if (!value) goto failed; |
---|
3164 | n/a | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
---|
3165 | n/a | goto failed; |
---|
3166 | n/a | Py_DECREF(value); |
---|
3167 | n/a | break; |
---|
3168 | n/a | case Set_kind: |
---|
3169 | n/a | result = PyType_GenericNew(Set_type, NULL, NULL); |
---|
3170 | n/a | if (!result) goto failed; |
---|
3171 | n/a | value = ast2obj_list(o->v.Set.elts, ast2obj_expr); |
---|
3172 | n/a | if (!value) goto failed; |
---|
3173 | n/a | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
---|
3174 | n/a | goto failed; |
---|
3175 | n/a | Py_DECREF(value); |
---|
3176 | n/a | break; |
---|
3177 | n/a | case ListComp_kind: |
---|
3178 | n/a | result = PyType_GenericNew(ListComp_type, NULL, NULL); |
---|
3179 | n/a | if (!result) goto failed; |
---|
3180 | n/a | value = ast2obj_expr(o->v.ListComp.elt); |
---|
3181 | n/a | if (!value) goto failed; |
---|
3182 | n/a | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
---|
3183 | n/a | goto failed; |
---|
3184 | n/a | Py_DECREF(value); |
---|
3185 | n/a | value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension); |
---|
3186 | n/a | if (!value) goto failed; |
---|
3187 | n/a | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
---|
3188 | n/a | goto failed; |
---|
3189 | n/a | Py_DECREF(value); |
---|
3190 | n/a | break; |
---|
3191 | n/a | case SetComp_kind: |
---|
3192 | n/a | result = PyType_GenericNew(SetComp_type, NULL, NULL); |
---|
3193 | n/a | if (!result) goto failed; |
---|
3194 | n/a | value = ast2obj_expr(o->v.SetComp.elt); |
---|
3195 | n/a | if (!value) goto failed; |
---|
3196 | n/a | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
---|
3197 | n/a | goto failed; |
---|
3198 | n/a | Py_DECREF(value); |
---|
3199 | n/a | value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension); |
---|
3200 | n/a | if (!value) goto failed; |
---|
3201 | n/a | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
---|
3202 | n/a | goto failed; |
---|
3203 | n/a | Py_DECREF(value); |
---|
3204 | n/a | break; |
---|
3205 | n/a | case DictComp_kind: |
---|
3206 | n/a | result = PyType_GenericNew(DictComp_type, NULL, NULL); |
---|
3207 | n/a | if (!result) goto failed; |
---|
3208 | n/a | value = ast2obj_expr(o->v.DictComp.key); |
---|
3209 | n/a | if (!value) goto failed; |
---|
3210 | n/a | if (_PyObject_SetAttrId(result, &PyId_key, value) == -1) |
---|
3211 | n/a | goto failed; |
---|
3212 | n/a | Py_DECREF(value); |
---|
3213 | n/a | value = ast2obj_expr(o->v.DictComp.value); |
---|
3214 | n/a | if (!value) goto failed; |
---|
3215 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3216 | n/a | goto failed; |
---|
3217 | n/a | Py_DECREF(value); |
---|
3218 | n/a | value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension); |
---|
3219 | n/a | if (!value) goto failed; |
---|
3220 | n/a | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
---|
3221 | n/a | goto failed; |
---|
3222 | n/a | Py_DECREF(value); |
---|
3223 | n/a | break; |
---|
3224 | n/a | case GeneratorExp_kind: |
---|
3225 | n/a | result = PyType_GenericNew(GeneratorExp_type, NULL, NULL); |
---|
3226 | n/a | if (!result) goto failed; |
---|
3227 | n/a | value = ast2obj_expr(o->v.GeneratorExp.elt); |
---|
3228 | n/a | if (!value) goto failed; |
---|
3229 | n/a | if (_PyObject_SetAttrId(result, &PyId_elt, value) == -1) |
---|
3230 | n/a | goto failed; |
---|
3231 | n/a | Py_DECREF(value); |
---|
3232 | n/a | value = ast2obj_list(o->v.GeneratorExp.generators, |
---|
3233 | n/a | ast2obj_comprehension); |
---|
3234 | n/a | if (!value) goto failed; |
---|
3235 | n/a | if (_PyObject_SetAttrId(result, &PyId_generators, value) == -1) |
---|
3236 | n/a | goto failed; |
---|
3237 | n/a | Py_DECREF(value); |
---|
3238 | n/a | break; |
---|
3239 | n/a | case Await_kind: |
---|
3240 | n/a | result = PyType_GenericNew(Await_type, NULL, NULL); |
---|
3241 | n/a | if (!result) goto failed; |
---|
3242 | n/a | value = ast2obj_expr(o->v.Await.value); |
---|
3243 | n/a | if (!value) goto failed; |
---|
3244 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3245 | n/a | goto failed; |
---|
3246 | n/a | Py_DECREF(value); |
---|
3247 | n/a | break; |
---|
3248 | n/a | case Yield_kind: |
---|
3249 | n/a | result = PyType_GenericNew(Yield_type, NULL, NULL); |
---|
3250 | n/a | if (!result) goto failed; |
---|
3251 | n/a | value = ast2obj_expr(o->v.Yield.value); |
---|
3252 | n/a | if (!value) goto failed; |
---|
3253 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3254 | n/a | goto failed; |
---|
3255 | n/a | Py_DECREF(value); |
---|
3256 | n/a | break; |
---|
3257 | n/a | case YieldFrom_kind: |
---|
3258 | n/a | result = PyType_GenericNew(YieldFrom_type, NULL, NULL); |
---|
3259 | n/a | if (!result) goto failed; |
---|
3260 | n/a | value = ast2obj_expr(o->v.YieldFrom.value); |
---|
3261 | n/a | if (!value) goto failed; |
---|
3262 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3263 | n/a | goto failed; |
---|
3264 | n/a | Py_DECREF(value); |
---|
3265 | n/a | break; |
---|
3266 | n/a | case Compare_kind: |
---|
3267 | n/a | result = PyType_GenericNew(Compare_type, NULL, NULL); |
---|
3268 | n/a | if (!result) goto failed; |
---|
3269 | n/a | value = ast2obj_expr(o->v.Compare.left); |
---|
3270 | n/a | if (!value) goto failed; |
---|
3271 | n/a | if (_PyObject_SetAttrId(result, &PyId_left, value) == -1) |
---|
3272 | n/a | goto failed; |
---|
3273 | n/a | Py_DECREF(value); |
---|
3274 | n/a | { |
---|
3275 | n/a | Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops); |
---|
3276 | n/a | value = PyList_New(n); |
---|
3277 | n/a | if (!value) goto failed; |
---|
3278 | n/a | for(i = 0; i < n; i++) |
---|
3279 | n/a | PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i))); |
---|
3280 | n/a | } |
---|
3281 | n/a | if (!value) goto failed; |
---|
3282 | n/a | if (_PyObject_SetAttrId(result, &PyId_ops, value) == -1) |
---|
3283 | n/a | goto failed; |
---|
3284 | n/a | Py_DECREF(value); |
---|
3285 | n/a | value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr); |
---|
3286 | n/a | if (!value) goto failed; |
---|
3287 | n/a | if (_PyObject_SetAttrId(result, &PyId_comparators, value) == -1) |
---|
3288 | n/a | goto failed; |
---|
3289 | n/a | Py_DECREF(value); |
---|
3290 | n/a | break; |
---|
3291 | n/a | case Call_kind: |
---|
3292 | n/a | result = PyType_GenericNew(Call_type, NULL, NULL); |
---|
3293 | n/a | if (!result) goto failed; |
---|
3294 | n/a | value = ast2obj_expr(o->v.Call.func); |
---|
3295 | n/a | if (!value) goto failed; |
---|
3296 | n/a | if (_PyObject_SetAttrId(result, &PyId_func, value) == -1) |
---|
3297 | n/a | goto failed; |
---|
3298 | n/a | Py_DECREF(value); |
---|
3299 | n/a | value = ast2obj_list(o->v.Call.args, ast2obj_expr); |
---|
3300 | n/a | if (!value) goto failed; |
---|
3301 | n/a | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
---|
3302 | n/a | goto failed; |
---|
3303 | n/a | Py_DECREF(value); |
---|
3304 | n/a | value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword); |
---|
3305 | n/a | if (!value) goto failed; |
---|
3306 | n/a | if (_PyObject_SetAttrId(result, &PyId_keywords, value) == -1) |
---|
3307 | n/a | goto failed; |
---|
3308 | n/a | Py_DECREF(value); |
---|
3309 | n/a | break; |
---|
3310 | n/a | case Num_kind: |
---|
3311 | n/a | result = PyType_GenericNew(Num_type, NULL, NULL); |
---|
3312 | n/a | if (!result) goto failed; |
---|
3313 | n/a | value = ast2obj_object(o->v.Num.n); |
---|
3314 | n/a | if (!value) goto failed; |
---|
3315 | n/a | if (_PyObject_SetAttrId(result, &PyId_n, value) == -1) |
---|
3316 | n/a | goto failed; |
---|
3317 | n/a | Py_DECREF(value); |
---|
3318 | n/a | break; |
---|
3319 | n/a | case Str_kind: |
---|
3320 | n/a | result = PyType_GenericNew(Str_type, NULL, NULL); |
---|
3321 | n/a | if (!result) goto failed; |
---|
3322 | n/a | value = ast2obj_string(o->v.Str.s); |
---|
3323 | n/a | if (!value) goto failed; |
---|
3324 | n/a | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
---|
3325 | n/a | goto failed; |
---|
3326 | n/a | Py_DECREF(value); |
---|
3327 | n/a | break; |
---|
3328 | n/a | case FormattedValue_kind: |
---|
3329 | n/a | result = PyType_GenericNew(FormattedValue_type, NULL, NULL); |
---|
3330 | n/a | if (!result) goto failed; |
---|
3331 | n/a | value = ast2obj_expr(o->v.FormattedValue.value); |
---|
3332 | n/a | if (!value) goto failed; |
---|
3333 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3334 | n/a | goto failed; |
---|
3335 | n/a | Py_DECREF(value); |
---|
3336 | n/a | value = ast2obj_int(o->v.FormattedValue.conversion); |
---|
3337 | n/a | if (!value) goto failed; |
---|
3338 | n/a | if (_PyObject_SetAttrId(result, &PyId_conversion, value) == -1) |
---|
3339 | n/a | goto failed; |
---|
3340 | n/a | Py_DECREF(value); |
---|
3341 | n/a | value = ast2obj_expr(o->v.FormattedValue.format_spec); |
---|
3342 | n/a | if (!value) goto failed; |
---|
3343 | n/a | if (_PyObject_SetAttrId(result, &PyId_format_spec, value) == -1) |
---|
3344 | n/a | goto failed; |
---|
3345 | n/a | Py_DECREF(value); |
---|
3346 | n/a | break; |
---|
3347 | n/a | case JoinedStr_kind: |
---|
3348 | n/a | result = PyType_GenericNew(JoinedStr_type, NULL, NULL); |
---|
3349 | n/a | if (!result) goto failed; |
---|
3350 | n/a | value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr); |
---|
3351 | n/a | if (!value) goto failed; |
---|
3352 | n/a | if (_PyObject_SetAttrId(result, &PyId_values, value) == -1) |
---|
3353 | n/a | goto failed; |
---|
3354 | n/a | Py_DECREF(value); |
---|
3355 | n/a | break; |
---|
3356 | n/a | case Bytes_kind: |
---|
3357 | n/a | result = PyType_GenericNew(Bytes_type, NULL, NULL); |
---|
3358 | n/a | if (!result) goto failed; |
---|
3359 | n/a | value = ast2obj_bytes(o->v.Bytes.s); |
---|
3360 | n/a | if (!value) goto failed; |
---|
3361 | n/a | if (_PyObject_SetAttrId(result, &PyId_s, value) == -1) |
---|
3362 | n/a | goto failed; |
---|
3363 | n/a | Py_DECREF(value); |
---|
3364 | n/a | break; |
---|
3365 | n/a | case NameConstant_kind: |
---|
3366 | n/a | result = PyType_GenericNew(NameConstant_type, NULL, NULL); |
---|
3367 | n/a | if (!result) goto failed; |
---|
3368 | n/a | value = ast2obj_singleton(o->v.NameConstant.value); |
---|
3369 | n/a | if (!value) goto failed; |
---|
3370 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3371 | n/a | goto failed; |
---|
3372 | n/a | Py_DECREF(value); |
---|
3373 | n/a | break; |
---|
3374 | n/a | case Ellipsis_kind: |
---|
3375 | n/a | result = PyType_GenericNew(Ellipsis_type, NULL, NULL); |
---|
3376 | n/a | if (!result) goto failed; |
---|
3377 | n/a | break; |
---|
3378 | n/a | case Constant_kind: |
---|
3379 | n/a | result = PyType_GenericNew(Constant_type, NULL, NULL); |
---|
3380 | n/a | if (!result) goto failed; |
---|
3381 | n/a | value = ast2obj_constant(o->v.Constant.value); |
---|
3382 | n/a | if (!value) goto failed; |
---|
3383 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3384 | n/a | goto failed; |
---|
3385 | n/a | Py_DECREF(value); |
---|
3386 | n/a | break; |
---|
3387 | n/a | case Attribute_kind: |
---|
3388 | n/a | result = PyType_GenericNew(Attribute_type, NULL, NULL); |
---|
3389 | n/a | if (!result) goto failed; |
---|
3390 | n/a | value = ast2obj_expr(o->v.Attribute.value); |
---|
3391 | n/a | if (!value) goto failed; |
---|
3392 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3393 | n/a | goto failed; |
---|
3394 | n/a | Py_DECREF(value); |
---|
3395 | n/a | value = ast2obj_identifier(o->v.Attribute.attr); |
---|
3396 | n/a | if (!value) goto failed; |
---|
3397 | n/a | if (_PyObject_SetAttrId(result, &PyId_attr, value) == -1) |
---|
3398 | n/a | goto failed; |
---|
3399 | n/a | Py_DECREF(value); |
---|
3400 | n/a | value = ast2obj_expr_context(o->v.Attribute.ctx); |
---|
3401 | n/a | if (!value) goto failed; |
---|
3402 | n/a | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
---|
3403 | n/a | goto failed; |
---|
3404 | n/a | Py_DECREF(value); |
---|
3405 | n/a | break; |
---|
3406 | n/a | case Subscript_kind: |
---|
3407 | n/a | result = PyType_GenericNew(Subscript_type, NULL, NULL); |
---|
3408 | n/a | if (!result) goto failed; |
---|
3409 | n/a | value = ast2obj_expr(o->v.Subscript.value); |
---|
3410 | n/a | if (!value) goto failed; |
---|
3411 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3412 | n/a | goto failed; |
---|
3413 | n/a | Py_DECREF(value); |
---|
3414 | n/a | value = ast2obj_slice(o->v.Subscript.slice); |
---|
3415 | n/a | if (!value) goto failed; |
---|
3416 | n/a | if (_PyObject_SetAttrId(result, &PyId_slice, value) == -1) |
---|
3417 | n/a | goto failed; |
---|
3418 | n/a | Py_DECREF(value); |
---|
3419 | n/a | value = ast2obj_expr_context(o->v.Subscript.ctx); |
---|
3420 | n/a | if (!value) goto failed; |
---|
3421 | n/a | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
---|
3422 | n/a | goto failed; |
---|
3423 | n/a | Py_DECREF(value); |
---|
3424 | n/a | break; |
---|
3425 | n/a | case Starred_kind: |
---|
3426 | n/a | result = PyType_GenericNew(Starred_type, NULL, NULL); |
---|
3427 | n/a | if (!result) goto failed; |
---|
3428 | n/a | value = ast2obj_expr(o->v.Starred.value); |
---|
3429 | n/a | if (!value) goto failed; |
---|
3430 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3431 | n/a | goto failed; |
---|
3432 | n/a | Py_DECREF(value); |
---|
3433 | n/a | value = ast2obj_expr_context(o->v.Starred.ctx); |
---|
3434 | n/a | if (!value) goto failed; |
---|
3435 | n/a | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
---|
3436 | n/a | goto failed; |
---|
3437 | n/a | Py_DECREF(value); |
---|
3438 | n/a | break; |
---|
3439 | n/a | case Name_kind: |
---|
3440 | n/a | result = PyType_GenericNew(Name_type, NULL, NULL); |
---|
3441 | n/a | if (!result) goto failed; |
---|
3442 | n/a | value = ast2obj_identifier(o->v.Name.id); |
---|
3443 | n/a | if (!value) goto failed; |
---|
3444 | n/a | if (_PyObject_SetAttrId(result, &PyId_id, value) == -1) |
---|
3445 | n/a | goto failed; |
---|
3446 | n/a | Py_DECREF(value); |
---|
3447 | n/a | value = ast2obj_expr_context(o->v.Name.ctx); |
---|
3448 | n/a | if (!value) goto failed; |
---|
3449 | n/a | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
---|
3450 | n/a | goto failed; |
---|
3451 | n/a | Py_DECREF(value); |
---|
3452 | n/a | break; |
---|
3453 | n/a | case List_kind: |
---|
3454 | n/a | result = PyType_GenericNew(List_type, NULL, NULL); |
---|
3455 | n/a | if (!result) goto failed; |
---|
3456 | n/a | value = ast2obj_list(o->v.List.elts, ast2obj_expr); |
---|
3457 | n/a | if (!value) goto failed; |
---|
3458 | n/a | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
---|
3459 | n/a | goto failed; |
---|
3460 | n/a | Py_DECREF(value); |
---|
3461 | n/a | value = ast2obj_expr_context(o->v.List.ctx); |
---|
3462 | n/a | if (!value) goto failed; |
---|
3463 | n/a | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
---|
3464 | n/a | goto failed; |
---|
3465 | n/a | Py_DECREF(value); |
---|
3466 | n/a | break; |
---|
3467 | n/a | case Tuple_kind: |
---|
3468 | n/a | result = PyType_GenericNew(Tuple_type, NULL, NULL); |
---|
3469 | n/a | if (!result) goto failed; |
---|
3470 | n/a | value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr); |
---|
3471 | n/a | if (!value) goto failed; |
---|
3472 | n/a | if (_PyObject_SetAttrId(result, &PyId_elts, value) == -1) |
---|
3473 | n/a | goto failed; |
---|
3474 | n/a | Py_DECREF(value); |
---|
3475 | n/a | value = ast2obj_expr_context(o->v.Tuple.ctx); |
---|
3476 | n/a | if (!value) goto failed; |
---|
3477 | n/a | if (_PyObject_SetAttrId(result, &PyId_ctx, value) == -1) |
---|
3478 | n/a | goto failed; |
---|
3479 | n/a | Py_DECREF(value); |
---|
3480 | n/a | break; |
---|
3481 | n/a | } |
---|
3482 | n/a | value = ast2obj_int(o->lineno); |
---|
3483 | n/a | if (!value) goto failed; |
---|
3484 | n/a | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
---|
3485 | n/a | goto failed; |
---|
3486 | n/a | Py_DECREF(value); |
---|
3487 | n/a | value = ast2obj_int(o->col_offset); |
---|
3488 | n/a | if (!value) goto failed; |
---|
3489 | n/a | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
---|
3490 | n/a | goto failed; |
---|
3491 | n/a | Py_DECREF(value); |
---|
3492 | n/a | return result; |
---|
3493 | n/a | failed: |
---|
3494 | n/a | Py_XDECREF(value); |
---|
3495 | n/a | Py_XDECREF(result); |
---|
3496 | n/a | return NULL; |
---|
3497 | n/a | } |
---|
3498 | n/a | |
---|
3499 | n/a | PyObject* ast2obj_expr_context(expr_context_ty o) |
---|
3500 | n/a | { |
---|
3501 | n/a | switch(o) { |
---|
3502 | n/a | case Load: |
---|
3503 | n/a | Py_INCREF(Load_singleton); |
---|
3504 | n/a | return Load_singleton; |
---|
3505 | n/a | case Store: |
---|
3506 | n/a | Py_INCREF(Store_singleton); |
---|
3507 | n/a | return Store_singleton; |
---|
3508 | n/a | case Del: |
---|
3509 | n/a | Py_INCREF(Del_singleton); |
---|
3510 | n/a | return Del_singleton; |
---|
3511 | n/a | case AugLoad: |
---|
3512 | n/a | Py_INCREF(AugLoad_singleton); |
---|
3513 | n/a | return AugLoad_singleton; |
---|
3514 | n/a | case AugStore: |
---|
3515 | n/a | Py_INCREF(AugStore_singleton); |
---|
3516 | n/a | return AugStore_singleton; |
---|
3517 | n/a | case Param: |
---|
3518 | n/a | Py_INCREF(Param_singleton); |
---|
3519 | n/a | return Param_singleton; |
---|
3520 | n/a | default: |
---|
3521 | n/a | /* should never happen, but just in case ... */ |
---|
3522 | n/a | PyErr_Format(PyExc_SystemError, "unknown expr_context found"); |
---|
3523 | n/a | return NULL; |
---|
3524 | n/a | } |
---|
3525 | n/a | } |
---|
3526 | n/a | PyObject* |
---|
3527 | n/a | ast2obj_slice(void* _o) |
---|
3528 | n/a | { |
---|
3529 | n/a | slice_ty o = (slice_ty)_o; |
---|
3530 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3531 | n/a | if (!o) { |
---|
3532 | n/a | Py_RETURN_NONE; |
---|
3533 | n/a | } |
---|
3534 | n/a | |
---|
3535 | n/a | switch (o->kind) { |
---|
3536 | n/a | case Slice_kind: |
---|
3537 | n/a | result = PyType_GenericNew(Slice_type, NULL, NULL); |
---|
3538 | n/a | if (!result) goto failed; |
---|
3539 | n/a | value = ast2obj_expr(o->v.Slice.lower); |
---|
3540 | n/a | if (!value) goto failed; |
---|
3541 | n/a | if (_PyObject_SetAttrId(result, &PyId_lower, value) == -1) |
---|
3542 | n/a | goto failed; |
---|
3543 | n/a | Py_DECREF(value); |
---|
3544 | n/a | value = ast2obj_expr(o->v.Slice.upper); |
---|
3545 | n/a | if (!value) goto failed; |
---|
3546 | n/a | if (_PyObject_SetAttrId(result, &PyId_upper, value) == -1) |
---|
3547 | n/a | goto failed; |
---|
3548 | n/a | Py_DECREF(value); |
---|
3549 | n/a | value = ast2obj_expr(o->v.Slice.step); |
---|
3550 | n/a | if (!value) goto failed; |
---|
3551 | n/a | if (_PyObject_SetAttrId(result, &PyId_step, value) == -1) |
---|
3552 | n/a | goto failed; |
---|
3553 | n/a | Py_DECREF(value); |
---|
3554 | n/a | break; |
---|
3555 | n/a | case ExtSlice_kind: |
---|
3556 | n/a | result = PyType_GenericNew(ExtSlice_type, NULL, NULL); |
---|
3557 | n/a | if (!result) goto failed; |
---|
3558 | n/a | value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice); |
---|
3559 | n/a | if (!value) goto failed; |
---|
3560 | n/a | if (_PyObject_SetAttrId(result, &PyId_dims, value) == -1) |
---|
3561 | n/a | goto failed; |
---|
3562 | n/a | Py_DECREF(value); |
---|
3563 | n/a | break; |
---|
3564 | n/a | case Index_kind: |
---|
3565 | n/a | result = PyType_GenericNew(Index_type, NULL, NULL); |
---|
3566 | n/a | if (!result) goto failed; |
---|
3567 | n/a | value = ast2obj_expr(o->v.Index.value); |
---|
3568 | n/a | if (!value) goto failed; |
---|
3569 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3570 | n/a | goto failed; |
---|
3571 | n/a | Py_DECREF(value); |
---|
3572 | n/a | break; |
---|
3573 | n/a | } |
---|
3574 | n/a | return result; |
---|
3575 | n/a | failed: |
---|
3576 | n/a | Py_XDECREF(value); |
---|
3577 | n/a | Py_XDECREF(result); |
---|
3578 | n/a | return NULL; |
---|
3579 | n/a | } |
---|
3580 | n/a | |
---|
3581 | n/a | PyObject* ast2obj_boolop(boolop_ty o) |
---|
3582 | n/a | { |
---|
3583 | n/a | switch(o) { |
---|
3584 | n/a | case And: |
---|
3585 | n/a | Py_INCREF(And_singleton); |
---|
3586 | n/a | return And_singleton; |
---|
3587 | n/a | case Or: |
---|
3588 | n/a | Py_INCREF(Or_singleton); |
---|
3589 | n/a | return Or_singleton; |
---|
3590 | n/a | default: |
---|
3591 | n/a | /* should never happen, but just in case ... */ |
---|
3592 | n/a | PyErr_Format(PyExc_SystemError, "unknown boolop found"); |
---|
3593 | n/a | return NULL; |
---|
3594 | n/a | } |
---|
3595 | n/a | } |
---|
3596 | n/a | PyObject* ast2obj_operator(operator_ty o) |
---|
3597 | n/a | { |
---|
3598 | n/a | switch(o) { |
---|
3599 | n/a | case Add: |
---|
3600 | n/a | Py_INCREF(Add_singleton); |
---|
3601 | n/a | return Add_singleton; |
---|
3602 | n/a | case Sub: |
---|
3603 | n/a | Py_INCREF(Sub_singleton); |
---|
3604 | n/a | return Sub_singleton; |
---|
3605 | n/a | case Mult: |
---|
3606 | n/a | Py_INCREF(Mult_singleton); |
---|
3607 | n/a | return Mult_singleton; |
---|
3608 | n/a | case MatMult: |
---|
3609 | n/a | Py_INCREF(MatMult_singleton); |
---|
3610 | n/a | return MatMult_singleton; |
---|
3611 | n/a | case Div: |
---|
3612 | n/a | Py_INCREF(Div_singleton); |
---|
3613 | n/a | return Div_singleton; |
---|
3614 | n/a | case Mod: |
---|
3615 | n/a | Py_INCREF(Mod_singleton); |
---|
3616 | n/a | return Mod_singleton; |
---|
3617 | n/a | case Pow: |
---|
3618 | n/a | Py_INCREF(Pow_singleton); |
---|
3619 | n/a | return Pow_singleton; |
---|
3620 | n/a | case LShift: |
---|
3621 | n/a | Py_INCREF(LShift_singleton); |
---|
3622 | n/a | return LShift_singleton; |
---|
3623 | n/a | case RShift: |
---|
3624 | n/a | Py_INCREF(RShift_singleton); |
---|
3625 | n/a | return RShift_singleton; |
---|
3626 | n/a | case BitOr: |
---|
3627 | n/a | Py_INCREF(BitOr_singleton); |
---|
3628 | n/a | return BitOr_singleton; |
---|
3629 | n/a | case BitXor: |
---|
3630 | n/a | Py_INCREF(BitXor_singleton); |
---|
3631 | n/a | return BitXor_singleton; |
---|
3632 | n/a | case BitAnd: |
---|
3633 | n/a | Py_INCREF(BitAnd_singleton); |
---|
3634 | n/a | return BitAnd_singleton; |
---|
3635 | n/a | case FloorDiv: |
---|
3636 | n/a | Py_INCREF(FloorDiv_singleton); |
---|
3637 | n/a | return FloorDiv_singleton; |
---|
3638 | n/a | default: |
---|
3639 | n/a | /* should never happen, but just in case ... */ |
---|
3640 | n/a | PyErr_Format(PyExc_SystemError, "unknown operator found"); |
---|
3641 | n/a | return NULL; |
---|
3642 | n/a | } |
---|
3643 | n/a | } |
---|
3644 | n/a | PyObject* ast2obj_unaryop(unaryop_ty o) |
---|
3645 | n/a | { |
---|
3646 | n/a | switch(o) { |
---|
3647 | n/a | case Invert: |
---|
3648 | n/a | Py_INCREF(Invert_singleton); |
---|
3649 | n/a | return Invert_singleton; |
---|
3650 | n/a | case Not: |
---|
3651 | n/a | Py_INCREF(Not_singleton); |
---|
3652 | n/a | return Not_singleton; |
---|
3653 | n/a | case UAdd: |
---|
3654 | n/a | Py_INCREF(UAdd_singleton); |
---|
3655 | n/a | return UAdd_singleton; |
---|
3656 | n/a | case USub: |
---|
3657 | n/a | Py_INCREF(USub_singleton); |
---|
3658 | n/a | return USub_singleton; |
---|
3659 | n/a | default: |
---|
3660 | n/a | /* should never happen, but just in case ... */ |
---|
3661 | n/a | PyErr_Format(PyExc_SystemError, "unknown unaryop found"); |
---|
3662 | n/a | return NULL; |
---|
3663 | n/a | } |
---|
3664 | n/a | } |
---|
3665 | n/a | PyObject* ast2obj_cmpop(cmpop_ty o) |
---|
3666 | n/a | { |
---|
3667 | n/a | switch(o) { |
---|
3668 | n/a | case Eq: |
---|
3669 | n/a | Py_INCREF(Eq_singleton); |
---|
3670 | n/a | return Eq_singleton; |
---|
3671 | n/a | case NotEq: |
---|
3672 | n/a | Py_INCREF(NotEq_singleton); |
---|
3673 | n/a | return NotEq_singleton; |
---|
3674 | n/a | case Lt: |
---|
3675 | n/a | Py_INCREF(Lt_singleton); |
---|
3676 | n/a | return Lt_singleton; |
---|
3677 | n/a | case LtE: |
---|
3678 | n/a | Py_INCREF(LtE_singleton); |
---|
3679 | n/a | return LtE_singleton; |
---|
3680 | n/a | case Gt: |
---|
3681 | n/a | Py_INCREF(Gt_singleton); |
---|
3682 | n/a | return Gt_singleton; |
---|
3683 | n/a | case GtE: |
---|
3684 | n/a | Py_INCREF(GtE_singleton); |
---|
3685 | n/a | return GtE_singleton; |
---|
3686 | n/a | case Is: |
---|
3687 | n/a | Py_INCREF(Is_singleton); |
---|
3688 | n/a | return Is_singleton; |
---|
3689 | n/a | case IsNot: |
---|
3690 | n/a | Py_INCREF(IsNot_singleton); |
---|
3691 | n/a | return IsNot_singleton; |
---|
3692 | n/a | case In: |
---|
3693 | n/a | Py_INCREF(In_singleton); |
---|
3694 | n/a | return In_singleton; |
---|
3695 | n/a | case NotIn: |
---|
3696 | n/a | Py_INCREF(NotIn_singleton); |
---|
3697 | n/a | return NotIn_singleton; |
---|
3698 | n/a | default: |
---|
3699 | n/a | /* should never happen, but just in case ... */ |
---|
3700 | n/a | PyErr_Format(PyExc_SystemError, "unknown cmpop found"); |
---|
3701 | n/a | return NULL; |
---|
3702 | n/a | } |
---|
3703 | n/a | } |
---|
3704 | n/a | PyObject* |
---|
3705 | n/a | ast2obj_comprehension(void* _o) |
---|
3706 | n/a | { |
---|
3707 | n/a | comprehension_ty o = (comprehension_ty)_o; |
---|
3708 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3709 | n/a | if (!o) { |
---|
3710 | n/a | Py_RETURN_NONE; |
---|
3711 | n/a | } |
---|
3712 | n/a | |
---|
3713 | n/a | result = PyType_GenericNew(comprehension_type, NULL, NULL); |
---|
3714 | n/a | if (!result) return NULL; |
---|
3715 | n/a | value = ast2obj_expr(o->target); |
---|
3716 | n/a | if (!value) goto failed; |
---|
3717 | n/a | if (_PyObject_SetAttrId(result, &PyId_target, value) == -1) |
---|
3718 | n/a | goto failed; |
---|
3719 | n/a | Py_DECREF(value); |
---|
3720 | n/a | value = ast2obj_expr(o->iter); |
---|
3721 | n/a | if (!value) goto failed; |
---|
3722 | n/a | if (_PyObject_SetAttrId(result, &PyId_iter, value) == -1) |
---|
3723 | n/a | goto failed; |
---|
3724 | n/a | Py_DECREF(value); |
---|
3725 | n/a | value = ast2obj_list(o->ifs, ast2obj_expr); |
---|
3726 | n/a | if (!value) goto failed; |
---|
3727 | n/a | if (_PyObject_SetAttrId(result, &PyId_ifs, value) == -1) |
---|
3728 | n/a | goto failed; |
---|
3729 | n/a | Py_DECREF(value); |
---|
3730 | n/a | value = ast2obj_int(o->is_async); |
---|
3731 | n/a | if (!value) goto failed; |
---|
3732 | n/a | if (_PyObject_SetAttrId(result, &PyId_is_async, value) == -1) |
---|
3733 | n/a | goto failed; |
---|
3734 | n/a | Py_DECREF(value); |
---|
3735 | n/a | return result; |
---|
3736 | n/a | failed: |
---|
3737 | n/a | Py_XDECREF(value); |
---|
3738 | n/a | Py_XDECREF(result); |
---|
3739 | n/a | return NULL; |
---|
3740 | n/a | } |
---|
3741 | n/a | |
---|
3742 | n/a | PyObject* |
---|
3743 | n/a | ast2obj_excepthandler(void* _o) |
---|
3744 | n/a | { |
---|
3745 | n/a | excepthandler_ty o = (excepthandler_ty)_o; |
---|
3746 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3747 | n/a | if (!o) { |
---|
3748 | n/a | Py_RETURN_NONE; |
---|
3749 | n/a | } |
---|
3750 | n/a | |
---|
3751 | n/a | switch (o->kind) { |
---|
3752 | n/a | case ExceptHandler_kind: |
---|
3753 | n/a | result = PyType_GenericNew(ExceptHandler_type, NULL, NULL); |
---|
3754 | n/a | if (!result) goto failed; |
---|
3755 | n/a | value = ast2obj_expr(o->v.ExceptHandler.type); |
---|
3756 | n/a | if (!value) goto failed; |
---|
3757 | n/a | if (_PyObject_SetAttrId(result, &PyId_type, value) == -1) |
---|
3758 | n/a | goto failed; |
---|
3759 | n/a | Py_DECREF(value); |
---|
3760 | n/a | value = ast2obj_identifier(o->v.ExceptHandler.name); |
---|
3761 | n/a | if (!value) goto failed; |
---|
3762 | n/a | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
---|
3763 | n/a | goto failed; |
---|
3764 | n/a | Py_DECREF(value); |
---|
3765 | n/a | value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt); |
---|
3766 | n/a | if (!value) goto failed; |
---|
3767 | n/a | if (_PyObject_SetAttrId(result, &PyId_body, value) == -1) |
---|
3768 | n/a | goto failed; |
---|
3769 | n/a | Py_DECREF(value); |
---|
3770 | n/a | break; |
---|
3771 | n/a | } |
---|
3772 | n/a | value = ast2obj_int(o->lineno); |
---|
3773 | n/a | if (!value) goto failed; |
---|
3774 | n/a | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
---|
3775 | n/a | goto failed; |
---|
3776 | n/a | Py_DECREF(value); |
---|
3777 | n/a | value = ast2obj_int(o->col_offset); |
---|
3778 | n/a | if (!value) goto failed; |
---|
3779 | n/a | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
---|
3780 | n/a | goto failed; |
---|
3781 | n/a | Py_DECREF(value); |
---|
3782 | n/a | return result; |
---|
3783 | n/a | failed: |
---|
3784 | n/a | Py_XDECREF(value); |
---|
3785 | n/a | Py_XDECREF(result); |
---|
3786 | n/a | return NULL; |
---|
3787 | n/a | } |
---|
3788 | n/a | |
---|
3789 | n/a | PyObject* |
---|
3790 | n/a | ast2obj_arguments(void* _o) |
---|
3791 | n/a | { |
---|
3792 | n/a | arguments_ty o = (arguments_ty)_o; |
---|
3793 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3794 | n/a | if (!o) { |
---|
3795 | n/a | Py_RETURN_NONE; |
---|
3796 | n/a | } |
---|
3797 | n/a | |
---|
3798 | n/a | result = PyType_GenericNew(arguments_type, NULL, NULL); |
---|
3799 | n/a | if (!result) return NULL; |
---|
3800 | n/a | value = ast2obj_list(o->args, ast2obj_arg); |
---|
3801 | n/a | if (!value) goto failed; |
---|
3802 | n/a | if (_PyObject_SetAttrId(result, &PyId_args, value) == -1) |
---|
3803 | n/a | goto failed; |
---|
3804 | n/a | Py_DECREF(value); |
---|
3805 | n/a | value = ast2obj_arg(o->vararg); |
---|
3806 | n/a | if (!value) goto failed; |
---|
3807 | n/a | if (_PyObject_SetAttrId(result, &PyId_vararg, value) == -1) |
---|
3808 | n/a | goto failed; |
---|
3809 | n/a | Py_DECREF(value); |
---|
3810 | n/a | value = ast2obj_list(o->kwonlyargs, ast2obj_arg); |
---|
3811 | n/a | if (!value) goto failed; |
---|
3812 | n/a | if (_PyObject_SetAttrId(result, &PyId_kwonlyargs, value) == -1) |
---|
3813 | n/a | goto failed; |
---|
3814 | n/a | Py_DECREF(value); |
---|
3815 | n/a | value = ast2obj_list(o->kw_defaults, ast2obj_expr); |
---|
3816 | n/a | if (!value) goto failed; |
---|
3817 | n/a | if (_PyObject_SetAttrId(result, &PyId_kw_defaults, value) == -1) |
---|
3818 | n/a | goto failed; |
---|
3819 | n/a | Py_DECREF(value); |
---|
3820 | n/a | value = ast2obj_arg(o->kwarg); |
---|
3821 | n/a | if (!value) goto failed; |
---|
3822 | n/a | if (_PyObject_SetAttrId(result, &PyId_kwarg, value) == -1) |
---|
3823 | n/a | goto failed; |
---|
3824 | n/a | Py_DECREF(value); |
---|
3825 | n/a | value = ast2obj_list(o->defaults, ast2obj_expr); |
---|
3826 | n/a | if (!value) goto failed; |
---|
3827 | n/a | if (_PyObject_SetAttrId(result, &PyId_defaults, value) == -1) |
---|
3828 | n/a | goto failed; |
---|
3829 | n/a | Py_DECREF(value); |
---|
3830 | n/a | return result; |
---|
3831 | n/a | failed: |
---|
3832 | n/a | Py_XDECREF(value); |
---|
3833 | n/a | Py_XDECREF(result); |
---|
3834 | n/a | return NULL; |
---|
3835 | n/a | } |
---|
3836 | n/a | |
---|
3837 | n/a | PyObject* |
---|
3838 | n/a | ast2obj_arg(void* _o) |
---|
3839 | n/a | { |
---|
3840 | n/a | arg_ty o = (arg_ty)_o; |
---|
3841 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3842 | n/a | if (!o) { |
---|
3843 | n/a | Py_RETURN_NONE; |
---|
3844 | n/a | } |
---|
3845 | n/a | |
---|
3846 | n/a | result = PyType_GenericNew(arg_type, NULL, NULL); |
---|
3847 | n/a | if (!result) return NULL; |
---|
3848 | n/a | value = ast2obj_identifier(o->arg); |
---|
3849 | n/a | if (!value) goto failed; |
---|
3850 | n/a | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
---|
3851 | n/a | goto failed; |
---|
3852 | n/a | Py_DECREF(value); |
---|
3853 | n/a | value = ast2obj_expr(o->annotation); |
---|
3854 | n/a | if (!value) goto failed; |
---|
3855 | n/a | if (_PyObject_SetAttrId(result, &PyId_annotation, value) == -1) |
---|
3856 | n/a | goto failed; |
---|
3857 | n/a | Py_DECREF(value); |
---|
3858 | n/a | value = ast2obj_int(o->lineno); |
---|
3859 | n/a | if (!value) goto failed; |
---|
3860 | n/a | if (_PyObject_SetAttrId(result, &PyId_lineno, value) < 0) |
---|
3861 | n/a | goto failed; |
---|
3862 | n/a | Py_DECREF(value); |
---|
3863 | n/a | value = ast2obj_int(o->col_offset); |
---|
3864 | n/a | if (!value) goto failed; |
---|
3865 | n/a | if (_PyObject_SetAttrId(result, &PyId_col_offset, value) < 0) |
---|
3866 | n/a | goto failed; |
---|
3867 | n/a | Py_DECREF(value); |
---|
3868 | n/a | return result; |
---|
3869 | n/a | failed: |
---|
3870 | n/a | Py_XDECREF(value); |
---|
3871 | n/a | Py_XDECREF(result); |
---|
3872 | n/a | return NULL; |
---|
3873 | n/a | } |
---|
3874 | n/a | |
---|
3875 | n/a | PyObject* |
---|
3876 | n/a | ast2obj_keyword(void* _o) |
---|
3877 | n/a | { |
---|
3878 | n/a | keyword_ty o = (keyword_ty)_o; |
---|
3879 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3880 | n/a | if (!o) { |
---|
3881 | n/a | Py_RETURN_NONE; |
---|
3882 | n/a | } |
---|
3883 | n/a | |
---|
3884 | n/a | result = PyType_GenericNew(keyword_type, NULL, NULL); |
---|
3885 | n/a | if (!result) return NULL; |
---|
3886 | n/a | value = ast2obj_identifier(o->arg); |
---|
3887 | n/a | if (!value) goto failed; |
---|
3888 | n/a | if (_PyObject_SetAttrId(result, &PyId_arg, value) == -1) |
---|
3889 | n/a | goto failed; |
---|
3890 | n/a | Py_DECREF(value); |
---|
3891 | n/a | value = ast2obj_expr(o->value); |
---|
3892 | n/a | if (!value) goto failed; |
---|
3893 | n/a | if (_PyObject_SetAttrId(result, &PyId_value, value) == -1) |
---|
3894 | n/a | goto failed; |
---|
3895 | n/a | Py_DECREF(value); |
---|
3896 | n/a | return result; |
---|
3897 | n/a | failed: |
---|
3898 | n/a | Py_XDECREF(value); |
---|
3899 | n/a | Py_XDECREF(result); |
---|
3900 | n/a | return NULL; |
---|
3901 | n/a | } |
---|
3902 | n/a | |
---|
3903 | n/a | PyObject* |
---|
3904 | n/a | ast2obj_alias(void* _o) |
---|
3905 | n/a | { |
---|
3906 | n/a | alias_ty o = (alias_ty)_o; |
---|
3907 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3908 | n/a | if (!o) { |
---|
3909 | n/a | Py_RETURN_NONE; |
---|
3910 | n/a | } |
---|
3911 | n/a | |
---|
3912 | n/a | result = PyType_GenericNew(alias_type, NULL, NULL); |
---|
3913 | n/a | if (!result) return NULL; |
---|
3914 | n/a | value = ast2obj_identifier(o->name); |
---|
3915 | n/a | if (!value) goto failed; |
---|
3916 | n/a | if (_PyObject_SetAttrId(result, &PyId_name, value) == -1) |
---|
3917 | n/a | goto failed; |
---|
3918 | n/a | Py_DECREF(value); |
---|
3919 | n/a | value = ast2obj_identifier(o->asname); |
---|
3920 | n/a | if (!value) goto failed; |
---|
3921 | n/a | if (_PyObject_SetAttrId(result, &PyId_asname, value) == -1) |
---|
3922 | n/a | goto failed; |
---|
3923 | n/a | Py_DECREF(value); |
---|
3924 | n/a | return result; |
---|
3925 | n/a | failed: |
---|
3926 | n/a | Py_XDECREF(value); |
---|
3927 | n/a | Py_XDECREF(result); |
---|
3928 | n/a | return NULL; |
---|
3929 | n/a | } |
---|
3930 | n/a | |
---|
3931 | n/a | PyObject* |
---|
3932 | n/a | ast2obj_withitem(void* _o) |
---|
3933 | n/a | { |
---|
3934 | n/a | withitem_ty o = (withitem_ty)_o; |
---|
3935 | n/a | PyObject *result = NULL, *value = NULL; |
---|
3936 | n/a | if (!o) { |
---|
3937 | n/a | Py_RETURN_NONE; |
---|
3938 | n/a | } |
---|
3939 | n/a | |
---|
3940 | n/a | result = PyType_GenericNew(withitem_type, NULL, NULL); |
---|
3941 | n/a | if (!result) return NULL; |
---|
3942 | n/a | value = ast2obj_expr(o->context_expr); |
---|
3943 | n/a | if (!value) goto failed; |
---|
3944 | n/a | if (_PyObject_SetAttrId(result, &PyId_context_expr, value) == -1) |
---|
3945 | n/a | goto failed; |
---|
3946 | n/a | Py_DECREF(value); |
---|
3947 | n/a | value = ast2obj_expr(o->optional_vars); |
---|
3948 | n/a | if (!value) goto failed; |
---|
3949 | n/a | if (_PyObject_SetAttrId(result, &PyId_optional_vars, value) == -1) |
---|
3950 | n/a | goto failed; |
---|
3951 | n/a | Py_DECREF(value); |
---|
3952 | n/a | return result; |
---|
3953 | n/a | failed: |
---|
3954 | n/a | Py_XDECREF(value); |
---|
3955 | n/a | Py_XDECREF(result); |
---|
3956 | n/a | return NULL; |
---|
3957 | n/a | } |
---|
3958 | n/a | |
---|
3959 | n/a | |
---|
3960 | n/a | int |
---|
3961 | n/a | obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena) |
---|
3962 | n/a | { |
---|
3963 | n/a | int isinstance; |
---|
3964 | n/a | |
---|
3965 | n/a | PyObject *tmp = NULL; |
---|
3966 | n/a | |
---|
3967 | n/a | if (obj == Py_None) { |
---|
3968 | n/a | *out = NULL; |
---|
3969 | n/a | return 0; |
---|
3970 | n/a | } |
---|
3971 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Module_type); |
---|
3972 | n/a | if (isinstance == -1) { |
---|
3973 | n/a | return 1; |
---|
3974 | n/a | } |
---|
3975 | n/a | if (isinstance) { |
---|
3976 | n/a | asdl_seq* body; |
---|
3977 | n/a | |
---|
3978 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
3979 | n/a | int res; |
---|
3980 | n/a | Py_ssize_t len; |
---|
3981 | n/a | Py_ssize_t i; |
---|
3982 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
3983 | n/a | if (tmp == NULL) goto failed; |
---|
3984 | n/a | if (!PyList_Check(tmp)) { |
---|
3985 | n/a | PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
3986 | n/a | goto failed; |
---|
3987 | n/a | } |
---|
3988 | n/a | len = PyList_GET_SIZE(tmp); |
---|
3989 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
3990 | n/a | if (body == NULL) goto failed; |
---|
3991 | n/a | for (i = 0; i < len; i++) { |
---|
3992 | n/a | stmt_ty value; |
---|
3993 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
3994 | n/a | if (res != 0) goto failed; |
---|
3995 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
3996 | n/a | PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration"); |
---|
3997 | n/a | goto failed; |
---|
3998 | n/a | } |
---|
3999 | n/a | asdl_seq_SET(body, i, value); |
---|
4000 | n/a | } |
---|
4001 | n/a | Py_CLEAR(tmp); |
---|
4002 | n/a | } else { |
---|
4003 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module"); |
---|
4004 | n/a | return 1; |
---|
4005 | n/a | } |
---|
4006 | n/a | *out = Module(body, arena); |
---|
4007 | n/a | if (*out == NULL) goto failed; |
---|
4008 | n/a | return 0; |
---|
4009 | n/a | } |
---|
4010 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Interactive_type); |
---|
4011 | n/a | if (isinstance == -1) { |
---|
4012 | n/a | return 1; |
---|
4013 | n/a | } |
---|
4014 | n/a | if (isinstance) { |
---|
4015 | n/a | asdl_seq* body; |
---|
4016 | n/a | |
---|
4017 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4018 | n/a | int res; |
---|
4019 | n/a | Py_ssize_t len; |
---|
4020 | n/a | Py_ssize_t i; |
---|
4021 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4022 | n/a | if (tmp == NULL) goto failed; |
---|
4023 | n/a | if (!PyList_Check(tmp)) { |
---|
4024 | n/a | PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4025 | n/a | goto failed; |
---|
4026 | n/a | } |
---|
4027 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4028 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4029 | n/a | if (body == NULL) goto failed; |
---|
4030 | n/a | for (i = 0; i < len; i++) { |
---|
4031 | n/a | stmt_ty value; |
---|
4032 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4033 | n/a | if (res != 0) goto failed; |
---|
4034 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4035 | n/a | PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration"); |
---|
4036 | n/a | goto failed; |
---|
4037 | n/a | } |
---|
4038 | n/a | asdl_seq_SET(body, i, value); |
---|
4039 | n/a | } |
---|
4040 | n/a | Py_CLEAR(tmp); |
---|
4041 | n/a | } else { |
---|
4042 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive"); |
---|
4043 | n/a | return 1; |
---|
4044 | n/a | } |
---|
4045 | n/a | *out = Interactive(body, arena); |
---|
4046 | n/a | if (*out == NULL) goto failed; |
---|
4047 | n/a | return 0; |
---|
4048 | n/a | } |
---|
4049 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Expression_type); |
---|
4050 | n/a | if (isinstance == -1) { |
---|
4051 | n/a | return 1; |
---|
4052 | n/a | } |
---|
4053 | n/a | if (isinstance) { |
---|
4054 | n/a | expr_ty body; |
---|
4055 | n/a | |
---|
4056 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4057 | n/a | int res; |
---|
4058 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4059 | n/a | if (tmp == NULL) goto failed; |
---|
4060 | n/a | res = obj2ast_expr(tmp, &body, arena); |
---|
4061 | n/a | if (res != 0) goto failed; |
---|
4062 | n/a | Py_CLEAR(tmp); |
---|
4063 | n/a | } else { |
---|
4064 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression"); |
---|
4065 | n/a | return 1; |
---|
4066 | n/a | } |
---|
4067 | n/a | *out = Expression(body, arena); |
---|
4068 | n/a | if (*out == NULL) goto failed; |
---|
4069 | n/a | return 0; |
---|
4070 | n/a | } |
---|
4071 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Suite_type); |
---|
4072 | n/a | if (isinstance == -1) { |
---|
4073 | n/a | return 1; |
---|
4074 | n/a | } |
---|
4075 | n/a | if (isinstance) { |
---|
4076 | n/a | asdl_seq* body; |
---|
4077 | n/a | |
---|
4078 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4079 | n/a | int res; |
---|
4080 | n/a | Py_ssize_t len; |
---|
4081 | n/a | Py_ssize_t i; |
---|
4082 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4083 | n/a | if (tmp == NULL) goto failed; |
---|
4084 | n/a | if (!PyList_Check(tmp)) { |
---|
4085 | n/a | PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4086 | n/a | goto failed; |
---|
4087 | n/a | } |
---|
4088 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4089 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4090 | n/a | if (body == NULL) goto failed; |
---|
4091 | n/a | for (i = 0; i < len; i++) { |
---|
4092 | n/a | stmt_ty value; |
---|
4093 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4094 | n/a | if (res != 0) goto failed; |
---|
4095 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4096 | n/a | PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration"); |
---|
4097 | n/a | goto failed; |
---|
4098 | n/a | } |
---|
4099 | n/a | asdl_seq_SET(body, i, value); |
---|
4100 | n/a | } |
---|
4101 | n/a | Py_CLEAR(tmp); |
---|
4102 | n/a | } else { |
---|
4103 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite"); |
---|
4104 | n/a | return 1; |
---|
4105 | n/a | } |
---|
4106 | n/a | *out = Suite(body, arena); |
---|
4107 | n/a | if (*out == NULL) goto failed; |
---|
4108 | n/a | return 0; |
---|
4109 | n/a | } |
---|
4110 | n/a | |
---|
4111 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj); |
---|
4112 | n/a | failed: |
---|
4113 | n/a | Py_XDECREF(tmp); |
---|
4114 | n/a | return 1; |
---|
4115 | n/a | } |
---|
4116 | n/a | |
---|
4117 | n/a | int |
---|
4118 | n/a | obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena) |
---|
4119 | n/a | { |
---|
4120 | n/a | int isinstance; |
---|
4121 | n/a | |
---|
4122 | n/a | PyObject *tmp = NULL; |
---|
4123 | n/a | int lineno; |
---|
4124 | n/a | int col_offset; |
---|
4125 | n/a | |
---|
4126 | n/a | if (obj == Py_None) { |
---|
4127 | n/a | *out = NULL; |
---|
4128 | n/a | return 0; |
---|
4129 | n/a | } |
---|
4130 | n/a | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
---|
4131 | n/a | int res; |
---|
4132 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
---|
4133 | n/a | if (tmp == NULL) goto failed; |
---|
4134 | n/a | res = obj2ast_int(tmp, &lineno, arena); |
---|
4135 | n/a | if (res != 0) goto failed; |
---|
4136 | n/a | Py_CLEAR(tmp); |
---|
4137 | n/a | } else { |
---|
4138 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt"); |
---|
4139 | n/a | return 1; |
---|
4140 | n/a | } |
---|
4141 | n/a | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
---|
4142 | n/a | int res; |
---|
4143 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
---|
4144 | n/a | if (tmp == NULL) goto failed; |
---|
4145 | n/a | res = obj2ast_int(tmp, &col_offset, arena); |
---|
4146 | n/a | if (res != 0) goto failed; |
---|
4147 | n/a | Py_CLEAR(tmp); |
---|
4148 | n/a | } else { |
---|
4149 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt"); |
---|
4150 | n/a | return 1; |
---|
4151 | n/a | } |
---|
4152 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)FunctionDef_type); |
---|
4153 | n/a | if (isinstance == -1) { |
---|
4154 | n/a | return 1; |
---|
4155 | n/a | } |
---|
4156 | n/a | if (isinstance) { |
---|
4157 | n/a | identifier name; |
---|
4158 | n/a | arguments_ty args; |
---|
4159 | n/a | asdl_seq* body; |
---|
4160 | n/a | asdl_seq* decorator_list; |
---|
4161 | n/a | expr_ty returns; |
---|
4162 | n/a | |
---|
4163 | n/a | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
---|
4164 | n/a | int res; |
---|
4165 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
---|
4166 | n/a | if (tmp == NULL) goto failed; |
---|
4167 | n/a | res = obj2ast_identifier(tmp, &name, arena); |
---|
4168 | n/a | if (res != 0) goto failed; |
---|
4169 | n/a | Py_CLEAR(tmp); |
---|
4170 | n/a | } else { |
---|
4171 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef"); |
---|
4172 | n/a | return 1; |
---|
4173 | n/a | } |
---|
4174 | n/a | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
---|
4175 | n/a | int res; |
---|
4176 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
---|
4177 | n/a | if (tmp == NULL) goto failed; |
---|
4178 | n/a | res = obj2ast_arguments(tmp, &args, arena); |
---|
4179 | n/a | if (res != 0) goto failed; |
---|
4180 | n/a | Py_CLEAR(tmp); |
---|
4181 | n/a | } else { |
---|
4182 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef"); |
---|
4183 | n/a | return 1; |
---|
4184 | n/a | } |
---|
4185 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4186 | n/a | int res; |
---|
4187 | n/a | Py_ssize_t len; |
---|
4188 | n/a | Py_ssize_t i; |
---|
4189 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4190 | n/a | if (tmp == NULL) goto failed; |
---|
4191 | n/a | if (!PyList_Check(tmp)) { |
---|
4192 | n/a | PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4193 | n/a | goto failed; |
---|
4194 | n/a | } |
---|
4195 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4196 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4197 | n/a | if (body == NULL) goto failed; |
---|
4198 | n/a | for (i = 0; i < len; i++) { |
---|
4199 | n/a | stmt_ty value; |
---|
4200 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4201 | n/a | if (res != 0) goto failed; |
---|
4202 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4203 | n/a | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration"); |
---|
4204 | n/a | goto failed; |
---|
4205 | n/a | } |
---|
4206 | n/a | asdl_seq_SET(body, i, value); |
---|
4207 | n/a | } |
---|
4208 | n/a | Py_CLEAR(tmp); |
---|
4209 | n/a | } else { |
---|
4210 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef"); |
---|
4211 | n/a | return 1; |
---|
4212 | n/a | } |
---|
4213 | n/a | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
---|
4214 | n/a | int res; |
---|
4215 | n/a | Py_ssize_t len; |
---|
4216 | n/a | Py_ssize_t i; |
---|
4217 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
---|
4218 | n/a | if (tmp == NULL) goto failed; |
---|
4219 | n/a | if (!PyList_Check(tmp)) { |
---|
4220 | n/a | PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4221 | n/a | goto failed; |
---|
4222 | n/a | } |
---|
4223 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4224 | n/a | decorator_list = _Py_asdl_seq_new(len, arena); |
---|
4225 | n/a | if (decorator_list == NULL) goto failed; |
---|
4226 | n/a | for (i = 0; i < len; i++) { |
---|
4227 | n/a | expr_ty value; |
---|
4228 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4229 | n/a | if (res != 0) goto failed; |
---|
4230 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4231 | n/a | PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration"); |
---|
4232 | n/a | goto failed; |
---|
4233 | n/a | } |
---|
4234 | n/a | asdl_seq_SET(decorator_list, i, value); |
---|
4235 | n/a | } |
---|
4236 | n/a | Py_CLEAR(tmp); |
---|
4237 | n/a | } else { |
---|
4238 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef"); |
---|
4239 | n/a | return 1; |
---|
4240 | n/a | } |
---|
4241 | n/a | if (exists_not_none(obj, &PyId_returns)) { |
---|
4242 | n/a | int res; |
---|
4243 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
---|
4244 | n/a | if (tmp == NULL) goto failed; |
---|
4245 | n/a | res = obj2ast_expr(tmp, &returns, arena); |
---|
4246 | n/a | if (res != 0) goto failed; |
---|
4247 | n/a | Py_CLEAR(tmp); |
---|
4248 | n/a | } else { |
---|
4249 | n/a | returns = NULL; |
---|
4250 | n/a | } |
---|
4251 | n/a | *out = FunctionDef(name, args, body, decorator_list, returns, lineno, |
---|
4252 | n/a | col_offset, arena); |
---|
4253 | n/a | if (*out == NULL) goto failed; |
---|
4254 | n/a | return 0; |
---|
4255 | n/a | } |
---|
4256 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFunctionDef_type); |
---|
4257 | n/a | if (isinstance == -1) { |
---|
4258 | n/a | return 1; |
---|
4259 | n/a | } |
---|
4260 | n/a | if (isinstance) { |
---|
4261 | n/a | identifier name; |
---|
4262 | n/a | arguments_ty args; |
---|
4263 | n/a | asdl_seq* body; |
---|
4264 | n/a | asdl_seq* decorator_list; |
---|
4265 | n/a | expr_ty returns; |
---|
4266 | n/a | |
---|
4267 | n/a | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
---|
4268 | n/a | int res; |
---|
4269 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
---|
4270 | n/a | if (tmp == NULL) goto failed; |
---|
4271 | n/a | res = obj2ast_identifier(tmp, &name, arena); |
---|
4272 | n/a | if (res != 0) goto failed; |
---|
4273 | n/a | Py_CLEAR(tmp); |
---|
4274 | n/a | } else { |
---|
4275 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef"); |
---|
4276 | n/a | return 1; |
---|
4277 | n/a | } |
---|
4278 | n/a | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
---|
4279 | n/a | int res; |
---|
4280 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
---|
4281 | n/a | if (tmp == NULL) goto failed; |
---|
4282 | n/a | res = obj2ast_arguments(tmp, &args, arena); |
---|
4283 | n/a | if (res != 0) goto failed; |
---|
4284 | n/a | Py_CLEAR(tmp); |
---|
4285 | n/a | } else { |
---|
4286 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef"); |
---|
4287 | n/a | return 1; |
---|
4288 | n/a | } |
---|
4289 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4290 | n/a | int res; |
---|
4291 | n/a | Py_ssize_t len; |
---|
4292 | n/a | Py_ssize_t i; |
---|
4293 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4294 | n/a | if (tmp == NULL) goto failed; |
---|
4295 | n/a | if (!PyList_Check(tmp)) { |
---|
4296 | n/a | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4297 | n/a | goto failed; |
---|
4298 | n/a | } |
---|
4299 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4300 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4301 | n/a | if (body == NULL) goto failed; |
---|
4302 | n/a | for (i = 0; i < len; i++) { |
---|
4303 | n/a | stmt_ty value; |
---|
4304 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4305 | n/a | if (res != 0) goto failed; |
---|
4306 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4307 | n/a | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration"); |
---|
4308 | n/a | goto failed; |
---|
4309 | n/a | } |
---|
4310 | n/a | asdl_seq_SET(body, i, value); |
---|
4311 | n/a | } |
---|
4312 | n/a | Py_CLEAR(tmp); |
---|
4313 | n/a | } else { |
---|
4314 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef"); |
---|
4315 | n/a | return 1; |
---|
4316 | n/a | } |
---|
4317 | n/a | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
---|
4318 | n/a | int res; |
---|
4319 | n/a | Py_ssize_t len; |
---|
4320 | n/a | Py_ssize_t i; |
---|
4321 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
---|
4322 | n/a | if (tmp == NULL) goto failed; |
---|
4323 | n/a | if (!PyList_Check(tmp)) { |
---|
4324 | n/a | PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4325 | n/a | goto failed; |
---|
4326 | n/a | } |
---|
4327 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4328 | n/a | decorator_list = _Py_asdl_seq_new(len, arena); |
---|
4329 | n/a | if (decorator_list == NULL) goto failed; |
---|
4330 | n/a | for (i = 0; i < len; i++) { |
---|
4331 | n/a | expr_ty value; |
---|
4332 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4333 | n/a | if (res != 0) goto failed; |
---|
4334 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4335 | n/a | PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration"); |
---|
4336 | n/a | goto failed; |
---|
4337 | n/a | } |
---|
4338 | n/a | asdl_seq_SET(decorator_list, i, value); |
---|
4339 | n/a | } |
---|
4340 | n/a | Py_CLEAR(tmp); |
---|
4341 | n/a | } else { |
---|
4342 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef"); |
---|
4343 | n/a | return 1; |
---|
4344 | n/a | } |
---|
4345 | n/a | if (exists_not_none(obj, &PyId_returns)) { |
---|
4346 | n/a | int res; |
---|
4347 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_returns); |
---|
4348 | n/a | if (tmp == NULL) goto failed; |
---|
4349 | n/a | res = obj2ast_expr(tmp, &returns, arena); |
---|
4350 | n/a | if (res != 0) goto failed; |
---|
4351 | n/a | Py_CLEAR(tmp); |
---|
4352 | n/a | } else { |
---|
4353 | n/a | returns = NULL; |
---|
4354 | n/a | } |
---|
4355 | n/a | *out = AsyncFunctionDef(name, args, body, decorator_list, returns, |
---|
4356 | n/a | lineno, col_offset, arena); |
---|
4357 | n/a | if (*out == NULL) goto failed; |
---|
4358 | n/a | return 0; |
---|
4359 | n/a | } |
---|
4360 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)ClassDef_type); |
---|
4361 | n/a | if (isinstance == -1) { |
---|
4362 | n/a | return 1; |
---|
4363 | n/a | } |
---|
4364 | n/a | if (isinstance) { |
---|
4365 | n/a | identifier name; |
---|
4366 | n/a | asdl_seq* bases; |
---|
4367 | n/a | asdl_seq* keywords; |
---|
4368 | n/a | asdl_seq* body; |
---|
4369 | n/a | asdl_seq* decorator_list; |
---|
4370 | n/a | |
---|
4371 | n/a | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
---|
4372 | n/a | int res; |
---|
4373 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
---|
4374 | n/a | if (tmp == NULL) goto failed; |
---|
4375 | n/a | res = obj2ast_identifier(tmp, &name, arena); |
---|
4376 | n/a | if (res != 0) goto failed; |
---|
4377 | n/a | Py_CLEAR(tmp); |
---|
4378 | n/a | } else { |
---|
4379 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef"); |
---|
4380 | n/a | return 1; |
---|
4381 | n/a | } |
---|
4382 | n/a | if (_PyObject_HasAttrId(obj, &PyId_bases)) { |
---|
4383 | n/a | int res; |
---|
4384 | n/a | Py_ssize_t len; |
---|
4385 | n/a | Py_ssize_t i; |
---|
4386 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_bases); |
---|
4387 | n/a | if (tmp == NULL) goto failed; |
---|
4388 | n/a | if (!PyList_Check(tmp)) { |
---|
4389 | n/a | PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4390 | n/a | goto failed; |
---|
4391 | n/a | } |
---|
4392 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4393 | n/a | bases = _Py_asdl_seq_new(len, arena); |
---|
4394 | n/a | if (bases == NULL) goto failed; |
---|
4395 | n/a | for (i = 0; i < len; i++) { |
---|
4396 | n/a | expr_ty value; |
---|
4397 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4398 | n/a | if (res != 0) goto failed; |
---|
4399 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4400 | n/a | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration"); |
---|
4401 | n/a | goto failed; |
---|
4402 | n/a | } |
---|
4403 | n/a | asdl_seq_SET(bases, i, value); |
---|
4404 | n/a | } |
---|
4405 | n/a | Py_CLEAR(tmp); |
---|
4406 | n/a | } else { |
---|
4407 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef"); |
---|
4408 | n/a | return 1; |
---|
4409 | n/a | } |
---|
4410 | n/a | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
---|
4411 | n/a | int res; |
---|
4412 | n/a | Py_ssize_t len; |
---|
4413 | n/a | Py_ssize_t i; |
---|
4414 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
---|
4415 | n/a | if (tmp == NULL) goto failed; |
---|
4416 | n/a | if (!PyList_Check(tmp)) { |
---|
4417 | n/a | PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4418 | n/a | goto failed; |
---|
4419 | n/a | } |
---|
4420 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4421 | n/a | keywords = _Py_asdl_seq_new(len, arena); |
---|
4422 | n/a | if (keywords == NULL) goto failed; |
---|
4423 | n/a | for (i = 0; i < len; i++) { |
---|
4424 | n/a | keyword_ty value; |
---|
4425 | n/a | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4426 | n/a | if (res != 0) goto failed; |
---|
4427 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4428 | n/a | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration"); |
---|
4429 | n/a | goto failed; |
---|
4430 | n/a | } |
---|
4431 | n/a | asdl_seq_SET(keywords, i, value); |
---|
4432 | n/a | } |
---|
4433 | n/a | Py_CLEAR(tmp); |
---|
4434 | n/a | } else { |
---|
4435 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef"); |
---|
4436 | n/a | return 1; |
---|
4437 | n/a | } |
---|
4438 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4439 | n/a | int res; |
---|
4440 | n/a | Py_ssize_t len; |
---|
4441 | n/a | Py_ssize_t i; |
---|
4442 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4443 | n/a | if (tmp == NULL) goto failed; |
---|
4444 | n/a | if (!PyList_Check(tmp)) { |
---|
4445 | n/a | PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4446 | n/a | goto failed; |
---|
4447 | n/a | } |
---|
4448 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4449 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4450 | n/a | if (body == NULL) goto failed; |
---|
4451 | n/a | for (i = 0; i < len; i++) { |
---|
4452 | n/a | stmt_ty value; |
---|
4453 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4454 | n/a | if (res != 0) goto failed; |
---|
4455 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4456 | n/a | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration"); |
---|
4457 | n/a | goto failed; |
---|
4458 | n/a | } |
---|
4459 | n/a | asdl_seq_SET(body, i, value); |
---|
4460 | n/a | } |
---|
4461 | n/a | Py_CLEAR(tmp); |
---|
4462 | n/a | } else { |
---|
4463 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef"); |
---|
4464 | n/a | return 1; |
---|
4465 | n/a | } |
---|
4466 | n/a | if (_PyObject_HasAttrId(obj, &PyId_decorator_list)) { |
---|
4467 | n/a | int res; |
---|
4468 | n/a | Py_ssize_t len; |
---|
4469 | n/a | Py_ssize_t i; |
---|
4470 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_decorator_list); |
---|
4471 | n/a | if (tmp == NULL) goto failed; |
---|
4472 | n/a | if (!PyList_Check(tmp)) { |
---|
4473 | n/a | PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4474 | n/a | goto failed; |
---|
4475 | n/a | } |
---|
4476 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4477 | n/a | decorator_list = _Py_asdl_seq_new(len, arena); |
---|
4478 | n/a | if (decorator_list == NULL) goto failed; |
---|
4479 | n/a | for (i = 0; i < len; i++) { |
---|
4480 | n/a | expr_ty value; |
---|
4481 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4482 | n/a | if (res != 0) goto failed; |
---|
4483 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4484 | n/a | PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration"); |
---|
4485 | n/a | goto failed; |
---|
4486 | n/a | } |
---|
4487 | n/a | asdl_seq_SET(decorator_list, i, value); |
---|
4488 | n/a | } |
---|
4489 | n/a | Py_CLEAR(tmp); |
---|
4490 | n/a | } else { |
---|
4491 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef"); |
---|
4492 | n/a | return 1; |
---|
4493 | n/a | } |
---|
4494 | n/a | *out = ClassDef(name, bases, keywords, body, decorator_list, lineno, |
---|
4495 | n/a | col_offset, arena); |
---|
4496 | n/a | if (*out == NULL) goto failed; |
---|
4497 | n/a | return 0; |
---|
4498 | n/a | } |
---|
4499 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Return_type); |
---|
4500 | n/a | if (isinstance == -1) { |
---|
4501 | n/a | return 1; |
---|
4502 | n/a | } |
---|
4503 | n/a | if (isinstance) { |
---|
4504 | n/a | expr_ty value; |
---|
4505 | n/a | |
---|
4506 | n/a | if (exists_not_none(obj, &PyId_value)) { |
---|
4507 | n/a | int res; |
---|
4508 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
4509 | n/a | if (tmp == NULL) goto failed; |
---|
4510 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
4511 | n/a | if (res != 0) goto failed; |
---|
4512 | n/a | Py_CLEAR(tmp); |
---|
4513 | n/a | } else { |
---|
4514 | n/a | value = NULL; |
---|
4515 | n/a | } |
---|
4516 | n/a | *out = Return(value, lineno, col_offset, arena); |
---|
4517 | n/a | if (*out == NULL) goto failed; |
---|
4518 | n/a | return 0; |
---|
4519 | n/a | } |
---|
4520 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Delete_type); |
---|
4521 | n/a | if (isinstance == -1) { |
---|
4522 | n/a | return 1; |
---|
4523 | n/a | } |
---|
4524 | n/a | if (isinstance) { |
---|
4525 | n/a | asdl_seq* targets; |
---|
4526 | n/a | |
---|
4527 | n/a | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
---|
4528 | n/a | int res; |
---|
4529 | n/a | Py_ssize_t len; |
---|
4530 | n/a | Py_ssize_t i; |
---|
4531 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
---|
4532 | n/a | if (tmp == NULL) goto failed; |
---|
4533 | n/a | if (!PyList_Check(tmp)) { |
---|
4534 | n/a | PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4535 | n/a | goto failed; |
---|
4536 | n/a | } |
---|
4537 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4538 | n/a | targets = _Py_asdl_seq_new(len, arena); |
---|
4539 | n/a | if (targets == NULL) goto failed; |
---|
4540 | n/a | for (i = 0; i < len; i++) { |
---|
4541 | n/a | expr_ty value; |
---|
4542 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4543 | n/a | if (res != 0) goto failed; |
---|
4544 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4545 | n/a | PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration"); |
---|
4546 | n/a | goto failed; |
---|
4547 | n/a | } |
---|
4548 | n/a | asdl_seq_SET(targets, i, value); |
---|
4549 | n/a | } |
---|
4550 | n/a | Py_CLEAR(tmp); |
---|
4551 | n/a | } else { |
---|
4552 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete"); |
---|
4553 | n/a | return 1; |
---|
4554 | n/a | } |
---|
4555 | n/a | *out = Delete(targets, lineno, col_offset, arena); |
---|
4556 | n/a | if (*out == NULL) goto failed; |
---|
4557 | n/a | return 0; |
---|
4558 | n/a | } |
---|
4559 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Assign_type); |
---|
4560 | n/a | if (isinstance == -1) { |
---|
4561 | n/a | return 1; |
---|
4562 | n/a | } |
---|
4563 | n/a | if (isinstance) { |
---|
4564 | n/a | asdl_seq* targets; |
---|
4565 | n/a | expr_ty value; |
---|
4566 | n/a | |
---|
4567 | n/a | if (_PyObject_HasAttrId(obj, &PyId_targets)) { |
---|
4568 | n/a | int res; |
---|
4569 | n/a | Py_ssize_t len; |
---|
4570 | n/a | Py_ssize_t i; |
---|
4571 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_targets); |
---|
4572 | n/a | if (tmp == NULL) goto failed; |
---|
4573 | n/a | if (!PyList_Check(tmp)) { |
---|
4574 | n/a | PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4575 | n/a | goto failed; |
---|
4576 | n/a | } |
---|
4577 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4578 | n/a | targets = _Py_asdl_seq_new(len, arena); |
---|
4579 | n/a | if (targets == NULL) goto failed; |
---|
4580 | n/a | for (i = 0; i < len; i++) { |
---|
4581 | n/a | expr_ty value; |
---|
4582 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4583 | n/a | if (res != 0) goto failed; |
---|
4584 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4585 | n/a | PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration"); |
---|
4586 | n/a | goto failed; |
---|
4587 | n/a | } |
---|
4588 | n/a | asdl_seq_SET(targets, i, value); |
---|
4589 | n/a | } |
---|
4590 | n/a | Py_CLEAR(tmp); |
---|
4591 | n/a | } else { |
---|
4592 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign"); |
---|
4593 | n/a | return 1; |
---|
4594 | n/a | } |
---|
4595 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
4596 | n/a | int res; |
---|
4597 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
4598 | n/a | if (tmp == NULL) goto failed; |
---|
4599 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
4600 | n/a | if (res != 0) goto failed; |
---|
4601 | n/a | Py_CLEAR(tmp); |
---|
4602 | n/a | } else { |
---|
4603 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign"); |
---|
4604 | n/a | return 1; |
---|
4605 | n/a | } |
---|
4606 | n/a | *out = Assign(targets, value, lineno, col_offset, arena); |
---|
4607 | n/a | if (*out == NULL) goto failed; |
---|
4608 | n/a | return 0; |
---|
4609 | n/a | } |
---|
4610 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)AugAssign_type); |
---|
4611 | n/a | if (isinstance == -1) { |
---|
4612 | n/a | return 1; |
---|
4613 | n/a | } |
---|
4614 | n/a | if (isinstance) { |
---|
4615 | n/a | expr_ty target; |
---|
4616 | n/a | operator_ty op; |
---|
4617 | n/a | expr_ty value; |
---|
4618 | n/a | |
---|
4619 | n/a | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
---|
4620 | n/a | int res; |
---|
4621 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
---|
4622 | n/a | if (tmp == NULL) goto failed; |
---|
4623 | n/a | res = obj2ast_expr(tmp, &target, arena); |
---|
4624 | n/a | if (res != 0) goto failed; |
---|
4625 | n/a | Py_CLEAR(tmp); |
---|
4626 | n/a | } else { |
---|
4627 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign"); |
---|
4628 | n/a | return 1; |
---|
4629 | n/a | } |
---|
4630 | n/a | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
---|
4631 | n/a | int res; |
---|
4632 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
---|
4633 | n/a | if (tmp == NULL) goto failed; |
---|
4634 | n/a | res = obj2ast_operator(tmp, &op, arena); |
---|
4635 | n/a | if (res != 0) goto failed; |
---|
4636 | n/a | Py_CLEAR(tmp); |
---|
4637 | n/a | } else { |
---|
4638 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign"); |
---|
4639 | n/a | return 1; |
---|
4640 | n/a | } |
---|
4641 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
4642 | n/a | int res; |
---|
4643 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
4644 | n/a | if (tmp == NULL) goto failed; |
---|
4645 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
4646 | n/a | if (res != 0) goto failed; |
---|
4647 | n/a | Py_CLEAR(tmp); |
---|
4648 | n/a | } else { |
---|
4649 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign"); |
---|
4650 | n/a | return 1; |
---|
4651 | n/a | } |
---|
4652 | n/a | *out = AugAssign(target, op, value, lineno, col_offset, arena); |
---|
4653 | n/a | if (*out == NULL) goto failed; |
---|
4654 | n/a | return 0; |
---|
4655 | n/a | } |
---|
4656 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)AnnAssign_type); |
---|
4657 | n/a | if (isinstance == -1) { |
---|
4658 | n/a | return 1; |
---|
4659 | n/a | } |
---|
4660 | n/a | if (isinstance) { |
---|
4661 | n/a | expr_ty target; |
---|
4662 | n/a | expr_ty annotation; |
---|
4663 | n/a | expr_ty value; |
---|
4664 | n/a | int simple; |
---|
4665 | n/a | |
---|
4666 | n/a | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
---|
4667 | n/a | int res; |
---|
4668 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
---|
4669 | n/a | if (tmp == NULL) goto failed; |
---|
4670 | n/a | res = obj2ast_expr(tmp, &target, arena); |
---|
4671 | n/a | if (res != 0) goto failed; |
---|
4672 | n/a | Py_CLEAR(tmp); |
---|
4673 | n/a | } else { |
---|
4674 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign"); |
---|
4675 | n/a | return 1; |
---|
4676 | n/a | } |
---|
4677 | n/a | if (_PyObject_HasAttrId(obj, &PyId_annotation)) { |
---|
4678 | n/a | int res; |
---|
4679 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
---|
4680 | n/a | if (tmp == NULL) goto failed; |
---|
4681 | n/a | res = obj2ast_expr(tmp, &annotation, arena); |
---|
4682 | n/a | if (res != 0) goto failed; |
---|
4683 | n/a | Py_CLEAR(tmp); |
---|
4684 | n/a | } else { |
---|
4685 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign"); |
---|
4686 | n/a | return 1; |
---|
4687 | n/a | } |
---|
4688 | n/a | if (exists_not_none(obj, &PyId_value)) { |
---|
4689 | n/a | int res; |
---|
4690 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
4691 | n/a | if (tmp == NULL) goto failed; |
---|
4692 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
4693 | n/a | if (res != 0) goto failed; |
---|
4694 | n/a | Py_CLEAR(tmp); |
---|
4695 | n/a | } else { |
---|
4696 | n/a | value = NULL; |
---|
4697 | n/a | } |
---|
4698 | n/a | if (_PyObject_HasAttrId(obj, &PyId_simple)) { |
---|
4699 | n/a | int res; |
---|
4700 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_simple); |
---|
4701 | n/a | if (tmp == NULL) goto failed; |
---|
4702 | n/a | res = obj2ast_int(tmp, &simple, arena); |
---|
4703 | n/a | if (res != 0) goto failed; |
---|
4704 | n/a | Py_CLEAR(tmp); |
---|
4705 | n/a | } else { |
---|
4706 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign"); |
---|
4707 | n/a | return 1; |
---|
4708 | n/a | } |
---|
4709 | n/a | *out = AnnAssign(target, annotation, value, simple, lineno, col_offset, |
---|
4710 | n/a | arena); |
---|
4711 | n/a | if (*out == NULL) goto failed; |
---|
4712 | n/a | return 0; |
---|
4713 | n/a | } |
---|
4714 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)For_type); |
---|
4715 | n/a | if (isinstance == -1) { |
---|
4716 | n/a | return 1; |
---|
4717 | n/a | } |
---|
4718 | n/a | if (isinstance) { |
---|
4719 | n/a | expr_ty target; |
---|
4720 | n/a | expr_ty iter; |
---|
4721 | n/a | asdl_seq* body; |
---|
4722 | n/a | asdl_seq* orelse; |
---|
4723 | n/a | |
---|
4724 | n/a | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
---|
4725 | n/a | int res; |
---|
4726 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
---|
4727 | n/a | if (tmp == NULL) goto failed; |
---|
4728 | n/a | res = obj2ast_expr(tmp, &target, arena); |
---|
4729 | n/a | if (res != 0) goto failed; |
---|
4730 | n/a | Py_CLEAR(tmp); |
---|
4731 | n/a | } else { |
---|
4732 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For"); |
---|
4733 | n/a | return 1; |
---|
4734 | n/a | } |
---|
4735 | n/a | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
---|
4736 | n/a | int res; |
---|
4737 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
---|
4738 | n/a | if (tmp == NULL) goto failed; |
---|
4739 | n/a | res = obj2ast_expr(tmp, &iter, arena); |
---|
4740 | n/a | if (res != 0) goto failed; |
---|
4741 | n/a | Py_CLEAR(tmp); |
---|
4742 | n/a | } else { |
---|
4743 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For"); |
---|
4744 | n/a | return 1; |
---|
4745 | n/a | } |
---|
4746 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4747 | n/a | int res; |
---|
4748 | n/a | Py_ssize_t len; |
---|
4749 | n/a | Py_ssize_t i; |
---|
4750 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4751 | n/a | if (tmp == NULL) goto failed; |
---|
4752 | n/a | if (!PyList_Check(tmp)) { |
---|
4753 | n/a | PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4754 | n/a | goto failed; |
---|
4755 | n/a | } |
---|
4756 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4757 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4758 | n/a | if (body == NULL) goto failed; |
---|
4759 | n/a | for (i = 0; i < len; i++) { |
---|
4760 | n/a | stmt_ty value; |
---|
4761 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4762 | n/a | if (res != 0) goto failed; |
---|
4763 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4764 | n/a | PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration"); |
---|
4765 | n/a | goto failed; |
---|
4766 | n/a | } |
---|
4767 | n/a | asdl_seq_SET(body, i, value); |
---|
4768 | n/a | } |
---|
4769 | n/a | Py_CLEAR(tmp); |
---|
4770 | n/a | } else { |
---|
4771 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For"); |
---|
4772 | n/a | return 1; |
---|
4773 | n/a | } |
---|
4774 | n/a | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
---|
4775 | n/a | int res; |
---|
4776 | n/a | Py_ssize_t len; |
---|
4777 | n/a | Py_ssize_t i; |
---|
4778 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
---|
4779 | n/a | if (tmp == NULL) goto failed; |
---|
4780 | n/a | if (!PyList_Check(tmp)) { |
---|
4781 | n/a | PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4782 | n/a | goto failed; |
---|
4783 | n/a | } |
---|
4784 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4785 | n/a | orelse = _Py_asdl_seq_new(len, arena); |
---|
4786 | n/a | if (orelse == NULL) goto failed; |
---|
4787 | n/a | for (i = 0; i < len; i++) { |
---|
4788 | n/a | stmt_ty value; |
---|
4789 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4790 | n/a | if (res != 0) goto failed; |
---|
4791 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4792 | n/a | PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration"); |
---|
4793 | n/a | goto failed; |
---|
4794 | n/a | } |
---|
4795 | n/a | asdl_seq_SET(orelse, i, value); |
---|
4796 | n/a | } |
---|
4797 | n/a | Py_CLEAR(tmp); |
---|
4798 | n/a | } else { |
---|
4799 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For"); |
---|
4800 | n/a | return 1; |
---|
4801 | n/a | } |
---|
4802 | n/a | *out = For(target, iter, body, orelse, lineno, col_offset, arena); |
---|
4803 | n/a | if (*out == NULL) goto failed; |
---|
4804 | n/a | return 0; |
---|
4805 | n/a | } |
---|
4806 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncFor_type); |
---|
4807 | n/a | if (isinstance == -1) { |
---|
4808 | n/a | return 1; |
---|
4809 | n/a | } |
---|
4810 | n/a | if (isinstance) { |
---|
4811 | n/a | expr_ty target; |
---|
4812 | n/a | expr_ty iter; |
---|
4813 | n/a | asdl_seq* body; |
---|
4814 | n/a | asdl_seq* orelse; |
---|
4815 | n/a | |
---|
4816 | n/a | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
---|
4817 | n/a | int res; |
---|
4818 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
---|
4819 | n/a | if (tmp == NULL) goto failed; |
---|
4820 | n/a | res = obj2ast_expr(tmp, &target, arena); |
---|
4821 | n/a | if (res != 0) goto failed; |
---|
4822 | n/a | Py_CLEAR(tmp); |
---|
4823 | n/a | } else { |
---|
4824 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor"); |
---|
4825 | n/a | return 1; |
---|
4826 | n/a | } |
---|
4827 | n/a | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
---|
4828 | n/a | int res; |
---|
4829 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
---|
4830 | n/a | if (tmp == NULL) goto failed; |
---|
4831 | n/a | res = obj2ast_expr(tmp, &iter, arena); |
---|
4832 | n/a | if (res != 0) goto failed; |
---|
4833 | n/a | Py_CLEAR(tmp); |
---|
4834 | n/a | } else { |
---|
4835 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor"); |
---|
4836 | n/a | return 1; |
---|
4837 | n/a | } |
---|
4838 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4839 | n/a | int res; |
---|
4840 | n/a | Py_ssize_t len; |
---|
4841 | n/a | Py_ssize_t i; |
---|
4842 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4843 | n/a | if (tmp == NULL) goto failed; |
---|
4844 | n/a | if (!PyList_Check(tmp)) { |
---|
4845 | n/a | PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4846 | n/a | goto failed; |
---|
4847 | n/a | } |
---|
4848 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4849 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4850 | n/a | if (body == NULL) goto failed; |
---|
4851 | n/a | for (i = 0; i < len; i++) { |
---|
4852 | n/a | stmt_ty value; |
---|
4853 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4854 | n/a | if (res != 0) goto failed; |
---|
4855 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4856 | n/a | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration"); |
---|
4857 | n/a | goto failed; |
---|
4858 | n/a | } |
---|
4859 | n/a | asdl_seq_SET(body, i, value); |
---|
4860 | n/a | } |
---|
4861 | n/a | Py_CLEAR(tmp); |
---|
4862 | n/a | } else { |
---|
4863 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor"); |
---|
4864 | n/a | return 1; |
---|
4865 | n/a | } |
---|
4866 | n/a | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
---|
4867 | n/a | int res; |
---|
4868 | n/a | Py_ssize_t len; |
---|
4869 | n/a | Py_ssize_t i; |
---|
4870 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
---|
4871 | n/a | if (tmp == NULL) goto failed; |
---|
4872 | n/a | if (!PyList_Check(tmp)) { |
---|
4873 | n/a | PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4874 | n/a | goto failed; |
---|
4875 | n/a | } |
---|
4876 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4877 | n/a | orelse = _Py_asdl_seq_new(len, arena); |
---|
4878 | n/a | if (orelse == NULL) goto failed; |
---|
4879 | n/a | for (i = 0; i < len; i++) { |
---|
4880 | n/a | stmt_ty value; |
---|
4881 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4882 | n/a | if (res != 0) goto failed; |
---|
4883 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4884 | n/a | PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration"); |
---|
4885 | n/a | goto failed; |
---|
4886 | n/a | } |
---|
4887 | n/a | asdl_seq_SET(orelse, i, value); |
---|
4888 | n/a | } |
---|
4889 | n/a | Py_CLEAR(tmp); |
---|
4890 | n/a | } else { |
---|
4891 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor"); |
---|
4892 | n/a | return 1; |
---|
4893 | n/a | } |
---|
4894 | n/a | *out = AsyncFor(target, iter, body, orelse, lineno, col_offset, arena); |
---|
4895 | n/a | if (*out == NULL) goto failed; |
---|
4896 | n/a | return 0; |
---|
4897 | n/a | } |
---|
4898 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)While_type); |
---|
4899 | n/a | if (isinstance == -1) { |
---|
4900 | n/a | return 1; |
---|
4901 | n/a | } |
---|
4902 | n/a | if (isinstance) { |
---|
4903 | n/a | expr_ty test; |
---|
4904 | n/a | asdl_seq* body; |
---|
4905 | n/a | asdl_seq* orelse; |
---|
4906 | n/a | |
---|
4907 | n/a | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
---|
4908 | n/a | int res; |
---|
4909 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
---|
4910 | n/a | if (tmp == NULL) goto failed; |
---|
4911 | n/a | res = obj2ast_expr(tmp, &test, arena); |
---|
4912 | n/a | if (res != 0) goto failed; |
---|
4913 | n/a | Py_CLEAR(tmp); |
---|
4914 | n/a | } else { |
---|
4915 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While"); |
---|
4916 | n/a | return 1; |
---|
4917 | n/a | } |
---|
4918 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4919 | n/a | int res; |
---|
4920 | n/a | Py_ssize_t len; |
---|
4921 | n/a | Py_ssize_t i; |
---|
4922 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
4923 | n/a | if (tmp == NULL) goto failed; |
---|
4924 | n/a | if (!PyList_Check(tmp)) { |
---|
4925 | n/a | PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4926 | n/a | goto failed; |
---|
4927 | n/a | } |
---|
4928 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4929 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
4930 | n/a | if (body == NULL) goto failed; |
---|
4931 | n/a | for (i = 0; i < len; i++) { |
---|
4932 | n/a | stmt_ty value; |
---|
4933 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4934 | n/a | if (res != 0) goto failed; |
---|
4935 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4936 | n/a | PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration"); |
---|
4937 | n/a | goto failed; |
---|
4938 | n/a | } |
---|
4939 | n/a | asdl_seq_SET(body, i, value); |
---|
4940 | n/a | } |
---|
4941 | n/a | Py_CLEAR(tmp); |
---|
4942 | n/a | } else { |
---|
4943 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While"); |
---|
4944 | n/a | return 1; |
---|
4945 | n/a | } |
---|
4946 | n/a | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
---|
4947 | n/a | int res; |
---|
4948 | n/a | Py_ssize_t len; |
---|
4949 | n/a | Py_ssize_t i; |
---|
4950 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
---|
4951 | n/a | if (tmp == NULL) goto failed; |
---|
4952 | n/a | if (!PyList_Check(tmp)) { |
---|
4953 | n/a | PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
4954 | n/a | goto failed; |
---|
4955 | n/a | } |
---|
4956 | n/a | len = PyList_GET_SIZE(tmp); |
---|
4957 | n/a | orelse = _Py_asdl_seq_new(len, arena); |
---|
4958 | n/a | if (orelse == NULL) goto failed; |
---|
4959 | n/a | for (i = 0; i < len; i++) { |
---|
4960 | n/a | stmt_ty value; |
---|
4961 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
4962 | n/a | if (res != 0) goto failed; |
---|
4963 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
4964 | n/a | PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration"); |
---|
4965 | n/a | goto failed; |
---|
4966 | n/a | } |
---|
4967 | n/a | asdl_seq_SET(orelse, i, value); |
---|
4968 | n/a | } |
---|
4969 | n/a | Py_CLEAR(tmp); |
---|
4970 | n/a | } else { |
---|
4971 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While"); |
---|
4972 | n/a | return 1; |
---|
4973 | n/a | } |
---|
4974 | n/a | *out = While(test, body, orelse, lineno, col_offset, arena); |
---|
4975 | n/a | if (*out == NULL) goto failed; |
---|
4976 | n/a | return 0; |
---|
4977 | n/a | } |
---|
4978 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)If_type); |
---|
4979 | n/a | if (isinstance == -1) { |
---|
4980 | n/a | return 1; |
---|
4981 | n/a | } |
---|
4982 | n/a | if (isinstance) { |
---|
4983 | n/a | expr_ty test; |
---|
4984 | n/a | asdl_seq* body; |
---|
4985 | n/a | asdl_seq* orelse; |
---|
4986 | n/a | |
---|
4987 | n/a | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
---|
4988 | n/a | int res; |
---|
4989 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
---|
4990 | n/a | if (tmp == NULL) goto failed; |
---|
4991 | n/a | res = obj2ast_expr(tmp, &test, arena); |
---|
4992 | n/a | if (res != 0) goto failed; |
---|
4993 | n/a | Py_CLEAR(tmp); |
---|
4994 | n/a | } else { |
---|
4995 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If"); |
---|
4996 | n/a | return 1; |
---|
4997 | n/a | } |
---|
4998 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
4999 | n/a | int res; |
---|
5000 | n/a | Py_ssize_t len; |
---|
5001 | n/a | Py_ssize_t i; |
---|
5002 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
5003 | n/a | if (tmp == NULL) goto failed; |
---|
5004 | n/a | if (!PyList_Check(tmp)) { |
---|
5005 | n/a | PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5006 | n/a | goto failed; |
---|
5007 | n/a | } |
---|
5008 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5009 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
5010 | n/a | if (body == NULL) goto failed; |
---|
5011 | n/a | for (i = 0; i < len; i++) { |
---|
5012 | n/a | stmt_ty value; |
---|
5013 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5014 | n/a | if (res != 0) goto failed; |
---|
5015 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5016 | n/a | PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration"); |
---|
5017 | n/a | goto failed; |
---|
5018 | n/a | } |
---|
5019 | n/a | asdl_seq_SET(body, i, value); |
---|
5020 | n/a | } |
---|
5021 | n/a | Py_CLEAR(tmp); |
---|
5022 | n/a | } else { |
---|
5023 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If"); |
---|
5024 | n/a | return 1; |
---|
5025 | n/a | } |
---|
5026 | n/a | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
---|
5027 | n/a | int res; |
---|
5028 | n/a | Py_ssize_t len; |
---|
5029 | n/a | Py_ssize_t i; |
---|
5030 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
---|
5031 | n/a | if (tmp == NULL) goto failed; |
---|
5032 | n/a | if (!PyList_Check(tmp)) { |
---|
5033 | n/a | PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5034 | n/a | goto failed; |
---|
5035 | n/a | } |
---|
5036 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5037 | n/a | orelse = _Py_asdl_seq_new(len, arena); |
---|
5038 | n/a | if (orelse == NULL) goto failed; |
---|
5039 | n/a | for (i = 0; i < len; i++) { |
---|
5040 | n/a | stmt_ty value; |
---|
5041 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5042 | n/a | if (res != 0) goto failed; |
---|
5043 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5044 | n/a | PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration"); |
---|
5045 | n/a | goto failed; |
---|
5046 | n/a | } |
---|
5047 | n/a | asdl_seq_SET(orelse, i, value); |
---|
5048 | n/a | } |
---|
5049 | n/a | Py_CLEAR(tmp); |
---|
5050 | n/a | } else { |
---|
5051 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If"); |
---|
5052 | n/a | return 1; |
---|
5053 | n/a | } |
---|
5054 | n/a | *out = If(test, body, orelse, lineno, col_offset, arena); |
---|
5055 | n/a | if (*out == NULL) goto failed; |
---|
5056 | n/a | return 0; |
---|
5057 | n/a | } |
---|
5058 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)With_type); |
---|
5059 | n/a | if (isinstance == -1) { |
---|
5060 | n/a | return 1; |
---|
5061 | n/a | } |
---|
5062 | n/a | if (isinstance) { |
---|
5063 | n/a | asdl_seq* items; |
---|
5064 | n/a | asdl_seq* body; |
---|
5065 | n/a | |
---|
5066 | n/a | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
---|
5067 | n/a | int res; |
---|
5068 | n/a | Py_ssize_t len; |
---|
5069 | n/a | Py_ssize_t i; |
---|
5070 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
---|
5071 | n/a | if (tmp == NULL) goto failed; |
---|
5072 | n/a | if (!PyList_Check(tmp)) { |
---|
5073 | n/a | PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5074 | n/a | goto failed; |
---|
5075 | n/a | } |
---|
5076 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5077 | n/a | items = _Py_asdl_seq_new(len, arena); |
---|
5078 | n/a | if (items == NULL) goto failed; |
---|
5079 | n/a | for (i = 0; i < len; i++) { |
---|
5080 | n/a | withitem_ty value; |
---|
5081 | n/a | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5082 | n/a | if (res != 0) goto failed; |
---|
5083 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5084 | n/a | PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration"); |
---|
5085 | n/a | goto failed; |
---|
5086 | n/a | } |
---|
5087 | n/a | asdl_seq_SET(items, i, value); |
---|
5088 | n/a | } |
---|
5089 | n/a | Py_CLEAR(tmp); |
---|
5090 | n/a | } else { |
---|
5091 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With"); |
---|
5092 | n/a | return 1; |
---|
5093 | n/a | } |
---|
5094 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
5095 | n/a | int res; |
---|
5096 | n/a | Py_ssize_t len; |
---|
5097 | n/a | Py_ssize_t i; |
---|
5098 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
5099 | n/a | if (tmp == NULL) goto failed; |
---|
5100 | n/a | if (!PyList_Check(tmp)) { |
---|
5101 | n/a | PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5102 | n/a | goto failed; |
---|
5103 | n/a | } |
---|
5104 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5105 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
5106 | n/a | if (body == NULL) goto failed; |
---|
5107 | n/a | for (i = 0; i < len; i++) { |
---|
5108 | n/a | stmt_ty value; |
---|
5109 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5110 | n/a | if (res != 0) goto failed; |
---|
5111 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5112 | n/a | PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration"); |
---|
5113 | n/a | goto failed; |
---|
5114 | n/a | } |
---|
5115 | n/a | asdl_seq_SET(body, i, value); |
---|
5116 | n/a | } |
---|
5117 | n/a | Py_CLEAR(tmp); |
---|
5118 | n/a | } else { |
---|
5119 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With"); |
---|
5120 | n/a | return 1; |
---|
5121 | n/a | } |
---|
5122 | n/a | *out = With(items, body, lineno, col_offset, arena); |
---|
5123 | n/a | if (*out == NULL) goto failed; |
---|
5124 | n/a | return 0; |
---|
5125 | n/a | } |
---|
5126 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)AsyncWith_type); |
---|
5127 | n/a | if (isinstance == -1) { |
---|
5128 | n/a | return 1; |
---|
5129 | n/a | } |
---|
5130 | n/a | if (isinstance) { |
---|
5131 | n/a | asdl_seq* items; |
---|
5132 | n/a | asdl_seq* body; |
---|
5133 | n/a | |
---|
5134 | n/a | if (_PyObject_HasAttrId(obj, &PyId_items)) { |
---|
5135 | n/a | int res; |
---|
5136 | n/a | Py_ssize_t len; |
---|
5137 | n/a | Py_ssize_t i; |
---|
5138 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_items); |
---|
5139 | n/a | if (tmp == NULL) goto failed; |
---|
5140 | n/a | if (!PyList_Check(tmp)) { |
---|
5141 | n/a | PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5142 | n/a | goto failed; |
---|
5143 | n/a | } |
---|
5144 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5145 | n/a | items = _Py_asdl_seq_new(len, arena); |
---|
5146 | n/a | if (items == NULL) goto failed; |
---|
5147 | n/a | for (i = 0; i < len; i++) { |
---|
5148 | n/a | withitem_ty value; |
---|
5149 | n/a | res = obj2ast_withitem(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5150 | n/a | if (res != 0) goto failed; |
---|
5151 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5152 | n/a | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration"); |
---|
5153 | n/a | goto failed; |
---|
5154 | n/a | } |
---|
5155 | n/a | asdl_seq_SET(items, i, value); |
---|
5156 | n/a | } |
---|
5157 | n/a | Py_CLEAR(tmp); |
---|
5158 | n/a | } else { |
---|
5159 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith"); |
---|
5160 | n/a | return 1; |
---|
5161 | n/a | } |
---|
5162 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
5163 | n/a | int res; |
---|
5164 | n/a | Py_ssize_t len; |
---|
5165 | n/a | Py_ssize_t i; |
---|
5166 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
5167 | n/a | if (tmp == NULL) goto failed; |
---|
5168 | n/a | if (!PyList_Check(tmp)) { |
---|
5169 | n/a | PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5170 | n/a | goto failed; |
---|
5171 | n/a | } |
---|
5172 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5173 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
5174 | n/a | if (body == NULL) goto failed; |
---|
5175 | n/a | for (i = 0; i < len; i++) { |
---|
5176 | n/a | stmt_ty value; |
---|
5177 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5178 | n/a | if (res != 0) goto failed; |
---|
5179 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5180 | n/a | PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration"); |
---|
5181 | n/a | goto failed; |
---|
5182 | n/a | } |
---|
5183 | n/a | asdl_seq_SET(body, i, value); |
---|
5184 | n/a | } |
---|
5185 | n/a | Py_CLEAR(tmp); |
---|
5186 | n/a | } else { |
---|
5187 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith"); |
---|
5188 | n/a | return 1; |
---|
5189 | n/a | } |
---|
5190 | n/a | *out = AsyncWith(items, body, lineno, col_offset, arena); |
---|
5191 | n/a | if (*out == NULL) goto failed; |
---|
5192 | n/a | return 0; |
---|
5193 | n/a | } |
---|
5194 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Raise_type); |
---|
5195 | n/a | if (isinstance == -1) { |
---|
5196 | n/a | return 1; |
---|
5197 | n/a | } |
---|
5198 | n/a | if (isinstance) { |
---|
5199 | n/a | expr_ty exc; |
---|
5200 | n/a | expr_ty cause; |
---|
5201 | n/a | |
---|
5202 | n/a | if (exists_not_none(obj, &PyId_exc)) { |
---|
5203 | n/a | int res; |
---|
5204 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_exc); |
---|
5205 | n/a | if (tmp == NULL) goto failed; |
---|
5206 | n/a | res = obj2ast_expr(tmp, &exc, arena); |
---|
5207 | n/a | if (res != 0) goto failed; |
---|
5208 | n/a | Py_CLEAR(tmp); |
---|
5209 | n/a | } else { |
---|
5210 | n/a | exc = NULL; |
---|
5211 | n/a | } |
---|
5212 | n/a | if (exists_not_none(obj, &PyId_cause)) { |
---|
5213 | n/a | int res; |
---|
5214 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_cause); |
---|
5215 | n/a | if (tmp == NULL) goto failed; |
---|
5216 | n/a | res = obj2ast_expr(tmp, &cause, arena); |
---|
5217 | n/a | if (res != 0) goto failed; |
---|
5218 | n/a | Py_CLEAR(tmp); |
---|
5219 | n/a | } else { |
---|
5220 | n/a | cause = NULL; |
---|
5221 | n/a | } |
---|
5222 | n/a | *out = Raise(exc, cause, lineno, col_offset, arena); |
---|
5223 | n/a | if (*out == NULL) goto failed; |
---|
5224 | n/a | return 0; |
---|
5225 | n/a | } |
---|
5226 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Try_type); |
---|
5227 | n/a | if (isinstance == -1) { |
---|
5228 | n/a | return 1; |
---|
5229 | n/a | } |
---|
5230 | n/a | if (isinstance) { |
---|
5231 | n/a | asdl_seq* body; |
---|
5232 | n/a | asdl_seq* handlers; |
---|
5233 | n/a | asdl_seq* orelse; |
---|
5234 | n/a | asdl_seq* finalbody; |
---|
5235 | n/a | |
---|
5236 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
5237 | n/a | int res; |
---|
5238 | n/a | Py_ssize_t len; |
---|
5239 | n/a | Py_ssize_t i; |
---|
5240 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
5241 | n/a | if (tmp == NULL) goto failed; |
---|
5242 | n/a | if (!PyList_Check(tmp)) { |
---|
5243 | n/a | PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5244 | n/a | goto failed; |
---|
5245 | n/a | } |
---|
5246 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5247 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
5248 | n/a | if (body == NULL) goto failed; |
---|
5249 | n/a | for (i = 0; i < len; i++) { |
---|
5250 | n/a | stmt_ty value; |
---|
5251 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5252 | n/a | if (res != 0) goto failed; |
---|
5253 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5254 | n/a | PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration"); |
---|
5255 | n/a | goto failed; |
---|
5256 | n/a | } |
---|
5257 | n/a | asdl_seq_SET(body, i, value); |
---|
5258 | n/a | } |
---|
5259 | n/a | Py_CLEAR(tmp); |
---|
5260 | n/a | } else { |
---|
5261 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try"); |
---|
5262 | n/a | return 1; |
---|
5263 | n/a | } |
---|
5264 | n/a | if (_PyObject_HasAttrId(obj, &PyId_handlers)) { |
---|
5265 | n/a | int res; |
---|
5266 | n/a | Py_ssize_t len; |
---|
5267 | n/a | Py_ssize_t i; |
---|
5268 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_handlers); |
---|
5269 | n/a | if (tmp == NULL) goto failed; |
---|
5270 | n/a | if (!PyList_Check(tmp)) { |
---|
5271 | n/a | PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5272 | n/a | goto failed; |
---|
5273 | n/a | } |
---|
5274 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5275 | n/a | handlers = _Py_asdl_seq_new(len, arena); |
---|
5276 | n/a | if (handlers == NULL) goto failed; |
---|
5277 | n/a | for (i = 0; i < len; i++) { |
---|
5278 | n/a | excepthandler_ty value; |
---|
5279 | n/a | res = obj2ast_excepthandler(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5280 | n/a | if (res != 0) goto failed; |
---|
5281 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5282 | n/a | PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration"); |
---|
5283 | n/a | goto failed; |
---|
5284 | n/a | } |
---|
5285 | n/a | asdl_seq_SET(handlers, i, value); |
---|
5286 | n/a | } |
---|
5287 | n/a | Py_CLEAR(tmp); |
---|
5288 | n/a | } else { |
---|
5289 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try"); |
---|
5290 | n/a | return 1; |
---|
5291 | n/a | } |
---|
5292 | n/a | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
---|
5293 | n/a | int res; |
---|
5294 | n/a | Py_ssize_t len; |
---|
5295 | n/a | Py_ssize_t i; |
---|
5296 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
---|
5297 | n/a | if (tmp == NULL) goto failed; |
---|
5298 | n/a | if (!PyList_Check(tmp)) { |
---|
5299 | n/a | PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5300 | n/a | goto failed; |
---|
5301 | n/a | } |
---|
5302 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5303 | n/a | orelse = _Py_asdl_seq_new(len, arena); |
---|
5304 | n/a | if (orelse == NULL) goto failed; |
---|
5305 | n/a | for (i = 0; i < len; i++) { |
---|
5306 | n/a | stmt_ty value; |
---|
5307 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5308 | n/a | if (res != 0) goto failed; |
---|
5309 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5310 | n/a | PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration"); |
---|
5311 | n/a | goto failed; |
---|
5312 | n/a | } |
---|
5313 | n/a | asdl_seq_SET(orelse, i, value); |
---|
5314 | n/a | } |
---|
5315 | n/a | Py_CLEAR(tmp); |
---|
5316 | n/a | } else { |
---|
5317 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try"); |
---|
5318 | n/a | return 1; |
---|
5319 | n/a | } |
---|
5320 | n/a | if (_PyObject_HasAttrId(obj, &PyId_finalbody)) { |
---|
5321 | n/a | int res; |
---|
5322 | n/a | Py_ssize_t len; |
---|
5323 | n/a | Py_ssize_t i; |
---|
5324 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_finalbody); |
---|
5325 | n/a | if (tmp == NULL) goto failed; |
---|
5326 | n/a | if (!PyList_Check(tmp)) { |
---|
5327 | n/a | PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5328 | n/a | goto failed; |
---|
5329 | n/a | } |
---|
5330 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5331 | n/a | finalbody = _Py_asdl_seq_new(len, arena); |
---|
5332 | n/a | if (finalbody == NULL) goto failed; |
---|
5333 | n/a | for (i = 0; i < len; i++) { |
---|
5334 | n/a | stmt_ty value; |
---|
5335 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5336 | n/a | if (res != 0) goto failed; |
---|
5337 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5338 | n/a | PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration"); |
---|
5339 | n/a | goto failed; |
---|
5340 | n/a | } |
---|
5341 | n/a | asdl_seq_SET(finalbody, i, value); |
---|
5342 | n/a | } |
---|
5343 | n/a | Py_CLEAR(tmp); |
---|
5344 | n/a | } else { |
---|
5345 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try"); |
---|
5346 | n/a | return 1; |
---|
5347 | n/a | } |
---|
5348 | n/a | *out = Try(body, handlers, orelse, finalbody, lineno, col_offset, |
---|
5349 | n/a | arena); |
---|
5350 | n/a | if (*out == NULL) goto failed; |
---|
5351 | n/a | return 0; |
---|
5352 | n/a | } |
---|
5353 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Assert_type); |
---|
5354 | n/a | if (isinstance == -1) { |
---|
5355 | n/a | return 1; |
---|
5356 | n/a | } |
---|
5357 | n/a | if (isinstance) { |
---|
5358 | n/a | expr_ty test; |
---|
5359 | n/a | expr_ty msg; |
---|
5360 | n/a | |
---|
5361 | n/a | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
---|
5362 | n/a | int res; |
---|
5363 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
---|
5364 | n/a | if (tmp == NULL) goto failed; |
---|
5365 | n/a | res = obj2ast_expr(tmp, &test, arena); |
---|
5366 | n/a | if (res != 0) goto failed; |
---|
5367 | n/a | Py_CLEAR(tmp); |
---|
5368 | n/a | } else { |
---|
5369 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert"); |
---|
5370 | n/a | return 1; |
---|
5371 | n/a | } |
---|
5372 | n/a | if (exists_not_none(obj, &PyId_msg)) { |
---|
5373 | n/a | int res; |
---|
5374 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_msg); |
---|
5375 | n/a | if (tmp == NULL) goto failed; |
---|
5376 | n/a | res = obj2ast_expr(tmp, &msg, arena); |
---|
5377 | n/a | if (res != 0) goto failed; |
---|
5378 | n/a | Py_CLEAR(tmp); |
---|
5379 | n/a | } else { |
---|
5380 | n/a | msg = NULL; |
---|
5381 | n/a | } |
---|
5382 | n/a | *out = Assert(test, msg, lineno, col_offset, arena); |
---|
5383 | n/a | if (*out == NULL) goto failed; |
---|
5384 | n/a | return 0; |
---|
5385 | n/a | } |
---|
5386 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Import_type); |
---|
5387 | n/a | if (isinstance == -1) { |
---|
5388 | n/a | return 1; |
---|
5389 | n/a | } |
---|
5390 | n/a | if (isinstance) { |
---|
5391 | n/a | asdl_seq* names; |
---|
5392 | n/a | |
---|
5393 | n/a | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
---|
5394 | n/a | int res; |
---|
5395 | n/a | Py_ssize_t len; |
---|
5396 | n/a | Py_ssize_t i; |
---|
5397 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
---|
5398 | n/a | if (tmp == NULL) goto failed; |
---|
5399 | n/a | if (!PyList_Check(tmp)) { |
---|
5400 | n/a | PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5401 | n/a | goto failed; |
---|
5402 | n/a | } |
---|
5403 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5404 | n/a | names = _Py_asdl_seq_new(len, arena); |
---|
5405 | n/a | if (names == NULL) goto failed; |
---|
5406 | n/a | for (i = 0; i < len; i++) { |
---|
5407 | n/a | alias_ty value; |
---|
5408 | n/a | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5409 | n/a | if (res != 0) goto failed; |
---|
5410 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5411 | n/a | PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration"); |
---|
5412 | n/a | goto failed; |
---|
5413 | n/a | } |
---|
5414 | n/a | asdl_seq_SET(names, i, value); |
---|
5415 | n/a | } |
---|
5416 | n/a | Py_CLEAR(tmp); |
---|
5417 | n/a | } else { |
---|
5418 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import"); |
---|
5419 | n/a | return 1; |
---|
5420 | n/a | } |
---|
5421 | n/a | *out = Import(names, lineno, col_offset, arena); |
---|
5422 | n/a | if (*out == NULL) goto failed; |
---|
5423 | n/a | return 0; |
---|
5424 | n/a | } |
---|
5425 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)ImportFrom_type); |
---|
5426 | n/a | if (isinstance == -1) { |
---|
5427 | n/a | return 1; |
---|
5428 | n/a | } |
---|
5429 | n/a | if (isinstance) { |
---|
5430 | n/a | identifier module; |
---|
5431 | n/a | asdl_seq* names; |
---|
5432 | n/a | int level; |
---|
5433 | n/a | |
---|
5434 | n/a | if (exists_not_none(obj, &PyId_module)) { |
---|
5435 | n/a | int res; |
---|
5436 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_module); |
---|
5437 | n/a | if (tmp == NULL) goto failed; |
---|
5438 | n/a | res = obj2ast_identifier(tmp, &module, arena); |
---|
5439 | n/a | if (res != 0) goto failed; |
---|
5440 | n/a | Py_CLEAR(tmp); |
---|
5441 | n/a | } else { |
---|
5442 | n/a | module = NULL; |
---|
5443 | n/a | } |
---|
5444 | n/a | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
---|
5445 | n/a | int res; |
---|
5446 | n/a | Py_ssize_t len; |
---|
5447 | n/a | Py_ssize_t i; |
---|
5448 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
---|
5449 | n/a | if (tmp == NULL) goto failed; |
---|
5450 | n/a | if (!PyList_Check(tmp)) { |
---|
5451 | n/a | PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5452 | n/a | goto failed; |
---|
5453 | n/a | } |
---|
5454 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5455 | n/a | names = _Py_asdl_seq_new(len, arena); |
---|
5456 | n/a | if (names == NULL) goto failed; |
---|
5457 | n/a | for (i = 0; i < len; i++) { |
---|
5458 | n/a | alias_ty value; |
---|
5459 | n/a | res = obj2ast_alias(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5460 | n/a | if (res != 0) goto failed; |
---|
5461 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5462 | n/a | PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration"); |
---|
5463 | n/a | goto failed; |
---|
5464 | n/a | } |
---|
5465 | n/a | asdl_seq_SET(names, i, value); |
---|
5466 | n/a | } |
---|
5467 | n/a | Py_CLEAR(tmp); |
---|
5468 | n/a | } else { |
---|
5469 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom"); |
---|
5470 | n/a | return 1; |
---|
5471 | n/a | } |
---|
5472 | n/a | if (exists_not_none(obj, &PyId_level)) { |
---|
5473 | n/a | int res; |
---|
5474 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_level); |
---|
5475 | n/a | if (tmp == NULL) goto failed; |
---|
5476 | n/a | res = obj2ast_int(tmp, &level, arena); |
---|
5477 | n/a | if (res != 0) goto failed; |
---|
5478 | n/a | Py_CLEAR(tmp); |
---|
5479 | n/a | } else { |
---|
5480 | n/a | level = 0; |
---|
5481 | n/a | } |
---|
5482 | n/a | *out = ImportFrom(module, names, level, lineno, col_offset, arena); |
---|
5483 | n/a | if (*out == NULL) goto failed; |
---|
5484 | n/a | return 0; |
---|
5485 | n/a | } |
---|
5486 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Global_type); |
---|
5487 | n/a | if (isinstance == -1) { |
---|
5488 | n/a | return 1; |
---|
5489 | n/a | } |
---|
5490 | n/a | if (isinstance) { |
---|
5491 | n/a | asdl_seq* names; |
---|
5492 | n/a | |
---|
5493 | n/a | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
---|
5494 | n/a | int res; |
---|
5495 | n/a | Py_ssize_t len; |
---|
5496 | n/a | Py_ssize_t i; |
---|
5497 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
---|
5498 | n/a | if (tmp == NULL) goto failed; |
---|
5499 | n/a | if (!PyList_Check(tmp)) { |
---|
5500 | n/a | PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5501 | n/a | goto failed; |
---|
5502 | n/a | } |
---|
5503 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5504 | n/a | names = _Py_asdl_seq_new(len, arena); |
---|
5505 | n/a | if (names == NULL) goto failed; |
---|
5506 | n/a | for (i = 0; i < len; i++) { |
---|
5507 | n/a | identifier value; |
---|
5508 | n/a | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5509 | n/a | if (res != 0) goto failed; |
---|
5510 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5511 | n/a | PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration"); |
---|
5512 | n/a | goto failed; |
---|
5513 | n/a | } |
---|
5514 | n/a | asdl_seq_SET(names, i, value); |
---|
5515 | n/a | } |
---|
5516 | n/a | Py_CLEAR(tmp); |
---|
5517 | n/a | } else { |
---|
5518 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global"); |
---|
5519 | n/a | return 1; |
---|
5520 | n/a | } |
---|
5521 | n/a | *out = Global(names, lineno, col_offset, arena); |
---|
5522 | n/a | if (*out == NULL) goto failed; |
---|
5523 | n/a | return 0; |
---|
5524 | n/a | } |
---|
5525 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Nonlocal_type); |
---|
5526 | n/a | if (isinstance == -1) { |
---|
5527 | n/a | return 1; |
---|
5528 | n/a | } |
---|
5529 | n/a | if (isinstance) { |
---|
5530 | n/a | asdl_seq* names; |
---|
5531 | n/a | |
---|
5532 | n/a | if (_PyObject_HasAttrId(obj, &PyId_names)) { |
---|
5533 | n/a | int res; |
---|
5534 | n/a | Py_ssize_t len; |
---|
5535 | n/a | Py_ssize_t i; |
---|
5536 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_names); |
---|
5537 | n/a | if (tmp == NULL) goto failed; |
---|
5538 | n/a | if (!PyList_Check(tmp)) { |
---|
5539 | n/a | PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5540 | n/a | goto failed; |
---|
5541 | n/a | } |
---|
5542 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5543 | n/a | names = _Py_asdl_seq_new(len, arena); |
---|
5544 | n/a | if (names == NULL) goto failed; |
---|
5545 | n/a | for (i = 0; i < len; i++) { |
---|
5546 | n/a | identifier value; |
---|
5547 | n/a | res = obj2ast_identifier(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5548 | n/a | if (res != 0) goto failed; |
---|
5549 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5550 | n/a | PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration"); |
---|
5551 | n/a | goto failed; |
---|
5552 | n/a | } |
---|
5553 | n/a | asdl_seq_SET(names, i, value); |
---|
5554 | n/a | } |
---|
5555 | n/a | Py_CLEAR(tmp); |
---|
5556 | n/a | } else { |
---|
5557 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal"); |
---|
5558 | n/a | return 1; |
---|
5559 | n/a | } |
---|
5560 | n/a | *out = Nonlocal(names, lineno, col_offset, arena); |
---|
5561 | n/a | if (*out == NULL) goto failed; |
---|
5562 | n/a | return 0; |
---|
5563 | n/a | } |
---|
5564 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Expr_type); |
---|
5565 | n/a | if (isinstance == -1) { |
---|
5566 | n/a | return 1; |
---|
5567 | n/a | } |
---|
5568 | n/a | if (isinstance) { |
---|
5569 | n/a | expr_ty value; |
---|
5570 | n/a | |
---|
5571 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
5572 | n/a | int res; |
---|
5573 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
5574 | n/a | if (tmp == NULL) goto failed; |
---|
5575 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
5576 | n/a | if (res != 0) goto failed; |
---|
5577 | n/a | Py_CLEAR(tmp); |
---|
5578 | n/a | } else { |
---|
5579 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr"); |
---|
5580 | n/a | return 1; |
---|
5581 | n/a | } |
---|
5582 | n/a | *out = Expr(value, lineno, col_offset, arena); |
---|
5583 | n/a | if (*out == NULL) goto failed; |
---|
5584 | n/a | return 0; |
---|
5585 | n/a | } |
---|
5586 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Pass_type); |
---|
5587 | n/a | if (isinstance == -1) { |
---|
5588 | n/a | return 1; |
---|
5589 | n/a | } |
---|
5590 | n/a | if (isinstance) { |
---|
5591 | n/a | |
---|
5592 | n/a | *out = Pass(lineno, col_offset, arena); |
---|
5593 | n/a | if (*out == NULL) goto failed; |
---|
5594 | n/a | return 0; |
---|
5595 | n/a | } |
---|
5596 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Break_type); |
---|
5597 | n/a | if (isinstance == -1) { |
---|
5598 | n/a | return 1; |
---|
5599 | n/a | } |
---|
5600 | n/a | if (isinstance) { |
---|
5601 | n/a | |
---|
5602 | n/a | *out = Break(lineno, col_offset, arena); |
---|
5603 | n/a | if (*out == NULL) goto failed; |
---|
5604 | n/a | return 0; |
---|
5605 | n/a | } |
---|
5606 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Continue_type); |
---|
5607 | n/a | if (isinstance == -1) { |
---|
5608 | n/a | return 1; |
---|
5609 | n/a | } |
---|
5610 | n/a | if (isinstance) { |
---|
5611 | n/a | |
---|
5612 | n/a | *out = Continue(lineno, col_offset, arena); |
---|
5613 | n/a | if (*out == NULL) goto failed; |
---|
5614 | n/a | return 0; |
---|
5615 | n/a | } |
---|
5616 | n/a | |
---|
5617 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj); |
---|
5618 | n/a | failed: |
---|
5619 | n/a | Py_XDECREF(tmp); |
---|
5620 | n/a | return 1; |
---|
5621 | n/a | } |
---|
5622 | n/a | |
---|
5623 | n/a | int |
---|
5624 | n/a | obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena) |
---|
5625 | n/a | { |
---|
5626 | n/a | int isinstance; |
---|
5627 | n/a | |
---|
5628 | n/a | PyObject *tmp = NULL; |
---|
5629 | n/a | int lineno; |
---|
5630 | n/a | int col_offset; |
---|
5631 | n/a | |
---|
5632 | n/a | if (obj == Py_None) { |
---|
5633 | n/a | *out = NULL; |
---|
5634 | n/a | return 0; |
---|
5635 | n/a | } |
---|
5636 | n/a | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
---|
5637 | n/a | int res; |
---|
5638 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
---|
5639 | n/a | if (tmp == NULL) goto failed; |
---|
5640 | n/a | res = obj2ast_int(tmp, &lineno, arena); |
---|
5641 | n/a | if (res != 0) goto failed; |
---|
5642 | n/a | Py_CLEAR(tmp); |
---|
5643 | n/a | } else { |
---|
5644 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr"); |
---|
5645 | n/a | return 1; |
---|
5646 | n/a | } |
---|
5647 | n/a | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
---|
5648 | n/a | int res; |
---|
5649 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
---|
5650 | n/a | if (tmp == NULL) goto failed; |
---|
5651 | n/a | res = obj2ast_int(tmp, &col_offset, arena); |
---|
5652 | n/a | if (res != 0) goto failed; |
---|
5653 | n/a | Py_CLEAR(tmp); |
---|
5654 | n/a | } else { |
---|
5655 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr"); |
---|
5656 | n/a | return 1; |
---|
5657 | n/a | } |
---|
5658 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)BoolOp_type); |
---|
5659 | n/a | if (isinstance == -1) { |
---|
5660 | n/a | return 1; |
---|
5661 | n/a | } |
---|
5662 | n/a | if (isinstance) { |
---|
5663 | n/a | boolop_ty op; |
---|
5664 | n/a | asdl_seq* values; |
---|
5665 | n/a | |
---|
5666 | n/a | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
---|
5667 | n/a | int res; |
---|
5668 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
---|
5669 | n/a | if (tmp == NULL) goto failed; |
---|
5670 | n/a | res = obj2ast_boolop(tmp, &op, arena); |
---|
5671 | n/a | if (res != 0) goto failed; |
---|
5672 | n/a | Py_CLEAR(tmp); |
---|
5673 | n/a | } else { |
---|
5674 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp"); |
---|
5675 | n/a | return 1; |
---|
5676 | n/a | } |
---|
5677 | n/a | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
---|
5678 | n/a | int res; |
---|
5679 | n/a | Py_ssize_t len; |
---|
5680 | n/a | Py_ssize_t i; |
---|
5681 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
---|
5682 | n/a | if (tmp == NULL) goto failed; |
---|
5683 | n/a | if (!PyList_Check(tmp)) { |
---|
5684 | n/a | PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5685 | n/a | goto failed; |
---|
5686 | n/a | } |
---|
5687 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5688 | n/a | values = _Py_asdl_seq_new(len, arena); |
---|
5689 | n/a | if (values == NULL) goto failed; |
---|
5690 | n/a | for (i = 0; i < len; i++) { |
---|
5691 | n/a | expr_ty value; |
---|
5692 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5693 | n/a | if (res != 0) goto failed; |
---|
5694 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5695 | n/a | PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration"); |
---|
5696 | n/a | goto failed; |
---|
5697 | n/a | } |
---|
5698 | n/a | asdl_seq_SET(values, i, value); |
---|
5699 | n/a | } |
---|
5700 | n/a | Py_CLEAR(tmp); |
---|
5701 | n/a | } else { |
---|
5702 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp"); |
---|
5703 | n/a | return 1; |
---|
5704 | n/a | } |
---|
5705 | n/a | *out = BoolOp(op, values, lineno, col_offset, arena); |
---|
5706 | n/a | if (*out == NULL) goto failed; |
---|
5707 | n/a | return 0; |
---|
5708 | n/a | } |
---|
5709 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)BinOp_type); |
---|
5710 | n/a | if (isinstance == -1) { |
---|
5711 | n/a | return 1; |
---|
5712 | n/a | } |
---|
5713 | n/a | if (isinstance) { |
---|
5714 | n/a | expr_ty left; |
---|
5715 | n/a | operator_ty op; |
---|
5716 | n/a | expr_ty right; |
---|
5717 | n/a | |
---|
5718 | n/a | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
---|
5719 | n/a | int res; |
---|
5720 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
---|
5721 | n/a | if (tmp == NULL) goto failed; |
---|
5722 | n/a | res = obj2ast_expr(tmp, &left, arena); |
---|
5723 | n/a | if (res != 0) goto failed; |
---|
5724 | n/a | Py_CLEAR(tmp); |
---|
5725 | n/a | } else { |
---|
5726 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp"); |
---|
5727 | n/a | return 1; |
---|
5728 | n/a | } |
---|
5729 | n/a | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
---|
5730 | n/a | int res; |
---|
5731 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
---|
5732 | n/a | if (tmp == NULL) goto failed; |
---|
5733 | n/a | res = obj2ast_operator(tmp, &op, arena); |
---|
5734 | n/a | if (res != 0) goto failed; |
---|
5735 | n/a | Py_CLEAR(tmp); |
---|
5736 | n/a | } else { |
---|
5737 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp"); |
---|
5738 | n/a | return 1; |
---|
5739 | n/a | } |
---|
5740 | n/a | if (_PyObject_HasAttrId(obj, &PyId_right)) { |
---|
5741 | n/a | int res; |
---|
5742 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_right); |
---|
5743 | n/a | if (tmp == NULL) goto failed; |
---|
5744 | n/a | res = obj2ast_expr(tmp, &right, arena); |
---|
5745 | n/a | if (res != 0) goto failed; |
---|
5746 | n/a | Py_CLEAR(tmp); |
---|
5747 | n/a | } else { |
---|
5748 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp"); |
---|
5749 | n/a | return 1; |
---|
5750 | n/a | } |
---|
5751 | n/a | *out = BinOp(left, op, right, lineno, col_offset, arena); |
---|
5752 | n/a | if (*out == NULL) goto failed; |
---|
5753 | n/a | return 0; |
---|
5754 | n/a | } |
---|
5755 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)UnaryOp_type); |
---|
5756 | n/a | if (isinstance == -1) { |
---|
5757 | n/a | return 1; |
---|
5758 | n/a | } |
---|
5759 | n/a | if (isinstance) { |
---|
5760 | n/a | unaryop_ty op; |
---|
5761 | n/a | expr_ty operand; |
---|
5762 | n/a | |
---|
5763 | n/a | if (_PyObject_HasAttrId(obj, &PyId_op)) { |
---|
5764 | n/a | int res; |
---|
5765 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_op); |
---|
5766 | n/a | if (tmp == NULL) goto failed; |
---|
5767 | n/a | res = obj2ast_unaryop(tmp, &op, arena); |
---|
5768 | n/a | if (res != 0) goto failed; |
---|
5769 | n/a | Py_CLEAR(tmp); |
---|
5770 | n/a | } else { |
---|
5771 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp"); |
---|
5772 | n/a | return 1; |
---|
5773 | n/a | } |
---|
5774 | n/a | if (_PyObject_HasAttrId(obj, &PyId_operand)) { |
---|
5775 | n/a | int res; |
---|
5776 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_operand); |
---|
5777 | n/a | if (tmp == NULL) goto failed; |
---|
5778 | n/a | res = obj2ast_expr(tmp, &operand, arena); |
---|
5779 | n/a | if (res != 0) goto failed; |
---|
5780 | n/a | Py_CLEAR(tmp); |
---|
5781 | n/a | } else { |
---|
5782 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp"); |
---|
5783 | n/a | return 1; |
---|
5784 | n/a | } |
---|
5785 | n/a | *out = UnaryOp(op, operand, lineno, col_offset, arena); |
---|
5786 | n/a | if (*out == NULL) goto failed; |
---|
5787 | n/a | return 0; |
---|
5788 | n/a | } |
---|
5789 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Lambda_type); |
---|
5790 | n/a | if (isinstance == -1) { |
---|
5791 | n/a | return 1; |
---|
5792 | n/a | } |
---|
5793 | n/a | if (isinstance) { |
---|
5794 | n/a | arguments_ty args; |
---|
5795 | n/a | expr_ty body; |
---|
5796 | n/a | |
---|
5797 | n/a | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
---|
5798 | n/a | int res; |
---|
5799 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
---|
5800 | n/a | if (tmp == NULL) goto failed; |
---|
5801 | n/a | res = obj2ast_arguments(tmp, &args, arena); |
---|
5802 | n/a | if (res != 0) goto failed; |
---|
5803 | n/a | Py_CLEAR(tmp); |
---|
5804 | n/a | } else { |
---|
5805 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda"); |
---|
5806 | n/a | return 1; |
---|
5807 | n/a | } |
---|
5808 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
5809 | n/a | int res; |
---|
5810 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
5811 | n/a | if (tmp == NULL) goto failed; |
---|
5812 | n/a | res = obj2ast_expr(tmp, &body, arena); |
---|
5813 | n/a | if (res != 0) goto failed; |
---|
5814 | n/a | Py_CLEAR(tmp); |
---|
5815 | n/a | } else { |
---|
5816 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda"); |
---|
5817 | n/a | return 1; |
---|
5818 | n/a | } |
---|
5819 | n/a | *out = Lambda(args, body, lineno, col_offset, arena); |
---|
5820 | n/a | if (*out == NULL) goto failed; |
---|
5821 | n/a | return 0; |
---|
5822 | n/a | } |
---|
5823 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)IfExp_type); |
---|
5824 | n/a | if (isinstance == -1) { |
---|
5825 | n/a | return 1; |
---|
5826 | n/a | } |
---|
5827 | n/a | if (isinstance) { |
---|
5828 | n/a | expr_ty test; |
---|
5829 | n/a | expr_ty body; |
---|
5830 | n/a | expr_ty orelse; |
---|
5831 | n/a | |
---|
5832 | n/a | if (_PyObject_HasAttrId(obj, &PyId_test)) { |
---|
5833 | n/a | int res; |
---|
5834 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_test); |
---|
5835 | n/a | if (tmp == NULL) goto failed; |
---|
5836 | n/a | res = obj2ast_expr(tmp, &test, arena); |
---|
5837 | n/a | if (res != 0) goto failed; |
---|
5838 | n/a | Py_CLEAR(tmp); |
---|
5839 | n/a | } else { |
---|
5840 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp"); |
---|
5841 | n/a | return 1; |
---|
5842 | n/a | } |
---|
5843 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
5844 | n/a | int res; |
---|
5845 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
5846 | n/a | if (tmp == NULL) goto failed; |
---|
5847 | n/a | res = obj2ast_expr(tmp, &body, arena); |
---|
5848 | n/a | if (res != 0) goto failed; |
---|
5849 | n/a | Py_CLEAR(tmp); |
---|
5850 | n/a | } else { |
---|
5851 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp"); |
---|
5852 | n/a | return 1; |
---|
5853 | n/a | } |
---|
5854 | n/a | if (_PyObject_HasAttrId(obj, &PyId_orelse)) { |
---|
5855 | n/a | int res; |
---|
5856 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_orelse); |
---|
5857 | n/a | if (tmp == NULL) goto failed; |
---|
5858 | n/a | res = obj2ast_expr(tmp, &orelse, arena); |
---|
5859 | n/a | if (res != 0) goto failed; |
---|
5860 | n/a | Py_CLEAR(tmp); |
---|
5861 | n/a | } else { |
---|
5862 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp"); |
---|
5863 | n/a | return 1; |
---|
5864 | n/a | } |
---|
5865 | n/a | *out = IfExp(test, body, orelse, lineno, col_offset, arena); |
---|
5866 | n/a | if (*out == NULL) goto failed; |
---|
5867 | n/a | return 0; |
---|
5868 | n/a | } |
---|
5869 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Dict_type); |
---|
5870 | n/a | if (isinstance == -1) { |
---|
5871 | n/a | return 1; |
---|
5872 | n/a | } |
---|
5873 | n/a | if (isinstance) { |
---|
5874 | n/a | asdl_seq* keys; |
---|
5875 | n/a | asdl_seq* values; |
---|
5876 | n/a | |
---|
5877 | n/a | if (_PyObject_HasAttrId(obj, &PyId_keys)) { |
---|
5878 | n/a | int res; |
---|
5879 | n/a | Py_ssize_t len; |
---|
5880 | n/a | Py_ssize_t i; |
---|
5881 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_keys); |
---|
5882 | n/a | if (tmp == NULL) goto failed; |
---|
5883 | n/a | if (!PyList_Check(tmp)) { |
---|
5884 | n/a | PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5885 | n/a | goto failed; |
---|
5886 | n/a | } |
---|
5887 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5888 | n/a | keys = _Py_asdl_seq_new(len, arena); |
---|
5889 | n/a | if (keys == NULL) goto failed; |
---|
5890 | n/a | for (i = 0; i < len; i++) { |
---|
5891 | n/a | expr_ty value; |
---|
5892 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5893 | n/a | if (res != 0) goto failed; |
---|
5894 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5895 | n/a | PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration"); |
---|
5896 | n/a | goto failed; |
---|
5897 | n/a | } |
---|
5898 | n/a | asdl_seq_SET(keys, i, value); |
---|
5899 | n/a | } |
---|
5900 | n/a | Py_CLEAR(tmp); |
---|
5901 | n/a | } else { |
---|
5902 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict"); |
---|
5903 | n/a | return 1; |
---|
5904 | n/a | } |
---|
5905 | n/a | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
---|
5906 | n/a | int res; |
---|
5907 | n/a | Py_ssize_t len; |
---|
5908 | n/a | Py_ssize_t i; |
---|
5909 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
---|
5910 | n/a | if (tmp == NULL) goto failed; |
---|
5911 | n/a | if (!PyList_Check(tmp)) { |
---|
5912 | n/a | PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5913 | n/a | goto failed; |
---|
5914 | n/a | } |
---|
5915 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5916 | n/a | values = _Py_asdl_seq_new(len, arena); |
---|
5917 | n/a | if (values == NULL) goto failed; |
---|
5918 | n/a | for (i = 0; i < len; i++) { |
---|
5919 | n/a | expr_ty value; |
---|
5920 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5921 | n/a | if (res != 0) goto failed; |
---|
5922 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5923 | n/a | PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration"); |
---|
5924 | n/a | goto failed; |
---|
5925 | n/a | } |
---|
5926 | n/a | asdl_seq_SET(values, i, value); |
---|
5927 | n/a | } |
---|
5928 | n/a | Py_CLEAR(tmp); |
---|
5929 | n/a | } else { |
---|
5930 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict"); |
---|
5931 | n/a | return 1; |
---|
5932 | n/a | } |
---|
5933 | n/a | *out = Dict(keys, values, lineno, col_offset, arena); |
---|
5934 | n/a | if (*out == NULL) goto failed; |
---|
5935 | n/a | return 0; |
---|
5936 | n/a | } |
---|
5937 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Set_type); |
---|
5938 | n/a | if (isinstance == -1) { |
---|
5939 | n/a | return 1; |
---|
5940 | n/a | } |
---|
5941 | n/a | if (isinstance) { |
---|
5942 | n/a | asdl_seq* elts; |
---|
5943 | n/a | |
---|
5944 | n/a | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
---|
5945 | n/a | int res; |
---|
5946 | n/a | Py_ssize_t len; |
---|
5947 | n/a | Py_ssize_t i; |
---|
5948 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
---|
5949 | n/a | if (tmp == NULL) goto failed; |
---|
5950 | n/a | if (!PyList_Check(tmp)) { |
---|
5951 | n/a | PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
5952 | n/a | goto failed; |
---|
5953 | n/a | } |
---|
5954 | n/a | len = PyList_GET_SIZE(tmp); |
---|
5955 | n/a | elts = _Py_asdl_seq_new(len, arena); |
---|
5956 | n/a | if (elts == NULL) goto failed; |
---|
5957 | n/a | for (i = 0; i < len; i++) { |
---|
5958 | n/a | expr_ty value; |
---|
5959 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
5960 | n/a | if (res != 0) goto failed; |
---|
5961 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
5962 | n/a | PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration"); |
---|
5963 | n/a | goto failed; |
---|
5964 | n/a | } |
---|
5965 | n/a | asdl_seq_SET(elts, i, value); |
---|
5966 | n/a | } |
---|
5967 | n/a | Py_CLEAR(tmp); |
---|
5968 | n/a | } else { |
---|
5969 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set"); |
---|
5970 | n/a | return 1; |
---|
5971 | n/a | } |
---|
5972 | n/a | *out = Set(elts, lineno, col_offset, arena); |
---|
5973 | n/a | if (*out == NULL) goto failed; |
---|
5974 | n/a | return 0; |
---|
5975 | n/a | } |
---|
5976 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)ListComp_type); |
---|
5977 | n/a | if (isinstance == -1) { |
---|
5978 | n/a | return 1; |
---|
5979 | n/a | } |
---|
5980 | n/a | if (isinstance) { |
---|
5981 | n/a | expr_ty elt; |
---|
5982 | n/a | asdl_seq* generators; |
---|
5983 | n/a | |
---|
5984 | n/a | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
---|
5985 | n/a | int res; |
---|
5986 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
---|
5987 | n/a | if (tmp == NULL) goto failed; |
---|
5988 | n/a | res = obj2ast_expr(tmp, &elt, arena); |
---|
5989 | n/a | if (res != 0) goto failed; |
---|
5990 | n/a | Py_CLEAR(tmp); |
---|
5991 | n/a | } else { |
---|
5992 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp"); |
---|
5993 | n/a | return 1; |
---|
5994 | n/a | } |
---|
5995 | n/a | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
---|
5996 | n/a | int res; |
---|
5997 | n/a | Py_ssize_t len; |
---|
5998 | n/a | Py_ssize_t i; |
---|
5999 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
---|
6000 | n/a | if (tmp == NULL) goto failed; |
---|
6001 | n/a | if (!PyList_Check(tmp)) { |
---|
6002 | n/a | PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6003 | n/a | goto failed; |
---|
6004 | n/a | } |
---|
6005 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6006 | n/a | generators = _Py_asdl_seq_new(len, arena); |
---|
6007 | n/a | if (generators == NULL) goto failed; |
---|
6008 | n/a | for (i = 0; i < len; i++) { |
---|
6009 | n/a | comprehension_ty value; |
---|
6010 | n/a | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6011 | n/a | if (res != 0) goto failed; |
---|
6012 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6013 | n/a | PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration"); |
---|
6014 | n/a | goto failed; |
---|
6015 | n/a | } |
---|
6016 | n/a | asdl_seq_SET(generators, i, value); |
---|
6017 | n/a | } |
---|
6018 | n/a | Py_CLEAR(tmp); |
---|
6019 | n/a | } else { |
---|
6020 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp"); |
---|
6021 | n/a | return 1; |
---|
6022 | n/a | } |
---|
6023 | n/a | *out = ListComp(elt, generators, lineno, col_offset, arena); |
---|
6024 | n/a | if (*out == NULL) goto failed; |
---|
6025 | n/a | return 0; |
---|
6026 | n/a | } |
---|
6027 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)SetComp_type); |
---|
6028 | n/a | if (isinstance == -1) { |
---|
6029 | n/a | return 1; |
---|
6030 | n/a | } |
---|
6031 | n/a | if (isinstance) { |
---|
6032 | n/a | expr_ty elt; |
---|
6033 | n/a | asdl_seq* generators; |
---|
6034 | n/a | |
---|
6035 | n/a | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
---|
6036 | n/a | int res; |
---|
6037 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
---|
6038 | n/a | if (tmp == NULL) goto failed; |
---|
6039 | n/a | res = obj2ast_expr(tmp, &elt, arena); |
---|
6040 | n/a | if (res != 0) goto failed; |
---|
6041 | n/a | Py_CLEAR(tmp); |
---|
6042 | n/a | } else { |
---|
6043 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp"); |
---|
6044 | n/a | return 1; |
---|
6045 | n/a | } |
---|
6046 | n/a | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
---|
6047 | n/a | int res; |
---|
6048 | n/a | Py_ssize_t len; |
---|
6049 | n/a | Py_ssize_t i; |
---|
6050 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
---|
6051 | n/a | if (tmp == NULL) goto failed; |
---|
6052 | n/a | if (!PyList_Check(tmp)) { |
---|
6053 | n/a | PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6054 | n/a | goto failed; |
---|
6055 | n/a | } |
---|
6056 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6057 | n/a | generators = _Py_asdl_seq_new(len, arena); |
---|
6058 | n/a | if (generators == NULL) goto failed; |
---|
6059 | n/a | for (i = 0; i < len; i++) { |
---|
6060 | n/a | comprehension_ty value; |
---|
6061 | n/a | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6062 | n/a | if (res != 0) goto failed; |
---|
6063 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6064 | n/a | PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration"); |
---|
6065 | n/a | goto failed; |
---|
6066 | n/a | } |
---|
6067 | n/a | asdl_seq_SET(generators, i, value); |
---|
6068 | n/a | } |
---|
6069 | n/a | Py_CLEAR(tmp); |
---|
6070 | n/a | } else { |
---|
6071 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp"); |
---|
6072 | n/a | return 1; |
---|
6073 | n/a | } |
---|
6074 | n/a | *out = SetComp(elt, generators, lineno, col_offset, arena); |
---|
6075 | n/a | if (*out == NULL) goto failed; |
---|
6076 | n/a | return 0; |
---|
6077 | n/a | } |
---|
6078 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)DictComp_type); |
---|
6079 | n/a | if (isinstance == -1) { |
---|
6080 | n/a | return 1; |
---|
6081 | n/a | } |
---|
6082 | n/a | if (isinstance) { |
---|
6083 | n/a | expr_ty key; |
---|
6084 | n/a | expr_ty value; |
---|
6085 | n/a | asdl_seq* generators; |
---|
6086 | n/a | |
---|
6087 | n/a | if (_PyObject_HasAttrId(obj, &PyId_key)) { |
---|
6088 | n/a | int res; |
---|
6089 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_key); |
---|
6090 | n/a | if (tmp == NULL) goto failed; |
---|
6091 | n/a | res = obj2ast_expr(tmp, &key, arena); |
---|
6092 | n/a | if (res != 0) goto failed; |
---|
6093 | n/a | Py_CLEAR(tmp); |
---|
6094 | n/a | } else { |
---|
6095 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp"); |
---|
6096 | n/a | return 1; |
---|
6097 | n/a | } |
---|
6098 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6099 | n/a | int res; |
---|
6100 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6101 | n/a | if (tmp == NULL) goto failed; |
---|
6102 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6103 | n/a | if (res != 0) goto failed; |
---|
6104 | n/a | Py_CLEAR(tmp); |
---|
6105 | n/a | } else { |
---|
6106 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp"); |
---|
6107 | n/a | return 1; |
---|
6108 | n/a | } |
---|
6109 | n/a | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
---|
6110 | n/a | int res; |
---|
6111 | n/a | Py_ssize_t len; |
---|
6112 | n/a | Py_ssize_t i; |
---|
6113 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
---|
6114 | n/a | if (tmp == NULL) goto failed; |
---|
6115 | n/a | if (!PyList_Check(tmp)) { |
---|
6116 | n/a | PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6117 | n/a | goto failed; |
---|
6118 | n/a | } |
---|
6119 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6120 | n/a | generators = _Py_asdl_seq_new(len, arena); |
---|
6121 | n/a | if (generators == NULL) goto failed; |
---|
6122 | n/a | for (i = 0; i < len; i++) { |
---|
6123 | n/a | comprehension_ty value; |
---|
6124 | n/a | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6125 | n/a | if (res != 0) goto failed; |
---|
6126 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6127 | n/a | PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration"); |
---|
6128 | n/a | goto failed; |
---|
6129 | n/a | } |
---|
6130 | n/a | asdl_seq_SET(generators, i, value); |
---|
6131 | n/a | } |
---|
6132 | n/a | Py_CLEAR(tmp); |
---|
6133 | n/a | } else { |
---|
6134 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp"); |
---|
6135 | n/a | return 1; |
---|
6136 | n/a | } |
---|
6137 | n/a | *out = DictComp(key, value, generators, lineno, col_offset, arena); |
---|
6138 | n/a | if (*out == NULL) goto failed; |
---|
6139 | n/a | return 0; |
---|
6140 | n/a | } |
---|
6141 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)GeneratorExp_type); |
---|
6142 | n/a | if (isinstance == -1) { |
---|
6143 | n/a | return 1; |
---|
6144 | n/a | } |
---|
6145 | n/a | if (isinstance) { |
---|
6146 | n/a | expr_ty elt; |
---|
6147 | n/a | asdl_seq* generators; |
---|
6148 | n/a | |
---|
6149 | n/a | if (_PyObject_HasAttrId(obj, &PyId_elt)) { |
---|
6150 | n/a | int res; |
---|
6151 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_elt); |
---|
6152 | n/a | if (tmp == NULL) goto failed; |
---|
6153 | n/a | res = obj2ast_expr(tmp, &elt, arena); |
---|
6154 | n/a | if (res != 0) goto failed; |
---|
6155 | n/a | Py_CLEAR(tmp); |
---|
6156 | n/a | } else { |
---|
6157 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp"); |
---|
6158 | n/a | return 1; |
---|
6159 | n/a | } |
---|
6160 | n/a | if (_PyObject_HasAttrId(obj, &PyId_generators)) { |
---|
6161 | n/a | int res; |
---|
6162 | n/a | Py_ssize_t len; |
---|
6163 | n/a | Py_ssize_t i; |
---|
6164 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_generators); |
---|
6165 | n/a | if (tmp == NULL) goto failed; |
---|
6166 | n/a | if (!PyList_Check(tmp)) { |
---|
6167 | n/a | PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6168 | n/a | goto failed; |
---|
6169 | n/a | } |
---|
6170 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6171 | n/a | generators = _Py_asdl_seq_new(len, arena); |
---|
6172 | n/a | if (generators == NULL) goto failed; |
---|
6173 | n/a | for (i = 0; i < len; i++) { |
---|
6174 | n/a | comprehension_ty value; |
---|
6175 | n/a | res = obj2ast_comprehension(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6176 | n/a | if (res != 0) goto failed; |
---|
6177 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6178 | n/a | PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration"); |
---|
6179 | n/a | goto failed; |
---|
6180 | n/a | } |
---|
6181 | n/a | asdl_seq_SET(generators, i, value); |
---|
6182 | n/a | } |
---|
6183 | n/a | Py_CLEAR(tmp); |
---|
6184 | n/a | } else { |
---|
6185 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp"); |
---|
6186 | n/a | return 1; |
---|
6187 | n/a | } |
---|
6188 | n/a | *out = GeneratorExp(elt, generators, lineno, col_offset, arena); |
---|
6189 | n/a | if (*out == NULL) goto failed; |
---|
6190 | n/a | return 0; |
---|
6191 | n/a | } |
---|
6192 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Await_type); |
---|
6193 | n/a | if (isinstance == -1) { |
---|
6194 | n/a | return 1; |
---|
6195 | n/a | } |
---|
6196 | n/a | if (isinstance) { |
---|
6197 | n/a | expr_ty value; |
---|
6198 | n/a | |
---|
6199 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6200 | n/a | int res; |
---|
6201 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6202 | n/a | if (tmp == NULL) goto failed; |
---|
6203 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6204 | n/a | if (res != 0) goto failed; |
---|
6205 | n/a | Py_CLEAR(tmp); |
---|
6206 | n/a | } else { |
---|
6207 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await"); |
---|
6208 | n/a | return 1; |
---|
6209 | n/a | } |
---|
6210 | n/a | *out = Await(value, lineno, col_offset, arena); |
---|
6211 | n/a | if (*out == NULL) goto failed; |
---|
6212 | n/a | return 0; |
---|
6213 | n/a | } |
---|
6214 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Yield_type); |
---|
6215 | n/a | if (isinstance == -1) { |
---|
6216 | n/a | return 1; |
---|
6217 | n/a | } |
---|
6218 | n/a | if (isinstance) { |
---|
6219 | n/a | expr_ty value; |
---|
6220 | n/a | |
---|
6221 | n/a | if (exists_not_none(obj, &PyId_value)) { |
---|
6222 | n/a | int res; |
---|
6223 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6224 | n/a | if (tmp == NULL) goto failed; |
---|
6225 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6226 | n/a | if (res != 0) goto failed; |
---|
6227 | n/a | Py_CLEAR(tmp); |
---|
6228 | n/a | } else { |
---|
6229 | n/a | value = NULL; |
---|
6230 | n/a | } |
---|
6231 | n/a | *out = Yield(value, lineno, col_offset, arena); |
---|
6232 | n/a | if (*out == NULL) goto failed; |
---|
6233 | n/a | return 0; |
---|
6234 | n/a | } |
---|
6235 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)YieldFrom_type); |
---|
6236 | n/a | if (isinstance == -1) { |
---|
6237 | n/a | return 1; |
---|
6238 | n/a | } |
---|
6239 | n/a | if (isinstance) { |
---|
6240 | n/a | expr_ty value; |
---|
6241 | n/a | |
---|
6242 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6243 | n/a | int res; |
---|
6244 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6245 | n/a | if (tmp == NULL) goto failed; |
---|
6246 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6247 | n/a | if (res != 0) goto failed; |
---|
6248 | n/a | Py_CLEAR(tmp); |
---|
6249 | n/a | } else { |
---|
6250 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom"); |
---|
6251 | n/a | return 1; |
---|
6252 | n/a | } |
---|
6253 | n/a | *out = YieldFrom(value, lineno, col_offset, arena); |
---|
6254 | n/a | if (*out == NULL) goto failed; |
---|
6255 | n/a | return 0; |
---|
6256 | n/a | } |
---|
6257 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Compare_type); |
---|
6258 | n/a | if (isinstance == -1) { |
---|
6259 | n/a | return 1; |
---|
6260 | n/a | } |
---|
6261 | n/a | if (isinstance) { |
---|
6262 | n/a | expr_ty left; |
---|
6263 | n/a | asdl_int_seq* ops; |
---|
6264 | n/a | asdl_seq* comparators; |
---|
6265 | n/a | |
---|
6266 | n/a | if (_PyObject_HasAttrId(obj, &PyId_left)) { |
---|
6267 | n/a | int res; |
---|
6268 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_left); |
---|
6269 | n/a | if (tmp == NULL) goto failed; |
---|
6270 | n/a | res = obj2ast_expr(tmp, &left, arena); |
---|
6271 | n/a | if (res != 0) goto failed; |
---|
6272 | n/a | Py_CLEAR(tmp); |
---|
6273 | n/a | } else { |
---|
6274 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare"); |
---|
6275 | n/a | return 1; |
---|
6276 | n/a | } |
---|
6277 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ops)) { |
---|
6278 | n/a | int res; |
---|
6279 | n/a | Py_ssize_t len; |
---|
6280 | n/a | Py_ssize_t i; |
---|
6281 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ops); |
---|
6282 | n/a | if (tmp == NULL) goto failed; |
---|
6283 | n/a | if (!PyList_Check(tmp)) { |
---|
6284 | n/a | PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6285 | n/a | goto failed; |
---|
6286 | n/a | } |
---|
6287 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6288 | n/a | ops = _Py_asdl_int_seq_new(len, arena); |
---|
6289 | n/a | if (ops == NULL) goto failed; |
---|
6290 | n/a | for (i = 0; i < len; i++) { |
---|
6291 | n/a | cmpop_ty value; |
---|
6292 | n/a | res = obj2ast_cmpop(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6293 | n/a | if (res != 0) goto failed; |
---|
6294 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6295 | n/a | PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration"); |
---|
6296 | n/a | goto failed; |
---|
6297 | n/a | } |
---|
6298 | n/a | asdl_seq_SET(ops, i, value); |
---|
6299 | n/a | } |
---|
6300 | n/a | Py_CLEAR(tmp); |
---|
6301 | n/a | } else { |
---|
6302 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare"); |
---|
6303 | n/a | return 1; |
---|
6304 | n/a | } |
---|
6305 | n/a | if (_PyObject_HasAttrId(obj, &PyId_comparators)) { |
---|
6306 | n/a | int res; |
---|
6307 | n/a | Py_ssize_t len; |
---|
6308 | n/a | Py_ssize_t i; |
---|
6309 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_comparators); |
---|
6310 | n/a | if (tmp == NULL) goto failed; |
---|
6311 | n/a | if (!PyList_Check(tmp)) { |
---|
6312 | n/a | PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6313 | n/a | goto failed; |
---|
6314 | n/a | } |
---|
6315 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6316 | n/a | comparators = _Py_asdl_seq_new(len, arena); |
---|
6317 | n/a | if (comparators == NULL) goto failed; |
---|
6318 | n/a | for (i = 0; i < len; i++) { |
---|
6319 | n/a | expr_ty value; |
---|
6320 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6321 | n/a | if (res != 0) goto failed; |
---|
6322 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6323 | n/a | PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration"); |
---|
6324 | n/a | goto failed; |
---|
6325 | n/a | } |
---|
6326 | n/a | asdl_seq_SET(comparators, i, value); |
---|
6327 | n/a | } |
---|
6328 | n/a | Py_CLEAR(tmp); |
---|
6329 | n/a | } else { |
---|
6330 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare"); |
---|
6331 | n/a | return 1; |
---|
6332 | n/a | } |
---|
6333 | n/a | *out = Compare(left, ops, comparators, lineno, col_offset, arena); |
---|
6334 | n/a | if (*out == NULL) goto failed; |
---|
6335 | n/a | return 0; |
---|
6336 | n/a | } |
---|
6337 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Call_type); |
---|
6338 | n/a | if (isinstance == -1) { |
---|
6339 | n/a | return 1; |
---|
6340 | n/a | } |
---|
6341 | n/a | if (isinstance) { |
---|
6342 | n/a | expr_ty func; |
---|
6343 | n/a | asdl_seq* args; |
---|
6344 | n/a | asdl_seq* keywords; |
---|
6345 | n/a | |
---|
6346 | n/a | if (_PyObject_HasAttrId(obj, &PyId_func)) { |
---|
6347 | n/a | int res; |
---|
6348 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_func); |
---|
6349 | n/a | if (tmp == NULL) goto failed; |
---|
6350 | n/a | res = obj2ast_expr(tmp, &func, arena); |
---|
6351 | n/a | if (res != 0) goto failed; |
---|
6352 | n/a | Py_CLEAR(tmp); |
---|
6353 | n/a | } else { |
---|
6354 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call"); |
---|
6355 | n/a | return 1; |
---|
6356 | n/a | } |
---|
6357 | n/a | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
---|
6358 | n/a | int res; |
---|
6359 | n/a | Py_ssize_t len; |
---|
6360 | n/a | Py_ssize_t i; |
---|
6361 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
---|
6362 | n/a | if (tmp == NULL) goto failed; |
---|
6363 | n/a | if (!PyList_Check(tmp)) { |
---|
6364 | n/a | PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6365 | n/a | goto failed; |
---|
6366 | n/a | } |
---|
6367 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6368 | n/a | args = _Py_asdl_seq_new(len, arena); |
---|
6369 | n/a | if (args == NULL) goto failed; |
---|
6370 | n/a | for (i = 0; i < len; i++) { |
---|
6371 | n/a | expr_ty value; |
---|
6372 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6373 | n/a | if (res != 0) goto failed; |
---|
6374 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6375 | n/a | PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration"); |
---|
6376 | n/a | goto failed; |
---|
6377 | n/a | } |
---|
6378 | n/a | asdl_seq_SET(args, i, value); |
---|
6379 | n/a | } |
---|
6380 | n/a | Py_CLEAR(tmp); |
---|
6381 | n/a | } else { |
---|
6382 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call"); |
---|
6383 | n/a | return 1; |
---|
6384 | n/a | } |
---|
6385 | n/a | if (_PyObject_HasAttrId(obj, &PyId_keywords)) { |
---|
6386 | n/a | int res; |
---|
6387 | n/a | Py_ssize_t len; |
---|
6388 | n/a | Py_ssize_t i; |
---|
6389 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_keywords); |
---|
6390 | n/a | if (tmp == NULL) goto failed; |
---|
6391 | n/a | if (!PyList_Check(tmp)) { |
---|
6392 | n/a | PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6393 | n/a | goto failed; |
---|
6394 | n/a | } |
---|
6395 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6396 | n/a | keywords = _Py_asdl_seq_new(len, arena); |
---|
6397 | n/a | if (keywords == NULL) goto failed; |
---|
6398 | n/a | for (i = 0; i < len; i++) { |
---|
6399 | n/a | keyword_ty value; |
---|
6400 | n/a | res = obj2ast_keyword(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6401 | n/a | if (res != 0) goto failed; |
---|
6402 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6403 | n/a | PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration"); |
---|
6404 | n/a | goto failed; |
---|
6405 | n/a | } |
---|
6406 | n/a | asdl_seq_SET(keywords, i, value); |
---|
6407 | n/a | } |
---|
6408 | n/a | Py_CLEAR(tmp); |
---|
6409 | n/a | } else { |
---|
6410 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call"); |
---|
6411 | n/a | return 1; |
---|
6412 | n/a | } |
---|
6413 | n/a | *out = Call(func, args, keywords, lineno, col_offset, arena); |
---|
6414 | n/a | if (*out == NULL) goto failed; |
---|
6415 | n/a | return 0; |
---|
6416 | n/a | } |
---|
6417 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Num_type); |
---|
6418 | n/a | if (isinstance == -1) { |
---|
6419 | n/a | return 1; |
---|
6420 | n/a | } |
---|
6421 | n/a | if (isinstance) { |
---|
6422 | n/a | object n; |
---|
6423 | n/a | |
---|
6424 | n/a | if (_PyObject_HasAttrId(obj, &PyId_n)) { |
---|
6425 | n/a | int res; |
---|
6426 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_n); |
---|
6427 | n/a | if (tmp == NULL) goto failed; |
---|
6428 | n/a | res = obj2ast_object(tmp, &n, arena); |
---|
6429 | n/a | if (res != 0) goto failed; |
---|
6430 | n/a | Py_CLEAR(tmp); |
---|
6431 | n/a | } else { |
---|
6432 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"n\" missing from Num"); |
---|
6433 | n/a | return 1; |
---|
6434 | n/a | } |
---|
6435 | n/a | *out = Num(n, lineno, col_offset, arena); |
---|
6436 | n/a | if (*out == NULL) goto failed; |
---|
6437 | n/a | return 0; |
---|
6438 | n/a | } |
---|
6439 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Str_type); |
---|
6440 | n/a | if (isinstance == -1) { |
---|
6441 | n/a | return 1; |
---|
6442 | n/a | } |
---|
6443 | n/a | if (isinstance) { |
---|
6444 | n/a | string s; |
---|
6445 | n/a | |
---|
6446 | n/a | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
---|
6447 | n/a | int res; |
---|
6448 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
---|
6449 | n/a | if (tmp == NULL) goto failed; |
---|
6450 | n/a | res = obj2ast_string(tmp, &s, arena); |
---|
6451 | n/a | if (res != 0) goto failed; |
---|
6452 | n/a | Py_CLEAR(tmp); |
---|
6453 | n/a | } else { |
---|
6454 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Str"); |
---|
6455 | n/a | return 1; |
---|
6456 | n/a | } |
---|
6457 | n/a | *out = Str(s, lineno, col_offset, arena); |
---|
6458 | n/a | if (*out == NULL) goto failed; |
---|
6459 | n/a | return 0; |
---|
6460 | n/a | } |
---|
6461 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)FormattedValue_type); |
---|
6462 | n/a | if (isinstance == -1) { |
---|
6463 | n/a | return 1; |
---|
6464 | n/a | } |
---|
6465 | n/a | if (isinstance) { |
---|
6466 | n/a | expr_ty value; |
---|
6467 | n/a | int conversion; |
---|
6468 | n/a | expr_ty format_spec; |
---|
6469 | n/a | |
---|
6470 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6471 | n/a | int res; |
---|
6472 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6473 | n/a | if (tmp == NULL) goto failed; |
---|
6474 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6475 | n/a | if (res != 0) goto failed; |
---|
6476 | n/a | Py_CLEAR(tmp); |
---|
6477 | n/a | } else { |
---|
6478 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue"); |
---|
6479 | n/a | return 1; |
---|
6480 | n/a | } |
---|
6481 | n/a | if (exists_not_none(obj, &PyId_conversion)) { |
---|
6482 | n/a | int res; |
---|
6483 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_conversion); |
---|
6484 | n/a | if (tmp == NULL) goto failed; |
---|
6485 | n/a | res = obj2ast_int(tmp, &conversion, arena); |
---|
6486 | n/a | if (res != 0) goto failed; |
---|
6487 | n/a | Py_CLEAR(tmp); |
---|
6488 | n/a | } else { |
---|
6489 | n/a | conversion = 0; |
---|
6490 | n/a | } |
---|
6491 | n/a | if (exists_not_none(obj, &PyId_format_spec)) { |
---|
6492 | n/a | int res; |
---|
6493 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_format_spec); |
---|
6494 | n/a | if (tmp == NULL) goto failed; |
---|
6495 | n/a | res = obj2ast_expr(tmp, &format_spec, arena); |
---|
6496 | n/a | if (res != 0) goto failed; |
---|
6497 | n/a | Py_CLEAR(tmp); |
---|
6498 | n/a | } else { |
---|
6499 | n/a | format_spec = NULL; |
---|
6500 | n/a | } |
---|
6501 | n/a | *out = FormattedValue(value, conversion, format_spec, lineno, |
---|
6502 | n/a | col_offset, arena); |
---|
6503 | n/a | if (*out == NULL) goto failed; |
---|
6504 | n/a | return 0; |
---|
6505 | n/a | } |
---|
6506 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)JoinedStr_type); |
---|
6507 | n/a | if (isinstance == -1) { |
---|
6508 | n/a | return 1; |
---|
6509 | n/a | } |
---|
6510 | n/a | if (isinstance) { |
---|
6511 | n/a | asdl_seq* values; |
---|
6512 | n/a | |
---|
6513 | n/a | if (_PyObject_HasAttrId(obj, &PyId_values)) { |
---|
6514 | n/a | int res; |
---|
6515 | n/a | Py_ssize_t len; |
---|
6516 | n/a | Py_ssize_t i; |
---|
6517 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_values); |
---|
6518 | n/a | if (tmp == NULL) goto failed; |
---|
6519 | n/a | if (!PyList_Check(tmp)) { |
---|
6520 | n/a | PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6521 | n/a | goto failed; |
---|
6522 | n/a | } |
---|
6523 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6524 | n/a | values = _Py_asdl_seq_new(len, arena); |
---|
6525 | n/a | if (values == NULL) goto failed; |
---|
6526 | n/a | for (i = 0; i < len; i++) { |
---|
6527 | n/a | expr_ty value; |
---|
6528 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6529 | n/a | if (res != 0) goto failed; |
---|
6530 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6531 | n/a | PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration"); |
---|
6532 | n/a | goto failed; |
---|
6533 | n/a | } |
---|
6534 | n/a | asdl_seq_SET(values, i, value); |
---|
6535 | n/a | } |
---|
6536 | n/a | Py_CLEAR(tmp); |
---|
6537 | n/a | } else { |
---|
6538 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr"); |
---|
6539 | n/a | return 1; |
---|
6540 | n/a | } |
---|
6541 | n/a | *out = JoinedStr(values, lineno, col_offset, arena); |
---|
6542 | n/a | if (*out == NULL) goto failed; |
---|
6543 | n/a | return 0; |
---|
6544 | n/a | } |
---|
6545 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Bytes_type); |
---|
6546 | n/a | if (isinstance == -1) { |
---|
6547 | n/a | return 1; |
---|
6548 | n/a | } |
---|
6549 | n/a | if (isinstance) { |
---|
6550 | n/a | bytes s; |
---|
6551 | n/a | |
---|
6552 | n/a | if (_PyObject_HasAttrId(obj, &PyId_s)) { |
---|
6553 | n/a | int res; |
---|
6554 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_s); |
---|
6555 | n/a | if (tmp == NULL) goto failed; |
---|
6556 | n/a | res = obj2ast_bytes(tmp, &s, arena); |
---|
6557 | n/a | if (res != 0) goto failed; |
---|
6558 | n/a | Py_CLEAR(tmp); |
---|
6559 | n/a | } else { |
---|
6560 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"s\" missing from Bytes"); |
---|
6561 | n/a | return 1; |
---|
6562 | n/a | } |
---|
6563 | n/a | *out = Bytes(s, lineno, col_offset, arena); |
---|
6564 | n/a | if (*out == NULL) goto failed; |
---|
6565 | n/a | return 0; |
---|
6566 | n/a | } |
---|
6567 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)NameConstant_type); |
---|
6568 | n/a | if (isinstance == -1) { |
---|
6569 | n/a | return 1; |
---|
6570 | n/a | } |
---|
6571 | n/a | if (isinstance) { |
---|
6572 | n/a | singleton value; |
---|
6573 | n/a | |
---|
6574 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6575 | n/a | int res; |
---|
6576 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6577 | n/a | if (tmp == NULL) goto failed; |
---|
6578 | n/a | res = obj2ast_singleton(tmp, &value, arena); |
---|
6579 | n/a | if (res != 0) goto failed; |
---|
6580 | n/a | Py_CLEAR(tmp); |
---|
6581 | n/a | } else { |
---|
6582 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NameConstant"); |
---|
6583 | n/a | return 1; |
---|
6584 | n/a | } |
---|
6585 | n/a | *out = NameConstant(value, lineno, col_offset, arena); |
---|
6586 | n/a | if (*out == NULL) goto failed; |
---|
6587 | n/a | return 0; |
---|
6588 | n/a | } |
---|
6589 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Ellipsis_type); |
---|
6590 | n/a | if (isinstance == -1) { |
---|
6591 | n/a | return 1; |
---|
6592 | n/a | } |
---|
6593 | n/a | if (isinstance) { |
---|
6594 | n/a | |
---|
6595 | n/a | *out = Ellipsis(lineno, col_offset, arena); |
---|
6596 | n/a | if (*out == NULL) goto failed; |
---|
6597 | n/a | return 0; |
---|
6598 | n/a | } |
---|
6599 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Constant_type); |
---|
6600 | n/a | if (isinstance == -1) { |
---|
6601 | n/a | return 1; |
---|
6602 | n/a | } |
---|
6603 | n/a | if (isinstance) { |
---|
6604 | n/a | constant value; |
---|
6605 | n/a | |
---|
6606 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6607 | n/a | int res; |
---|
6608 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6609 | n/a | if (tmp == NULL) goto failed; |
---|
6610 | n/a | res = obj2ast_constant(tmp, &value, arena); |
---|
6611 | n/a | if (res != 0) goto failed; |
---|
6612 | n/a | Py_CLEAR(tmp); |
---|
6613 | n/a | } else { |
---|
6614 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant"); |
---|
6615 | n/a | return 1; |
---|
6616 | n/a | } |
---|
6617 | n/a | *out = Constant(value, lineno, col_offset, arena); |
---|
6618 | n/a | if (*out == NULL) goto failed; |
---|
6619 | n/a | return 0; |
---|
6620 | n/a | } |
---|
6621 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Attribute_type); |
---|
6622 | n/a | if (isinstance == -1) { |
---|
6623 | n/a | return 1; |
---|
6624 | n/a | } |
---|
6625 | n/a | if (isinstance) { |
---|
6626 | n/a | expr_ty value; |
---|
6627 | n/a | identifier attr; |
---|
6628 | n/a | expr_context_ty ctx; |
---|
6629 | n/a | |
---|
6630 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6631 | n/a | int res; |
---|
6632 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6633 | n/a | if (tmp == NULL) goto failed; |
---|
6634 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6635 | n/a | if (res != 0) goto failed; |
---|
6636 | n/a | Py_CLEAR(tmp); |
---|
6637 | n/a | } else { |
---|
6638 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute"); |
---|
6639 | n/a | return 1; |
---|
6640 | n/a | } |
---|
6641 | n/a | if (_PyObject_HasAttrId(obj, &PyId_attr)) { |
---|
6642 | n/a | int res; |
---|
6643 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_attr); |
---|
6644 | n/a | if (tmp == NULL) goto failed; |
---|
6645 | n/a | res = obj2ast_identifier(tmp, &attr, arena); |
---|
6646 | n/a | if (res != 0) goto failed; |
---|
6647 | n/a | Py_CLEAR(tmp); |
---|
6648 | n/a | } else { |
---|
6649 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute"); |
---|
6650 | n/a | return 1; |
---|
6651 | n/a | } |
---|
6652 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
---|
6653 | n/a | int res; |
---|
6654 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
---|
6655 | n/a | if (tmp == NULL) goto failed; |
---|
6656 | n/a | res = obj2ast_expr_context(tmp, &ctx, arena); |
---|
6657 | n/a | if (res != 0) goto failed; |
---|
6658 | n/a | Py_CLEAR(tmp); |
---|
6659 | n/a | } else { |
---|
6660 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute"); |
---|
6661 | n/a | return 1; |
---|
6662 | n/a | } |
---|
6663 | n/a | *out = Attribute(value, attr, ctx, lineno, col_offset, arena); |
---|
6664 | n/a | if (*out == NULL) goto failed; |
---|
6665 | n/a | return 0; |
---|
6666 | n/a | } |
---|
6667 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Subscript_type); |
---|
6668 | n/a | if (isinstance == -1) { |
---|
6669 | n/a | return 1; |
---|
6670 | n/a | } |
---|
6671 | n/a | if (isinstance) { |
---|
6672 | n/a | expr_ty value; |
---|
6673 | n/a | slice_ty slice; |
---|
6674 | n/a | expr_context_ty ctx; |
---|
6675 | n/a | |
---|
6676 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6677 | n/a | int res; |
---|
6678 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6679 | n/a | if (tmp == NULL) goto failed; |
---|
6680 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6681 | n/a | if (res != 0) goto failed; |
---|
6682 | n/a | Py_CLEAR(tmp); |
---|
6683 | n/a | } else { |
---|
6684 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript"); |
---|
6685 | n/a | return 1; |
---|
6686 | n/a | } |
---|
6687 | n/a | if (_PyObject_HasAttrId(obj, &PyId_slice)) { |
---|
6688 | n/a | int res; |
---|
6689 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_slice); |
---|
6690 | n/a | if (tmp == NULL) goto failed; |
---|
6691 | n/a | res = obj2ast_slice(tmp, &slice, arena); |
---|
6692 | n/a | if (res != 0) goto failed; |
---|
6693 | n/a | Py_CLEAR(tmp); |
---|
6694 | n/a | } else { |
---|
6695 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript"); |
---|
6696 | n/a | return 1; |
---|
6697 | n/a | } |
---|
6698 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
---|
6699 | n/a | int res; |
---|
6700 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
---|
6701 | n/a | if (tmp == NULL) goto failed; |
---|
6702 | n/a | res = obj2ast_expr_context(tmp, &ctx, arena); |
---|
6703 | n/a | if (res != 0) goto failed; |
---|
6704 | n/a | Py_CLEAR(tmp); |
---|
6705 | n/a | } else { |
---|
6706 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript"); |
---|
6707 | n/a | return 1; |
---|
6708 | n/a | } |
---|
6709 | n/a | *out = Subscript(value, slice, ctx, lineno, col_offset, arena); |
---|
6710 | n/a | if (*out == NULL) goto failed; |
---|
6711 | n/a | return 0; |
---|
6712 | n/a | } |
---|
6713 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Starred_type); |
---|
6714 | n/a | if (isinstance == -1) { |
---|
6715 | n/a | return 1; |
---|
6716 | n/a | } |
---|
6717 | n/a | if (isinstance) { |
---|
6718 | n/a | expr_ty value; |
---|
6719 | n/a | expr_context_ty ctx; |
---|
6720 | n/a | |
---|
6721 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
6722 | n/a | int res; |
---|
6723 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
6724 | n/a | if (tmp == NULL) goto failed; |
---|
6725 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
6726 | n/a | if (res != 0) goto failed; |
---|
6727 | n/a | Py_CLEAR(tmp); |
---|
6728 | n/a | } else { |
---|
6729 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred"); |
---|
6730 | n/a | return 1; |
---|
6731 | n/a | } |
---|
6732 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
---|
6733 | n/a | int res; |
---|
6734 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
---|
6735 | n/a | if (tmp == NULL) goto failed; |
---|
6736 | n/a | res = obj2ast_expr_context(tmp, &ctx, arena); |
---|
6737 | n/a | if (res != 0) goto failed; |
---|
6738 | n/a | Py_CLEAR(tmp); |
---|
6739 | n/a | } else { |
---|
6740 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred"); |
---|
6741 | n/a | return 1; |
---|
6742 | n/a | } |
---|
6743 | n/a | *out = Starred(value, ctx, lineno, col_offset, arena); |
---|
6744 | n/a | if (*out == NULL) goto failed; |
---|
6745 | n/a | return 0; |
---|
6746 | n/a | } |
---|
6747 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Name_type); |
---|
6748 | n/a | if (isinstance == -1) { |
---|
6749 | n/a | return 1; |
---|
6750 | n/a | } |
---|
6751 | n/a | if (isinstance) { |
---|
6752 | n/a | identifier id; |
---|
6753 | n/a | expr_context_ty ctx; |
---|
6754 | n/a | |
---|
6755 | n/a | if (_PyObject_HasAttrId(obj, &PyId_id)) { |
---|
6756 | n/a | int res; |
---|
6757 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_id); |
---|
6758 | n/a | if (tmp == NULL) goto failed; |
---|
6759 | n/a | res = obj2ast_identifier(tmp, &id, arena); |
---|
6760 | n/a | if (res != 0) goto failed; |
---|
6761 | n/a | Py_CLEAR(tmp); |
---|
6762 | n/a | } else { |
---|
6763 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name"); |
---|
6764 | n/a | return 1; |
---|
6765 | n/a | } |
---|
6766 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
---|
6767 | n/a | int res; |
---|
6768 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
---|
6769 | n/a | if (tmp == NULL) goto failed; |
---|
6770 | n/a | res = obj2ast_expr_context(tmp, &ctx, arena); |
---|
6771 | n/a | if (res != 0) goto failed; |
---|
6772 | n/a | Py_CLEAR(tmp); |
---|
6773 | n/a | } else { |
---|
6774 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name"); |
---|
6775 | n/a | return 1; |
---|
6776 | n/a | } |
---|
6777 | n/a | *out = Name(id, ctx, lineno, col_offset, arena); |
---|
6778 | n/a | if (*out == NULL) goto failed; |
---|
6779 | n/a | return 0; |
---|
6780 | n/a | } |
---|
6781 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)List_type); |
---|
6782 | n/a | if (isinstance == -1) { |
---|
6783 | n/a | return 1; |
---|
6784 | n/a | } |
---|
6785 | n/a | if (isinstance) { |
---|
6786 | n/a | asdl_seq* elts; |
---|
6787 | n/a | expr_context_ty ctx; |
---|
6788 | n/a | |
---|
6789 | n/a | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
---|
6790 | n/a | int res; |
---|
6791 | n/a | Py_ssize_t len; |
---|
6792 | n/a | Py_ssize_t i; |
---|
6793 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
---|
6794 | n/a | if (tmp == NULL) goto failed; |
---|
6795 | n/a | if (!PyList_Check(tmp)) { |
---|
6796 | n/a | PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6797 | n/a | goto failed; |
---|
6798 | n/a | } |
---|
6799 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6800 | n/a | elts = _Py_asdl_seq_new(len, arena); |
---|
6801 | n/a | if (elts == NULL) goto failed; |
---|
6802 | n/a | for (i = 0; i < len; i++) { |
---|
6803 | n/a | expr_ty value; |
---|
6804 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6805 | n/a | if (res != 0) goto failed; |
---|
6806 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6807 | n/a | PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration"); |
---|
6808 | n/a | goto failed; |
---|
6809 | n/a | } |
---|
6810 | n/a | asdl_seq_SET(elts, i, value); |
---|
6811 | n/a | } |
---|
6812 | n/a | Py_CLEAR(tmp); |
---|
6813 | n/a | } else { |
---|
6814 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List"); |
---|
6815 | n/a | return 1; |
---|
6816 | n/a | } |
---|
6817 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
---|
6818 | n/a | int res; |
---|
6819 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
---|
6820 | n/a | if (tmp == NULL) goto failed; |
---|
6821 | n/a | res = obj2ast_expr_context(tmp, &ctx, arena); |
---|
6822 | n/a | if (res != 0) goto failed; |
---|
6823 | n/a | Py_CLEAR(tmp); |
---|
6824 | n/a | } else { |
---|
6825 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List"); |
---|
6826 | n/a | return 1; |
---|
6827 | n/a | } |
---|
6828 | n/a | *out = List(elts, ctx, lineno, col_offset, arena); |
---|
6829 | n/a | if (*out == NULL) goto failed; |
---|
6830 | n/a | return 0; |
---|
6831 | n/a | } |
---|
6832 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Tuple_type); |
---|
6833 | n/a | if (isinstance == -1) { |
---|
6834 | n/a | return 1; |
---|
6835 | n/a | } |
---|
6836 | n/a | if (isinstance) { |
---|
6837 | n/a | asdl_seq* elts; |
---|
6838 | n/a | expr_context_ty ctx; |
---|
6839 | n/a | |
---|
6840 | n/a | if (_PyObject_HasAttrId(obj, &PyId_elts)) { |
---|
6841 | n/a | int res; |
---|
6842 | n/a | Py_ssize_t len; |
---|
6843 | n/a | Py_ssize_t i; |
---|
6844 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_elts); |
---|
6845 | n/a | if (tmp == NULL) goto failed; |
---|
6846 | n/a | if (!PyList_Check(tmp)) { |
---|
6847 | n/a | PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
6848 | n/a | goto failed; |
---|
6849 | n/a | } |
---|
6850 | n/a | len = PyList_GET_SIZE(tmp); |
---|
6851 | n/a | elts = _Py_asdl_seq_new(len, arena); |
---|
6852 | n/a | if (elts == NULL) goto failed; |
---|
6853 | n/a | for (i = 0; i < len; i++) { |
---|
6854 | n/a | expr_ty value; |
---|
6855 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
6856 | n/a | if (res != 0) goto failed; |
---|
6857 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
6858 | n/a | PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration"); |
---|
6859 | n/a | goto failed; |
---|
6860 | n/a | } |
---|
6861 | n/a | asdl_seq_SET(elts, i, value); |
---|
6862 | n/a | } |
---|
6863 | n/a | Py_CLEAR(tmp); |
---|
6864 | n/a | } else { |
---|
6865 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple"); |
---|
6866 | n/a | return 1; |
---|
6867 | n/a | } |
---|
6868 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ctx)) { |
---|
6869 | n/a | int res; |
---|
6870 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ctx); |
---|
6871 | n/a | if (tmp == NULL) goto failed; |
---|
6872 | n/a | res = obj2ast_expr_context(tmp, &ctx, arena); |
---|
6873 | n/a | if (res != 0) goto failed; |
---|
6874 | n/a | Py_CLEAR(tmp); |
---|
6875 | n/a | } else { |
---|
6876 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple"); |
---|
6877 | n/a | return 1; |
---|
6878 | n/a | } |
---|
6879 | n/a | *out = Tuple(elts, ctx, lineno, col_offset, arena); |
---|
6880 | n/a | if (*out == NULL) goto failed; |
---|
6881 | n/a | return 0; |
---|
6882 | n/a | } |
---|
6883 | n/a | |
---|
6884 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj); |
---|
6885 | n/a | failed: |
---|
6886 | n/a | Py_XDECREF(tmp); |
---|
6887 | n/a | return 1; |
---|
6888 | n/a | } |
---|
6889 | n/a | |
---|
6890 | n/a | int |
---|
6891 | n/a | obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena) |
---|
6892 | n/a | { |
---|
6893 | n/a | int isinstance; |
---|
6894 | n/a | |
---|
6895 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Load_type); |
---|
6896 | n/a | if (isinstance == -1) { |
---|
6897 | n/a | return 1; |
---|
6898 | n/a | } |
---|
6899 | n/a | if (isinstance) { |
---|
6900 | n/a | *out = Load; |
---|
6901 | n/a | return 0; |
---|
6902 | n/a | } |
---|
6903 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Store_type); |
---|
6904 | n/a | if (isinstance == -1) { |
---|
6905 | n/a | return 1; |
---|
6906 | n/a | } |
---|
6907 | n/a | if (isinstance) { |
---|
6908 | n/a | *out = Store; |
---|
6909 | n/a | return 0; |
---|
6910 | n/a | } |
---|
6911 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Del_type); |
---|
6912 | n/a | if (isinstance == -1) { |
---|
6913 | n/a | return 1; |
---|
6914 | n/a | } |
---|
6915 | n/a | if (isinstance) { |
---|
6916 | n/a | *out = Del; |
---|
6917 | n/a | return 0; |
---|
6918 | n/a | } |
---|
6919 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)AugLoad_type); |
---|
6920 | n/a | if (isinstance == -1) { |
---|
6921 | n/a | return 1; |
---|
6922 | n/a | } |
---|
6923 | n/a | if (isinstance) { |
---|
6924 | n/a | *out = AugLoad; |
---|
6925 | n/a | return 0; |
---|
6926 | n/a | } |
---|
6927 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)AugStore_type); |
---|
6928 | n/a | if (isinstance == -1) { |
---|
6929 | n/a | return 1; |
---|
6930 | n/a | } |
---|
6931 | n/a | if (isinstance) { |
---|
6932 | n/a | *out = AugStore; |
---|
6933 | n/a | return 0; |
---|
6934 | n/a | } |
---|
6935 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Param_type); |
---|
6936 | n/a | if (isinstance == -1) { |
---|
6937 | n/a | return 1; |
---|
6938 | n/a | } |
---|
6939 | n/a | if (isinstance) { |
---|
6940 | n/a | *out = Param; |
---|
6941 | n/a | return 0; |
---|
6942 | n/a | } |
---|
6943 | n/a | |
---|
6944 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj); |
---|
6945 | n/a | return 1; |
---|
6946 | n/a | } |
---|
6947 | n/a | |
---|
6948 | n/a | int |
---|
6949 | n/a | obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena) |
---|
6950 | n/a | { |
---|
6951 | n/a | int isinstance; |
---|
6952 | n/a | |
---|
6953 | n/a | PyObject *tmp = NULL; |
---|
6954 | n/a | |
---|
6955 | n/a | if (obj == Py_None) { |
---|
6956 | n/a | *out = NULL; |
---|
6957 | n/a | return 0; |
---|
6958 | n/a | } |
---|
6959 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Slice_type); |
---|
6960 | n/a | if (isinstance == -1) { |
---|
6961 | n/a | return 1; |
---|
6962 | n/a | } |
---|
6963 | n/a | if (isinstance) { |
---|
6964 | n/a | expr_ty lower; |
---|
6965 | n/a | expr_ty upper; |
---|
6966 | n/a | expr_ty step; |
---|
6967 | n/a | |
---|
6968 | n/a | if (exists_not_none(obj, &PyId_lower)) { |
---|
6969 | n/a | int res; |
---|
6970 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_lower); |
---|
6971 | n/a | if (tmp == NULL) goto failed; |
---|
6972 | n/a | res = obj2ast_expr(tmp, &lower, arena); |
---|
6973 | n/a | if (res != 0) goto failed; |
---|
6974 | n/a | Py_CLEAR(tmp); |
---|
6975 | n/a | } else { |
---|
6976 | n/a | lower = NULL; |
---|
6977 | n/a | } |
---|
6978 | n/a | if (exists_not_none(obj, &PyId_upper)) { |
---|
6979 | n/a | int res; |
---|
6980 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_upper); |
---|
6981 | n/a | if (tmp == NULL) goto failed; |
---|
6982 | n/a | res = obj2ast_expr(tmp, &upper, arena); |
---|
6983 | n/a | if (res != 0) goto failed; |
---|
6984 | n/a | Py_CLEAR(tmp); |
---|
6985 | n/a | } else { |
---|
6986 | n/a | upper = NULL; |
---|
6987 | n/a | } |
---|
6988 | n/a | if (exists_not_none(obj, &PyId_step)) { |
---|
6989 | n/a | int res; |
---|
6990 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_step); |
---|
6991 | n/a | if (tmp == NULL) goto failed; |
---|
6992 | n/a | res = obj2ast_expr(tmp, &step, arena); |
---|
6993 | n/a | if (res != 0) goto failed; |
---|
6994 | n/a | Py_CLEAR(tmp); |
---|
6995 | n/a | } else { |
---|
6996 | n/a | step = NULL; |
---|
6997 | n/a | } |
---|
6998 | n/a | *out = Slice(lower, upper, step, arena); |
---|
6999 | n/a | if (*out == NULL) goto failed; |
---|
7000 | n/a | return 0; |
---|
7001 | n/a | } |
---|
7002 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)ExtSlice_type); |
---|
7003 | n/a | if (isinstance == -1) { |
---|
7004 | n/a | return 1; |
---|
7005 | n/a | } |
---|
7006 | n/a | if (isinstance) { |
---|
7007 | n/a | asdl_seq* dims; |
---|
7008 | n/a | |
---|
7009 | n/a | if (_PyObject_HasAttrId(obj, &PyId_dims)) { |
---|
7010 | n/a | int res; |
---|
7011 | n/a | Py_ssize_t len; |
---|
7012 | n/a | Py_ssize_t i; |
---|
7013 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_dims); |
---|
7014 | n/a | if (tmp == NULL) goto failed; |
---|
7015 | n/a | if (!PyList_Check(tmp)) { |
---|
7016 | n/a | PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7017 | n/a | goto failed; |
---|
7018 | n/a | } |
---|
7019 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7020 | n/a | dims = _Py_asdl_seq_new(len, arena); |
---|
7021 | n/a | if (dims == NULL) goto failed; |
---|
7022 | n/a | for (i = 0; i < len; i++) { |
---|
7023 | n/a | slice_ty value; |
---|
7024 | n/a | res = obj2ast_slice(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7025 | n/a | if (res != 0) goto failed; |
---|
7026 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7027 | n/a | PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration"); |
---|
7028 | n/a | goto failed; |
---|
7029 | n/a | } |
---|
7030 | n/a | asdl_seq_SET(dims, i, value); |
---|
7031 | n/a | } |
---|
7032 | n/a | Py_CLEAR(tmp); |
---|
7033 | n/a | } else { |
---|
7034 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice"); |
---|
7035 | n/a | return 1; |
---|
7036 | n/a | } |
---|
7037 | n/a | *out = ExtSlice(dims, arena); |
---|
7038 | n/a | if (*out == NULL) goto failed; |
---|
7039 | n/a | return 0; |
---|
7040 | n/a | } |
---|
7041 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)Index_type); |
---|
7042 | n/a | if (isinstance == -1) { |
---|
7043 | n/a | return 1; |
---|
7044 | n/a | } |
---|
7045 | n/a | if (isinstance) { |
---|
7046 | n/a | expr_ty value; |
---|
7047 | n/a | |
---|
7048 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
7049 | n/a | int res; |
---|
7050 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
7051 | n/a | if (tmp == NULL) goto failed; |
---|
7052 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
7053 | n/a | if (res != 0) goto failed; |
---|
7054 | n/a | Py_CLEAR(tmp); |
---|
7055 | n/a | } else { |
---|
7056 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index"); |
---|
7057 | n/a | return 1; |
---|
7058 | n/a | } |
---|
7059 | n/a | *out = Index(value, arena); |
---|
7060 | n/a | if (*out == NULL) goto failed; |
---|
7061 | n/a | return 0; |
---|
7062 | n/a | } |
---|
7063 | n/a | |
---|
7064 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj); |
---|
7065 | n/a | failed: |
---|
7066 | n/a | Py_XDECREF(tmp); |
---|
7067 | n/a | return 1; |
---|
7068 | n/a | } |
---|
7069 | n/a | |
---|
7070 | n/a | int |
---|
7071 | n/a | obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena) |
---|
7072 | n/a | { |
---|
7073 | n/a | int isinstance; |
---|
7074 | n/a | |
---|
7075 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)And_type); |
---|
7076 | n/a | if (isinstance == -1) { |
---|
7077 | n/a | return 1; |
---|
7078 | n/a | } |
---|
7079 | n/a | if (isinstance) { |
---|
7080 | n/a | *out = And; |
---|
7081 | n/a | return 0; |
---|
7082 | n/a | } |
---|
7083 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Or_type); |
---|
7084 | n/a | if (isinstance == -1) { |
---|
7085 | n/a | return 1; |
---|
7086 | n/a | } |
---|
7087 | n/a | if (isinstance) { |
---|
7088 | n/a | *out = Or; |
---|
7089 | n/a | return 0; |
---|
7090 | n/a | } |
---|
7091 | n/a | |
---|
7092 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj); |
---|
7093 | n/a | return 1; |
---|
7094 | n/a | } |
---|
7095 | n/a | |
---|
7096 | n/a | int |
---|
7097 | n/a | obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena) |
---|
7098 | n/a | { |
---|
7099 | n/a | int isinstance; |
---|
7100 | n/a | |
---|
7101 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Add_type); |
---|
7102 | n/a | if (isinstance == -1) { |
---|
7103 | n/a | return 1; |
---|
7104 | n/a | } |
---|
7105 | n/a | if (isinstance) { |
---|
7106 | n/a | *out = Add; |
---|
7107 | n/a | return 0; |
---|
7108 | n/a | } |
---|
7109 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Sub_type); |
---|
7110 | n/a | if (isinstance == -1) { |
---|
7111 | n/a | return 1; |
---|
7112 | n/a | } |
---|
7113 | n/a | if (isinstance) { |
---|
7114 | n/a | *out = Sub; |
---|
7115 | n/a | return 0; |
---|
7116 | n/a | } |
---|
7117 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Mult_type); |
---|
7118 | n/a | if (isinstance == -1) { |
---|
7119 | n/a | return 1; |
---|
7120 | n/a | } |
---|
7121 | n/a | if (isinstance) { |
---|
7122 | n/a | *out = Mult; |
---|
7123 | n/a | return 0; |
---|
7124 | n/a | } |
---|
7125 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)MatMult_type); |
---|
7126 | n/a | if (isinstance == -1) { |
---|
7127 | n/a | return 1; |
---|
7128 | n/a | } |
---|
7129 | n/a | if (isinstance) { |
---|
7130 | n/a | *out = MatMult; |
---|
7131 | n/a | return 0; |
---|
7132 | n/a | } |
---|
7133 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Div_type); |
---|
7134 | n/a | if (isinstance == -1) { |
---|
7135 | n/a | return 1; |
---|
7136 | n/a | } |
---|
7137 | n/a | if (isinstance) { |
---|
7138 | n/a | *out = Div; |
---|
7139 | n/a | return 0; |
---|
7140 | n/a | } |
---|
7141 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Mod_type); |
---|
7142 | n/a | if (isinstance == -1) { |
---|
7143 | n/a | return 1; |
---|
7144 | n/a | } |
---|
7145 | n/a | if (isinstance) { |
---|
7146 | n/a | *out = Mod; |
---|
7147 | n/a | return 0; |
---|
7148 | n/a | } |
---|
7149 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Pow_type); |
---|
7150 | n/a | if (isinstance == -1) { |
---|
7151 | n/a | return 1; |
---|
7152 | n/a | } |
---|
7153 | n/a | if (isinstance) { |
---|
7154 | n/a | *out = Pow; |
---|
7155 | n/a | return 0; |
---|
7156 | n/a | } |
---|
7157 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)LShift_type); |
---|
7158 | n/a | if (isinstance == -1) { |
---|
7159 | n/a | return 1; |
---|
7160 | n/a | } |
---|
7161 | n/a | if (isinstance) { |
---|
7162 | n/a | *out = LShift; |
---|
7163 | n/a | return 0; |
---|
7164 | n/a | } |
---|
7165 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)RShift_type); |
---|
7166 | n/a | if (isinstance == -1) { |
---|
7167 | n/a | return 1; |
---|
7168 | n/a | } |
---|
7169 | n/a | if (isinstance) { |
---|
7170 | n/a | *out = RShift; |
---|
7171 | n/a | return 0; |
---|
7172 | n/a | } |
---|
7173 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)BitOr_type); |
---|
7174 | n/a | if (isinstance == -1) { |
---|
7175 | n/a | return 1; |
---|
7176 | n/a | } |
---|
7177 | n/a | if (isinstance) { |
---|
7178 | n/a | *out = BitOr; |
---|
7179 | n/a | return 0; |
---|
7180 | n/a | } |
---|
7181 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)BitXor_type); |
---|
7182 | n/a | if (isinstance == -1) { |
---|
7183 | n/a | return 1; |
---|
7184 | n/a | } |
---|
7185 | n/a | if (isinstance) { |
---|
7186 | n/a | *out = BitXor; |
---|
7187 | n/a | return 0; |
---|
7188 | n/a | } |
---|
7189 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)BitAnd_type); |
---|
7190 | n/a | if (isinstance == -1) { |
---|
7191 | n/a | return 1; |
---|
7192 | n/a | } |
---|
7193 | n/a | if (isinstance) { |
---|
7194 | n/a | *out = BitAnd; |
---|
7195 | n/a | return 0; |
---|
7196 | n/a | } |
---|
7197 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)FloorDiv_type); |
---|
7198 | n/a | if (isinstance == -1) { |
---|
7199 | n/a | return 1; |
---|
7200 | n/a | } |
---|
7201 | n/a | if (isinstance) { |
---|
7202 | n/a | *out = FloorDiv; |
---|
7203 | n/a | return 0; |
---|
7204 | n/a | } |
---|
7205 | n/a | |
---|
7206 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj); |
---|
7207 | n/a | return 1; |
---|
7208 | n/a | } |
---|
7209 | n/a | |
---|
7210 | n/a | int |
---|
7211 | n/a | obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena) |
---|
7212 | n/a | { |
---|
7213 | n/a | int isinstance; |
---|
7214 | n/a | |
---|
7215 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Invert_type); |
---|
7216 | n/a | if (isinstance == -1) { |
---|
7217 | n/a | return 1; |
---|
7218 | n/a | } |
---|
7219 | n/a | if (isinstance) { |
---|
7220 | n/a | *out = Invert; |
---|
7221 | n/a | return 0; |
---|
7222 | n/a | } |
---|
7223 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Not_type); |
---|
7224 | n/a | if (isinstance == -1) { |
---|
7225 | n/a | return 1; |
---|
7226 | n/a | } |
---|
7227 | n/a | if (isinstance) { |
---|
7228 | n/a | *out = Not; |
---|
7229 | n/a | return 0; |
---|
7230 | n/a | } |
---|
7231 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)UAdd_type); |
---|
7232 | n/a | if (isinstance == -1) { |
---|
7233 | n/a | return 1; |
---|
7234 | n/a | } |
---|
7235 | n/a | if (isinstance) { |
---|
7236 | n/a | *out = UAdd; |
---|
7237 | n/a | return 0; |
---|
7238 | n/a | } |
---|
7239 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)USub_type); |
---|
7240 | n/a | if (isinstance == -1) { |
---|
7241 | n/a | return 1; |
---|
7242 | n/a | } |
---|
7243 | n/a | if (isinstance) { |
---|
7244 | n/a | *out = USub; |
---|
7245 | n/a | return 0; |
---|
7246 | n/a | } |
---|
7247 | n/a | |
---|
7248 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj); |
---|
7249 | n/a | return 1; |
---|
7250 | n/a | } |
---|
7251 | n/a | |
---|
7252 | n/a | int |
---|
7253 | n/a | obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena) |
---|
7254 | n/a | { |
---|
7255 | n/a | int isinstance; |
---|
7256 | n/a | |
---|
7257 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Eq_type); |
---|
7258 | n/a | if (isinstance == -1) { |
---|
7259 | n/a | return 1; |
---|
7260 | n/a | } |
---|
7261 | n/a | if (isinstance) { |
---|
7262 | n/a | *out = Eq; |
---|
7263 | n/a | return 0; |
---|
7264 | n/a | } |
---|
7265 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)NotEq_type); |
---|
7266 | n/a | if (isinstance == -1) { |
---|
7267 | n/a | return 1; |
---|
7268 | n/a | } |
---|
7269 | n/a | if (isinstance) { |
---|
7270 | n/a | *out = NotEq; |
---|
7271 | n/a | return 0; |
---|
7272 | n/a | } |
---|
7273 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Lt_type); |
---|
7274 | n/a | if (isinstance == -1) { |
---|
7275 | n/a | return 1; |
---|
7276 | n/a | } |
---|
7277 | n/a | if (isinstance) { |
---|
7278 | n/a | *out = Lt; |
---|
7279 | n/a | return 0; |
---|
7280 | n/a | } |
---|
7281 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)LtE_type); |
---|
7282 | n/a | if (isinstance == -1) { |
---|
7283 | n/a | return 1; |
---|
7284 | n/a | } |
---|
7285 | n/a | if (isinstance) { |
---|
7286 | n/a | *out = LtE; |
---|
7287 | n/a | return 0; |
---|
7288 | n/a | } |
---|
7289 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Gt_type); |
---|
7290 | n/a | if (isinstance == -1) { |
---|
7291 | n/a | return 1; |
---|
7292 | n/a | } |
---|
7293 | n/a | if (isinstance) { |
---|
7294 | n/a | *out = Gt; |
---|
7295 | n/a | return 0; |
---|
7296 | n/a | } |
---|
7297 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)GtE_type); |
---|
7298 | n/a | if (isinstance == -1) { |
---|
7299 | n/a | return 1; |
---|
7300 | n/a | } |
---|
7301 | n/a | if (isinstance) { |
---|
7302 | n/a | *out = GtE; |
---|
7303 | n/a | return 0; |
---|
7304 | n/a | } |
---|
7305 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)Is_type); |
---|
7306 | n/a | if (isinstance == -1) { |
---|
7307 | n/a | return 1; |
---|
7308 | n/a | } |
---|
7309 | n/a | if (isinstance) { |
---|
7310 | n/a | *out = Is; |
---|
7311 | n/a | return 0; |
---|
7312 | n/a | } |
---|
7313 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)IsNot_type); |
---|
7314 | n/a | if (isinstance == -1) { |
---|
7315 | n/a | return 1; |
---|
7316 | n/a | } |
---|
7317 | n/a | if (isinstance) { |
---|
7318 | n/a | *out = IsNot; |
---|
7319 | n/a | return 0; |
---|
7320 | n/a | } |
---|
7321 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)In_type); |
---|
7322 | n/a | if (isinstance == -1) { |
---|
7323 | n/a | return 1; |
---|
7324 | n/a | } |
---|
7325 | n/a | if (isinstance) { |
---|
7326 | n/a | *out = In; |
---|
7327 | n/a | return 0; |
---|
7328 | n/a | } |
---|
7329 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject *)NotIn_type); |
---|
7330 | n/a | if (isinstance == -1) { |
---|
7331 | n/a | return 1; |
---|
7332 | n/a | } |
---|
7333 | n/a | if (isinstance) { |
---|
7334 | n/a | *out = NotIn; |
---|
7335 | n/a | return 0; |
---|
7336 | n/a | } |
---|
7337 | n/a | |
---|
7338 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj); |
---|
7339 | n/a | return 1; |
---|
7340 | n/a | } |
---|
7341 | n/a | |
---|
7342 | n/a | int |
---|
7343 | n/a | obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena) |
---|
7344 | n/a | { |
---|
7345 | n/a | PyObject* tmp = NULL; |
---|
7346 | n/a | expr_ty target; |
---|
7347 | n/a | expr_ty iter; |
---|
7348 | n/a | asdl_seq* ifs; |
---|
7349 | n/a | int is_async; |
---|
7350 | n/a | |
---|
7351 | n/a | if (_PyObject_HasAttrId(obj, &PyId_target)) { |
---|
7352 | n/a | int res; |
---|
7353 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_target); |
---|
7354 | n/a | if (tmp == NULL) goto failed; |
---|
7355 | n/a | res = obj2ast_expr(tmp, &target, arena); |
---|
7356 | n/a | if (res != 0) goto failed; |
---|
7357 | n/a | Py_CLEAR(tmp); |
---|
7358 | n/a | } else { |
---|
7359 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension"); |
---|
7360 | n/a | return 1; |
---|
7361 | n/a | } |
---|
7362 | n/a | if (_PyObject_HasAttrId(obj, &PyId_iter)) { |
---|
7363 | n/a | int res; |
---|
7364 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_iter); |
---|
7365 | n/a | if (tmp == NULL) goto failed; |
---|
7366 | n/a | res = obj2ast_expr(tmp, &iter, arena); |
---|
7367 | n/a | if (res != 0) goto failed; |
---|
7368 | n/a | Py_CLEAR(tmp); |
---|
7369 | n/a | } else { |
---|
7370 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension"); |
---|
7371 | n/a | return 1; |
---|
7372 | n/a | } |
---|
7373 | n/a | if (_PyObject_HasAttrId(obj, &PyId_ifs)) { |
---|
7374 | n/a | int res; |
---|
7375 | n/a | Py_ssize_t len; |
---|
7376 | n/a | Py_ssize_t i; |
---|
7377 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_ifs); |
---|
7378 | n/a | if (tmp == NULL) goto failed; |
---|
7379 | n/a | if (!PyList_Check(tmp)) { |
---|
7380 | n/a | PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7381 | n/a | goto failed; |
---|
7382 | n/a | } |
---|
7383 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7384 | n/a | ifs = _Py_asdl_seq_new(len, arena); |
---|
7385 | n/a | if (ifs == NULL) goto failed; |
---|
7386 | n/a | for (i = 0; i < len; i++) { |
---|
7387 | n/a | expr_ty value; |
---|
7388 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7389 | n/a | if (res != 0) goto failed; |
---|
7390 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7391 | n/a | PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration"); |
---|
7392 | n/a | goto failed; |
---|
7393 | n/a | } |
---|
7394 | n/a | asdl_seq_SET(ifs, i, value); |
---|
7395 | n/a | } |
---|
7396 | n/a | Py_CLEAR(tmp); |
---|
7397 | n/a | } else { |
---|
7398 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension"); |
---|
7399 | n/a | return 1; |
---|
7400 | n/a | } |
---|
7401 | n/a | if (_PyObject_HasAttrId(obj, &PyId_is_async)) { |
---|
7402 | n/a | int res; |
---|
7403 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_is_async); |
---|
7404 | n/a | if (tmp == NULL) goto failed; |
---|
7405 | n/a | res = obj2ast_int(tmp, &is_async, arena); |
---|
7406 | n/a | if (res != 0) goto failed; |
---|
7407 | n/a | Py_CLEAR(tmp); |
---|
7408 | n/a | } else { |
---|
7409 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension"); |
---|
7410 | n/a | return 1; |
---|
7411 | n/a | } |
---|
7412 | n/a | *out = comprehension(target, iter, ifs, is_async, arena); |
---|
7413 | n/a | return 0; |
---|
7414 | n/a | failed: |
---|
7415 | n/a | Py_XDECREF(tmp); |
---|
7416 | n/a | return 1; |
---|
7417 | n/a | } |
---|
7418 | n/a | |
---|
7419 | n/a | int |
---|
7420 | n/a | obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena) |
---|
7421 | n/a | { |
---|
7422 | n/a | int isinstance; |
---|
7423 | n/a | |
---|
7424 | n/a | PyObject *tmp = NULL; |
---|
7425 | n/a | int lineno; |
---|
7426 | n/a | int col_offset; |
---|
7427 | n/a | |
---|
7428 | n/a | if (obj == Py_None) { |
---|
7429 | n/a | *out = NULL; |
---|
7430 | n/a | return 0; |
---|
7431 | n/a | } |
---|
7432 | n/a | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
---|
7433 | n/a | int res; |
---|
7434 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
---|
7435 | n/a | if (tmp == NULL) goto failed; |
---|
7436 | n/a | res = obj2ast_int(tmp, &lineno, arena); |
---|
7437 | n/a | if (res != 0) goto failed; |
---|
7438 | n/a | Py_CLEAR(tmp); |
---|
7439 | n/a | } else { |
---|
7440 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler"); |
---|
7441 | n/a | return 1; |
---|
7442 | n/a | } |
---|
7443 | n/a | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
---|
7444 | n/a | int res; |
---|
7445 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
---|
7446 | n/a | if (tmp == NULL) goto failed; |
---|
7447 | n/a | res = obj2ast_int(tmp, &col_offset, arena); |
---|
7448 | n/a | if (res != 0) goto failed; |
---|
7449 | n/a | Py_CLEAR(tmp); |
---|
7450 | n/a | } else { |
---|
7451 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler"); |
---|
7452 | n/a | return 1; |
---|
7453 | n/a | } |
---|
7454 | n/a | isinstance = PyObject_IsInstance(obj, (PyObject*)ExceptHandler_type); |
---|
7455 | n/a | if (isinstance == -1) { |
---|
7456 | n/a | return 1; |
---|
7457 | n/a | } |
---|
7458 | n/a | if (isinstance) { |
---|
7459 | n/a | expr_ty type; |
---|
7460 | n/a | identifier name; |
---|
7461 | n/a | asdl_seq* body; |
---|
7462 | n/a | |
---|
7463 | n/a | if (exists_not_none(obj, &PyId_type)) { |
---|
7464 | n/a | int res; |
---|
7465 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_type); |
---|
7466 | n/a | if (tmp == NULL) goto failed; |
---|
7467 | n/a | res = obj2ast_expr(tmp, &type, arena); |
---|
7468 | n/a | if (res != 0) goto failed; |
---|
7469 | n/a | Py_CLEAR(tmp); |
---|
7470 | n/a | } else { |
---|
7471 | n/a | type = NULL; |
---|
7472 | n/a | } |
---|
7473 | n/a | if (exists_not_none(obj, &PyId_name)) { |
---|
7474 | n/a | int res; |
---|
7475 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
---|
7476 | n/a | if (tmp == NULL) goto failed; |
---|
7477 | n/a | res = obj2ast_identifier(tmp, &name, arena); |
---|
7478 | n/a | if (res != 0) goto failed; |
---|
7479 | n/a | Py_CLEAR(tmp); |
---|
7480 | n/a | } else { |
---|
7481 | n/a | name = NULL; |
---|
7482 | n/a | } |
---|
7483 | n/a | if (_PyObject_HasAttrId(obj, &PyId_body)) { |
---|
7484 | n/a | int res; |
---|
7485 | n/a | Py_ssize_t len; |
---|
7486 | n/a | Py_ssize_t i; |
---|
7487 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_body); |
---|
7488 | n/a | if (tmp == NULL) goto failed; |
---|
7489 | n/a | if (!PyList_Check(tmp)) { |
---|
7490 | n/a | PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7491 | n/a | goto failed; |
---|
7492 | n/a | } |
---|
7493 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7494 | n/a | body = _Py_asdl_seq_new(len, arena); |
---|
7495 | n/a | if (body == NULL) goto failed; |
---|
7496 | n/a | for (i = 0; i < len; i++) { |
---|
7497 | n/a | stmt_ty value; |
---|
7498 | n/a | res = obj2ast_stmt(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7499 | n/a | if (res != 0) goto failed; |
---|
7500 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7501 | n/a | PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration"); |
---|
7502 | n/a | goto failed; |
---|
7503 | n/a | } |
---|
7504 | n/a | asdl_seq_SET(body, i, value); |
---|
7505 | n/a | } |
---|
7506 | n/a | Py_CLEAR(tmp); |
---|
7507 | n/a | } else { |
---|
7508 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler"); |
---|
7509 | n/a | return 1; |
---|
7510 | n/a | } |
---|
7511 | n/a | *out = ExceptHandler(type, name, body, lineno, col_offset, arena); |
---|
7512 | n/a | if (*out == NULL) goto failed; |
---|
7513 | n/a | return 0; |
---|
7514 | n/a | } |
---|
7515 | n/a | |
---|
7516 | n/a | PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj); |
---|
7517 | n/a | failed: |
---|
7518 | n/a | Py_XDECREF(tmp); |
---|
7519 | n/a | return 1; |
---|
7520 | n/a | } |
---|
7521 | n/a | |
---|
7522 | n/a | int |
---|
7523 | n/a | obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena) |
---|
7524 | n/a | { |
---|
7525 | n/a | PyObject* tmp = NULL; |
---|
7526 | n/a | asdl_seq* args; |
---|
7527 | n/a | arg_ty vararg; |
---|
7528 | n/a | asdl_seq* kwonlyargs; |
---|
7529 | n/a | asdl_seq* kw_defaults; |
---|
7530 | n/a | arg_ty kwarg; |
---|
7531 | n/a | asdl_seq* defaults; |
---|
7532 | n/a | |
---|
7533 | n/a | if (_PyObject_HasAttrId(obj, &PyId_args)) { |
---|
7534 | n/a | int res; |
---|
7535 | n/a | Py_ssize_t len; |
---|
7536 | n/a | Py_ssize_t i; |
---|
7537 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_args); |
---|
7538 | n/a | if (tmp == NULL) goto failed; |
---|
7539 | n/a | if (!PyList_Check(tmp)) { |
---|
7540 | n/a | PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7541 | n/a | goto failed; |
---|
7542 | n/a | } |
---|
7543 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7544 | n/a | args = _Py_asdl_seq_new(len, arena); |
---|
7545 | n/a | if (args == NULL) goto failed; |
---|
7546 | n/a | for (i = 0; i < len; i++) { |
---|
7547 | n/a | arg_ty value; |
---|
7548 | n/a | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7549 | n/a | if (res != 0) goto failed; |
---|
7550 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7551 | n/a | PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration"); |
---|
7552 | n/a | goto failed; |
---|
7553 | n/a | } |
---|
7554 | n/a | asdl_seq_SET(args, i, value); |
---|
7555 | n/a | } |
---|
7556 | n/a | Py_CLEAR(tmp); |
---|
7557 | n/a | } else { |
---|
7558 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments"); |
---|
7559 | n/a | return 1; |
---|
7560 | n/a | } |
---|
7561 | n/a | if (exists_not_none(obj, &PyId_vararg)) { |
---|
7562 | n/a | int res; |
---|
7563 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_vararg); |
---|
7564 | n/a | if (tmp == NULL) goto failed; |
---|
7565 | n/a | res = obj2ast_arg(tmp, &vararg, arena); |
---|
7566 | n/a | if (res != 0) goto failed; |
---|
7567 | n/a | Py_CLEAR(tmp); |
---|
7568 | n/a | } else { |
---|
7569 | n/a | vararg = NULL; |
---|
7570 | n/a | } |
---|
7571 | n/a | if (_PyObject_HasAttrId(obj, &PyId_kwonlyargs)) { |
---|
7572 | n/a | int res; |
---|
7573 | n/a | Py_ssize_t len; |
---|
7574 | n/a | Py_ssize_t i; |
---|
7575 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_kwonlyargs); |
---|
7576 | n/a | if (tmp == NULL) goto failed; |
---|
7577 | n/a | if (!PyList_Check(tmp)) { |
---|
7578 | n/a | PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7579 | n/a | goto failed; |
---|
7580 | n/a | } |
---|
7581 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7582 | n/a | kwonlyargs = _Py_asdl_seq_new(len, arena); |
---|
7583 | n/a | if (kwonlyargs == NULL) goto failed; |
---|
7584 | n/a | for (i = 0; i < len; i++) { |
---|
7585 | n/a | arg_ty value; |
---|
7586 | n/a | res = obj2ast_arg(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7587 | n/a | if (res != 0) goto failed; |
---|
7588 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7589 | n/a | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration"); |
---|
7590 | n/a | goto failed; |
---|
7591 | n/a | } |
---|
7592 | n/a | asdl_seq_SET(kwonlyargs, i, value); |
---|
7593 | n/a | } |
---|
7594 | n/a | Py_CLEAR(tmp); |
---|
7595 | n/a | } else { |
---|
7596 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments"); |
---|
7597 | n/a | return 1; |
---|
7598 | n/a | } |
---|
7599 | n/a | if (_PyObject_HasAttrId(obj, &PyId_kw_defaults)) { |
---|
7600 | n/a | int res; |
---|
7601 | n/a | Py_ssize_t len; |
---|
7602 | n/a | Py_ssize_t i; |
---|
7603 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_kw_defaults); |
---|
7604 | n/a | if (tmp == NULL) goto failed; |
---|
7605 | n/a | if (!PyList_Check(tmp)) { |
---|
7606 | n/a | PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7607 | n/a | goto failed; |
---|
7608 | n/a | } |
---|
7609 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7610 | n/a | kw_defaults = _Py_asdl_seq_new(len, arena); |
---|
7611 | n/a | if (kw_defaults == NULL) goto failed; |
---|
7612 | n/a | for (i = 0; i < len; i++) { |
---|
7613 | n/a | expr_ty value; |
---|
7614 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7615 | n/a | if (res != 0) goto failed; |
---|
7616 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7617 | n/a | PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration"); |
---|
7618 | n/a | goto failed; |
---|
7619 | n/a | } |
---|
7620 | n/a | asdl_seq_SET(kw_defaults, i, value); |
---|
7621 | n/a | } |
---|
7622 | n/a | Py_CLEAR(tmp); |
---|
7623 | n/a | } else { |
---|
7624 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments"); |
---|
7625 | n/a | return 1; |
---|
7626 | n/a | } |
---|
7627 | n/a | if (exists_not_none(obj, &PyId_kwarg)) { |
---|
7628 | n/a | int res; |
---|
7629 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_kwarg); |
---|
7630 | n/a | if (tmp == NULL) goto failed; |
---|
7631 | n/a | res = obj2ast_arg(tmp, &kwarg, arena); |
---|
7632 | n/a | if (res != 0) goto failed; |
---|
7633 | n/a | Py_CLEAR(tmp); |
---|
7634 | n/a | } else { |
---|
7635 | n/a | kwarg = NULL; |
---|
7636 | n/a | } |
---|
7637 | n/a | if (_PyObject_HasAttrId(obj, &PyId_defaults)) { |
---|
7638 | n/a | int res; |
---|
7639 | n/a | Py_ssize_t len; |
---|
7640 | n/a | Py_ssize_t i; |
---|
7641 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_defaults); |
---|
7642 | n/a | if (tmp == NULL) goto failed; |
---|
7643 | n/a | if (!PyList_Check(tmp)) { |
---|
7644 | n/a | PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", tmp->ob_type->tp_name); |
---|
7645 | n/a | goto failed; |
---|
7646 | n/a | } |
---|
7647 | n/a | len = PyList_GET_SIZE(tmp); |
---|
7648 | n/a | defaults = _Py_asdl_seq_new(len, arena); |
---|
7649 | n/a | if (defaults == NULL) goto failed; |
---|
7650 | n/a | for (i = 0; i < len; i++) { |
---|
7651 | n/a | expr_ty value; |
---|
7652 | n/a | res = obj2ast_expr(PyList_GET_ITEM(tmp, i), &value, arena); |
---|
7653 | n/a | if (res != 0) goto failed; |
---|
7654 | n/a | if (len != PyList_GET_SIZE(tmp)) { |
---|
7655 | n/a | PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration"); |
---|
7656 | n/a | goto failed; |
---|
7657 | n/a | } |
---|
7658 | n/a | asdl_seq_SET(defaults, i, value); |
---|
7659 | n/a | } |
---|
7660 | n/a | Py_CLEAR(tmp); |
---|
7661 | n/a | } else { |
---|
7662 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments"); |
---|
7663 | n/a | return 1; |
---|
7664 | n/a | } |
---|
7665 | n/a | *out = arguments(args, vararg, kwonlyargs, kw_defaults, kwarg, defaults, |
---|
7666 | n/a | arena); |
---|
7667 | n/a | return 0; |
---|
7668 | n/a | failed: |
---|
7669 | n/a | Py_XDECREF(tmp); |
---|
7670 | n/a | return 1; |
---|
7671 | n/a | } |
---|
7672 | n/a | |
---|
7673 | n/a | int |
---|
7674 | n/a | obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena) |
---|
7675 | n/a | { |
---|
7676 | n/a | PyObject* tmp = NULL; |
---|
7677 | n/a | identifier arg; |
---|
7678 | n/a | expr_ty annotation; |
---|
7679 | n/a | int lineno; |
---|
7680 | n/a | int col_offset; |
---|
7681 | n/a | |
---|
7682 | n/a | if (_PyObject_HasAttrId(obj, &PyId_arg)) { |
---|
7683 | n/a | int res; |
---|
7684 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
---|
7685 | n/a | if (tmp == NULL) goto failed; |
---|
7686 | n/a | res = obj2ast_identifier(tmp, &arg, arena); |
---|
7687 | n/a | if (res != 0) goto failed; |
---|
7688 | n/a | Py_CLEAR(tmp); |
---|
7689 | n/a | } else { |
---|
7690 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg"); |
---|
7691 | n/a | return 1; |
---|
7692 | n/a | } |
---|
7693 | n/a | if (exists_not_none(obj, &PyId_annotation)) { |
---|
7694 | n/a | int res; |
---|
7695 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_annotation); |
---|
7696 | n/a | if (tmp == NULL) goto failed; |
---|
7697 | n/a | res = obj2ast_expr(tmp, &annotation, arena); |
---|
7698 | n/a | if (res != 0) goto failed; |
---|
7699 | n/a | Py_CLEAR(tmp); |
---|
7700 | n/a | } else { |
---|
7701 | n/a | annotation = NULL; |
---|
7702 | n/a | } |
---|
7703 | n/a | if (_PyObject_HasAttrId(obj, &PyId_lineno)) { |
---|
7704 | n/a | int res; |
---|
7705 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_lineno); |
---|
7706 | n/a | if (tmp == NULL) goto failed; |
---|
7707 | n/a | res = obj2ast_int(tmp, &lineno, arena); |
---|
7708 | n/a | if (res != 0) goto failed; |
---|
7709 | n/a | Py_CLEAR(tmp); |
---|
7710 | n/a | } else { |
---|
7711 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg"); |
---|
7712 | n/a | return 1; |
---|
7713 | n/a | } |
---|
7714 | n/a | if (_PyObject_HasAttrId(obj, &PyId_col_offset)) { |
---|
7715 | n/a | int res; |
---|
7716 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_col_offset); |
---|
7717 | n/a | if (tmp == NULL) goto failed; |
---|
7718 | n/a | res = obj2ast_int(tmp, &col_offset, arena); |
---|
7719 | n/a | if (res != 0) goto failed; |
---|
7720 | n/a | Py_CLEAR(tmp); |
---|
7721 | n/a | } else { |
---|
7722 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg"); |
---|
7723 | n/a | return 1; |
---|
7724 | n/a | } |
---|
7725 | n/a | *out = arg(arg, annotation, lineno, col_offset, arena); |
---|
7726 | n/a | return 0; |
---|
7727 | n/a | failed: |
---|
7728 | n/a | Py_XDECREF(tmp); |
---|
7729 | n/a | return 1; |
---|
7730 | n/a | } |
---|
7731 | n/a | |
---|
7732 | n/a | int |
---|
7733 | n/a | obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena) |
---|
7734 | n/a | { |
---|
7735 | n/a | PyObject* tmp = NULL; |
---|
7736 | n/a | identifier arg; |
---|
7737 | n/a | expr_ty value; |
---|
7738 | n/a | |
---|
7739 | n/a | if (exists_not_none(obj, &PyId_arg)) { |
---|
7740 | n/a | int res; |
---|
7741 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_arg); |
---|
7742 | n/a | if (tmp == NULL) goto failed; |
---|
7743 | n/a | res = obj2ast_identifier(tmp, &arg, arena); |
---|
7744 | n/a | if (res != 0) goto failed; |
---|
7745 | n/a | Py_CLEAR(tmp); |
---|
7746 | n/a | } else { |
---|
7747 | n/a | arg = NULL; |
---|
7748 | n/a | } |
---|
7749 | n/a | if (_PyObject_HasAttrId(obj, &PyId_value)) { |
---|
7750 | n/a | int res; |
---|
7751 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_value); |
---|
7752 | n/a | if (tmp == NULL) goto failed; |
---|
7753 | n/a | res = obj2ast_expr(tmp, &value, arena); |
---|
7754 | n/a | if (res != 0) goto failed; |
---|
7755 | n/a | Py_CLEAR(tmp); |
---|
7756 | n/a | } else { |
---|
7757 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword"); |
---|
7758 | n/a | return 1; |
---|
7759 | n/a | } |
---|
7760 | n/a | *out = keyword(arg, value, arena); |
---|
7761 | n/a | return 0; |
---|
7762 | n/a | failed: |
---|
7763 | n/a | Py_XDECREF(tmp); |
---|
7764 | n/a | return 1; |
---|
7765 | n/a | } |
---|
7766 | n/a | |
---|
7767 | n/a | int |
---|
7768 | n/a | obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena) |
---|
7769 | n/a | { |
---|
7770 | n/a | PyObject* tmp = NULL; |
---|
7771 | n/a | identifier name; |
---|
7772 | n/a | identifier asname; |
---|
7773 | n/a | |
---|
7774 | n/a | if (_PyObject_HasAttrId(obj, &PyId_name)) { |
---|
7775 | n/a | int res; |
---|
7776 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_name); |
---|
7777 | n/a | if (tmp == NULL) goto failed; |
---|
7778 | n/a | res = obj2ast_identifier(tmp, &name, arena); |
---|
7779 | n/a | if (res != 0) goto failed; |
---|
7780 | n/a | Py_CLEAR(tmp); |
---|
7781 | n/a | } else { |
---|
7782 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias"); |
---|
7783 | n/a | return 1; |
---|
7784 | n/a | } |
---|
7785 | n/a | if (exists_not_none(obj, &PyId_asname)) { |
---|
7786 | n/a | int res; |
---|
7787 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_asname); |
---|
7788 | n/a | if (tmp == NULL) goto failed; |
---|
7789 | n/a | res = obj2ast_identifier(tmp, &asname, arena); |
---|
7790 | n/a | if (res != 0) goto failed; |
---|
7791 | n/a | Py_CLEAR(tmp); |
---|
7792 | n/a | } else { |
---|
7793 | n/a | asname = NULL; |
---|
7794 | n/a | } |
---|
7795 | n/a | *out = alias(name, asname, arena); |
---|
7796 | n/a | return 0; |
---|
7797 | n/a | failed: |
---|
7798 | n/a | Py_XDECREF(tmp); |
---|
7799 | n/a | return 1; |
---|
7800 | n/a | } |
---|
7801 | n/a | |
---|
7802 | n/a | int |
---|
7803 | n/a | obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena) |
---|
7804 | n/a | { |
---|
7805 | n/a | PyObject* tmp = NULL; |
---|
7806 | n/a | expr_ty context_expr; |
---|
7807 | n/a | expr_ty optional_vars; |
---|
7808 | n/a | |
---|
7809 | n/a | if (_PyObject_HasAttrId(obj, &PyId_context_expr)) { |
---|
7810 | n/a | int res; |
---|
7811 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_context_expr); |
---|
7812 | n/a | if (tmp == NULL) goto failed; |
---|
7813 | n/a | res = obj2ast_expr(tmp, &context_expr, arena); |
---|
7814 | n/a | if (res != 0) goto failed; |
---|
7815 | n/a | Py_CLEAR(tmp); |
---|
7816 | n/a | } else { |
---|
7817 | n/a | PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem"); |
---|
7818 | n/a | return 1; |
---|
7819 | n/a | } |
---|
7820 | n/a | if (exists_not_none(obj, &PyId_optional_vars)) { |
---|
7821 | n/a | int res; |
---|
7822 | n/a | tmp = _PyObject_GetAttrId(obj, &PyId_optional_vars); |
---|
7823 | n/a | if (tmp == NULL) goto failed; |
---|
7824 | n/a | res = obj2ast_expr(tmp, &optional_vars, arena); |
---|
7825 | n/a | if (res != 0) goto failed; |
---|
7826 | n/a | Py_CLEAR(tmp); |
---|
7827 | n/a | } else { |
---|
7828 | n/a | optional_vars = NULL; |
---|
7829 | n/a | } |
---|
7830 | n/a | *out = withitem(context_expr, optional_vars, arena); |
---|
7831 | n/a | return 0; |
---|
7832 | n/a | failed: |
---|
7833 | n/a | Py_XDECREF(tmp); |
---|
7834 | n/a | return 1; |
---|
7835 | n/a | } |
---|
7836 | n/a | |
---|
7837 | n/a | |
---|
7838 | n/a | static struct PyModuleDef _astmodule = { |
---|
7839 | n/a | PyModuleDef_HEAD_INIT, "_ast" |
---|
7840 | n/a | }; |
---|
7841 | n/a | PyMODINIT_FUNC |
---|
7842 | n/a | PyInit__ast(void) |
---|
7843 | n/a | { |
---|
7844 | n/a | PyObject *m, *d; |
---|
7845 | n/a | if (!init_types()) return NULL; |
---|
7846 | n/a | m = PyModule_Create(&_astmodule); |
---|
7847 | n/a | if (!m) return NULL; |
---|
7848 | n/a | d = PyModule_GetDict(m); |
---|
7849 | n/a | if (PyDict_SetItemString(d, "AST", (PyObject*)&AST_type) < 0) return NULL; |
---|
7850 | n/a | if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) |
---|
7851 | n/a | return NULL; |
---|
7852 | n/a | if (PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return NULL; |
---|
7853 | n/a | if (PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0) return |
---|
7854 | n/a | NULL; |
---|
7855 | n/a | if (PyDict_SetItemString(d, "Interactive", (PyObject*)Interactive_type) < |
---|
7856 | n/a | 0) return NULL; |
---|
7857 | n/a | if (PyDict_SetItemString(d, "Expression", (PyObject*)Expression_type) < 0) |
---|
7858 | n/a | return NULL; |
---|
7859 | n/a | if (PyDict_SetItemString(d, "Suite", (PyObject*)Suite_type) < 0) return |
---|
7860 | n/a | NULL; |
---|
7861 | n/a | if (PyDict_SetItemString(d, "stmt", (PyObject*)stmt_type) < 0) return NULL; |
---|
7862 | n/a | if (PyDict_SetItemString(d, "FunctionDef", (PyObject*)FunctionDef_type) < |
---|
7863 | n/a | 0) return NULL; |
---|
7864 | n/a | if (PyDict_SetItemString(d, "AsyncFunctionDef", |
---|
7865 | n/a | (PyObject*)AsyncFunctionDef_type) < 0) return NULL; |
---|
7866 | n/a | if (PyDict_SetItemString(d, "ClassDef", (PyObject*)ClassDef_type) < 0) |
---|
7867 | n/a | return NULL; |
---|
7868 | n/a | if (PyDict_SetItemString(d, "Return", (PyObject*)Return_type) < 0) return |
---|
7869 | n/a | NULL; |
---|
7870 | n/a | if (PyDict_SetItemString(d, "Delete", (PyObject*)Delete_type) < 0) return |
---|
7871 | n/a | NULL; |
---|
7872 | n/a | if (PyDict_SetItemString(d, "Assign", (PyObject*)Assign_type) < 0) return |
---|
7873 | n/a | NULL; |
---|
7874 | n/a | if (PyDict_SetItemString(d, "AugAssign", (PyObject*)AugAssign_type) < 0) |
---|
7875 | n/a | return NULL; |
---|
7876 | n/a | if (PyDict_SetItemString(d, "AnnAssign", (PyObject*)AnnAssign_type) < 0) |
---|
7877 | n/a | return NULL; |
---|
7878 | n/a | if (PyDict_SetItemString(d, "For", (PyObject*)For_type) < 0) return NULL; |
---|
7879 | n/a | if (PyDict_SetItemString(d, "AsyncFor", (PyObject*)AsyncFor_type) < 0) |
---|
7880 | n/a | return NULL; |
---|
7881 | n/a | if (PyDict_SetItemString(d, "While", (PyObject*)While_type) < 0) return |
---|
7882 | n/a | NULL; |
---|
7883 | n/a | if (PyDict_SetItemString(d, "If", (PyObject*)If_type) < 0) return NULL; |
---|
7884 | n/a | if (PyDict_SetItemString(d, "With", (PyObject*)With_type) < 0) return NULL; |
---|
7885 | n/a | if (PyDict_SetItemString(d, "AsyncWith", (PyObject*)AsyncWith_type) < 0) |
---|
7886 | n/a | return NULL; |
---|
7887 | n/a | if (PyDict_SetItemString(d, "Raise", (PyObject*)Raise_type) < 0) return |
---|
7888 | n/a | NULL; |
---|
7889 | n/a | if (PyDict_SetItemString(d, "Try", (PyObject*)Try_type) < 0) return NULL; |
---|
7890 | n/a | if (PyDict_SetItemString(d, "Assert", (PyObject*)Assert_type) < 0) return |
---|
7891 | n/a | NULL; |
---|
7892 | n/a | if (PyDict_SetItemString(d, "Import", (PyObject*)Import_type) < 0) return |
---|
7893 | n/a | NULL; |
---|
7894 | n/a | if (PyDict_SetItemString(d, "ImportFrom", (PyObject*)ImportFrom_type) < 0) |
---|
7895 | n/a | return NULL; |
---|
7896 | n/a | if (PyDict_SetItemString(d, "Global", (PyObject*)Global_type) < 0) return |
---|
7897 | n/a | NULL; |
---|
7898 | n/a | if (PyDict_SetItemString(d, "Nonlocal", (PyObject*)Nonlocal_type) < 0) |
---|
7899 | n/a | return NULL; |
---|
7900 | n/a | if (PyDict_SetItemString(d, "Expr", (PyObject*)Expr_type) < 0) return NULL; |
---|
7901 | n/a | if (PyDict_SetItemString(d, "Pass", (PyObject*)Pass_type) < 0) return NULL; |
---|
7902 | n/a | if (PyDict_SetItemString(d, "Break", (PyObject*)Break_type) < 0) return |
---|
7903 | n/a | NULL; |
---|
7904 | n/a | if (PyDict_SetItemString(d, "Continue", (PyObject*)Continue_type) < 0) |
---|
7905 | n/a | return NULL; |
---|
7906 | n/a | if (PyDict_SetItemString(d, "expr", (PyObject*)expr_type) < 0) return NULL; |
---|
7907 | n/a | if (PyDict_SetItemString(d, "BoolOp", (PyObject*)BoolOp_type) < 0) return |
---|
7908 | n/a | NULL; |
---|
7909 | n/a | if (PyDict_SetItemString(d, "BinOp", (PyObject*)BinOp_type) < 0) return |
---|
7910 | n/a | NULL; |
---|
7911 | n/a | if (PyDict_SetItemString(d, "UnaryOp", (PyObject*)UnaryOp_type) < 0) return |
---|
7912 | n/a | NULL; |
---|
7913 | n/a | if (PyDict_SetItemString(d, "Lambda", (PyObject*)Lambda_type) < 0) return |
---|
7914 | n/a | NULL; |
---|
7915 | n/a | if (PyDict_SetItemString(d, "IfExp", (PyObject*)IfExp_type) < 0) return |
---|
7916 | n/a | NULL; |
---|
7917 | n/a | if (PyDict_SetItemString(d, "Dict", (PyObject*)Dict_type) < 0) return NULL; |
---|
7918 | n/a | if (PyDict_SetItemString(d, "Set", (PyObject*)Set_type) < 0) return NULL; |
---|
7919 | n/a | if (PyDict_SetItemString(d, "ListComp", (PyObject*)ListComp_type) < 0) |
---|
7920 | n/a | return NULL; |
---|
7921 | n/a | if (PyDict_SetItemString(d, "SetComp", (PyObject*)SetComp_type) < 0) return |
---|
7922 | n/a | NULL; |
---|
7923 | n/a | if (PyDict_SetItemString(d, "DictComp", (PyObject*)DictComp_type) < 0) |
---|
7924 | n/a | return NULL; |
---|
7925 | n/a | if (PyDict_SetItemString(d, "GeneratorExp", (PyObject*)GeneratorExp_type) < |
---|
7926 | n/a | 0) return NULL; |
---|
7927 | n/a | if (PyDict_SetItemString(d, "Await", (PyObject*)Await_type) < 0) return |
---|
7928 | n/a | NULL; |
---|
7929 | n/a | if (PyDict_SetItemString(d, "Yield", (PyObject*)Yield_type) < 0) return |
---|
7930 | n/a | NULL; |
---|
7931 | n/a | if (PyDict_SetItemString(d, "YieldFrom", (PyObject*)YieldFrom_type) < 0) |
---|
7932 | n/a | return NULL; |
---|
7933 | n/a | if (PyDict_SetItemString(d, "Compare", (PyObject*)Compare_type) < 0) return |
---|
7934 | n/a | NULL; |
---|
7935 | n/a | if (PyDict_SetItemString(d, "Call", (PyObject*)Call_type) < 0) return NULL; |
---|
7936 | n/a | if (PyDict_SetItemString(d, "Num", (PyObject*)Num_type) < 0) return NULL; |
---|
7937 | n/a | if (PyDict_SetItemString(d, "Str", (PyObject*)Str_type) < 0) return NULL; |
---|
7938 | n/a | if (PyDict_SetItemString(d, "FormattedValue", |
---|
7939 | n/a | (PyObject*)FormattedValue_type) < 0) return NULL; |
---|
7940 | n/a | if (PyDict_SetItemString(d, "JoinedStr", (PyObject*)JoinedStr_type) < 0) |
---|
7941 | n/a | return NULL; |
---|
7942 | n/a | if (PyDict_SetItemString(d, "Bytes", (PyObject*)Bytes_type) < 0) return |
---|
7943 | n/a | NULL; |
---|
7944 | n/a | if (PyDict_SetItemString(d, "NameConstant", (PyObject*)NameConstant_type) < |
---|
7945 | n/a | 0) return NULL; |
---|
7946 | n/a | if (PyDict_SetItemString(d, "Ellipsis", (PyObject*)Ellipsis_type) < 0) |
---|
7947 | n/a | return NULL; |
---|
7948 | n/a | if (PyDict_SetItemString(d, "Constant", (PyObject*)Constant_type) < 0) |
---|
7949 | n/a | return NULL; |
---|
7950 | n/a | if (PyDict_SetItemString(d, "Attribute", (PyObject*)Attribute_type) < 0) |
---|
7951 | n/a | return NULL; |
---|
7952 | n/a | if (PyDict_SetItemString(d, "Subscript", (PyObject*)Subscript_type) < 0) |
---|
7953 | n/a | return NULL; |
---|
7954 | n/a | if (PyDict_SetItemString(d, "Starred", (PyObject*)Starred_type) < 0) return |
---|
7955 | n/a | NULL; |
---|
7956 | n/a | if (PyDict_SetItemString(d, "Name", (PyObject*)Name_type) < 0) return NULL; |
---|
7957 | n/a | if (PyDict_SetItemString(d, "List", (PyObject*)List_type) < 0) return NULL; |
---|
7958 | n/a | if (PyDict_SetItemString(d, "Tuple", (PyObject*)Tuple_type) < 0) return |
---|
7959 | n/a | NULL; |
---|
7960 | n/a | if (PyDict_SetItemString(d, "expr_context", (PyObject*)expr_context_type) < |
---|
7961 | n/a | 0) return NULL; |
---|
7962 | n/a | if (PyDict_SetItemString(d, "Load", (PyObject*)Load_type) < 0) return NULL; |
---|
7963 | n/a | if (PyDict_SetItemString(d, "Store", (PyObject*)Store_type) < 0) return |
---|
7964 | n/a | NULL; |
---|
7965 | n/a | if (PyDict_SetItemString(d, "Del", (PyObject*)Del_type) < 0) return NULL; |
---|
7966 | n/a | if (PyDict_SetItemString(d, "AugLoad", (PyObject*)AugLoad_type) < 0) return |
---|
7967 | n/a | NULL; |
---|
7968 | n/a | if (PyDict_SetItemString(d, "AugStore", (PyObject*)AugStore_type) < 0) |
---|
7969 | n/a | return NULL; |
---|
7970 | n/a | if (PyDict_SetItemString(d, "Param", (PyObject*)Param_type) < 0) return |
---|
7971 | n/a | NULL; |
---|
7972 | n/a | if (PyDict_SetItemString(d, "slice", (PyObject*)slice_type) < 0) return |
---|
7973 | n/a | NULL; |
---|
7974 | n/a | if (PyDict_SetItemString(d, "Slice", (PyObject*)Slice_type) < 0) return |
---|
7975 | n/a | NULL; |
---|
7976 | n/a | if (PyDict_SetItemString(d, "ExtSlice", (PyObject*)ExtSlice_type) < 0) |
---|
7977 | n/a | return NULL; |
---|
7978 | n/a | if (PyDict_SetItemString(d, "Index", (PyObject*)Index_type) < 0) return |
---|
7979 | n/a | NULL; |
---|
7980 | n/a | if (PyDict_SetItemString(d, "boolop", (PyObject*)boolop_type) < 0) return |
---|
7981 | n/a | NULL; |
---|
7982 | n/a | if (PyDict_SetItemString(d, "And", (PyObject*)And_type) < 0) return NULL; |
---|
7983 | n/a | if (PyDict_SetItemString(d, "Or", (PyObject*)Or_type) < 0) return NULL; |
---|
7984 | n/a | if (PyDict_SetItemString(d, "operator", (PyObject*)operator_type) < 0) |
---|
7985 | n/a | return NULL; |
---|
7986 | n/a | if (PyDict_SetItemString(d, "Add", (PyObject*)Add_type) < 0) return NULL; |
---|
7987 | n/a | if (PyDict_SetItemString(d, "Sub", (PyObject*)Sub_type) < 0) return NULL; |
---|
7988 | n/a | if (PyDict_SetItemString(d, "Mult", (PyObject*)Mult_type) < 0) return NULL; |
---|
7989 | n/a | if (PyDict_SetItemString(d, "MatMult", (PyObject*)MatMult_type) < 0) return |
---|
7990 | n/a | NULL; |
---|
7991 | n/a | if (PyDict_SetItemString(d, "Div", (PyObject*)Div_type) < 0) return NULL; |
---|
7992 | n/a | if (PyDict_SetItemString(d, "Mod", (PyObject*)Mod_type) < 0) return NULL; |
---|
7993 | n/a | if (PyDict_SetItemString(d, "Pow", (PyObject*)Pow_type) < 0) return NULL; |
---|
7994 | n/a | if (PyDict_SetItemString(d, "LShift", (PyObject*)LShift_type) < 0) return |
---|
7995 | n/a | NULL; |
---|
7996 | n/a | if (PyDict_SetItemString(d, "RShift", (PyObject*)RShift_type) < 0) return |
---|
7997 | n/a | NULL; |
---|
7998 | n/a | if (PyDict_SetItemString(d, "BitOr", (PyObject*)BitOr_type) < 0) return |
---|
7999 | n/a | NULL; |
---|
8000 | n/a | if (PyDict_SetItemString(d, "BitXor", (PyObject*)BitXor_type) < 0) return |
---|
8001 | n/a | NULL; |
---|
8002 | n/a | if (PyDict_SetItemString(d, "BitAnd", (PyObject*)BitAnd_type) < 0) return |
---|
8003 | n/a | NULL; |
---|
8004 | n/a | if (PyDict_SetItemString(d, "FloorDiv", (PyObject*)FloorDiv_type) < 0) |
---|
8005 | n/a | return NULL; |
---|
8006 | n/a | if (PyDict_SetItemString(d, "unaryop", (PyObject*)unaryop_type) < 0) return |
---|
8007 | n/a | NULL; |
---|
8008 | n/a | if (PyDict_SetItemString(d, "Invert", (PyObject*)Invert_type) < 0) return |
---|
8009 | n/a | NULL; |
---|
8010 | n/a | if (PyDict_SetItemString(d, "Not", (PyObject*)Not_type) < 0) return NULL; |
---|
8011 | n/a | if (PyDict_SetItemString(d, "UAdd", (PyObject*)UAdd_type) < 0) return NULL; |
---|
8012 | n/a | if (PyDict_SetItemString(d, "USub", (PyObject*)USub_type) < 0) return NULL; |
---|
8013 | n/a | if (PyDict_SetItemString(d, "cmpop", (PyObject*)cmpop_type) < 0) return |
---|
8014 | n/a | NULL; |
---|
8015 | n/a | if (PyDict_SetItemString(d, "Eq", (PyObject*)Eq_type) < 0) return NULL; |
---|
8016 | n/a | if (PyDict_SetItemString(d, "NotEq", (PyObject*)NotEq_type) < 0) return |
---|
8017 | n/a | NULL; |
---|
8018 | n/a | if (PyDict_SetItemString(d, "Lt", (PyObject*)Lt_type) < 0) return NULL; |
---|
8019 | n/a | if (PyDict_SetItemString(d, "LtE", (PyObject*)LtE_type) < 0) return NULL; |
---|
8020 | n/a | if (PyDict_SetItemString(d, "Gt", (PyObject*)Gt_type) < 0) return NULL; |
---|
8021 | n/a | if (PyDict_SetItemString(d, "GtE", (PyObject*)GtE_type) < 0) return NULL; |
---|
8022 | n/a | if (PyDict_SetItemString(d, "Is", (PyObject*)Is_type) < 0) return NULL; |
---|
8023 | n/a | if (PyDict_SetItemString(d, "IsNot", (PyObject*)IsNot_type) < 0) return |
---|
8024 | n/a | NULL; |
---|
8025 | n/a | if (PyDict_SetItemString(d, "In", (PyObject*)In_type) < 0) return NULL; |
---|
8026 | n/a | if (PyDict_SetItemString(d, "NotIn", (PyObject*)NotIn_type) < 0) return |
---|
8027 | n/a | NULL; |
---|
8028 | n/a | if (PyDict_SetItemString(d, "comprehension", (PyObject*)comprehension_type) |
---|
8029 | n/a | < 0) return NULL; |
---|
8030 | n/a | if (PyDict_SetItemString(d, "excepthandler", (PyObject*)excepthandler_type) |
---|
8031 | n/a | < 0) return NULL; |
---|
8032 | n/a | if (PyDict_SetItemString(d, "ExceptHandler", (PyObject*)ExceptHandler_type) |
---|
8033 | n/a | < 0) return NULL; |
---|
8034 | n/a | if (PyDict_SetItemString(d, "arguments", (PyObject*)arguments_type) < 0) |
---|
8035 | n/a | return NULL; |
---|
8036 | n/a | if (PyDict_SetItemString(d, "arg", (PyObject*)arg_type) < 0) return NULL; |
---|
8037 | n/a | if (PyDict_SetItemString(d, "keyword", (PyObject*)keyword_type) < 0) return |
---|
8038 | n/a | NULL; |
---|
8039 | n/a | if (PyDict_SetItemString(d, "alias", (PyObject*)alias_type) < 0) return |
---|
8040 | n/a | NULL; |
---|
8041 | n/a | if (PyDict_SetItemString(d, "withitem", (PyObject*)withitem_type) < 0) |
---|
8042 | n/a | return NULL; |
---|
8043 | n/a | return m; |
---|
8044 | n/a | } |
---|
8045 | n/a | |
---|
8046 | n/a | |
---|
8047 | n/a | PyObject* PyAST_mod2obj(mod_ty t) |
---|
8048 | n/a | { |
---|
8049 | n/a | if (!init_types()) |
---|
8050 | n/a | return NULL; |
---|
8051 | n/a | return ast2obj_mod(t); |
---|
8052 | n/a | } |
---|
8053 | n/a | |
---|
8054 | n/a | /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */ |
---|
8055 | n/a | mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode) |
---|
8056 | n/a | { |
---|
8057 | n/a | mod_ty res; |
---|
8058 | n/a | PyObject *req_type[3]; |
---|
8059 | n/a | char *req_name[] = {"Module", "Expression", "Interactive"}; |
---|
8060 | n/a | int isinstance; |
---|
8061 | n/a | |
---|
8062 | n/a | req_type[0] = (PyObject*)Module_type; |
---|
8063 | n/a | req_type[1] = (PyObject*)Expression_type; |
---|
8064 | n/a | req_type[2] = (PyObject*)Interactive_type; |
---|
8065 | n/a | |
---|
8066 | n/a | assert(0 <= mode && mode <= 2); |
---|
8067 | n/a | |
---|
8068 | n/a | if (!init_types()) |
---|
8069 | n/a | return NULL; |
---|
8070 | n/a | |
---|
8071 | n/a | isinstance = PyObject_IsInstance(ast, req_type[mode]); |
---|
8072 | n/a | if (isinstance == -1) |
---|
8073 | n/a | return NULL; |
---|
8074 | n/a | if (!isinstance) { |
---|
8075 | n/a | PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s", |
---|
8076 | n/a | req_name[mode], Py_TYPE(ast)->tp_name); |
---|
8077 | n/a | return NULL; |
---|
8078 | n/a | } |
---|
8079 | n/a | if (obj2ast_mod(ast, &res, arena) != 0) |
---|
8080 | n/a | return NULL; |
---|
8081 | n/a | else |
---|
8082 | n/a | return res; |
---|
8083 | n/a | } |
---|
8084 | n/a | |
---|
8085 | n/a | int PyAST_Check(PyObject* obj) |
---|
8086 | n/a | { |
---|
8087 | n/a | if (!init_types()) |
---|
8088 | n/a | return -1; |
---|
8089 | n/a | return PyObject_IsInstance(obj, (PyObject*)&AST_type); |
---|
8090 | n/a | } |
---|
8091 | n/a | |
---|
8092 | n/a | |
---|