blob: 5190a90f13bf3fe463d76b673d4be4208f8aaca9 [file] [log] [blame]
Thomas Wouterscf297e42007-02-23 15:07:44 +00001/* File automatically generated by Parser/asdl_c.py. */
2
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07003#include <stddef.h>
4
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005#include "Python.h"
6#include "Python-ast.h"
7
Dino Viehlandac46eb42019-09-11 10:16:34 -07008typedef struct {
9 int initialized;
10 PyObject *AST_type;
11 PyObject *Add_singleton;
12 PyObject *Add_type;
13 PyObject *And_singleton;
14 PyObject *And_type;
15 PyObject *AnnAssign_type;
16 PyObject *Assert_type;
17 PyObject *Assign_type;
18 PyObject *AsyncFor_type;
19 PyObject *AsyncFunctionDef_type;
20 PyObject *AsyncWith_type;
21 PyObject *Attribute_type;
22 PyObject *AugAssign_type;
23 PyObject *AugLoad_singleton;
24 PyObject *AugLoad_type;
25 PyObject *AugStore_singleton;
26 PyObject *AugStore_type;
27 PyObject *Await_type;
28 PyObject *BinOp_type;
29 PyObject *BitAnd_singleton;
30 PyObject *BitAnd_type;
31 PyObject *BitOr_singleton;
32 PyObject *BitOr_type;
33 PyObject *BitXor_singleton;
34 PyObject *BitXor_type;
35 PyObject *BoolOp_type;
36 PyObject *Break_type;
37 PyObject *Call_type;
38 PyObject *ClassDef_type;
39 PyObject *Compare_type;
40 PyObject *Constant_type;
41 PyObject *Continue_type;
42 PyObject *Del_singleton;
43 PyObject *Del_type;
44 PyObject *Delete_type;
45 PyObject *DictComp_type;
46 PyObject *Dict_type;
47 PyObject *Div_singleton;
48 PyObject *Div_type;
49 PyObject *Eq_singleton;
50 PyObject *Eq_type;
51 PyObject *ExceptHandler_type;
52 PyObject *Expr_type;
53 PyObject *Expression_type;
54 PyObject *ExtSlice_type;
55 PyObject *FloorDiv_singleton;
56 PyObject *FloorDiv_type;
57 PyObject *For_type;
58 PyObject *FormattedValue_type;
59 PyObject *FunctionDef_type;
60 PyObject *FunctionType_type;
61 PyObject *GeneratorExp_type;
62 PyObject *Global_type;
63 PyObject *GtE_singleton;
64 PyObject *GtE_type;
65 PyObject *Gt_singleton;
66 PyObject *Gt_type;
67 PyObject *IfExp_type;
68 PyObject *If_type;
69 PyObject *ImportFrom_type;
70 PyObject *Import_type;
71 PyObject *In_singleton;
72 PyObject *In_type;
73 PyObject *Index_type;
74 PyObject *Interactive_type;
75 PyObject *Invert_singleton;
76 PyObject *Invert_type;
77 PyObject *IsNot_singleton;
78 PyObject *IsNot_type;
79 PyObject *Is_singleton;
80 PyObject *Is_type;
81 PyObject *JoinedStr_type;
82 PyObject *LShift_singleton;
83 PyObject *LShift_type;
84 PyObject *Lambda_type;
85 PyObject *ListComp_type;
86 PyObject *List_type;
87 PyObject *Load_singleton;
88 PyObject *Load_type;
89 PyObject *LtE_singleton;
90 PyObject *LtE_type;
91 PyObject *Lt_singleton;
92 PyObject *Lt_type;
93 PyObject *MatMult_singleton;
94 PyObject *MatMult_type;
95 PyObject *Mod_singleton;
96 PyObject *Mod_type;
97 PyObject *Module_type;
98 PyObject *Mult_singleton;
99 PyObject *Mult_type;
100 PyObject *Name_type;
101 PyObject *NamedExpr_type;
102 PyObject *Nonlocal_type;
103 PyObject *NotEq_singleton;
104 PyObject *NotEq_type;
105 PyObject *NotIn_singleton;
106 PyObject *NotIn_type;
107 PyObject *Not_singleton;
108 PyObject *Not_type;
109 PyObject *Or_singleton;
110 PyObject *Or_type;
111 PyObject *Param_singleton;
112 PyObject *Param_type;
113 PyObject *Pass_type;
114 PyObject *Pow_singleton;
115 PyObject *Pow_type;
116 PyObject *RShift_singleton;
117 PyObject *RShift_type;
118 PyObject *Raise_type;
119 PyObject *Return_type;
120 PyObject *SetComp_type;
121 PyObject *Set_type;
122 PyObject *Slice_type;
123 PyObject *Starred_type;
124 PyObject *Store_singleton;
125 PyObject *Store_type;
126 PyObject *Sub_singleton;
127 PyObject *Sub_type;
128 PyObject *Subscript_type;
129 PyObject *Suite_type;
130 PyObject *Try_type;
131 PyObject *Tuple_type;
132 PyObject *TypeIgnore_type;
133 PyObject *UAdd_singleton;
134 PyObject *UAdd_type;
135 PyObject *USub_singleton;
136 PyObject *USub_type;
137 PyObject *UnaryOp_type;
138 PyObject *While_type;
139 PyObject *With_type;
140 PyObject *YieldFrom_type;
141 PyObject *Yield_type;
142 PyObject *__dict__;
143 PyObject *__module__;
144 PyObject *_ast;
145 PyObject *_attributes;
146 PyObject *_fields;
147 PyObject *alias_type;
148 PyObject *annotation;
149 PyObject *arg;
150 PyObject *arg_type;
151 PyObject *args;
152 PyObject *argtypes;
153 PyObject *arguments_type;
154 PyObject *asname;
155 PyObject *attr;
156 PyObject *bases;
157 PyObject *body;
158 PyObject *boolop_type;
159 PyObject *cause;
160 PyObject *cmpop_type;
161 PyObject *col_offset;
162 PyObject *comparators;
163 PyObject *comprehension_type;
164 PyObject *context_expr;
165 PyObject *conversion;
166 PyObject *ctx;
167 PyObject *decorator_list;
168 PyObject *defaults;
169 PyObject *dims;
170 PyObject *elt;
171 PyObject *elts;
172 PyObject *end_col_offset;
173 PyObject *end_lineno;
174 PyObject *exc;
175 PyObject *excepthandler_type;
176 PyObject *expr_context_type;
177 PyObject *expr_type;
178 PyObject *finalbody;
179 PyObject *format_spec;
180 PyObject *func;
181 PyObject *generators;
182 PyObject *handlers;
183 PyObject *id;
184 PyObject *ifs;
185 PyObject *is_async;
186 PyObject *items;
187 PyObject *iter;
188 PyObject *key;
189 PyObject *keys;
190 PyObject *keyword_type;
191 PyObject *keywords;
192 PyObject *kind;
193 PyObject *kw_defaults;
194 PyObject *kwarg;
195 PyObject *kwonlyargs;
196 PyObject *left;
197 PyObject *level;
198 PyObject *lineno;
199 PyObject *lower;
200 PyObject *mod_type;
201 PyObject *module;
202 PyObject *msg;
203 PyObject *name;
204 PyObject *names;
205 PyObject *op;
206 PyObject *operand;
207 PyObject *operator_type;
208 PyObject *ops;
209 PyObject *optional_vars;
210 PyObject *orelse;
211 PyObject *posonlyargs;
212 PyObject *returns;
213 PyObject *right;
214 PyObject *simple;
215 PyObject *slice;
216 PyObject *slice_type;
217 PyObject *step;
218 PyObject *stmt_type;
219 PyObject *tag;
220 PyObject *target;
221 PyObject *targets;
222 PyObject *test;
223 PyObject *type;
224 PyObject *type_comment;
225 PyObject *type_ignore_type;
226 PyObject *type_ignores;
227 PyObject *unaryop_type;
228 PyObject *upper;
229 PyObject *value;
230 PyObject *values;
231 PyObject *vararg;
232 PyObject *withitem_type;
233} astmodulestate;
234
235
236#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
237
238static int astmodule_clear(PyObject *module)
239{
240 Py_CLEAR(astmodulestate(module)->AST_type);
241 Py_CLEAR(astmodulestate(module)->Add_singleton);
242 Py_CLEAR(astmodulestate(module)->Add_type);
243 Py_CLEAR(astmodulestate(module)->And_singleton);
244 Py_CLEAR(astmodulestate(module)->And_type);
245 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
246 Py_CLEAR(astmodulestate(module)->Assert_type);
247 Py_CLEAR(astmodulestate(module)->Assign_type);
248 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
249 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
250 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
251 Py_CLEAR(astmodulestate(module)->Attribute_type);
252 Py_CLEAR(astmodulestate(module)->AugAssign_type);
253 Py_CLEAR(astmodulestate(module)->AugLoad_singleton);
254 Py_CLEAR(astmodulestate(module)->AugLoad_type);
255 Py_CLEAR(astmodulestate(module)->AugStore_singleton);
256 Py_CLEAR(astmodulestate(module)->AugStore_type);
257 Py_CLEAR(astmodulestate(module)->Await_type);
258 Py_CLEAR(astmodulestate(module)->BinOp_type);
259 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
260 Py_CLEAR(astmodulestate(module)->BitAnd_type);
261 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
262 Py_CLEAR(astmodulestate(module)->BitOr_type);
263 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
264 Py_CLEAR(astmodulestate(module)->BitXor_type);
265 Py_CLEAR(astmodulestate(module)->BoolOp_type);
266 Py_CLEAR(astmodulestate(module)->Break_type);
267 Py_CLEAR(astmodulestate(module)->Call_type);
268 Py_CLEAR(astmodulestate(module)->ClassDef_type);
269 Py_CLEAR(astmodulestate(module)->Compare_type);
270 Py_CLEAR(astmodulestate(module)->Constant_type);
271 Py_CLEAR(astmodulestate(module)->Continue_type);
272 Py_CLEAR(astmodulestate(module)->Del_singleton);
273 Py_CLEAR(astmodulestate(module)->Del_type);
274 Py_CLEAR(astmodulestate(module)->Delete_type);
275 Py_CLEAR(astmodulestate(module)->DictComp_type);
276 Py_CLEAR(astmodulestate(module)->Dict_type);
277 Py_CLEAR(astmodulestate(module)->Div_singleton);
278 Py_CLEAR(astmodulestate(module)->Div_type);
279 Py_CLEAR(astmodulestate(module)->Eq_singleton);
280 Py_CLEAR(astmodulestate(module)->Eq_type);
281 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
282 Py_CLEAR(astmodulestate(module)->Expr_type);
283 Py_CLEAR(astmodulestate(module)->Expression_type);
284 Py_CLEAR(astmodulestate(module)->ExtSlice_type);
285 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
286 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
287 Py_CLEAR(astmodulestate(module)->For_type);
288 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
289 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
290 Py_CLEAR(astmodulestate(module)->FunctionType_type);
291 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
292 Py_CLEAR(astmodulestate(module)->Global_type);
293 Py_CLEAR(astmodulestate(module)->GtE_singleton);
294 Py_CLEAR(astmodulestate(module)->GtE_type);
295 Py_CLEAR(astmodulestate(module)->Gt_singleton);
296 Py_CLEAR(astmodulestate(module)->Gt_type);
297 Py_CLEAR(astmodulestate(module)->IfExp_type);
298 Py_CLEAR(astmodulestate(module)->If_type);
299 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
300 Py_CLEAR(astmodulestate(module)->Import_type);
301 Py_CLEAR(astmodulestate(module)->In_singleton);
302 Py_CLEAR(astmodulestate(module)->In_type);
303 Py_CLEAR(astmodulestate(module)->Index_type);
304 Py_CLEAR(astmodulestate(module)->Interactive_type);
305 Py_CLEAR(astmodulestate(module)->Invert_singleton);
306 Py_CLEAR(astmodulestate(module)->Invert_type);
307 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
308 Py_CLEAR(astmodulestate(module)->IsNot_type);
309 Py_CLEAR(astmodulestate(module)->Is_singleton);
310 Py_CLEAR(astmodulestate(module)->Is_type);
311 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
312 Py_CLEAR(astmodulestate(module)->LShift_singleton);
313 Py_CLEAR(astmodulestate(module)->LShift_type);
314 Py_CLEAR(astmodulestate(module)->Lambda_type);
315 Py_CLEAR(astmodulestate(module)->ListComp_type);
316 Py_CLEAR(astmodulestate(module)->List_type);
317 Py_CLEAR(astmodulestate(module)->Load_singleton);
318 Py_CLEAR(astmodulestate(module)->Load_type);
319 Py_CLEAR(astmodulestate(module)->LtE_singleton);
320 Py_CLEAR(astmodulestate(module)->LtE_type);
321 Py_CLEAR(astmodulestate(module)->Lt_singleton);
322 Py_CLEAR(astmodulestate(module)->Lt_type);
323 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
324 Py_CLEAR(astmodulestate(module)->MatMult_type);
325 Py_CLEAR(astmodulestate(module)->Mod_singleton);
326 Py_CLEAR(astmodulestate(module)->Mod_type);
327 Py_CLEAR(astmodulestate(module)->Module_type);
328 Py_CLEAR(astmodulestate(module)->Mult_singleton);
329 Py_CLEAR(astmodulestate(module)->Mult_type);
330 Py_CLEAR(astmodulestate(module)->Name_type);
331 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
332 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
333 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
334 Py_CLEAR(astmodulestate(module)->NotEq_type);
335 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
336 Py_CLEAR(astmodulestate(module)->NotIn_type);
337 Py_CLEAR(astmodulestate(module)->Not_singleton);
338 Py_CLEAR(astmodulestate(module)->Not_type);
339 Py_CLEAR(astmodulestate(module)->Or_singleton);
340 Py_CLEAR(astmodulestate(module)->Or_type);
341 Py_CLEAR(astmodulestate(module)->Param_singleton);
342 Py_CLEAR(astmodulestate(module)->Param_type);
343 Py_CLEAR(astmodulestate(module)->Pass_type);
344 Py_CLEAR(astmodulestate(module)->Pow_singleton);
345 Py_CLEAR(astmodulestate(module)->Pow_type);
346 Py_CLEAR(astmodulestate(module)->RShift_singleton);
347 Py_CLEAR(astmodulestate(module)->RShift_type);
348 Py_CLEAR(astmodulestate(module)->Raise_type);
349 Py_CLEAR(astmodulestate(module)->Return_type);
350 Py_CLEAR(astmodulestate(module)->SetComp_type);
351 Py_CLEAR(astmodulestate(module)->Set_type);
352 Py_CLEAR(astmodulestate(module)->Slice_type);
353 Py_CLEAR(astmodulestate(module)->Starred_type);
354 Py_CLEAR(astmodulestate(module)->Store_singleton);
355 Py_CLEAR(astmodulestate(module)->Store_type);
356 Py_CLEAR(astmodulestate(module)->Sub_singleton);
357 Py_CLEAR(astmodulestate(module)->Sub_type);
358 Py_CLEAR(astmodulestate(module)->Subscript_type);
359 Py_CLEAR(astmodulestate(module)->Suite_type);
360 Py_CLEAR(astmodulestate(module)->Try_type);
361 Py_CLEAR(astmodulestate(module)->Tuple_type);
362 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
363 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
364 Py_CLEAR(astmodulestate(module)->UAdd_type);
365 Py_CLEAR(astmodulestate(module)->USub_singleton);
366 Py_CLEAR(astmodulestate(module)->USub_type);
367 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
368 Py_CLEAR(astmodulestate(module)->While_type);
369 Py_CLEAR(astmodulestate(module)->With_type);
370 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
371 Py_CLEAR(astmodulestate(module)->Yield_type);
372 Py_CLEAR(astmodulestate(module)->__dict__);
373 Py_CLEAR(astmodulestate(module)->__module__);
374 Py_CLEAR(astmodulestate(module)->_ast);
375 Py_CLEAR(astmodulestate(module)->_attributes);
376 Py_CLEAR(astmodulestate(module)->_fields);
377 Py_CLEAR(astmodulestate(module)->alias_type);
378 Py_CLEAR(astmodulestate(module)->annotation);
379 Py_CLEAR(astmodulestate(module)->arg);
380 Py_CLEAR(astmodulestate(module)->arg_type);
381 Py_CLEAR(astmodulestate(module)->args);
382 Py_CLEAR(astmodulestate(module)->argtypes);
383 Py_CLEAR(astmodulestate(module)->arguments_type);
384 Py_CLEAR(astmodulestate(module)->asname);
385 Py_CLEAR(astmodulestate(module)->attr);
386 Py_CLEAR(astmodulestate(module)->bases);
387 Py_CLEAR(astmodulestate(module)->body);
388 Py_CLEAR(astmodulestate(module)->boolop_type);
389 Py_CLEAR(astmodulestate(module)->cause);
390 Py_CLEAR(astmodulestate(module)->cmpop_type);
391 Py_CLEAR(astmodulestate(module)->col_offset);
392 Py_CLEAR(astmodulestate(module)->comparators);
393 Py_CLEAR(astmodulestate(module)->comprehension_type);
394 Py_CLEAR(astmodulestate(module)->context_expr);
395 Py_CLEAR(astmodulestate(module)->conversion);
396 Py_CLEAR(astmodulestate(module)->ctx);
397 Py_CLEAR(astmodulestate(module)->decorator_list);
398 Py_CLEAR(astmodulestate(module)->defaults);
399 Py_CLEAR(astmodulestate(module)->dims);
400 Py_CLEAR(astmodulestate(module)->elt);
401 Py_CLEAR(astmodulestate(module)->elts);
402 Py_CLEAR(astmodulestate(module)->end_col_offset);
403 Py_CLEAR(astmodulestate(module)->end_lineno);
404 Py_CLEAR(astmodulestate(module)->exc);
405 Py_CLEAR(astmodulestate(module)->excepthandler_type);
406 Py_CLEAR(astmodulestate(module)->expr_context_type);
407 Py_CLEAR(astmodulestate(module)->expr_type);
408 Py_CLEAR(astmodulestate(module)->finalbody);
409 Py_CLEAR(astmodulestate(module)->format_spec);
410 Py_CLEAR(astmodulestate(module)->func);
411 Py_CLEAR(astmodulestate(module)->generators);
412 Py_CLEAR(astmodulestate(module)->handlers);
413 Py_CLEAR(astmodulestate(module)->id);
414 Py_CLEAR(astmodulestate(module)->ifs);
415 Py_CLEAR(astmodulestate(module)->is_async);
416 Py_CLEAR(astmodulestate(module)->items);
417 Py_CLEAR(astmodulestate(module)->iter);
418 Py_CLEAR(astmodulestate(module)->key);
419 Py_CLEAR(astmodulestate(module)->keys);
420 Py_CLEAR(astmodulestate(module)->keyword_type);
421 Py_CLEAR(astmodulestate(module)->keywords);
422 Py_CLEAR(astmodulestate(module)->kind);
423 Py_CLEAR(astmodulestate(module)->kw_defaults);
424 Py_CLEAR(astmodulestate(module)->kwarg);
425 Py_CLEAR(astmodulestate(module)->kwonlyargs);
426 Py_CLEAR(astmodulestate(module)->left);
427 Py_CLEAR(astmodulestate(module)->level);
428 Py_CLEAR(astmodulestate(module)->lineno);
429 Py_CLEAR(astmodulestate(module)->lower);
430 Py_CLEAR(astmodulestate(module)->mod_type);
431 Py_CLEAR(astmodulestate(module)->module);
432 Py_CLEAR(astmodulestate(module)->msg);
433 Py_CLEAR(astmodulestate(module)->name);
434 Py_CLEAR(astmodulestate(module)->names);
435 Py_CLEAR(astmodulestate(module)->op);
436 Py_CLEAR(astmodulestate(module)->operand);
437 Py_CLEAR(astmodulestate(module)->operator_type);
438 Py_CLEAR(astmodulestate(module)->ops);
439 Py_CLEAR(astmodulestate(module)->optional_vars);
440 Py_CLEAR(astmodulestate(module)->orelse);
441 Py_CLEAR(astmodulestate(module)->posonlyargs);
442 Py_CLEAR(astmodulestate(module)->returns);
443 Py_CLEAR(astmodulestate(module)->right);
444 Py_CLEAR(astmodulestate(module)->simple);
445 Py_CLEAR(astmodulestate(module)->slice);
446 Py_CLEAR(astmodulestate(module)->slice_type);
447 Py_CLEAR(astmodulestate(module)->step);
448 Py_CLEAR(astmodulestate(module)->stmt_type);
449 Py_CLEAR(astmodulestate(module)->tag);
450 Py_CLEAR(astmodulestate(module)->target);
451 Py_CLEAR(astmodulestate(module)->targets);
452 Py_CLEAR(astmodulestate(module)->test);
453 Py_CLEAR(astmodulestate(module)->type);
454 Py_CLEAR(astmodulestate(module)->type_comment);
455 Py_CLEAR(astmodulestate(module)->type_ignore_type);
456 Py_CLEAR(astmodulestate(module)->type_ignores);
457 Py_CLEAR(astmodulestate(module)->unaryop_type);
458 Py_CLEAR(astmodulestate(module)->upper);
459 Py_CLEAR(astmodulestate(module)->value);
460 Py_CLEAR(astmodulestate(module)->values);
461 Py_CLEAR(astmodulestate(module)->vararg);
462 Py_CLEAR(astmodulestate(module)->withitem_type);
463
464 return 0;
465}
466
467static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
468{
469 Py_VISIT(astmodulestate(module)->AST_type);
470 Py_VISIT(astmodulestate(module)->Add_singleton);
471 Py_VISIT(astmodulestate(module)->Add_type);
472 Py_VISIT(astmodulestate(module)->And_singleton);
473 Py_VISIT(astmodulestate(module)->And_type);
474 Py_VISIT(astmodulestate(module)->AnnAssign_type);
475 Py_VISIT(astmodulestate(module)->Assert_type);
476 Py_VISIT(astmodulestate(module)->Assign_type);
477 Py_VISIT(astmodulestate(module)->AsyncFor_type);
478 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
479 Py_VISIT(astmodulestate(module)->AsyncWith_type);
480 Py_VISIT(astmodulestate(module)->Attribute_type);
481 Py_VISIT(astmodulestate(module)->AugAssign_type);
482 Py_VISIT(astmodulestate(module)->AugLoad_singleton);
483 Py_VISIT(astmodulestate(module)->AugLoad_type);
484 Py_VISIT(astmodulestate(module)->AugStore_singleton);
485 Py_VISIT(astmodulestate(module)->AugStore_type);
486 Py_VISIT(astmodulestate(module)->Await_type);
487 Py_VISIT(astmodulestate(module)->BinOp_type);
488 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
489 Py_VISIT(astmodulestate(module)->BitAnd_type);
490 Py_VISIT(astmodulestate(module)->BitOr_singleton);
491 Py_VISIT(astmodulestate(module)->BitOr_type);
492 Py_VISIT(astmodulestate(module)->BitXor_singleton);
493 Py_VISIT(astmodulestate(module)->BitXor_type);
494 Py_VISIT(astmodulestate(module)->BoolOp_type);
495 Py_VISIT(astmodulestate(module)->Break_type);
496 Py_VISIT(astmodulestate(module)->Call_type);
497 Py_VISIT(astmodulestate(module)->ClassDef_type);
498 Py_VISIT(astmodulestate(module)->Compare_type);
499 Py_VISIT(astmodulestate(module)->Constant_type);
500 Py_VISIT(astmodulestate(module)->Continue_type);
501 Py_VISIT(astmodulestate(module)->Del_singleton);
502 Py_VISIT(astmodulestate(module)->Del_type);
503 Py_VISIT(astmodulestate(module)->Delete_type);
504 Py_VISIT(astmodulestate(module)->DictComp_type);
505 Py_VISIT(astmodulestate(module)->Dict_type);
506 Py_VISIT(astmodulestate(module)->Div_singleton);
507 Py_VISIT(astmodulestate(module)->Div_type);
508 Py_VISIT(astmodulestate(module)->Eq_singleton);
509 Py_VISIT(astmodulestate(module)->Eq_type);
510 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
511 Py_VISIT(astmodulestate(module)->Expr_type);
512 Py_VISIT(astmodulestate(module)->Expression_type);
513 Py_VISIT(astmodulestate(module)->ExtSlice_type);
514 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
515 Py_VISIT(astmodulestate(module)->FloorDiv_type);
516 Py_VISIT(astmodulestate(module)->For_type);
517 Py_VISIT(astmodulestate(module)->FormattedValue_type);
518 Py_VISIT(astmodulestate(module)->FunctionDef_type);
519 Py_VISIT(astmodulestate(module)->FunctionType_type);
520 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
521 Py_VISIT(astmodulestate(module)->Global_type);
522 Py_VISIT(astmodulestate(module)->GtE_singleton);
523 Py_VISIT(astmodulestate(module)->GtE_type);
524 Py_VISIT(astmodulestate(module)->Gt_singleton);
525 Py_VISIT(astmodulestate(module)->Gt_type);
526 Py_VISIT(astmodulestate(module)->IfExp_type);
527 Py_VISIT(astmodulestate(module)->If_type);
528 Py_VISIT(astmodulestate(module)->ImportFrom_type);
529 Py_VISIT(astmodulestate(module)->Import_type);
530 Py_VISIT(astmodulestate(module)->In_singleton);
531 Py_VISIT(astmodulestate(module)->In_type);
532 Py_VISIT(astmodulestate(module)->Index_type);
533 Py_VISIT(astmodulestate(module)->Interactive_type);
534 Py_VISIT(astmodulestate(module)->Invert_singleton);
535 Py_VISIT(astmodulestate(module)->Invert_type);
536 Py_VISIT(astmodulestate(module)->IsNot_singleton);
537 Py_VISIT(astmodulestate(module)->IsNot_type);
538 Py_VISIT(astmodulestate(module)->Is_singleton);
539 Py_VISIT(astmodulestate(module)->Is_type);
540 Py_VISIT(astmodulestate(module)->JoinedStr_type);
541 Py_VISIT(astmodulestate(module)->LShift_singleton);
542 Py_VISIT(astmodulestate(module)->LShift_type);
543 Py_VISIT(astmodulestate(module)->Lambda_type);
544 Py_VISIT(astmodulestate(module)->ListComp_type);
545 Py_VISIT(astmodulestate(module)->List_type);
546 Py_VISIT(astmodulestate(module)->Load_singleton);
547 Py_VISIT(astmodulestate(module)->Load_type);
548 Py_VISIT(astmodulestate(module)->LtE_singleton);
549 Py_VISIT(astmodulestate(module)->LtE_type);
550 Py_VISIT(astmodulestate(module)->Lt_singleton);
551 Py_VISIT(astmodulestate(module)->Lt_type);
552 Py_VISIT(astmodulestate(module)->MatMult_singleton);
553 Py_VISIT(astmodulestate(module)->MatMult_type);
554 Py_VISIT(astmodulestate(module)->Mod_singleton);
555 Py_VISIT(astmodulestate(module)->Mod_type);
556 Py_VISIT(astmodulestate(module)->Module_type);
557 Py_VISIT(astmodulestate(module)->Mult_singleton);
558 Py_VISIT(astmodulestate(module)->Mult_type);
559 Py_VISIT(astmodulestate(module)->Name_type);
560 Py_VISIT(astmodulestate(module)->NamedExpr_type);
561 Py_VISIT(astmodulestate(module)->Nonlocal_type);
562 Py_VISIT(astmodulestate(module)->NotEq_singleton);
563 Py_VISIT(astmodulestate(module)->NotEq_type);
564 Py_VISIT(astmodulestate(module)->NotIn_singleton);
565 Py_VISIT(astmodulestate(module)->NotIn_type);
566 Py_VISIT(astmodulestate(module)->Not_singleton);
567 Py_VISIT(astmodulestate(module)->Not_type);
568 Py_VISIT(astmodulestate(module)->Or_singleton);
569 Py_VISIT(astmodulestate(module)->Or_type);
570 Py_VISIT(astmodulestate(module)->Param_singleton);
571 Py_VISIT(astmodulestate(module)->Param_type);
572 Py_VISIT(astmodulestate(module)->Pass_type);
573 Py_VISIT(astmodulestate(module)->Pow_singleton);
574 Py_VISIT(astmodulestate(module)->Pow_type);
575 Py_VISIT(astmodulestate(module)->RShift_singleton);
576 Py_VISIT(astmodulestate(module)->RShift_type);
577 Py_VISIT(astmodulestate(module)->Raise_type);
578 Py_VISIT(astmodulestate(module)->Return_type);
579 Py_VISIT(astmodulestate(module)->SetComp_type);
580 Py_VISIT(astmodulestate(module)->Set_type);
581 Py_VISIT(astmodulestate(module)->Slice_type);
582 Py_VISIT(astmodulestate(module)->Starred_type);
583 Py_VISIT(astmodulestate(module)->Store_singleton);
584 Py_VISIT(astmodulestate(module)->Store_type);
585 Py_VISIT(astmodulestate(module)->Sub_singleton);
586 Py_VISIT(astmodulestate(module)->Sub_type);
587 Py_VISIT(astmodulestate(module)->Subscript_type);
588 Py_VISIT(astmodulestate(module)->Suite_type);
589 Py_VISIT(astmodulestate(module)->Try_type);
590 Py_VISIT(astmodulestate(module)->Tuple_type);
591 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
592 Py_VISIT(astmodulestate(module)->UAdd_singleton);
593 Py_VISIT(astmodulestate(module)->UAdd_type);
594 Py_VISIT(astmodulestate(module)->USub_singleton);
595 Py_VISIT(astmodulestate(module)->USub_type);
596 Py_VISIT(astmodulestate(module)->UnaryOp_type);
597 Py_VISIT(astmodulestate(module)->While_type);
598 Py_VISIT(astmodulestate(module)->With_type);
599 Py_VISIT(astmodulestate(module)->YieldFrom_type);
600 Py_VISIT(astmodulestate(module)->Yield_type);
601 Py_VISIT(astmodulestate(module)->__dict__);
602 Py_VISIT(astmodulestate(module)->__module__);
603 Py_VISIT(astmodulestate(module)->_ast);
604 Py_VISIT(astmodulestate(module)->_attributes);
605 Py_VISIT(astmodulestate(module)->_fields);
606 Py_VISIT(astmodulestate(module)->alias_type);
607 Py_VISIT(astmodulestate(module)->annotation);
608 Py_VISIT(astmodulestate(module)->arg);
609 Py_VISIT(astmodulestate(module)->arg_type);
610 Py_VISIT(astmodulestate(module)->args);
611 Py_VISIT(astmodulestate(module)->argtypes);
612 Py_VISIT(astmodulestate(module)->arguments_type);
613 Py_VISIT(astmodulestate(module)->asname);
614 Py_VISIT(astmodulestate(module)->attr);
615 Py_VISIT(astmodulestate(module)->bases);
616 Py_VISIT(astmodulestate(module)->body);
617 Py_VISIT(astmodulestate(module)->boolop_type);
618 Py_VISIT(astmodulestate(module)->cause);
619 Py_VISIT(astmodulestate(module)->cmpop_type);
620 Py_VISIT(astmodulestate(module)->col_offset);
621 Py_VISIT(astmodulestate(module)->comparators);
622 Py_VISIT(astmodulestate(module)->comprehension_type);
623 Py_VISIT(astmodulestate(module)->context_expr);
624 Py_VISIT(astmodulestate(module)->conversion);
625 Py_VISIT(astmodulestate(module)->ctx);
626 Py_VISIT(astmodulestate(module)->decorator_list);
627 Py_VISIT(astmodulestate(module)->defaults);
628 Py_VISIT(astmodulestate(module)->dims);
629 Py_VISIT(astmodulestate(module)->elt);
630 Py_VISIT(astmodulestate(module)->elts);
631 Py_VISIT(astmodulestate(module)->end_col_offset);
632 Py_VISIT(astmodulestate(module)->end_lineno);
633 Py_VISIT(astmodulestate(module)->exc);
634 Py_VISIT(astmodulestate(module)->excepthandler_type);
635 Py_VISIT(astmodulestate(module)->expr_context_type);
636 Py_VISIT(astmodulestate(module)->expr_type);
637 Py_VISIT(astmodulestate(module)->finalbody);
638 Py_VISIT(astmodulestate(module)->format_spec);
639 Py_VISIT(astmodulestate(module)->func);
640 Py_VISIT(astmodulestate(module)->generators);
641 Py_VISIT(astmodulestate(module)->handlers);
642 Py_VISIT(astmodulestate(module)->id);
643 Py_VISIT(astmodulestate(module)->ifs);
644 Py_VISIT(astmodulestate(module)->is_async);
645 Py_VISIT(astmodulestate(module)->items);
646 Py_VISIT(astmodulestate(module)->iter);
647 Py_VISIT(astmodulestate(module)->key);
648 Py_VISIT(astmodulestate(module)->keys);
649 Py_VISIT(astmodulestate(module)->keyword_type);
650 Py_VISIT(astmodulestate(module)->keywords);
651 Py_VISIT(astmodulestate(module)->kind);
652 Py_VISIT(astmodulestate(module)->kw_defaults);
653 Py_VISIT(astmodulestate(module)->kwarg);
654 Py_VISIT(astmodulestate(module)->kwonlyargs);
655 Py_VISIT(astmodulestate(module)->left);
656 Py_VISIT(astmodulestate(module)->level);
657 Py_VISIT(astmodulestate(module)->lineno);
658 Py_VISIT(astmodulestate(module)->lower);
659 Py_VISIT(astmodulestate(module)->mod_type);
660 Py_VISIT(astmodulestate(module)->module);
661 Py_VISIT(astmodulestate(module)->msg);
662 Py_VISIT(astmodulestate(module)->name);
663 Py_VISIT(astmodulestate(module)->names);
664 Py_VISIT(astmodulestate(module)->op);
665 Py_VISIT(astmodulestate(module)->operand);
666 Py_VISIT(astmodulestate(module)->operator_type);
667 Py_VISIT(astmodulestate(module)->ops);
668 Py_VISIT(astmodulestate(module)->optional_vars);
669 Py_VISIT(astmodulestate(module)->orelse);
670 Py_VISIT(astmodulestate(module)->posonlyargs);
671 Py_VISIT(astmodulestate(module)->returns);
672 Py_VISIT(astmodulestate(module)->right);
673 Py_VISIT(astmodulestate(module)->simple);
674 Py_VISIT(astmodulestate(module)->slice);
675 Py_VISIT(astmodulestate(module)->slice_type);
676 Py_VISIT(astmodulestate(module)->step);
677 Py_VISIT(astmodulestate(module)->stmt_type);
678 Py_VISIT(astmodulestate(module)->tag);
679 Py_VISIT(astmodulestate(module)->target);
680 Py_VISIT(astmodulestate(module)->targets);
681 Py_VISIT(astmodulestate(module)->test);
682 Py_VISIT(astmodulestate(module)->type);
683 Py_VISIT(astmodulestate(module)->type_comment);
684 Py_VISIT(astmodulestate(module)->type_ignore_type);
685 Py_VISIT(astmodulestate(module)->type_ignores);
686 Py_VISIT(astmodulestate(module)->unaryop_type);
687 Py_VISIT(astmodulestate(module)->upper);
688 Py_VISIT(astmodulestate(module)->value);
689 Py_VISIT(astmodulestate(module)->values);
690 Py_VISIT(astmodulestate(module)->vararg);
691 Py_VISIT(astmodulestate(module)->withitem_type);
692
693 return 0;
694}
695
696static void astmodule_free(void* module) {
697 astmodule_clear((PyObject*)module);
698}
699
700static struct PyModuleDef _astmodule = {
701 PyModuleDef_HEAD_INIT,
702 "_ast",
703 NULL,
704 sizeof(astmodulestate),
705 NULL,
706 NULL,
707 astmodule_traverse,
708 astmodule_clear,
709 astmodule_free,
710};
711
712#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
713
714static int init_identifiers(void)
715{
716 astmodulestate *state = astmodulestate_global;
717 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
718 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
719 if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0;
720 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
721 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
722 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
723 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
724 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
725 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
726 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
727 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
728 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
729 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
730 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
731 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
732 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
733 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
734 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
735 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
736 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
737 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
738 if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0;
739 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
740 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
741 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
742 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
743 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
744 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
745 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
746 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
747 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
748 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
749 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
750 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
751 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
752 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
753 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
754 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
755 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
756 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
757 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
758 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
759 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
760 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
761 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
762 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
763 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
764 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
765 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
766 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
767 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
768 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
769 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
770 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
771 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
772 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
773 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
774 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
775 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
776 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
777 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
778 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
779 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
780 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
781 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
782 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
783 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
784 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
785 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
786 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
787 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
788 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
789 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
790 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
791 return 1;
792};
793
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000794static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300795static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200796 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800797 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000798};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300799static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200800 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000801};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300802static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200803 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000804};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300805static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800806 "argtypes",
807 "returns",
808};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300809static const char * const Suite_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200810 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000811};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300812static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200813 "lineno",
814 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000815 "end_lineno",
816 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000817};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000818static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300819static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200820 "name",
821 "args",
822 "body",
823 "decorator_list",
824 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800825 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000826};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300827static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400828 "name",
829 "args",
830 "body",
831 "decorator_list",
832 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800833 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400834};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300835static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200836 "name",
837 "bases",
838 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200839 "body",
840 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000841};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300842static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200843 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000844};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300845static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200846 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000847};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300848static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200849 "targets",
850 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800851 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000852};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300853static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200854 "target",
855 "op",
856 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000857};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300858static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700859 "target",
860 "annotation",
861 "value",
862 "simple",
863};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300864static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200865 "target",
866 "iter",
867 "body",
868 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800869 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000870};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300871static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400872 "target",
873 "iter",
874 "body",
875 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800876 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400877};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300878static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200879 "test",
880 "body",
881 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000882};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300883static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200884 "test",
885 "body",
886 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000887};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300888static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200889 "items",
890 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800891 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000892};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300893static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400894 "items",
895 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800896 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400897};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300898static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200899 "exc",
900 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000901};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300902static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200903 "body",
904 "handlers",
905 "orelse",
906 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000907};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300908static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200909 "test",
910 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000911};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300912static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200913 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000914};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300915static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200916 "module",
917 "names",
918 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000919};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300920static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200921 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000922};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300923static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200924 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000925};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300926static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200927 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000928};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300929static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200930 "lineno",
931 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000932 "end_lineno",
933 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000934};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000935static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300936static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200937 "op",
938 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000939};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300940static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700941 "target",
942 "value",
943};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300944static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200945 "left",
946 "op",
947 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000948};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300949static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200950 "op",
951 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000952};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300953static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200954 "args",
955 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000956};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300957static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200958 "test",
959 "body",
960 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000961};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300962static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200963 "keys",
964 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000965};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300966static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200967 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000968};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300969static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200970 "elt",
971 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000972};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300973static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200974 "elt",
975 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000976};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300977static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200978 "key",
979 "value",
980 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000981};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300982static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200983 "elt",
984 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000985};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300986static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400987 "value",
988};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300989static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200990 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500991};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300992static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200993 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000994};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300995static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200996 "left",
997 "ops",
998 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000999};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001000static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001001 "func",
1002 "args",
1003 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001004};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001005static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -04001006 "value",
1007 "conversion",
1008 "format_spec",
1009};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001010static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -04001011 "values",
1012};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001013static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001014 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -07001015 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001016};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001017static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001018 "value",
1019 "attr",
1020 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001021};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001022static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001023 "value",
1024 "slice",
1025 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001026};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001027static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001028 "value",
1029 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +00001030};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001031static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001032 "id",
1033 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001034};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001035static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001036 "elts",
1037 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001038};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001039static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001040 "elts",
1041 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001042};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001043static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001044static PyObject* ast2obj_slice(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001045static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001046 "lower",
1047 "upper",
1048 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001049};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001050static const char * const ExtSlice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001051 "dims",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001052};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001053static const char * const Index_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001054 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001055};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001056static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001057static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001058static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001059static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001060static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001061static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001062 "target",
1063 "iter",
1064 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001065 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001066};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001067static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001068 "lineno",
1069 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001070 "end_lineno",
1071 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001072};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001073static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001074static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001075 "type",
1076 "name",
1077 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001078};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001079static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001080static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001081 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001082 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001083 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001084 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001085 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001086 "kwarg",
1087 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001088};
Neal Norwitzc1505362006-12-28 06:47:50 +00001089static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001090static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001091 "lineno",
1092 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001093 "end_lineno",
1094 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001095};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001096static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001097 "arg",
1098 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001099 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001100};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001101static PyObject* ast2obj_keyword(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001102static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001103 "arg",
1104 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001105};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001106static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001107static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001108 "name",
1109 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001110};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001111static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001112static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001113 "context_expr",
1114 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001115};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001116static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001117static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001118 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001119 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001120};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001121
1122
INADA Naokifc489082017-01-25 22:33:43 +09001123
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001124typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001125 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001126 PyObject *dict;
1127} AST_object;
1128
Benjamin Peterson1767e022012-03-14 21:50:29 -05001129static void
1130ast_dealloc(AST_object *self)
1131{
INADA Naokia6296d32017-08-24 14:55:17 +09001132 /* bpo-31095: UnTrack is needed before calling any callbacks */
1133 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001134 Py_CLEAR(self->dict);
Antoine Pitrou50750742012-07-08 12:43:32 +02001135 Py_TYPE(self)->tp_free(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001136}
1137
Neal Norwitz207c9f32008-03-31 04:42:11 +00001138static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001139ast_traverse(AST_object *self, visitproc visit, void *arg)
1140{
1141 Py_VISIT(self->dict);
1142 return 0;
1143}
1144
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001145static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001146ast_clear(AST_object *self)
1147{
1148 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001149 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001150}
1151
1152static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001153ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1154{
1155 Py_ssize_t i, numfields = 0;
1156 int res = -1;
1157 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001158 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001159 goto cleanup;
1160 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001161 if (fields) {
1162 numfields = PySequence_Size(fields);
1163 if (numfields == -1)
1164 goto cleanup;
1165 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001166
Neal Norwitz207c9f32008-03-31 04:42:11 +00001167 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001168 if (numfields < PyTuple_GET_SIZE(args)) {
1169 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1170 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001171 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001172 numfields, numfields == 1 ? "" : "s");
1173 res = -1;
1174 goto cleanup;
1175 }
1176 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1177 /* cannot be reached when fields is NULL */
1178 PyObject *name = PySequence_GetItem(fields, i);
1179 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001180 res = -1;
1181 goto cleanup;
1182 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001183 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1184 Py_DECREF(name);
1185 if (res < 0)
1186 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001187 }
1188 if (kw) {
1189 i = 0; /* needed by PyDict_Next */
1190 while (PyDict_Next(kw, &i, &key, &value)) {
1191 res = PyObject_SetAttr(self, key, value);
1192 if (res < 0)
1193 goto cleanup;
1194 }
1195 }
1196 cleanup:
1197 Py_XDECREF(fields);
1198 return res;
1199}
1200
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001201/* Pickling support */
1202static PyObject *
1203ast_type_reduce(PyObject *self, PyObject *unused)
1204{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001205 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001206 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001207 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001208 }
1209 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001210 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001211 }
1212 return Py_BuildValue("O()", Py_TYPE(self));
1213}
1214
1215static PyMethodDef ast_type_methods[] = {
1216 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1217 {NULL}
1218};
1219
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001220static PyGetSetDef ast_type_getsets[] = {
1221 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1222 {NULL}
1223};
1224
Dino Viehlandac46eb42019-09-11 10:16:34 -07001225static PyType_Slot AST_type_slots[] = {
1226 {Py_tp_dealloc, ast_dealloc},
1227 {Py_tp_getattro, PyObject_GenericGetAttr},
1228 {Py_tp_setattro, PyObject_GenericSetAttr},
1229 {Py_tp_traverse, ast_traverse},
1230 {Py_tp_clear, ast_clear},
1231 {Py_tp_methods, ast_type_methods},
1232 {Py_tp_getset, ast_type_getsets},
1233 {Py_tp_init, ast_type_init},
1234 {Py_tp_alloc, PyType_GenericAlloc},
1235 {Py_tp_new, PyType_GenericNew},
1236 {Py_tp_free, PyType_GenericNew},
1237 {Py_tp_free, PyObject_GC_Del},
1238 {0, 0},
1239};
1240
1241static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001242 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001243 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001244 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001245 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1246 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001247};
1248
Dino Viehlandac46eb42019-09-11 10:16:34 -07001249static PyObject *
1250make_type(const char *type, PyObject* base, const char* const* fields, int num_fields)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001251{
1252 PyObject *fnames, *result;
1253 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001254 fnames = PyTuple_New(num_fields);
1255 if (!fnames) return NULL;
1256 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001257 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001258 if (!field) {
1259 Py_DECREF(fnames);
1260 return NULL;
1261 }
1262 PyTuple_SET_ITEM(fnames, i, field);
1263 }
INADA Naokifc489082017-01-25 22:33:43 +09001264 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
1265 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001266 astmodulestate_global->_fields, fnames,
1267 astmodulestate_global->__module__,
1268 astmodulestate_global->_ast);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001269 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001270 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001271}
1272
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001273static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001274add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001275{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001276 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001277 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001278 if (!l)
1279 return 0;
1280 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001281 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001282 if (!s) {
1283 Py_DECREF(l);
1284 return 0;
1285 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001286 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001288 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001289 Py_DECREF(l);
1290 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001291}
1292
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001293/* Conversion AST -> Python */
1294
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001295static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1296{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001297 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001298 PyObject *result = PyList_New(n);
1299 PyObject *value;
1300 if (!result)
1301 return NULL;
1302 for (i = 0; i < n; i++) {
1303 value = func(asdl_seq_GET(seq, i));
1304 if (!value) {
1305 Py_DECREF(result);
1306 return NULL;
1307 }
1308 PyList_SET_ITEM(result, i, value);
1309 }
1310 return result;
1311}
1312
1313static PyObject* ast2obj_object(void *o)
1314{
1315 if (!o)
1316 o = Py_None;
1317 Py_INCREF((PyObject*)o);
1318 return (PyObject*)o;
1319}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001320#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001321#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001322#define ast2obj_identifier ast2obj_object
1323#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001324#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001325
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001326static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001327{
Christian Heimes217cfd12007-12-02 14:31:20 +00001328 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001329}
1330
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001331/* Conversion Python -> AST */
1332
1333static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1334{
1335 if (obj == Py_None)
1336 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001337 if (obj) {
1338 if (PyArena_AddPyObject(arena, obj) < 0) {
1339 *out = NULL;
1340 return -1;
1341 }
1342 Py_INCREF(obj);
1343 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001344 *out = obj;
1345 return 0;
1346}
1347
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001348static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1349{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001350 if (PyArena_AddPyObject(arena, obj) < 0) {
1351 *out = NULL;
1352 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001353 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001354 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001355 *out = obj;
1356 return 0;
1357}
1358
Benjamin Peterson180e6352011-07-22 11:09:07 -05001359static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001360{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001361 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1362 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001363 return 1;
1364 }
1365 return obj2ast_object(obj, out, arena);
1366}
1367
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001368static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1369{
1370 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1371 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1372 return 1;
1373 }
1374 return obj2ast_object(obj, out, arena);
1375}
1376
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001377static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1378{
1379 int i;
1380 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001381 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001382 return 1;
1383 }
1384
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001385 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001386 if (i == -1 && PyErr_Occurred())
1387 return 1;
1388 *out = i;
1389 return 0;
1390}
1391
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001392static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001393{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001394 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001395 empty_tuple = PyTuple_New(0);
1396 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001397 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1398 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001399 Py_XDECREF(empty_tuple);
1400 return -1;
1401 }
1402 Py_DECREF(empty_tuple);
1403 return 0;
1404}
1405
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001406
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001407static int init_types(void)
1408{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001409 PyObject *m;
1410 if (PyState_FindModule(&_astmodule) == NULL) {
1411 m = PyModule_Create(&_astmodule);
1412 if (!m) return 0;
1413 PyState_AddModule(m, &_astmodule);
1414 }
1415 astmodulestate *state = astmodulestate_global;
1416 if (state->initialized) return 1;
1417 if (init_identifiers() < 0) return 0;
1418 state->AST_type = PyType_FromSpec(&AST_type_spec);
1419 if (!state->AST_type) return 0;
1420 ((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object,
1421 dict);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001422 if (add_ast_fields() < 0) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001423 state->mod_type = make_type("mod", state->AST_type, NULL, 0);
1424 if (!state->mod_type) return 0;
1425 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
1426 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2);
1427 if (!state->Module_type) return 0;
1428 state->Interactive_type = make_type("Interactive", state->mod_type,
1429 Interactive_fields, 1);
1430 if (!state->Interactive_type) return 0;
1431 state->Expression_type = make_type("Expression", state->mod_type,
1432 Expression_fields, 1);
1433 if (!state->Expression_type) return 0;
1434 state->FunctionType_type = make_type("FunctionType", state->mod_type,
1435 FunctionType_fields, 2);
1436 if (!state->FunctionType_type) return 0;
1437 state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1);
1438 if (!state->Suite_type) return 0;
1439 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
1440 if (!state->stmt_type) return 0;
1441 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
1442 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1443 FunctionDef_fields, 6);
1444 if (!state->FunctionDef_type) return 0;
1445 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1446 state->stmt_type,
1447 AsyncFunctionDef_fields, 6);
1448 if (!state->AsyncFunctionDef_type) return 0;
1449 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1450 ClassDef_fields, 5);
1451 if (!state->ClassDef_type) return 0;
1452 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1453 1);
1454 if (!state->Return_type) return 0;
1455 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1456 1);
1457 if (!state->Delete_type) return 0;
1458 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1459 3);
1460 if (!state->Assign_type) return 0;
1461 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1462 AugAssign_fields, 3);
1463 if (!state->AugAssign_type) return 0;
1464 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1465 AnnAssign_fields, 4);
1466 if (!state->AnnAssign_type) return 0;
1467 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1468 if (!state->For_type) return 0;
1469 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1470 AsyncFor_fields, 5);
1471 if (!state->AsyncFor_type) return 0;
1472 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1473 if (!state->While_type) return 0;
1474 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1475 if (!state->If_type) return 0;
1476 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1477 if (!state->With_type) return 0;
1478 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1479 AsyncWith_fields, 3);
1480 if (!state->AsyncWith_type) return 0;
1481 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1482 if (!state->Raise_type) return 0;
1483 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1484 if (!state->Try_type) return 0;
1485 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1486 2);
1487 if (!state->Assert_type) return 0;
1488 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1489 1);
1490 if (!state->Import_type) return 0;
1491 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1492 ImportFrom_fields, 3);
1493 if (!state->ImportFrom_type) return 0;
1494 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1495 1);
1496 if (!state->Global_type) return 0;
1497 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1498 Nonlocal_fields, 1);
1499 if (!state->Nonlocal_type) return 0;
1500 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1501 if (!state->Expr_type) return 0;
1502 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1503 if (!state->Pass_type) return 0;
1504 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1505 if (!state->Break_type) return 0;
1506 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1507 if (!state->Continue_type) return 0;
1508 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1509 if (!state->expr_type) return 0;
1510 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
1511 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1512 2);
1513 if (!state->BoolOp_type) return 0;
1514 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1515 NamedExpr_fields, 2);
1516 if (!state->NamedExpr_type) return 0;
1517 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1518 if (!state->BinOp_type) return 0;
1519 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1520 UnaryOp_fields, 2);
1521 if (!state->UnaryOp_type) return 0;
1522 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1523 2);
1524 if (!state->Lambda_type) return 0;
1525 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1526 if (!state->IfExp_type) return 0;
1527 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1528 if (!state->Dict_type) return 0;
1529 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1530 if (!state->Set_type) return 0;
1531 state->ListComp_type = make_type("ListComp", state->expr_type,
1532 ListComp_fields, 2);
1533 if (!state->ListComp_type) return 0;
1534 state->SetComp_type = make_type("SetComp", state->expr_type,
1535 SetComp_fields, 2);
1536 if (!state->SetComp_type) return 0;
1537 state->DictComp_type = make_type("DictComp", state->expr_type,
1538 DictComp_fields, 3);
1539 if (!state->DictComp_type) return 0;
1540 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1541 GeneratorExp_fields, 2);
1542 if (!state->GeneratorExp_type) return 0;
1543 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1544 if (!state->Await_type) return 0;
1545 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1546 if (!state->Yield_type) return 0;
1547 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1548 YieldFrom_fields, 1);
1549 if (!state->YieldFrom_type) return 0;
1550 state->Compare_type = make_type("Compare", state->expr_type,
1551 Compare_fields, 3);
1552 if (!state->Compare_type) return 0;
1553 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1554 if (!state->Call_type) return 0;
1555 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1556 FormattedValue_fields, 3);
1557 if (!state->FormattedValue_type) return 0;
1558 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1559 JoinedStr_fields, 1);
1560 if (!state->JoinedStr_type) return 0;
1561 state->Constant_type = make_type("Constant", state->expr_type,
1562 Constant_fields, 2);
1563 if (!state->Constant_type) return 0;
1564 state->Attribute_type = make_type("Attribute", state->expr_type,
1565 Attribute_fields, 3);
1566 if (!state->Attribute_type) return 0;
1567 state->Subscript_type = make_type("Subscript", state->expr_type,
1568 Subscript_fields, 3);
1569 if (!state->Subscript_type) return 0;
1570 state->Starred_type = make_type("Starred", state->expr_type,
1571 Starred_fields, 2);
1572 if (!state->Starred_type) return 0;
1573 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1574 if (!state->Name_type) return 0;
1575 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1576 if (!state->List_type) return 0;
1577 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1578 if (!state->Tuple_type) return 0;
1579 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1580 0);
1581 if (!state->expr_context_type) return 0;
1582 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1583 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1584 if (!state->Load_type) return 0;
1585 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1586 NULL, NULL);
1587 if (!state->Load_singleton) return 0;
1588 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1589 if (!state->Store_type) return 0;
1590 state->Store_singleton = PyType_GenericNew((PyTypeObject
1591 *)state->Store_type, NULL, NULL);
1592 if (!state->Store_singleton) return 0;
1593 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1594 if (!state->Del_type) return 0;
1595 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1596 NULL, NULL);
1597 if (!state->Del_singleton) return 0;
1598 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1599 0);
1600 if (!state->AugLoad_type) return 0;
1601 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1602 *)state->AugLoad_type, NULL,
1603 NULL);
1604 if (!state->AugLoad_singleton) return 0;
1605 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1606 NULL, 0);
1607 if (!state->AugStore_type) return 0;
1608 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1609 *)state->AugStore_type, NULL,
1610 NULL);
1611 if (!state->AugStore_singleton) return 0;
1612 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1613 if (!state->Param_type) return 0;
1614 state->Param_singleton = PyType_GenericNew((PyTypeObject
1615 *)state->Param_type, NULL, NULL);
1616 if (!state->Param_singleton) return 0;
1617 state->slice_type = make_type("slice", state->AST_type, NULL, 0);
1618 if (!state->slice_type) return 0;
1619 if (!add_attributes(state->slice_type, NULL, 0)) return 0;
1620 state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3);
1621 if (!state->Slice_type) return 0;
1622 state->ExtSlice_type = make_type("ExtSlice", state->slice_type,
1623 ExtSlice_fields, 1);
1624 if (!state->ExtSlice_type) return 0;
1625 state->Index_type = make_type("Index", state->slice_type, Index_fields, 1);
1626 if (!state->Index_type) return 0;
1627 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1628 if (!state->boolop_type) return 0;
1629 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1630 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1631 if (!state->And_type) return 0;
1632 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1633 NULL, NULL);
1634 if (!state->And_singleton) return 0;
1635 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1636 if (!state->Or_type) return 0;
1637 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1638 NULL, NULL);
1639 if (!state->Or_singleton) return 0;
1640 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1641 if (!state->operator_type) return 0;
1642 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1643 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1644 if (!state->Add_type) return 0;
1645 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1646 NULL, NULL);
1647 if (!state->Add_singleton) return 0;
1648 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1649 if (!state->Sub_type) return 0;
1650 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1651 NULL, NULL);
1652 if (!state->Sub_singleton) return 0;
1653 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1654 if (!state->Mult_type) return 0;
1655 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1656 NULL, NULL);
1657 if (!state->Mult_singleton) return 0;
1658 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1659 if (!state->MatMult_type) return 0;
1660 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1661 *)state->MatMult_type, NULL,
1662 NULL);
1663 if (!state->MatMult_singleton) return 0;
1664 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1665 if (!state->Div_type) return 0;
1666 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1667 NULL, NULL);
1668 if (!state->Div_singleton) return 0;
1669 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1670 if (!state->Mod_type) return 0;
1671 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1672 NULL, NULL);
1673 if (!state->Mod_singleton) return 0;
1674 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1675 if (!state->Pow_type) return 0;
1676 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1677 NULL, NULL);
1678 if (!state->Pow_singleton) return 0;
1679 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1680 if (!state->LShift_type) return 0;
1681 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1682 *)state->LShift_type, NULL,
1683 NULL);
1684 if (!state->LShift_singleton) return 0;
1685 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1686 if (!state->RShift_type) return 0;
1687 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1688 *)state->RShift_type, NULL,
1689 NULL);
1690 if (!state->RShift_singleton) return 0;
1691 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1692 if (!state->BitOr_type) return 0;
1693 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1694 *)state->BitOr_type, NULL, NULL);
1695 if (!state->BitOr_singleton) return 0;
1696 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1697 if (!state->BitXor_type) return 0;
1698 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1699 *)state->BitXor_type, NULL,
1700 NULL);
1701 if (!state->BitXor_singleton) return 0;
1702 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1703 if (!state->BitAnd_type) return 0;
1704 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1705 *)state->BitAnd_type, NULL,
1706 NULL);
1707 if (!state->BitAnd_singleton) return 0;
1708 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1709 if (!state->FloorDiv_type) return 0;
1710 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1711 *)state->FloorDiv_type, NULL,
1712 NULL);
1713 if (!state->FloorDiv_singleton) return 0;
1714 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1715 if (!state->unaryop_type) return 0;
1716 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1717 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1718 if (!state->Invert_type) return 0;
1719 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1720 *)state->Invert_type, NULL,
1721 NULL);
1722 if (!state->Invert_singleton) return 0;
1723 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1724 if (!state->Not_type) return 0;
1725 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1726 NULL, NULL);
1727 if (!state->Not_singleton) return 0;
1728 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1729 if (!state->UAdd_type) return 0;
1730 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1731 NULL, NULL);
1732 if (!state->UAdd_singleton) return 0;
1733 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1734 if (!state->USub_type) return 0;
1735 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1736 NULL, NULL);
1737 if (!state->USub_singleton) return 0;
1738 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1739 if (!state->cmpop_type) return 0;
1740 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1741 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1742 if (!state->Eq_type) return 0;
1743 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1744 NULL, NULL);
1745 if (!state->Eq_singleton) return 0;
1746 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1747 if (!state->NotEq_type) return 0;
1748 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1749 *)state->NotEq_type, NULL, NULL);
1750 if (!state->NotEq_singleton) return 0;
1751 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1752 if (!state->Lt_type) return 0;
1753 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1754 NULL, NULL);
1755 if (!state->Lt_singleton) return 0;
1756 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1757 if (!state->LtE_type) return 0;
1758 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1759 NULL, NULL);
1760 if (!state->LtE_singleton) return 0;
1761 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1762 if (!state->Gt_type) return 0;
1763 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1764 NULL, NULL);
1765 if (!state->Gt_singleton) return 0;
1766 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1767 if (!state->GtE_type) return 0;
1768 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1769 NULL, NULL);
1770 if (!state->GtE_singleton) return 0;
1771 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1772 if (!state->Is_type) return 0;
1773 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1774 NULL, NULL);
1775 if (!state->Is_singleton) return 0;
1776 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1777 if (!state->IsNot_type) return 0;
1778 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1779 *)state->IsNot_type, NULL, NULL);
1780 if (!state->IsNot_singleton) return 0;
1781 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1782 if (!state->In_type) return 0;
1783 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1784 NULL, NULL);
1785 if (!state->In_singleton) return 0;
1786 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1787 if (!state->NotIn_type) return 0;
1788 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1789 *)state->NotIn_type, NULL, NULL);
1790 if (!state->NotIn_singleton) return 0;
1791 state->comprehension_type = make_type("comprehension", state->AST_type,
1792 comprehension_fields, 4);
1793 if (!state->comprehension_type) return 0;
1794 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1795 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1796 NULL, 0);
1797 if (!state->excepthandler_type) return 0;
1798 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1799 4)) return 0;
1800 state->ExceptHandler_type = make_type("ExceptHandler",
1801 state->excepthandler_type,
1802 ExceptHandler_fields, 3);
1803 if (!state->ExceptHandler_type) return 0;
1804 state->arguments_type = make_type("arguments", state->AST_type,
1805 arguments_fields, 7);
1806 if (!state->arguments_type) return 0;
1807 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
1808 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1809 if (!state->arg_type) return 0;
1810 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
1811 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1812 2);
1813 if (!state->keyword_type) return 0;
1814 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
1815 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1816 if (!state->alias_type) return 0;
1817 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
1818 state->withitem_type = make_type("withitem", state->AST_type,
1819 withitem_fields, 2);
1820 if (!state->withitem_type) return 0;
1821 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
1822 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1823 0);
1824 if (!state->type_ignore_type) return 0;
1825 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1826 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1827 TypeIgnore_fields, 2);
1828 if (!state->TypeIgnore_type) return 0;
1829 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001830 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001831}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001832
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001833static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1834static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1835static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1836static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1837 arena);
1838static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1839static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1840static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1841static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1842static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1843static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1844 arena);
1845static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1846 arena);
1847static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1848static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1849static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1850static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001851static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001852static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1853 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001854
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001856Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001857{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001858 mod_ty p;
1859 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1860 if (!p)
1861 return NULL;
1862 p->kind = Module_kind;
1863 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001864 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001865 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866}
1867
1868mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001869Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001871 mod_ty p;
1872 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1873 if (!p)
1874 return NULL;
1875 p->kind = Interactive_kind;
1876 p->v.Interactive.body = body;
1877 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001878}
1879
1880mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001881Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001883 mod_ty p;
1884 if (!body) {
1885 PyErr_SetString(PyExc_ValueError,
1886 "field body is required for Expression");
1887 return NULL;
1888 }
1889 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1890 if (!p)
1891 return NULL;
1892 p->kind = Expression_kind;
1893 p->v.Expression.body = body;
1894 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001895}
1896
1897mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001898FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1899{
1900 mod_ty p;
1901 if (!returns) {
1902 PyErr_SetString(PyExc_ValueError,
1903 "field returns is required for FunctionType");
1904 return NULL;
1905 }
1906 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1907 if (!p)
1908 return NULL;
1909 p->kind = FunctionType_kind;
1910 p->v.FunctionType.argtypes = argtypes;
1911 p->v.FunctionType.returns = returns;
1912 return p;
1913}
1914
1915mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001916Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001917{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001918 mod_ty p;
1919 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1920 if (!p)
1921 return NULL;
1922 p->kind = Suite_kind;
1923 p->v.Suite.body = body;
1924 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001925}
1926
1927stmt_ty
1928FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001929 decorator_list, expr_ty returns, string type_comment, int lineno,
1930 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001931{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001932 stmt_ty p;
1933 if (!name) {
1934 PyErr_SetString(PyExc_ValueError,
1935 "field name is required for FunctionDef");
1936 return NULL;
1937 }
1938 if (!args) {
1939 PyErr_SetString(PyExc_ValueError,
1940 "field args is required for FunctionDef");
1941 return NULL;
1942 }
1943 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1944 if (!p)
1945 return NULL;
1946 p->kind = FunctionDef_kind;
1947 p->v.FunctionDef.name = name;
1948 p->v.FunctionDef.args = args;
1949 p->v.FunctionDef.body = body;
1950 p->v.FunctionDef.decorator_list = decorator_list;
1951 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001952 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001953 p->lineno = lineno;
1954 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001955 p->end_lineno = end_lineno;
1956 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001957 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001958}
1959
1960stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001961AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001962 * decorator_list, expr_ty returns, string type_comment, int
1963 lineno, int col_offset, int end_lineno, int end_col_offset,
1964 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001965{
1966 stmt_ty p;
1967 if (!name) {
1968 PyErr_SetString(PyExc_ValueError,
1969 "field name is required for AsyncFunctionDef");
1970 return NULL;
1971 }
1972 if (!args) {
1973 PyErr_SetString(PyExc_ValueError,
1974 "field args is required for AsyncFunctionDef");
1975 return NULL;
1976 }
1977 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1978 if (!p)
1979 return NULL;
1980 p->kind = AsyncFunctionDef_kind;
1981 p->v.AsyncFunctionDef.name = name;
1982 p->v.AsyncFunctionDef.args = args;
1983 p->v.AsyncFunctionDef.body = body;
1984 p->v.AsyncFunctionDef.decorator_list = decorator_list;
1985 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001986 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04001987 p->lineno = lineno;
1988 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001989 p->end_lineno = end_lineno;
1990 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04001991 return p;
1992}
1993
1994stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04001995ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001996 body, asdl_seq * decorator_list, int lineno, int col_offset, int
1997 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001998{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001999 stmt_ty p;
2000 if (!name) {
2001 PyErr_SetString(PyExc_ValueError,
2002 "field name is required for ClassDef");
2003 return NULL;
2004 }
2005 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2006 if (!p)
2007 return NULL;
2008 p->kind = ClassDef_kind;
2009 p->v.ClassDef.name = name;
2010 p->v.ClassDef.bases = bases;
2011 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002012 p->v.ClassDef.body = body;
2013 p->v.ClassDef.decorator_list = decorator_list;
2014 p->lineno = lineno;
2015 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002016 p->end_lineno = end_lineno;
2017 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002018 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002019}
2020
2021stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002022Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2023 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002024{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002025 stmt_ty p;
2026 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2027 if (!p)
2028 return NULL;
2029 p->kind = Return_kind;
2030 p->v.Return.value = value;
2031 p->lineno = lineno;
2032 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002033 p->end_lineno = end_lineno;
2034 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002035 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002036}
2037
2038stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002039Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2040 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002041{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002042 stmt_ty p;
2043 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2044 if (!p)
2045 return NULL;
2046 p->kind = Delete_kind;
2047 p->v.Delete.targets = targets;
2048 p->lineno = lineno;
2049 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002050 p->end_lineno = end_lineno;
2051 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002052 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002053}
2054
2055stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002056Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2057 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002058{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002059 stmt_ty p;
2060 if (!value) {
2061 PyErr_SetString(PyExc_ValueError,
2062 "field value is required for Assign");
2063 return NULL;
2064 }
2065 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2066 if (!p)
2067 return NULL;
2068 p->kind = Assign_kind;
2069 p->v.Assign.targets = targets;
2070 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002071 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002072 p->lineno = lineno;
2073 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002074 p->end_lineno = end_lineno;
2075 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002076 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002077}
2078
2079stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002080AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002081 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002082{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002083 stmt_ty p;
2084 if (!target) {
2085 PyErr_SetString(PyExc_ValueError,
2086 "field target is required for AugAssign");
2087 return NULL;
2088 }
2089 if (!op) {
2090 PyErr_SetString(PyExc_ValueError,
2091 "field op is required for AugAssign");
2092 return NULL;
2093 }
2094 if (!value) {
2095 PyErr_SetString(PyExc_ValueError,
2096 "field value is required for AugAssign");
2097 return NULL;
2098 }
2099 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2100 if (!p)
2101 return NULL;
2102 p->kind = AugAssign_kind;
2103 p->v.AugAssign.target = target;
2104 p->v.AugAssign.op = op;
2105 p->v.AugAssign.value = value;
2106 p->lineno = lineno;
2107 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002108 p->end_lineno = end_lineno;
2109 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002110 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002111}
2112
2113stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002114AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002115 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2116 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002117{
2118 stmt_ty p;
2119 if (!target) {
2120 PyErr_SetString(PyExc_ValueError,
2121 "field target is required for AnnAssign");
2122 return NULL;
2123 }
2124 if (!annotation) {
2125 PyErr_SetString(PyExc_ValueError,
2126 "field annotation is required for AnnAssign");
2127 return NULL;
2128 }
2129 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2130 if (!p)
2131 return NULL;
2132 p->kind = AnnAssign_kind;
2133 p->v.AnnAssign.target = target;
2134 p->v.AnnAssign.annotation = annotation;
2135 p->v.AnnAssign.value = value;
2136 p->v.AnnAssign.simple = simple;
2137 p->lineno = lineno;
2138 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002139 p->end_lineno = end_lineno;
2140 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002141 return p;
2142}
2143
2144stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002145For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2146 type_comment, int lineno, int col_offset, int end_lineno, int
2147 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002148{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002149 stmt_ty p;
2150 if (!target) {
2151 PyErr_SetString(PyExc_ValueError,
2152 "field target is required for For");
2153 return NULL;
2154 }
2155 if (!iter) {
2156 PyErr_SetString(PyExc_ValueError,
2157 "field iter is required for For");
2158 return NULL;
2159 }
2160 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2161 if (!p)
2162 return NULL;
2163 p->kind = For_kind;
2164 p->v.For.target = target;
2165 p->v.For.iter = iter;
2166 p->v.For.body = body;
2167 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002168 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002169 p->lineno = lineno;
2170 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002171 p->end_lineno = end_lineno;
2172 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002173 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002174}
2175
2176stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002177AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2178 string type_comment, int lineno, int col_offset, int end_lineno, int
2179 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002180{
2181 stmt_ty p;
2182 if (!target) {
2183 PyErr_SetString(PyExc_ValueError,
2184 "field target is required for AsyncFor");
2185 return NULL;
2186 }
2187 if (!iter) {
2188 PyErr_SetString(PyExc_ValueError,
2189 "field iter is required for AsyncFor");
2190 return NULL;
2191 }
2192 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2193 if (!p)
2194 return NULL;
2195 p->kind = AsyncFor_kind;
2196 p->v.AsyncFor.target = target;
2197 p->v.AsyncFor.iter = iter;
2198 p->v.AsyncFor.body = body;
2199 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002200 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002201 p->lineno = lineno;
2202 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002203 p->end_lineno = end_lineno;
2204 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002205 return p;
2206}
2207
2208stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002209While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002210 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002211{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002212 stmt_ty p;
2213 if (!test) {
2214 PyErr_SetString(PyExc_ValueError,
2215 "field test is required for While");
2216 return NULL;
2217 }
2218 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2219 if (!p)
2220 return NULL;
2221 p->kind = While_kind;
2222 p->v.While.test = test;
2223 p->v.While.body = body;
2224 p->v.While.orelse = orelse;
2225 p->lineno = lineno;
2226 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002227 p->end_lineno = end_lineno;
2228 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002229 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002230}
2231
2232stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002233If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002234 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002235{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002236 stmt_ty p;
2237 if (!test) {
2238 PyErr_SetString(PyExc_ValueError,
2239 "field test is required for If");
2240 return NULL;
2241 }
2242 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2243 if (!p)
2244 return NULL;
2245 p->kind = If_kind;
2246 p->v.If.test = test;
2247 p->v.If.body = body;
2248 p->v.If.orelse = orelse;
2249 p->lineno = lineno;
2250 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002251 p->end_lineno = end_lineno;
2252 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002253 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002254}
2255
2256stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002257With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2258 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002259{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002260 stmt_ty p;
2261 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2262 if (!p)
2263 return NULL;
2264 p->kind = With_kind;
2265 p->v.With.items = items;
2266 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002267 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002268 p->lineno = lineno;
2269 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002270 p->end_lineno = end_lineno;
2271 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002272 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002273}
2274
2275stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002276AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2277 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002278{
2279 stmt_ty p;
2280 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2281 if (!p)
2282 return NULL;
2283 p->kind = AsyncWith_kind;
2284 p->v.AsyncWith.items = items;
2285 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002286 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002287 p->lineno = lineno;
2288 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002289 p->end_lineno = end_lineno;
2290 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002291 return p;
2292}
2293
2294stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002295Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2296 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002297{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002298 stmt_ty p;
2299 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2300 if (!p)
2301 return NULL;
2302 p->kind = Raise_kind;
2303 p->v.Raise.exc = exc;
2304 p->v.Raise.cause = cause;
2305 p->lineno = lineno;
2306 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002307 p->end_lineno = end_lineno;
2308 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002309 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002310}
2311
2312stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002313Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002314 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2315 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002316{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002317 stmt_ty p;
2318 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2319 if (!p)
2320 return NULL;
2321 p->kind = Try_kind;
2322 p->v.Try.body = body;
2323 p->v.Try.handlers = handlers;
2324 p->v.Try.orelse = orelse;
2325 p->v.Try.finalbody = finalbody;
2326 p->lineno = lineno;
2327 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002328 p->end_lineno = end_lineno;
2329 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002330 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002331}
2332
2333stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002334Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2335 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002336{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002337 stmt_ty p;
2338 if (!test) {
2339 PyErr_SetString(PyExc_ValueError,
2340 "field test is required for Assert");
2341 return NULL;
2342 }
2343 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2344 if (!p)
2345 return NULL;
2346 p->kind = Assert_kind;
2347 p->v.Assert.test = test;
2348 p->v.Assert.msg = msg;
2349 p->lineno = lineno;
2350 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002351 p->end_lineno = end_lineno;
2352 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002353 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002354}
2355
2356stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002357Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2358 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002359{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002360 stmt_ty p;
2361 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2362 if (!p)
2363 return NULL;
2364 p->kind = Import_kind;
2365 p->v.Import.names = names;
2366 p->lineno = lineno;
2367 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002368 p->end_lineno = end_lineno;
2369 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002370 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002371}
2372
2373stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002374ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002375 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002376{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002377 stmt_ty p;
2378 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2379 if (!p)
2380 return NULL;
2381 p->kind = ImportFrom_kind;
2382 p->v.ImportFrom.module = module;
2383 p->v.ImportFrom.names = names;
2384 p->v.ImportFrom.level = level;
2385 p->lineno = lineno;
2386 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002387 p->end_lineno = end_lineno;
2388 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002389 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002390}
2391
2392stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002393Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2394 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002395{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002396 stmt_ty p;
2397 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2398 if (!p)
2399 return NULL;
2400 p->kind = Global_kind;
2401 p->v.Global.names = names;
2402 p->lineno = lineno;
2403 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002404 p->end_lineno = end_lineno;
2405 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002406 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002407}
2408
2409stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002410Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2411 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002412{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002413 stmt_ty p;
2414 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2415 if (!p)
2416 return NULL;
2417 p->kind = Nonlocal_kind;
2418 p->v.Nonlocal.names = names;
2419 p->lineno = lineno;
2420 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002421 p->end_lineno = end_lineno;
2422 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002423 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002424}
2425
2426stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002427Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2428 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002429{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002430 stmt_ty p;
2431 if (!value) {
2432 PyErr_SetString(PyExc_ValueError,
2433 "field value is required for Expr");
2434 return NULL;
2435 }
2436 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2437 if (!p)
2438 return NULL;
2439 p->kind = Expr_kind;
2440 p->v.Expr.value = value;
2441 p->lineno = lineno;
2442 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002443 p->end_lineno = end_lineno;
2444 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002445 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002446}
2447
2448stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002449Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2450 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002451{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002452 stmt_ty p;
2453 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2454 if (!p)
2455 return NULL;
2456 p->kind = Pass_kind;
2457 p->lineno = lineno;
2458 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002459 p->end_lineno = end_lineno;
2460 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002461 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002462}
2463
2464stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002465Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2466 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002467{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002468 stmt_ty p;
2469 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2470 if (!p)
2471 return NULL;
2472 p->kind = Break_kind;
2473 p->lineno = lineno;
2474 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002475 p->end_lineno = end_lineno;
2476 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002477 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002478}
2479
2480stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002481Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2482 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002483{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002484 stmt_ty p;
2485 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2486 if (!p)
2487 return NULL;
2488 p->kind = Continue_kind;
2489 p->lineno = lineno;
2490 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002491 p->end_lineno = end_lineno;
2492 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002493 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002494}
2495
2496expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002497BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2498 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002499{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002500 expr_ty p;
2501 if (!op) {
2502 PyErr_SetString(PyExc_ValueError,
2503 "field op is required for BoolOp");
2504 return NULL;
2505 }
2506 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2507 if (!p)
2508 return NULL;
2509 p->kind = BoolOp_kind;
2510 p->v.BoolOp.op = op;
2511 p->v.BoolOp.values = values;
2512 p->lineno = lineno;
2513 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002514 p->end_lineno = end_lineno;
2515 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002516 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002517}
2518
2519expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002520NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2521 end_lineno, int end_col_offset, PyArena *arena)
2522{
2523 expr_ty p;
2524 if (!target) {
2525 PyErr_SetString(PyExc_ValueError,
2526 "field target is required for NamedExpr");
2527 return NULL;
2528 }
2529 if (!value) {
2530 PyErr_SetString(PyExc_ValueError,
2531 "field value is required for NamedExpr");
2532 return NULL;
2533 }
2534 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2535 if (!p)
2536 return NULL;
2537 p->kind = NamedExpr_kind;
2538 p->v.NamedExpr.target = target;
2539 p->v.NamedExpr.value = value;
2540 p->lineno = lineno;
2541 p->col_offset = col_offset;
2542 p->end_lineno = end_lineno;
2543 p->end_col_offset = end_col_offset;
2544 return p;
2545}
2546
2547expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002548BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002549 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002550{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002551 expr_ty p;
2552 if (!left) {
2553 PyErr_SetString(PyExc_ValueError,
2554 "field left is required for BinOp");
2555 return NULL;
2556 }
2557 if (!op) {
2558 PyErr_SetString(PyExc_ValueError,
2559 "field op is required for BinOp");
2560 return NULL;
2561 }
2562 if (!right) {
2563 PyErr_SetString(PyExc_ValueError,
2564 "field right is required for BinOp");
2565 return NULL;
2566 }
2567 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2568 if (!p)
2569 return NULL;
2570 p->kind = BinOp_kind;
2571 p->v.BinOp.left = left;
2572 p->v.BinOp.op = op;
2573 p->v.BinOp.right = right;
2574 p->lineno = lineno;
2575 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002576 p->end_lineno = end_lineno;
2577 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002578 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002579}
2580
2581expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002582UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2583 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002584{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002585 expr_ty p;
2586 if (!op) {
2587 PyErr_SetString(PyExc_ValueError,
2588 "field op is required for UnaryOp");
2589 return NULL;
2590 }
2591 if (!operand) {
2592 PyErr_SetString(PyExc_ValueError,
2593 "field operand is required for UnaryOp");
2594 return NULL;
2595 }
2596 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2597 if (!p)
2598 return NULL;
2599 p->kind = UnaryOp_kind;
2600 p->v.UnaryOp.op = op;
2601 p->v.UnaryOp.operand = operand;
2602 p->lineno = lineno;
2603 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002604 p->end_lineno = end_lineno;
2605 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002606 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002607}
2608
2609expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002610Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2611 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002612{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002613 expr_ty p;
2614 if (!args) {
2615 PyErr_SetString(PyExc_ValueError,
2616 "field args is required for Lambda");
2617 return NULL;
2618 }
2619 if (!body) {
2620 PyErr_SetString(PyExc_ValueError,
2621 "field body is required for Lambda");
2622 return NULL;
2623 }
2624 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2625 if (!p)
2626 return NULL;
2627 p->kind = Lambda_kind;
2628 p->v.Lambda.args = args;
2629 p->v.Lambda.body = body;
2630 p->lineno = lineno;
2631 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002632 p->end_lineno = end_lineno;
2633 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002634 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002635}
2636
2637expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002638IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002639 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002640{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002641 expr_ty p;
2642 if (!test) {
2643 PyErr_SetString(PyExc_ValueError,
2644 "field test is required for IfExp");
2645 return NULL;
2646 }
2647 if (!body) {
2648 PyErr_SetString(PyExc_ValueError,
2649 "field body is required for IfExp");
2650 return NULL;
2651 }
2652 if (!orelse) {
2653 PyErr_SetString(PyExc_ValueError,
2654 "field orelse is required for IfExp");
2655 return NULL;
2656 }
2657 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2658 if (!p)
2659 return NULL;
2660 p->kind = IfExp_kind;
2661 p->v.IfExp.test = test;
2662 p->v.IfExp.body = body;
2663 p->v.IfExp.orelse = orelse;
2664 p->lineno = lineno;
2665 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002666 p->end_lineno = end_lineno;
2667 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002668 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002669}
2670
2671expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002672Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2673 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002674{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002675 expr_ty p;
2676 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2677 if (!p)
2678 return NULL;
2679 p->kind = Dict_kind;
2680 p->v.Dict.keys = keys;
2681 p->v.Dict.values = values;
2682 p->lineno = lineno;
2683 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002684 p->end_lineno = end_lineno;
2685 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002686 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002687}
2688
2689expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002690Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2691 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002692{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002693 expr_ty p;
2694 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2695 if (!p)
2696 return NULL;
2697 p->kind = Set_kind;
2698 p->v.Set.elts = elts;
2699 p->lineno = lineno;
2700 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002701 p->end_lineno = end_lineno;
2702 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002703 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002704}
2705
2706expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002707ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2708 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002709{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002710 expr_ty p;
2711 if (!elt) {
2712 PyErr_SetString(PyExc_ValueError,
2713 "field elt is required for ListComp");
2714 return NULL;
2715 }
2716 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2717 if (!p)
2718 return NULL;
2719 p->kind = ListComp_kind;
2720 p->v.ListComp.elt = elt;
2721 p->v.ListComp.generators = generators;
2722 p->lineno = lineno;
2723 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002724 p->end_lineno = end_lineno;
2725 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002726 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002727}
2728
2729expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002730SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2731 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002732{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002733 expr_ty p;
2734 if (!elt) {
2735 PyErr_SetString(PyExc_ValueError,
2736 "field elt is required for SetComp");
2737 return NULL;
2738 }
2739 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2740 if (!p)
2741 return NULL;
2742 p->kind = SetComp_kind;
2743 p->v.SetComp.elt = elt;
2744 p->v.SetComp.generators = generators;
2745 p->lineno = lineno;
2746 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002747 p->end_lineno = end_lineno;
2748 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002749 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002750}
2751
2752expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002753DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002754 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002755{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002756 expr_ty p;
2757 if (!key) {
2758 PyErr_SetString(PyExc_ValueError,
2759 "field key is required for DictComp");
2760 return NULL;
2761 }
2762 if (!value) {
2763 PyErr_SetString(PyExc_ValueError,
2764 "field value is required for DictComp");
2765 return NULL;
2766 }
2767 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2768 if (!p)
2769 return NULL;
2770 p->kind = DictComp_kind;
2771 p->v.DictComp.key = key;
2772 p->v.DictComp.value = value;
2773 p->v.DictComp.generators = generators;
2774 p->lineno = lineno;
2775 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002776 p->end_lineno = end_lineno;
2777 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002778 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002779}
2780
2781expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002782GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002783 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002784{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002785 expr_ty p;
2786 if (!elt) {
2787 PyErr_SetString(PyExc_ValueError,
2788 "field elt is required for GeneratorExp");
2789 return NULL;
2790 }
2791 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2792 if (!p)
2793 return NULL;
2794 p->kind = GeneratorExp_kind;
2795 p->v.GeneratorExp.elt = elt;
2796 p->v.GeneratorExp.generators = generators;
2797 p->lineno = lineno;
2798 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002799 p->end_lineno = end_lineno;
2800 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002801 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002802}
2803
2804expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002805Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2806 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002807{
2808 expr_ty p;
2809 if (!value) {
2810 PyErr_SetString(PyExc_ValueError,
2811 "field value is required for Await");
2812 return NULL;
2813 }
2814 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2815 if (!p)
2816 return NULL;
2817 p->kind = Await_kind;
2818 p->v.Await.value = value;
2819 p->lineno = lineno;
2820 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002821 p->end_lineno = end_lineno;
2822 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002823 return p;
2824}
2825
2826expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002827Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2828 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002829{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002830 expr_ty p;
2831 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2832 if (!p)
2833 return NULL;
2834 p->kind = Yield_kind;
2835 p->v.Yield.value = value;
2836 p->lineno = lineno;
2837 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002838 p->end_lineno = end_lineno;
2839 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002840 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002841}
2842
2843expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002844YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2845 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002846{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002847 expr_ty p;
2848 if (!value) {
2849 PyErr_SetString(PyExc_ValueError,
2850 "field value is required for YieldFrom");
2851 return NULL;
2852 }
2853 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2854 if (!p)
2855 return NULL;
2856 p->kind = YieldFrom_kind;
2857 p->v.YieldFrom.value = value;
2858 p->lineno = lineno;
2859 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002860 p->end_lineno = end_lineno;
2861 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002862 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002863}
2864
2865expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002866Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002867 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002868{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002869 expr_ty p;
2870 if (!left) {
2871 PyErr_SetString(PyExc_ValueError,
2872 "field left is required for Compare");
2873 return NULL;
2874 }
2875 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2876 if (!p)
2877 return NULL;
2878 p->kind = Compare_kind;
2879 p->v.Compare.left = left;
2880 p->v.Compare.ops = ops;
2881 p->v.Compare.comparators = comparators;
2882 p->lineno = lineno;
2883 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002884 p->end_lineno = end_lineno;
2885 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002886 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002887}
2888
2889expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002890Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002891 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002892{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002893 expr_ty p;
2894 if (!func) {
2895 PyErr_SetString(PyExc_ValueError,
2896 "field func is required for Call");
2897 return NULL;
2898 }
2899 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2900 if (!p)
2901 return NULL;
2902 p->kind = Call_kind;
2903 p->v.Call.func = func;
2904 p->v.Call.args = args;
2905 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002906 p->lineno = lineno;
2907 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002908 p->end_lineno = end_lineno;
2909 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002910 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002911}
2912
2913expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002914FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2915 int col_offset, int end_lineno, int end_col_offset, PyArena
2916 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002917{
2918 expr_ty p;
2919 if (!value) {
2920 PyErr_SetString(PyExc_ValueError,
2921 "field value is required for FormattedValue");
2922 return NULL;
2923 }
2924 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2925 if (!p)
2926 return NULL;
2927 p->kind = FormattedValue_kind;
2928 p->v.FormattedValue.value = value;
2929 p->v.FormattedValue.conversion = conversion;
2930 p->v.FormattedValue.format_spec = format_spec;
2931 p->lineno = lineno;
2932 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002933 p->end_lineno = end_lineno;
2934 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002935 return p;
2936}
2937
2938expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002939JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2940 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002941{
2942 expr_ty p;
2943 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2944 if (!p)
2945 return NULL;
2946 p->kind = JoinedStr_kind;
2947 p->v.JoinedStr.values = values;
2948 p->lineno = lineno;
2949 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002950 p->end_lineno = end_lineno;
2951 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002952 return p;
2953}
2954
2955expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002956Constant(constant value, string kind, int lineno, int col_offset, int
2957 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002958{
2959 expr_ty p;
2960 if (!value) {
2961 PyErr_SetString(PyExc_ValueError,
2962 "field value is required for Constant");
2963 return NULL;
2964 }
2965 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2966 if (!p)
2967 return NULL;
2968 p->kind = Constant_kind;
2969 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002970 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002971 p->lineno = lineno;
2972 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002973 p->end_lineno = end_lineno;
2974 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002975 return p;
2976}
2977
2978expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002979Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002980 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002981{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002982 expr_ty p;
2983 if (!value) {
2984 PyErr_SetString(PyExc_ValueError,
2985 "field value is required for Attribute");
2986 return NULL;
2987 }
2988 if (!attr) {
2989 PyErr_SetString(PyExc_ValueError,
2990 "field attr is required for Attribute");
2991 return NULL;
2992 }
2993 if (!ctx) {
2994 PyErr_SetString(PyExc_ValueError,
2995 "field ctx is required for Attribute");
2996 return NULL;
2997 }
2998 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2999 if (!p)
3000 return NULL;
3001 p->kind = Attribute_kind;
3002 p->v.Attribute.value = value;
3003 p->v.Attribute.attr = attr;
3004 p->v.Attribute.ctx = ctx;
3005 p->lineno = lineno;
3006 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003007 p->end_lineno = end_lineno;
3008 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003009 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003010}
3011
3012expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003013Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003014 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003015{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003016 expr_ty p;
3017 if (!value) {
3018 PyErr_SetString(PyExc_ValueError,
3019 "field value is required for Subscript");
3020 return NULL;
3021 }
3022 if (!slice) {
3023 PyErr_SetString(PyExc_ValueError,
3024 "field slice is required for Subscript");
3025 return NULL;
3026 }
3027 if (!ctx) {
3028 PyErr_SetString(PyExc_ValueError,
3029 "field ctx is required for Subscript");
3030 return NULL;
3031 }
3032 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3033 if (!p)
3034 return NULL;
3035 p->kind = Subscript_kind;
3036 p->v.Subscript.value = value;
3037 p->v.Subscript.slice = slice;
3038 p->v.Subscript.ctx = ctx;
3039 p->lineno = lineno;
3040 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003041 p->end_lineno = end_lineno;
3042 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003043 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003044}
3045
3046expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003047Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3048 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003049{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003050 expr_ty p;
3051 if (!value) {
3052 PyErr_SetString(PyExc_ValueError,
3053 "field value is required for Starred");
3054 return NULL;
3055 }
3056 if (!ctx) {
3057 PyErr_SetString(PyExc_ValueError,
3058 "field ctx is required for Starred");
3059 return NULL;
3060 }
3061 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3062 if (!p)
3063 return NULL;
3064 p->kind = Starred_kind;
3065 p->v.Starred.value = value;
3066 p->v.Starred.ctx = ctx;
3067 p->lineno = lineno;
3068 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003069 p->end_lineno = end_lineno;
3070 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003071 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003072}
3073
3074expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003075Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3076 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003077{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003078 expr_ty p;
3079 if (!id) {
3080 PyErr_SetString(PyExc_ValueError,
3081 "field id is required for Name");
3082 return NULL;
3083 }
3084 if (!ctx) {
3085 PyErr_SetString(PyExc_ValueError,
3086 "field ctx is required for Name");
3087 return NULL;
3088 }
3089 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3090 if (!p)
3091 return NULL;
3092 p->kind = Name_kind;
3093 p->v.Name.id = id;
3094 p->v.Name.ctx = ctx;
3095 p->lineno = lineno;
3096 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003097 p->end_lineno = end_lineno;
3098 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003099 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003100}
3101
3102expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003103List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3104 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003105{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003106 expr_ty p;
3107 if (!ctx) {
3108 PyErr_SetString(PyExc_ValueError,
3109 "field ctx is required for List");
3110 return NULL;
3111 }
3112 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3113 if (!p)
3114 return NULL;
3115 p->kind = List_kind;
3116 p->v.List.elts = elts;
3117 p->v.List.ctx = ctx;
3118 p->lineno = lineno;
3119 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003120 p->end_lineno = end_lineno;
3121 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003122 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003123}
3124
3125expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003126Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3127 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003128{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003129 expr_ty p;
3130 if (!ctx) {
3131 PyErr_SetString(PyExc_ValueError,
3132 "field ctx is required for Tuple");
3133 return NULL;
3134 }
3135 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3136 if (!p)
3137 return NULL;
3138 p->kind = Tuple_kind;
3139 p->v.Tuple.elts = elts;
3140 p->v.Tuple.ctx = ctx;
3141 p->lineno = lineno;
3142 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003143 p->end_lineno = end_lineno;
3144 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003145 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003146}
3147
3148slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003149Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003150{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003151 slice_ty p;
3152 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3153 if (!p)
3154 return NULL;
3155 p->kind = Slice_kind;
3156 p->v.Slice.lower = lower;
3157 p->v.Slice.upper = upper;
3158 p->v.Slice.step = step;
3159 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003160}
3161
3162slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003163ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003164{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003165 slice_ty p;
3166 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3167 if (!p)
3168 return NULL;
3169 p->kind = ExtSlice_kind;
3170 p->v.ExtSlice.dims = dims;
3171 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003172}
3173
3174slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003175Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003176{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003177 slice_ty p;
3178 if (!value) {
3179 PyErr_SetString(PyExc_ValueError,
3180 "field value is required for Index");
3181 return NULL;
3182 }
3183 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3184 if (!p)
3185 return NULL;
3186 p->kind = Index_kind;
3187 p->v.Index.value = value;
3188 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003189}
3190
3191comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003192comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3193 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003194{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003195 comprehension_ty p;
3196 if (!target) {
3197 PyErr_SetString(PyExc_ValueError,
3198 "field target is required for comprehension");
3199 return NULL;
3200 }
3201 if (!iter) {
3202 PyErr_SetString(PyExc_ValueError,
3203 "field iter is required for comprehension");
3204 return NULL;
3205 }
3206 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3207 if (!p)
3208 return NULL;
3209 p->target = target;
3210 p->iter = iter;
3211 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003212 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003213 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003214}
3215
3216excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003217ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003218 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003219{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003220 excepthandler_ty p;
3221 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3222 if (!p)
3223 return NULL;
3224 p->kind = ExceptHandler_kind;
3225 p->v.ExceptHandler.type = type;
3226 p->v.ExceptHandler.name = name;
3227 p->v.ExceptHandler.body = body;
3228 p->lineno = lineno;
3229 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003230 p->end_lineno = end_lineno;
3231 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003232 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003233}
3234
3235arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003236arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003237 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3238 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003239{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003240 arguments_ty p;
3241 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3242 if (!p)
3243 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003244 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003245 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003246 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003247 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003248 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003249 p->kwarg = kwarg;
3250 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003251 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003252}
3253
Neal Norwitzc1505362006-12-28 06:47:50 +00003254arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003255arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3256 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003257{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003258 arg_ty p;
3259 if (!arg) {
3260 PyErr_SetString(PyExc_ValueError,
3261 "field arg is required for arg");
3262 return NULL;
3263 }
3264 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3265 if (!p)
3266 return NULL;
3267 p->arg = arg;
3268 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003269 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003270 p->lineno = lineno;
3271 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003272 p->end_lineno = end_lineno;
3273 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003274 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003275}
3276
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003277keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003278keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003279{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003280 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003281 if (!value) {
3282 PyErr_SetString(PyExc_ValueError,
3283 "field value is required for keyword");
3284 return NULL;
3285 }
3286 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3287 if (!p)
3288 return NULL;
3289 p->arg = arg;
3290 p->value = value;
3291 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003292}
3293
3294alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003295alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003296{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003297 alias_ty p;
3298 if (!name) {
3299 PyErr_SetString(PyExc_ValueError,
3300 "field name is required for alias");
3301 return NULL;
3302 }
3303 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3304 if (!p)
3305 return NULL;
3306 p->name = name;
3307 p->asname = asname;
3308 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003309}
3310
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003311withitem_ty
3312withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3313{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003314 withitem_ty p;
3315 if (!context_expr) {
3316 PyErr_SetString(PyExc_ValueError,
3317 "field context_expr is required for withitem");
3318 return NULL;
3319 }
3320 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3321 if (!p)
3322 return NULL;
3323 p->context_expr = context_expr;
3324 p->optional_vars = optional_vars;
3325 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003326}
3327
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003328type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003329TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003330{
3331 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003332 if (!tag) {
3333 PyErr_SetString(PyExc_ValueError,
3334 "field tag is required for TypeIgnore");
3335 return NULL;
3336 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003337 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3338 if (!p)
3339 return NULL;
3340 p->kind = TypeIgnore_kind;
3341 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003342 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003343 return p;
3344}
3345
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003346
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003347PyObject*
3348ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003349{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003350 mod_ty o = (mod_ty)_o;
3351 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003352 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003353 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003354 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003355 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003356
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003357 switch (o->kind) {
3358 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003359 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3360 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003361 if (!result) goto failed;
3362 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3363 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003364 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003365 goto failed;
3366 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003367 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3368 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003369 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3370 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003371 goto failed;
3372 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003373 break;
3374 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003375 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3376 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003377 if (!result) goto failed;
3378 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3379 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003380 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003381 goto failed;
3382 Py_DECREF(value);
3383 break;
3384 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003385 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3386 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003387 if (!result) goto failed;
3388 value = ast2obj_expr(o->v.Expression.body);
3389 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003390 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003391 goto failed;
3392 Py_DECREF(value);
3393 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003394 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003395 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3396 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003397 if (!result) goto failed;
3398 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3399 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003400 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3401 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003402 goto failed;
3403 Py_DECREF(value);
3404 value = ast2obj_expr(o->v.FunctionType.returns);
3405 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003406 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3407 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003408 goto failed;
3409 Py_DECREF(value);
3410 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003411 case Suite_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003412 tp = (PyTypeObject *)astmodulestate_global->Suite_type;
3413 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003414 if (!result) goto failed;
3415 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
3416 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003417 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003418 goto failed;
3419 Py_DECREF(value);
3420 break;
3421 }
3422 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003423failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003424 Py_XDECREF(value);
3425 Py_XDECREF(result);
3426 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003427}
3428
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003429PyObject*
3430ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003431{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003432 stmt_ty o = (stmt_ty)_o;
3433 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003434 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003435 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003436 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003437 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003438
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003439 switch (o->kind) {
3440 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003441 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3442 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003443 if (!result) goto failed;
3444 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003445 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003446 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003447 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003448 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003449 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003450 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003451 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003452 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003453 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003454 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3455 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003456 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003457 goto failed;
3458 Py_DECREF(value);
3459 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3460 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003461 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3462 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003463 goto failed;
3464 Py_DECREF(value);
3465 value = ast2obj_expr(o->v.FunctionDef.returns);
3466 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003467 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3468 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003469 goto failed;
3470 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003471 value = ast2obj_string(o->v.FunctionDef.type_comment);
3472 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003473 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3474 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003475 goto failed;
3476 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003477 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003478 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003479 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3480 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003481 if (!result) goto failed;
3482 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3483 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003484 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003485 goto failed;
3486 Py_DECREF(value);
3487 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3488 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003489 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003490 goto failed;
3491 Py_DECREF(value);
3492 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3493 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003494 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003495 goto failed;
3496 Py_DECREF(value);
3497 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3498 ast2obj_expr);
3499 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003500 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3501 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003502 goto failed;
3503 Py_DECREF(value);
3504 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3505 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003506 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3507 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003508 goto failed;
3509 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003510 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3511 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003512 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3513 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003514 goto failed;
3515 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003516 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003517 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003518 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3519 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003520 if (!result) goto failed;
3521 value = ast2obj_identifier(o->v.ClassDef.name);
3522 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003523 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003524 goto failed;
3525 Py_DECREF(value);
3526 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3527 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003528 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003529 goto failed;
3530 Py_DECREF(value);
3531 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3532 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003533 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3534 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003535 goto failed;
3536 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003537 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3538 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003539 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003540 goto failed;
3541 Py_DECREF(value);
3542 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3543 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003544 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3545 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003546 goto failed;
3547 Py_DECREF(value);
3548 break;
3549 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003550 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3551 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003552 if (!result) goto failed;
3553 value = ast2obj_expr(o->v.Return.value);
3554 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003555 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003556 goto failed;
3557 Py_DECREF(value);
3558 break;
3559 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003560 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3561 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003562 if (!result) goto failed;
3563 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3564 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003565 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3566 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003567 goto failed;
3568 Py_DECREF(value);
3569 break;
3570 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003571 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3572 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003573 if (!result) goto failed;
3574 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3575 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003576 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3577 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003578 goto failed;
3579 Py_DECREF(value);
3580 value = ast2obj_expr(o->v.Assign.value);
3581 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003582 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003583 goto failed;
3584 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003585 value = ast2obj_string(o->v.Assign.type_comment);
3586 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003587 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3588 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003589 goto failed;
3590 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003591 break;
3592 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003593 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3594 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003595 if (!result) goto failed;
3596 value = ast2obj_expr(o->v.AugAssign.target);
3597 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003598 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3599 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003600 goto failed;
3601 Py_DECREF(value);
3602 value = ast2obj_operator(o->v.AugAssign.op);
3603 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003604 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003605 goto failed;
3606 Py_DECREF(value);
3607 value = ast2obj_expr(o->v.AugAssign.value);
3608 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003609 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003610 goto failed;
3611 Py_DECREF(value);
3612 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003613 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003614 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3615 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003616 if (!result) goto failed;
3617 value = ast2obj_expr(o->v.AnnAssign.target);
3618 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003619 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3620 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003621 goto failed;
3622 Py_DECREF(value);
3623 value = ast2obj_expr(o->v.AnnAssign.annotation);
3624 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003625 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3626 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003627 goto failed;
3628 Py_DECREF(value);
3629 value = ast2obj_expr(o->v.AnnAssign.value);
3630 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003631 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003632 goto failed;
3633 Py_DECREF(value);
3634 value = ast2obj_int(o->v.AnnAssign.simple);
3635 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003636 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3637 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003638 goto failed;
3639 Py_DECREF(value);
3640 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003641 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003642 tp = (PyTypeObject *)astmodulestate_global->For_type;
3643 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003644 if (!result) goto failed;
3645 value = ast2obj_expr(o->v.For.target);
3646 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003647 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3648 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003649 goto failed;
3650 Py_DECREF(value);
3651 value = ast2obj_expr(o->v.For.iter);
3652 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003653 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003654 goto failed;
3655 Py_DECREF(value);
3656 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3657 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003658 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003659 goto failed;
3660 Py_DECREF(value);
3661 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3662 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003663 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3664 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003665 goto failed;
3666 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003667 value = ast2obj_string(o->v.For.type_comment);
3668 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003669 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3670 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003671 goto failed;
3672 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003673 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003674 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003675 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3676 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003677 if (!result) goto failed;
3678 value = ast2obj_expr(o->v.AsyncFor.target);
3679 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003680 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3681 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003682 goto failed;
3683 Py_DECREF(value);
3684 value = ast2obj_expr(o->v.AsyncFor.iter);
3685 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003686 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003687 goto failed;
3688 Py_DECREF(value);
3689 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3690 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003691 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003692 goto failed;
3693 Py_DECREF(value);
3694 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3695 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003696 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3697 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003698 goto failed;
3699 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003700 value = ast2obj_string(o->v.AsyncFor.type_comment);
3701 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003702 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3703 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003704 goto failed;
3705 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003706 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003707 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003708 tp = (PyTypeObject *)astmodulestate_global->While_type;
3709 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003710 if (!result) goto failed;
3711 value = ast2obj_expr(o->v.While.test);
3712 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003713 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003714 goto failed;
3715 Py_DECREF(value);
3716 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3717 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003718 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003719 goto failed;
3720 Py_DECREF(value);
3721 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3722 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003723 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3724 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003725 goto failed;
3726 Py_DECREF(value);
3727 break;
3728 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003729 tp = (PyTypeObject *)astmodulestate_global->If_type;
3730 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003731 if (!result) goto failed;
3732 value = ast2obj_expr(o->v.If.test);
3733 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003734 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003735 goto failed;
3736 Py_DECREF(value);
3737 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3738 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003739 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003740 goto failed;
3741 Py_DECREF(value);
3742 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3743 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003744 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3745 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003746 goto failed;
3747 Py_DECREF(value);
3748 break;
3749 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003750 tp = (PyTypeObject *)astmodulestate_global->With_type;
3751 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003752 if (!result) goto failed;
3753 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3754 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003755 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003756 goto failed;
3757 Py_DECREF(value);
3758 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3759 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003760 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003761 goto failed;
3762 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003763 value = ast2obj_string(o->v.With.type_comment);
3764 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003765 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3766 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003767 goto failed;
3768 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003769 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003770 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003771 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3772 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003773 if (!result) goto failed;
3774 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3775 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003776 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003777 goto failed;
3778 Py_DECREF(value);
3779 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3780 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003781 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003782 goto failed;
3783 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003784 value = ast2obj_string(o->v.AsyncWith.type_comment);
3785 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003786 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3787 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003788 goto failed;
3789 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003790 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003791 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003792 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3793 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003794 if (!result) goto failed;
3795 value = ast2obj_expr(o->v.Raise.exc);
3796 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003797 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003798 goto failed;
3799 Py_DECREF(value);
3800 value = ast2obj_expr(o->v.Raise.cause);
3801 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003802 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003803 goto failed;
3804 Py_DECREF(value);
3805 break;
3806 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003807 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3808 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003809 if (!result) goto failed;
3810 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3811 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003812 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003813 goto failed;
3814 Py_DECREF(value);
3815 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3816 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003817 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3818 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003819 goto failed;
3820 Py_DECREF(value);
3821 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003823 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3824 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003825 goto failed;
3826 Py_DECREF(value);
3827 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3828 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003829 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3830 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003831 goto failed;
3832 Py_DECREF(value);
3833 break;
3834 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003835 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3836 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003837 if (!result) goto failed;
3838 value = ast2obj_expr(o->v.Assert.test);
3839 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003840 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003841 goto failed;
3842 Py_DECREF(value);
3843 value = ast2obj_expr(o->v.Assert.msg);
3844 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003845 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003846 goto failed;
3847 Py_DECREF(value);
3848 break;
3849 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003850 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3851 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003852 if (!result) goto failed;
3853 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3854 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003855 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003856 goto failed;
3857 Py_DECREF(value);
3858 break;
3859 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003860 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3861 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003862 if (!result) goto failed;
3863 value = ast2obj_identifier(o->v.ImportFrom.module);
3864 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003865 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3866 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003867 goto failed;
3868 Py_DECREF(value);
3869 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3870 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003871 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003872 goto failed;
3873 Py_DECREF(value);
3874 value = ast2obj_int(o->v.ImportFrom.level);
3875 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003876 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003877 goto failed;
3878 Py_DECREF(value);
3879 break;
3880 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003881 tp = (PyTypeObject *)astmodulestate_global->Global_type;
3882 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003883 if (!result) goto failed;
3884 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3885 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003886 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003887 goto failed;
3888 Py_DECREF(value);
3889 break;
3890 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003891 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3892 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003893 if (!result) goto failed;
3894 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3895 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003896 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003897 goto failed;
3898 Py_DECREF(value);
3899 break;
3900 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003901 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3902 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003903 if (!result) goto failed;
3904 value = ast2obj_expr(o->v.Expr.value);
3905 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003906 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003907 goto failed;
3908 Py_DECREF(value);
3909 break;
3910 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003911 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3912 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003913 if (!result) goto failed;
3914 break;
3915 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003916 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3917 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003918 if (!result) goto failed;
3919 break;
3920 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003921 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3922 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003923 if (!result) goto failed;
3924 break;
3925 }
3926 value = ast2obj_int(o->lineno);
3927 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003928 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003929 goto failed;
3930 Py_DECREF(value);
3931 value = ast2obj_int(o->col_offset);
3932 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003933 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003934 goto failed;
3935 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003936 value = ast2obj_int(o->end_lineno);
3937 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003938 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003939 goto failed;
3940 Py_DECREF(value);
3941 value = ast2obj_int(o->end_col_offset);
3942 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003943 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
3944 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003945 goto failed;
3946 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003947 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003948failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003949 Py_XDECREF(value);
3950 Py_XDECREF(result);
3951 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003952}
3953
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003954PyObject*
3955ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003956{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003957 expr_ty o = (expr_ty)_o;
3958 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003959 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003960 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003961 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003962 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003963
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003964 switch (o->kind) {
3965 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003966 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
3967 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 if (!result) goto failed;
3969 value = ast2obj_boolop(o->v.BoolOp.op);
3970 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003971 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003972 goto failed;
3973 Py_DECREF(value);
3974 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3975 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003976 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
3977 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003978 goto failed;
3979 Py_DECREF(value);
3980 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003981 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003982 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
3983 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003984 if (!result) goto failed;
3985 value = ast2obj_expr(o->v.NamedExpr.target);
3986 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003987 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3988 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003989 goto failed;
3990 Py_DECREF(value);
3991 value = ast2obj_expr(o->v.NamedExpr.value);
3992 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003993 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003994 goto failed;
3995 Py_DECREF(value);
3996 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003997 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003998 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
3999 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004000 if (!result) goto failed;
4001 value = ast2obj_expr(o->v.BinOp.left);
4002 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004003 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004004 goto failed;
4005 Py_DECREF(value);
4006 value = ast2obj_operator(o->v.BinOp.op);
4007 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004008 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004009 goto failed;
4010 Py_DECREF(value);
4011 value = ast2obj_expr(o->v.BinOp.right);
4012 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004013 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004014 goto failed;
4015 Py_DECREF(value);
4016 break;
4017 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004018 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4019 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004020 if (!result) goto failed;
4021 value = ast2obj_unaryop(o->v.UnaryOp.op);
4022 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004023 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004024 goto failed;
4025 Py_DECREF(value);
4026 value = ast2obj_expr(o->v.UnaryOp.operand);
4027 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004028 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4029 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004030 goto failed;
4031 Py_DECREF(value);
4032 break;
4033 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004034 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4035 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004036 if (!result) goto failed;
4037 value = ast2obj_arguments(o->v.Lambda.args);
4038 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004039 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 goto failed;
4041 Py_DECREF(value);
4042 value = ast2obj_expr(o->v.Lambda.body);
4043 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004044 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004045 goto failed;
4046 Py_DECREF(value);
4047 break;
4048 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004049 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4050 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004051 if (!result) goto failed;
4052 value = ast2obj_expr(o->v.IfExp.test);
4053 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004054 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004055 goto failed;
4056 Py_DECREF(value);
4057 value = ast2obj_expr(o->v.IfExp.body);
4058 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004059 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004060 goto failed;
4061 Py_DECREF(value);
4062 value = ast2obj_expr(o->v.IfExp.orelse);
4063 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004064 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4065 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004066 goto failed;
4067 Py_DECREF(value);
4068 break;
4069 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004070 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4071 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004072 if (!result) goto failed;
4073 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4074 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004075 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004076 goto failed;
4077 Py_DECREF(value);
4078 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4079 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004080 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4081 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004082 goto failed;
4083 Py_DECREF(value);
4084 break;
4085 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004086 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4087 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004088 if (!result) goto failed;
4089 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4090 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004091 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004092 goto failed;
4093 Py_DECREF(value);
4094 break;
4095 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004096 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4097 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004098 if (!result) goto failed;
4099 value = ast2obj_expr(o->v.ListComp.elt);
4100 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004101 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 goto failed;
4103 Py_DECREF(value);
4104 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4105 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004106 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4107 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004108 goto failed;
4109 Py_DECREF(value);
4110 break;
4111 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004112 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4113 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004114 if (!result) goto failed;
4115 value = ast2obj_expr(o->v.SetComp.elt);
4116 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004117 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004118 goto failed;
4119 Py_DECREF(value);
4120 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4121 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004122 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4123 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004124 goto failed;
4125 Py_DECREF(value);
4126 break;
4127 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004128 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4129 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004130 if (!result) goto failed;
4131 value = ast2obj_expr(o->v.DictComp.key);
4132 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004133 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004134 goto failed;
4135 Py_DECREF(value);
4136 value = ast2obj_expr(o->v.DictComp.value);
4137 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004138 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004139 goto failed;
4140 Py_DECREF(value);
4141 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4142 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004143 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4144 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004145 goto failed;
4146 Py_DECREF(value);
4147 break;
4148 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004149 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4150 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004151 if (!result) goto failed;
4152 value = ast2obj_expr(o->v.GeneratorExp.elt);
4153 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004154 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004155 goto failed;
4156 Py_DECREF(value);
4157 value = ast2obj_list(o->v.GeneratorExp.generators,
4158 ast2obj_comprehension);
4159 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004160 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4161 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004162 goto failed;
4163 Py_DECREF(value);
4164 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004165 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004166 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4167 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004168 if (!result) goto failed;
4169 value = ast2obj_expr(o->v.Await.value);
4170 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004171 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004172 goto failed;
4173 Py_DECREF(value);
4174 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004175 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004176 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4177 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004178 if (!result) goto failed;
4179 value = ast2obj_expr(o->v.Yield.value);
4180 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004181 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004182 goto failed;
4183 Py_DECREF(value);
4184 break;
4185 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004186 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4187 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004188 if (!result) goto failed;
4189 value = ast2obj_expr(o->v.YieldFrom.value);
4190 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004191 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004192 goto failed;
4193 Py_DECREF(value);
4194 break;
4195 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004196 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4197 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004198 if (!result) goto failed;
4199 value = ast2obj_expr(o->v.Compare.left);
4200 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004201 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004202 goto failed;
4203 Py_DECREF(value);
4204 {
4205 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4206 value = PyList_New(n);
4207 if (!value) goto failed;
4208 for(i = 0; i < n; i++)
4209 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004210 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004211 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004212 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004213 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004214 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004215 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004216 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004217 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4218 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004219 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004220 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004221 break;
4222 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004223 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4224 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004225 if (!result) goto failed;
4226 value = ast2obj_expr(o->v.Call.func);
4227 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004228 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004229 goto failed;
4230 Py_DECREF(value);
4231 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4232 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004233 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004234 goto failed;
4235 Py_DECREF(value);
4236 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4237 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004238 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4239 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004240 goto failed;
4241 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004242 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004243 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004244 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4245 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004246 if (!result) goto failed;
4247 value = ast2obj_expr(o->v.FormattedValue.value);
4248 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004249 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004250 goto failed;
4251 Py_DECREF(value);
4252 value = ast2obj_int(o->v.FormattedValue.conversion);
4253 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004254 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4255 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004256 goto failed;
4257 Py_DECREF(value);
4258 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4259 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004260 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4261 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004262 goto failed;
4263 Py_DECREF(value);
4264 break;
4265 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004266 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4267 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004268 if (!result) goto failed;
4269 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4270 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004271 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4272 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004273 goto failed;
4274 Py_DECREF(value);
4275 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004276 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004277 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4278 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004279 if (!result) goto failed;
4280 value = ast2obj_constant(o->v.Constant.value);
4281 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004282 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004283 goto failed;
4284 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004285 value = ast2obj_string(o->v.Constant.kind);
4286 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004287 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004288 goto failed;
4289 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004290 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004291 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004292 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4293 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004294 if (!result) goto failed;
4295 value = ast2obj_expr(o->v.Attribute.value);
4296 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004297 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004298 goto failed;
4299 Py_DECREF(value);
4300 value = ast2obj_identifier(o->v.Attribute.attr);
4301 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004302 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004303 goto failed;
4304 Py_DECREF(value);
4305 value = ast2obj_expr_context(o->v.Attribute.ctx);
4306 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004307 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004308 goto failed;
4309 Py_DECREF(value);
4310 break;
4311 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004312 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4313 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004314 if (!result) goto failed;
4315 value = ast2obj_expr(o->v.Subscript.value);
4316 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004317 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004318 goto failed;
4319 Py_DECREF(value);
4320 value = ast2obj_slice(o->v.Subscript.slice);
4321 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004322 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004323 goto failed;
4324 Py_DECREF(value);
4325 value = ast2obj_expr_context(o->v.Subscript.ctx);
4326 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004327 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004328 goto failed;
4329 Py_DECREF(value);
4330 break;
4331 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004332 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4333 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004334 if (!result) goto failed;
4335 value = ast2obj_expr(o->v.Starred.value);
4336 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004337 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004338 goto failed;
4339 Py_DECREF(value);
4340 value = ast2obj_expr_context(o->v.Starred.ctx);
4341 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004342 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004343 goto failed;
4344 Py_DECREF(value);
4345 break;
4346 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004347 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4348 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004349 if (!result) goto failed;
4350 value = ast2obj_identifier(o->v.Name.id);
4351 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004352 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004353 goto failed;
4354 Py_DECREF(value);
4355 value = ast2obj_expr_context(o->v.Name.ctx);
4356 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004357 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004358 goto failed;
4359 Py_DECREF(value);
4360 break;
4361 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004362 tp = (PyTypeObject *)astmodulestate_global->List_type;
4363 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004364 if (!result) goto failed;
4365 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4366 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004367 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004368 goto failed;
4369 Py_DECREF(value);
4370 value = ast2obj_expr_context(o->v.List.ctx);
4371 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004372 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004373 goto failed;
4374 Py_DECREF(value);
4375 break;
4376 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004377 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4378 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004379 if (!result) goto failed;
4380 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4381 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004382 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004383 goto failed;
4384 Py_DECREF(value);
4385 value = ast2obj_expr_context(o->v.Tuple.ctx);
4386 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004387 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004388 goto failed;
4389 Py_DECREF(value);
4390 break;
4391 }
4392 value = ast2obj_int(o->lineno);
4393 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004394 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004395 goto failed;
4396 Py_DECREF(value);
4397 value = ast2obj_int(o->col_offset);
4398 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004399 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004400 goto failed;
4401 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004402 value = ast2obj_int(o->end_lineno);
4403 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004404 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004405 goto failed;
4406 Py_DECREF(value);
4407 value = ast2obj_int(o->end_col_offset);
4408 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004409 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4410 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004411 goto failed;
4412 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004413 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004414failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004415 Py_XDECREF(value);
4416 Py_XDECREF(result);
4417 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004418}
4419
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004420PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004421{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004422 switch(o) {
4423 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004424 Py_INCREF(astmodulestate_global->Load_singleton);
4425 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004426 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004427 Py_INCREF(astmodulestate_global->Store_singleton);
4428 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004429 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004430 Py_INCREF(astmodulestate_global->Del_singleton);
4431 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004432 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004433 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4434 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004435 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004436 Py_INCREF(astmodulestate_global->AugStore_singleton);
4437 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004438 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004439 Py_INCREF(astmodulestate_global->Param_singleton);
4440 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004441 default:
4442 /* should never happen, but just in case ... */
4443 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4444 return NULL;
4445 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004446}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004447PyObject*
4448ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004449{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004450 slice_ty o = (slice_ty)_o;
4451 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004452 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004453 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004454 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004455 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004456
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004457 switch (o->kind) {
4458 case Slice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004459 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4460 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004461 if (!result) goto failed;
4462 value = ast2obj_expr(o->v.Slice.lower);
4463 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004464 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004465 goto failed;
4466 Py_DECREF(value);
4467 value = ast2obj_expr(o->v.Slice.upper);
4468 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004469 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004470 goto failed;
4471 Py_DECREF(value);
4472 value = ast2obj_expr(o->v.Slice.step);
4473 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004474 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004475 goto failed;
4476 Py_DECREF(value);
4477 break;
4478 case ExtSlice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004479 tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type;
4480 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004481 if (!result) goto failed;
4482 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
4483 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004484 if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004485 goto failed;
4486 Py_DECREF(value);
4487 break;
4488 case Index_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004489 tp = (PyTypeObject *)astmodulestate_global->Index_type;
4490 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004491 if (!result) goto failed;
4492 value = ast2obj_expr(o->v.Index.value);
4493 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004494 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004495 goto failed;
4496 Py_DECREF(value);
4497 break;
4498 }
4499 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004500failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004501 Py_XDECREF(value);
4502 Py_XDECREF(result);
4503 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004504}
4505
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004506PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004507{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004508 switch(o) {
4509 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004510 Py_INCREF(astmodulestate_global->And_singleton);
4511 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004512 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004513 Py_INCREF(astmodulestate_global->Or_singleton);
4514 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004515 default:
4516 /* should never happen, but just in case ... */
4517 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4518 return NULL;
4519 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004520}
4521PyObject* ast2obj_operator(operator_ty o)
4522{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004523 switch(o) {
4524 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004525 Py_INCREF(astmodulestate_global->Add_singleton);
4526 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004527 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004528 Py_INCREF(astmodulestate_global->Sub_singleton);
4529 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004530 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004531 Py_INCREF(astmodulestate_global->Mult_singleton);
4532 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004533 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004534 Py_INCREF(astmodulestate_global->MatMult_singleton);
4535 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004536 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004537 Py_INCREF(astmodulestate_global->Div_singleton);
4538 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004539 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004540 Py_INCREF(astmodulestate_global->Mod_singleton);
4541 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004542 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004543 Py_INCREF(astmodulestate_global->Pow_singleton);
4544 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004545 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004546 Py_INCREF(astmodulestate_global->LShift_singleton);
4547 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004548 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004549 Py_INCREF(astmodulestate_global->RShift_singleton);
4550 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004551 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004552 Py_INCREF(astmodulestate_global->BitOr_singleton);
4553 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004554 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004555 Py_INCREF(astmodulestate_global->BitXor_singleton);
4556 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004557 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004558 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4559 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004560 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004561 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4562 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004563 default:
4564 /* should never happen, but just in case ... */
4565 PyErr_Format(PyExc_SystemError, "unknown operator found");
4566 return NULL;
4567 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004568}
4569PyObject* ast2obj_unaryop(unaryop_ty o)
4570{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004571 switch(o) {
4572 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004573 Py_INCREF(astmodulestate_global->Invert_singleton);
4574 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004575 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004576 Py_INCREF(astmodulestate_global->Not_singleton);
4577 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004578 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004579 Py_INCREF(astmodulestate_global->UAdd_singleton);
4580 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004581 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004582 Py_INCREF(astmodulestate_global->USub_singleton);
4583 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004584 default:
4585 /* should never happen, but just in case ... */
4586 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4587 return NULL;
4588 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004589}
4590PyObject* ast2obj_cmpop(cmpop_ty o)
4591{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004592 switch(o) {
4593 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004594 Py_INCREF(astmodulestate_global->Eq_singleton);
4595 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004596 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004597 Py_INCREF(astmodulestate_global->NotEq_singleton);
4598 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004599 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004600 Py_INCREF(astmodulestate_global->Lt_singleton);
4601 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004602 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004603 Py_INCREF(astmodulestate_global->LtE_singleton);
4604 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004605 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004606 Py_INCREF(astmodulestate_global->Gt_singleton);
4607 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004608 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004609 Py_INCREF(astmodulestate_global->GtE_singleton);
4610 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004611 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004612 Py_INCREF(astmodulestate_global->Is_singleton);
4613 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004614 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004615 Py_INCREF(astmodulestate_global->IsNot_singleton);
4616 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004617 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004618 Py_INCREF(astmodulestate_global->In_singleton);
4619 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004621 Py_INCREF(astmodulestate_global->NotIn_singleton);
4622 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004623 default:
4624 /* should never happen, but just in case ... */
4625 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4626 return NULL;
4627 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004628}
4629PyObject*
4630ast2obj_comprehension(void* _o)
4631{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004632 comprehension_ty o = (comprehension_ty)_o;
4633 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004634 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004635 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004636 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004637 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004638
Dino Viehlandac46eb42019-09-11 10:16:34 -07004639 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4640 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004641 if (!result) return NULL;
4642 value = ast2obj_expr(o->target);
4643 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004644 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004645 goto failed;
4646 Py_DECREF(value);
4647 value = ast2obj_expr(o->iter);
4648 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004649 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 goto failed;
4651 Py_DECREF(value);
4652 value = ast2obj_list(o->ifs, ast2obj_expr);
4653 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004654 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004655 goto failed;
4656 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004657 value = ast2obj_int(o->is_async);
4658 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004659 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004660 goto failed;
4661 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004662 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004663failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004664 Py_XDECREF(value);
4665 Py_XDECREF(result);
4666 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004667}
4668
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004669PyObject*
4670ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004671{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 excepthandler_ty o = (excepthandler_ty)_o;
4673 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004674 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004675 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004676 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004677 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004678
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004679 switch (o->kind) {
4680 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004681 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4682 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 if (!result) goto failed;
4684 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004685 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004686 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004688 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004689 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004690 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004691 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004692 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004693 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004694 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4695 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004696 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004697 goto failed;
4698 Py_DECREF(value);
4699 break;
4700 }
4701 value = ast2obj_int(o->lineno);
4702 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004703 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004704 goto failed;
4705 Py_DECREF(value);
4706 value = ast2obj_int(o->col_offset);
4707 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004708 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004709 goto failed;
4710 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004711 value = ast2obj_int(o->end_lineno);
4712 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004713 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004714 goto failed;
4715 Py_DECREF(value);
4716 value = ast2obj_int(o->end_col_offset);
4717 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004718 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4719 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004720 goto failed;
4721 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004722 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004723failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004724 Py_XDECREF(value);
4725 Py_XDECREF(result);
4726 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004727}
4728
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004729PyObject*
4730ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004731{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004732 arguments_ty o = (arguments_ty)_o;
4733 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004734 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004735 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004736 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004737 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004738
Dino Viehlandac46eb42019-09-11 10:16:34 -07004739 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4740 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004741 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004742 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4743 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004744 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4745 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004746 goto failed;
4747 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004748 value = ast2obj_list(o->args, ast2obj_arg);
4749 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004750 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004751 goto failed;
4752 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004753 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004754 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004755 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004756 goto failed;
4757 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004758 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4759 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004760 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4761 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004762 goto failed;
4763 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004764 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004766 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4767 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004768 goto failed;
4769 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004770 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004772 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004773 goto failed;
4774 Py_DECREF(value);
4775 value = ast2obj_list(o->defaults, ast2obj_expr);
4776 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004777 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004778 goto failed;
4779 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004780 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004781failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 Py_XDECREF(value);
4783 Py_XDECREF(result);
4784 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004785}
4786
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004787PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004788ast2obj_arg(void* _o)
4789{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004790 arg_ty o = (arg_ty)_o;
4791 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004792 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004793 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004794 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004795 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004796
Dino Viehlandac46eb42019-09-11 10:16:34 -07004797 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4798 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004799 if (!result) return NULL;
4800 value = ast2obj_identifier(o->arg);
4801 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004802 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004803 goto failed;
4804 Py_DECREF(value);
4805 value = ast2obj_expr(o->annotation);
4806 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004807 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4808 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004809 goto failed;
4810 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004811 value = ast2obj_string(o->type_comment);
4812 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004813 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4814 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004815 goto failed;
4816 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004817 value = ast2obj_int(o->lineno);
4818 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004819 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004820 goto failed;
4821 Py_DECREF(value);
4822 value = ast2obj_int(o->col_offset);
4823 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004824 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004825 goto failed;
4826 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004827 value = ast2obj_int(o->end_lineno);
4828 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004829 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004830 goto failed;
4831 Py_DECREF(value);
4832 value = ast2obj_int(o->end_col_offset);
4833 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004834 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4835 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004836 goto failed;
4837 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004838 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004839failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004840 Py_XDECREF(value);
4841 Py_XDECREF(result);
4842 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004843}
4844
4845PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004846ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004847{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004848 keyword_ty o = (keyword_ty)_o;
4849 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004850 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004851 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004852 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004853 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004854
Dino Viehlandac46eb42019-09-11 10:16:34 -07004855 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4856 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004857 if (!result) return NULL;
4858 value = ast2obj_identifier(o->arg);
4859 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004860 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 goto failed;
4862 Py_DECREF(value);
4863 value = ast2obj_expr(o->value);
4864 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004865 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004866 goto failed;
4867 Py_DECREF(value);
4868 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004869failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004870 Py_XDECREF(value);
4871 Py_XDECREF(result);
4872 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004873}
4874
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004875PyObject*
4876ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004877{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 alias_ty o = (alias_ty)_o;
4879 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004880 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004881 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004882 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004883 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004884
Dino Viehlandac46eb42019-09-11 10:16:34 -07004885 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4886 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004887 if (!result) return NULL;
4888 value = ast2obj_identifier(o->name);
4889 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004890 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 goto failed;
4892 Py_DECREF(value);
4893 value = ast2obj_identifier(o->asname);
4894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004895 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004896 goto failed;
4897 Py_DECREF(value);
4898 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004899failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 Py_XDECREF(value);
4901 Py_XDECREF(result);
4902 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004903}
4904
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004905PyObject*
4906ast2obj_withitem(void* _o)
4907{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004908 withitem_ty o = (withitem_ty)_o;
4909 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004910 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004911 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004912 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004913 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004914
Dino Viehlandac46eb42019-09-11 10:16:34 -07004915 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4916 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004917 if (!result) return NULL;
4918 value = ast2obj_expr(o->context_expr);
4919 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004920 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4921 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004922 goto failed;
4923 Py_DECREF(value);
4924 value = ast2obj_expr(o->optional_vars);
4925 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004926 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4927 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004928 goto failed;
4929 Py_DECREF(value);
4930 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004931failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004932 Py_XDECREF(value);
4933 Py_XDECREF(result);
4934 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004935}
4936
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004937PyObject*
4938ast2obj_type_ignore(void* _o)
4939{
4940 type_ignore_ty o = (type_ignore_ty)_o;
4941 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004942 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004943 if (!o) {
4944 Py_RETURN_NONE;
4945 }
4946
4947 switch (o->kind) {
4948 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004949 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
4950 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004951 if (!result) goto failed;
4952 value = ast2obj_int(o->v.TypeIgnore.lineno);
4953 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004954 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
4955 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004956 goto failed;
4957 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004958 value = ast2obj_string(o->v.TypeIgnore.tag);
4959 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004960 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004961 goto failed;
4962 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004963 break;
4964 }
4965 return result;
4966failed:
4967 Py_XDECREF(value);
4968 Py_XDECREF(result);
4969 return NULL;
4970}
4971
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004972
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004973int
4974obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4975{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004976 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004977
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004978 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004979 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004980
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004981 if (obj == Py_None) {
4982 *out = NULL;
4983 return 0;
4984 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07004985 tp = astmodulestate_global->Module_type;
4986 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004987 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004988 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 }
4990 if (isinstance) {
4991 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004992 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004993
Dino Viehlandac46eb42019-09-11 10:16:34 -07004994 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02004995 return 1;
4996 }
4997 if (tmp == NULL) {
4998 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
4999 return 1;
5000 }
5001 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005002 int res;
5003 Py_ssize_t len;
5004 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005005 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005006 PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005007 goto failed;
5008 }
5009 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005010 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005011 if (body == NULL) goto failed;
5012 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005013 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005014 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5015 Py_INCREF(tmp2);
5016 res = obj2ast_stmt(tmp2, &val, arena);
5017 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005018 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005019 if (len != PyList_GET_SIZE(tmp)) {
5020 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5021 goto failed;
5022 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005023 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005024 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005025 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005026 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005027 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5028 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005029 return 1;
5030 }
5031 if (tmp == NULL) {
5032 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5033 return 1;
5034 }
5035 else {
5036 int res;
5037 Py_ssize_t len;
5038 Py_ssize_t i;
5039 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005040 PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005041 goto failed;
5042 }
5043 len = PyList_GET_SIZE(tmp);
5044 type_ignores = _Py_asdl_seq_new(len, arena);
5045 if (type_ignores == NULL) goto failed;
5046 for (i = 0; i < len; i++) {
5047 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005048 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5049 Py_INCREF(tmp2);
5050 res = obj2ast_type_ignore(tmp2, &val, arena);
5051 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005052 if (res != 0) goto failed;
5053 if (len != PyList_GET_SIZE(tmp)) {
5054 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5055 goto failed;
5056 }
5057 asdl_seq_SET(type_ignores, i, val);
5058 }
5059 Py_CLEAR(tmp);
5060 }
5061 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005062 if (*out == NULL) goto failed;
5063 return 0;
5064 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005065 tp = astmodulestate_global->Interactive_type;
5066 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005067 if (isinstance == -1) {
5068 return 1;
5069 }
5070 if (isinstance) {
5071 asdl_seq* body;
5072
Dino Viehlandac46eb42019-09-11 10:16:34 -07005073 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005074 return 1;
5075 }
5076 if (tmp == NULL) {
5077 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5078 return 1;
5079 }
5080 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005081 int res;
5082 Py_ssize_t len;
5083 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005084 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005085 PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005086 goto failed;
5087 }
5088 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005089 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005090 if (body == NULL) goto failed;
5091 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005092 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005093 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5094 Py_INCREF(tmp2);
5095 res = obj2ast_stmt(tmp2, &val, arena);
5096 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005097 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005098 if (len != PyList_GET_SIZE(tmp)) {
5099 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5100 goto failed;
5101 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005102 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005103 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005104 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005105 }
5106 *out = Interactive(body, arena);
5107 if (*out == NULL) goto failed;
5108 return 0;
5109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005110 tp = astmodulestate_global->Expression_type;
5111 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005112 if (isinstance == -1) {
5113 return 1;
5114 }
5115 if (isinstance) {
5116 expr_ty body;
5117
Dino Viehlandac46eb42019-09-11 10:16:34 -07005118 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005119 return 1;
5120 }
5121 if (tmp == NULL) {
5122 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5123 return 1;
5124 }
5125 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005126 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005127 res = obj2ast_expr(tmp, &body, arena);
5128 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005129 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005130 }
5131 *out = Expression(body, arena);
5132 if (*out == NULL) goto failed;
5133 return 0;
5134 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005135 tp = astmodulestate_global->FunctionType_type;
5136 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005137 if (isinstance == -1) {
5138 return 1;
5139 }
5140 if (isinstance) {
5141 asdl_seq* argtypes;
5142 expr_ty returns;
5143
Dino Viehlandac46eb42019-09-11 10:16:34 -07005144 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5145 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005146 return 1;
5147 }
5148 if (tmp == NULL) {
5149 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5150 return 1;
5151 }
5152 else {
5153 int res;
5154 Py_ssize_t len;
5155 Py_ssize_t i;
5156 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005157 PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005158 goto failed;
5159 }
5160 len = PyList_GET_SIZE(tmp);
5161 argtypes = _Py_asdl_seq_new(len, arena);
5162 if (argtypes == NULL) goto failed;
5163 for (i = 0; i < len; i++) {
5164 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005165 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5166 Py_INCREF(tmp2);
5167 res = obj2ast_expr(tmp2, &val, arena);
5168 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005169 if (res != 0) goto failed;
5170 if (len != PyList_GET_SIZE(tmp)) {
5171 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5172 goto failed;
5173 }
5174 asdl_seq_SET(argtypes, i, val);
5175 }
5176 Py_CLEAR(tmp);
5177 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005178 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5179 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005180 return 1;
5181 }
5182 if (tmp == NULL) {
5183 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5184 return 1;
5185 }
5186 else {
5187 int res;
5188 res = obj2ast_expr(tmp, &returns, arena);
5189 if (res != 0) goto failed;
5190 Py_CLEAR(tmp);
5191 }
5192 *out = FunctionType(argtypes, returns, arena);
5193 if (*out == NULL) goto failed;
5194 return 0;
5195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005196 tp = astmodulestate_global->Suite_type;
5197 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005198 if (isinstance == -1) {
5199 return 1;
5200 }
5201 if (isinstance) {
5202 asdl_seq* body;
5203
Dino Viehlandac46eb42019-09-11 10:16:34 -07005204 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005205 return 1;
5206 }
5207 if (tmp == NULL) {
5208 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
5209 return 1;
5210 }
5211 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005212 int res;
5213 Py_ssize_t len;
5214 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005215 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005216 PyErr_Format(PyExc_TypeError, "Suite field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005217 goto failed;
5218 }
5219 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005220 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005221 if (body == NULL) goto failed;
5222 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005223 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005224 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5225 Py_INCREF(tmp2);
5226 res = obj2ast_stmt(tmp2, &val, arena);
5227 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005228 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005229 if (len != PyList_GET_SIZE(tmp)) {
5230 PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
5231 goto failed;
5232 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005233 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005234 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005235 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005236 }
5237 *out = Suite(body, arena);
5238 if (*out == NULL) goto failed;
5239 return 0;
5240 }
5241
5242 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5243 failed:
5244 Py_XDECREF(tmp);
5245 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005246}
5247
5248int
5249obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5250{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005251 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005252
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005253 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005254 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005255 int lineno;
5256 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005257 int end_lineno;
5258 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005259
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005260 if (obj == Py_None) {
5261 *out = NULL;
5262 return 0;
5263 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005264 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005265 return 1;
5266 }
5267 if (tmp == NULL) {
5268 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5269 return 1;
5270 }
5271 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005272 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005273 res = obj2ast_int(tmp, &lineno, arena);
5274 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005275 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005277 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5278 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005279 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005280 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005281 if (tmp == NULL) {
5282 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5283 return 1;
5284 }
5285 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005286 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005287 res = obj2ast_int(tmp, &col_offset, arena);
5288 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005289 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005290 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005291 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5292 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005293 return 1;
5294 }
5295 if (tmp == NULL || tmp == Py_None) {
5296 Py_CLEAR(tmp);
5297 end_lineno = 0;
5298 }
5299 else {
5300 int res;
5301 res = obj2ast_int(tmp, &end_lineno, arena);
5302 if (res != 0) goto failed;
5303 Py_CLEAR(tmp);
5304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005305 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5306 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005307 return 1;
5308 }
5309 if (tmp == NULL || tmp == Py_None) {
5310 Py_CLEAR(tmp);
5311 end_col_offset = 0;
5312 }
5313 else {
5314 int res;
5315 res = obj2ast_int(tmp, &end_col_offset, arena);
5316 if (res != 0) goto failed;
5317 Py_CLEAR(tmp);
5318 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005319 tp = astmodulestate_global->FunctionDef_type;
5320 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005321 if (isinstance == -1) {
5322 return 1;
5323 }
5324 if (isinstance) {
5325 identifier name;
5326 arguments_ty args;
5327 asdl_seq* body;
5328 asdl_seq* decorator_list;
5329 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005330 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005331
Dino Viehlandac46eb42019-09-11 10:16:34 -07005332 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005333 return 1;
5334 }
5335 if (tmp == NULL) {
5336 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5337 return 1;
5338 }
5339 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005340 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005341 res = obj2ast_identifier(tmp, &name, arena);
5342 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005343 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005344 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005345 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005346 return 1;
5347 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005348 if (tmp == NULL) {
5349 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5350 return 1;
5351 }
5352 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005353 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005354 res = obj2ast_arguments(tmp, &args, arena);
5355 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005356 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005357 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005358 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005359 return 1;
5360 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005361 if (tmp == NULL) {
5362 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5363 return 1;
5364 }
5365 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005366 int res;
5367 Py_ssize_t len;
5368 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005369 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005370 PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005371 goto failed;
5372 }
5373 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005374 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005375 if (body == NULL) goto failed;
5376 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005377 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005378 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5379 Py_INCREF(tmp2);
5380 res = obj2ast_stmt(tmp2, &val, arena);
5381 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005382 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005383 if (len != PyList_GET_SIZE(tmp)) {
5384 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5385 goto failed;
5386 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005387 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005388 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005389 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005391 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5392 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005393 return 1;
5394 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005395 if (tmp == NULL) {
5396 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5397 return 1;
5398 }
5399 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005400 int res;
5401 Py_ssize_t len;
5402 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005403 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005404 PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005405 goto failed;
5406 }
5407 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005408 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005409 if (decorator_list == NULL) goto failed;
5410 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005411 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005412 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5413 Py_INCREF(tmp2);
5414 res = obj2ast_expr(tmp2, &val, arena);
5415 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005416 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005417 if (len != PyList_GET_SIZE(tmp)) {
5418 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5419 goto failed;
5420 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005421 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005422 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005423 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005424 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005425 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5426 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005427 return 1;
5428 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005429 if (tmp == NULL || tmp == Py_None) {
5430 Py_CLEAR(tmp);
5431 returns = NULL;
5432 }
5433 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005434 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005435 res = obj2ast_expr(tmp, &returns, arena);
5436 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005437 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005438 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005439 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5440 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005441 return 1;
5442 }
5443 if (tmp == NULL || tmp == Py_None) {
5444 Py_CLEAR(tmp);
5445 type_comment = NULL;
5446 }
5447 else {
5448 int res;
5449 res = obj2ast_string(tmp, &type_comment, arena);
5450 if (res != 0) goto failed;
5451 Py_CLEAR(tmp);
5452 }
5453 *out = FunctionDef(name, args, body, decorator_list, returns,
5454 type_comment, lineno, col_offset, end_lineno,
5455 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005456 if (*out == NULL) goto failed;
5457 return 0;
5458 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005459 tp = astmodulestate_global->AsyncFunctionDef_type;
5460 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005461 if (isinstance == -1) {
5462 return 1;
5463 }
5464 if (isinstance) {
5465 identifier name;
5466 arguments_ty args;
5467 asdl_seq* body;
5468 asdl_seq* decorator_list;
5469 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005470 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005471
Dino Viehlandac46eb42019-09-11 10:16:34 -07005472 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005473 return 1;
5474 }
5475 if (tmp == NULL) {
5476 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5477 return 1;
5478 }
5479 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005480 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005481 res = obj2ast_identifier(tmp, &name, arena);
5482 if (res != 0) goto failed;
5483 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005484 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005485 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005486 return 1;
5487 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005488 if (tmp == NULL) {
5489 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5490 return 1;
5491 }
5492 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005493 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005494 res = obj2ast_arguments(tmp, &args, arena);
5495 if (res != 0) goto failed;
5496 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005497 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005498 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005499 return 1;
5500 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005501 if (tmp == NULL) {
5502 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5503 return 1;
5504 }
5505 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005506 int res;
5507 Py_ssize_t len;
5508 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005509 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005510 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04005511 goto failed;
5512 }
5513 len = PyList_GET_SIZE(tmp);
5514 body = _Py_asdl_seq_new(len, arena);
5515 if (body == NULL) goto failed;
5516 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005517 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005518 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5519 Py_INCREF(tmp2);
5520 res = obj2ast_stmt(tmp2, &val, arena);
5521 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005522 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005523 if (len != PyList_GET_SIZE(tmp)) {
5524 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5525 goto failed;
5526 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005527 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005528 }
5529 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005530 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005531 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5532 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005533 return 1;
5534 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005535 if (tmp == NULL) {
5536 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5537 return 1;
5538 }
5539 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005540 int res;
5541 Py_ssize_t len;
5542 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005543 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005544 PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04005545 goto failed;
5546 }
5547 len = PyList_GET_SIZE(tmp);
5548 decorator_list = _Py_asdl_seq_new(len, arena);
5549 if (decorator_list == NULL) goto failed;
5550 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005551 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005552 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5553 Py_INCREF(tmp2);
5554 res = obj2ast_expr(tmp2, &val, arena);
5555 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005556 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005557 if (len != PyList_GET_SIZE(tmp)) {
5558 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5559 goto failed;
5560 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005561 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005562 }
5563 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005564 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005565 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5566 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005567 return 1;
5568 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005569 if (tmp == NULL || tmp == Py_None) {
5570 Py_CLEAR(tmp);
5571 returns = NULL;
5572 }
5573 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005574 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005575 res = obj2ast_expr(tmp, &returns, arena);
5576 if (res != 0) goto failed;
5577 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005578 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005579 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5580 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005581 return 1;
5582 }
5583 if (tmp == NULL || tmp == Py_None) {
5584 Py_CLEAR(tmp);
5585 type_comment = NULL;
5586 }
5587 else {
5588 int res;
5589 res = obj2ast_string(tmp, &type_comment, arena);
5590 if (res != 0) goto failed;
5591 Py_CLEAR(tmp);
5592 }
Yury Selivanov75445082015-05-11 22:57:16 -04005593 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005594 type_comment, lineno, col_offset, end_lineno,
5595 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005596 if (*out == NULL) goto failed;
5597 return 0;
5598 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005599 tp = astmodulestate_global->ClassDef_type;
5600 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005601 if (isinstance == -1) {
5602 return 1;
5603 }
5604 if (isinstance) {
5605 identifier name;
5606 asdl_seq* bases;
5607 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005608 asdl_seq* body;
5609 asdl_seq* decorator_list;
5610
Dino Viehlandac46eb42019-09-11 10:16:34 -07005611 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005612 return 1;
5613 }
5614 if (tmp == NULL) {
5615 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5616 return 1;
5617 }
5618 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005619 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005620 res = obj2ast_identifier(tmp, &name, arena);
5621 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005622 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005623 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005624 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005625 return 1;
5626 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005627 if (tmp == NULL) {
5628 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5629 return 1;
5630 }
5631 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005632 int res;
5633 Py_ssize_t len;
5634 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005635 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005636 PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005637 goto failed;
5638 }
5639 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005640 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005641 if (bases == NULL) goto failed;
5642 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005643 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005644 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5645 Py_INCREF(tmp2);
5646 res = obj2ast_expr(tmp2, &val, arena);
5647 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005648 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005649 if (len != PyList_GET_SIZE(tmp)) {
5650 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5651 goto failed;
5652 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005653 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005654 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005655 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005656 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005657 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5658 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005659 return 1;
5660 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005661 if (tmp == NULL) {
5662 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5663 return 1;
5664 }
5665 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005666 int res;
5667 Py_ssize_t len;
5668 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005669 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005670 PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005671 goto failed;
5672 }
5673 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005674 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005675 if (keywords == NULL) goto failed;
5676 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005677 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005678 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5679 Py_INCREF(tmp2);
5680 res = obj2ast_keyword(tmp2, &val, arena);
5681 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005682 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005683 if (len != PyList_GET_SIZE(tmp)) {
5684 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5685 goto failed;
5686 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005687 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005688 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005689 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005690 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005691 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005692 return 1;
5693 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005694 if (tmp == NULL) {
5695 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5696 return 1;
5697 }
5698 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005699 int res;
5700 Py_ssize_t len;
5701 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005702 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005703 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005704 goto failed;
5705 }
5706 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005707 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005708 if (body == NULL) goto failed;
5709 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005710 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005711 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5712 Py_INCREF(tmp2);
5713 res = obj2ast_stmt(tmp2, &val, arena);
5714 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005715 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005716 if (len != PyList_GET_SIZE(tmp)) {
5717 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5718 goto failed;
5719 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005720 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005721 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005722 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005723 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005724 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5725 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005726 return 1;
5727 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005728 if (tmp == NULL) {
5729 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5730 return 1;
5731 }
5732 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005733 int res;
5734 Py_ssize_t len;
5735 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005736 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005737 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005738 goto failed;
5739 }
5740 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005741 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005742 if (decorator_list == NULL) goto failed;
5743 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005744 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005745 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5746 Py_INCREF(tmp2);
5747 res = obj2ast_expr(tmp2, &val, arena);
5748 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005749 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005750 if (len != PyList_GET_SIZE(tmp)) {
5751 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5752 goto failed;
5753 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005754 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005755 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005756 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005757 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005758 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005759 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005760 if (*out == NULL) goto failed;
5761 return 0;
5762 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005763 tp = astmodulestate_global->Return_type;
5764 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005765 if (isinstance == -1) {
5766 return 1;
5767 }
5768 if (isinstance) {
5769 expr_ty value;
5770
Dino Viehlandac46eb42019-09-11 10:16:34 -07005771 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005772 return 1;
5773 }
5774 if (tmp == NULL || tmp == Py_None) {
5775 Py_CLEAR(tmp);
5776 value = NULL;
5777 }
5778 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005779 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005780 res = obj2ast_expr(tmp, &value, arena);
5781 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005782 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005783 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005784 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5785 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005786 if (*out == NULL) goto failed;
5787 return 0;
5788 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005789 tp = astmodulestate_global->Delete_type;
5790 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005791 if (isinstance == -1) {
5792 return 1;
5793 }
5794 if (isinstance) {
5795 asdl_seq* targets;
5796
Dino Viehlandac46eb42019-09-11 10:16:34 -07005797 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5798 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005799 return 1;
5800 }
5801 if (tmp == NULL) {
5802 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5803 return 1;
5804 }
5805 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005806 int res;
5807 Py_ssize_t len;
5808 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005809 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005810 PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005811 goto failed;
5812 }
5813 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005814 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005815 if (targets == NULL) goto failed;
5816 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005817 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005818 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5819 Py_INCREF(tmp2);
5820 res = obj2ast_expr(tmp2, &val, arena);
5821 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005822 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005823 if (len != PyList_GET_SIZE(tmp)) {
5824 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5825 goto failed;
5826 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005827 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005828 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005829 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005830 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005831 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5832 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005833 if (*out == NULL) goto failed;
5834 return 0;
5835 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005836 tp = astmodulestate_global->Assign_type;
5837 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005838 if (isinstance == -1) {
5839 return 1;
5840 }
5841 if (isinstance) {
5842 asdl_seq* targets;
5843 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005844 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005845
Dino Viehlandac46eb42019-09-11 10:16:34 -07005846 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5847 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005848 return 1;
5849 }
5850 if (tmp == NULL) {
5851 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5852 return 1;
5853 }
5854 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005855 int res;
5856 Py_ssize_t len;
5857 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005858 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005859 PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005860 goto failed;
5861 }
5862 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005863 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005864 if (targets == NULL) goto failed;
5865 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005866 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005867 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5868 Py_INCREF(tmp2);
5869 res = obj2ast_expr(tmp2, &val, arena);
5870 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005871 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005872 if (len != PyList_GET_SIZE(tmp)) {
5873 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5874 goto failed;
5875 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005876 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005877 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005878 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005880 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005881 return 1;
5882 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005883 if (tmp == NULL) {
5884 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5885 return 1;
5886 }
5887 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005888 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005889 res = obj2ast_expr(tmp, &value, arena);
5890 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005891 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005892 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005893 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5894 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005895 return 1;
5896 }
5897 if (tmp == NULL || tmp == Py_None) {
5898 Py_CLEAR(tmp);
5899 type_comment = NULL;
5900 }
5901 else {
5902 int res;
5903 res = obj2ast_string(tmp, &type_comment, arena);
5904 if (res != 0) goto failed;
5905 Py_CLEAR(tmp);
5906 }
5907 *out = Assign(targets, value, type_comment, lineno, col_offset,
5908 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005909 if (*out == NULL) goto failed;
5910 return 0;
5911 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005912 tp = astmodulestate_global->AugAssign_type;
5913 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005914 if (isinstance == -1) {
5915 return 1;
5916 }
5917 if (isinstance) {
5918 expr_ty target;
5919 operator_ty op;
5920 expr_ty value;
5921
Dino Viehlandac46eb42019-09-11 10:16:34 -07005922 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5923 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005924 return 1;
5925 }
5926 if (tmp == NULL) {
5927 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5928 return 1;
5929 }
5930 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005931 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005932 res = obj2ast_expr(tmp, &target, arena);
5933 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005934 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005935 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005936 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005937 return 1;
5938 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005939 if (tmp == NULL) {
5940 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5941 return 1;
5942 }
5943 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005944 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005945 res = obj2ast_operator(tmp, &op, arena);
5946 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005947 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005949 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005950 return 1;
5951 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005952 if (tmp == NULL) {
5953 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5954 return 1;
5955 }
5956 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005957 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005958 res = obj2ast_expr(tmp, &value, arena);
5959 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005960 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005961 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005962 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5963 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005964 if (*out == NULL) goto failed;
5965 return 0;
5966 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005967 tp = astmodulestate_global->AnnAssign_type;
5968 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005969 if (isinstance == -1) {
5970 return 1;
5971 }
5972 if (isinstance) {
5973 expr_ty target;
5974 expr_ty annotation;
5975 expr_ty value;
5976 int simple;
5977
Dino Viehlandac46eb42019-09-11 10:16:34 -07005978 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5979 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005980 return 1;
5981 }
5982 if (tmp == NULL) {
5983 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5984 return 1;
5985 }
5986 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005987 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005988 res = obj2ast_expr(tmp, &target, arena);
5989 if (res != 0) goto failed;
5990 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005991 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005992 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
5993 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005994 return 1;
5995 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005996 if (tmp == NULL) {
5997 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
5998 return 1;
5999 }
6000 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006001 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006002 res = obj2ast_expr(tmp, &annotation, arena);
6003 if (res != 0) goto failed;
6004 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006005 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006006 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006007 return 1;
6008 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006009 if (tmp == NULL || tmp == Py_None) {
6010 Py_CLEAR(tmp);
6011 value = NULL;
6012 }
6013 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006014 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006015 res = obj2ast_expr(tmp, &value, arena);
6016 if (res != 0) goto failed;
6017 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006018 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006019 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6020 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006021 return 1;
6022 }
6023 if (tmp == NULL) {
6024 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6025 return 1;
6026 }
6027 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006028 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006029 res = obj2ast_int(tmp, &simple, arena);
6030 if (res != 0) goto failed;
6031 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006032 }
6033 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006034 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006035 if (*out == NULL) goto failed;
6036 return 0;
6037 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006038 tp = astmodulestate_global->For_type;
6039 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006040 if (isinstance == -1) {
6041 return 1;
6042 }
6043 if (isinstance) {
6044 expr_ty target;
6045 expr_ty iter;
6046 asdl_seq* body;
6047 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006048 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006049
Dino Viehlandac46eb42019-09-11 10:16:34 -07006050 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6051 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006052 return 1;
6053 }
6054 if (tmp == NULL) {
6055 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6056 return 1;
6057 }
6058 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006059 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006060 res = obj2ast_expr(tmp, &target, arena);
6061 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006062 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006063 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006064 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006065 return 1;
6066 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006067 if (tmp == NULL) {
6068 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6069 return 1;
6070 }
6071 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006072 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006073 res = obj2ast_expr(tmp, &iter, arena);
6074 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006075 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006076 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006077 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006078 return 1;
6079 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006080 if (tmp == NULL) {
6081 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6082 return 1;
6083 }
6084 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006085 int res;
6086 Py_ssize_t len;
6087 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006088 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006089 PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006090 goto failed;
6091 }
6092 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006093 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006094 if (body == NULL) goto failed;
6095 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006096 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006097 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6098 Py_INCREF(tmp2);
6099 res = obj2ast_stmt(tmp2, &val, arena);
6100 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006101 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006102 if (len != PyList_GET_SIZE(tmp)) {
6103 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6104 goto failed;
6105 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006106 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006107 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006108 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006110 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6111 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006112 return 1;
6113 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006114 if (tmp == NULL) {
6115 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6116 return 1;
6117 }
6118 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006119 int res;
6120 Py_ssize_t len;
6121 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006122 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006123 PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006124 goto failed;
6125 }
6126 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006127 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006128 if (orelse == NULL) goto failed;
6129 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006130 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006131 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6132 Py_INCREF(tmp2);
6133 res = obj2ast_stmt(tmp2, &val, arena);
6134 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006135 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006136 if (len != PyList_GET_SIZE(tmp)) {
6137 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6138 goto failed;
6139 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006140 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006141 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006142 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006143 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006144 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6145 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006146 return 1;
6147 }
6148 if (tmp == NULL || tmp == Py_None) {
6149 Py_CLEAR(tmp);
6150 type_comment = NULL;
6151 }
6152 else {
6153 int res;
6154 res = obj2ast_string(tmp, &type_comment, arena);
6155 if (res != 0) goto failed;
6156 Py_CLEAR(tmp);
6157 }
6158 *out = For(target, iter, body, orelse, type_comment, lineno,
6159 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006160 if (*out == NULL) goto failed;
6161 return 0;
6162 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006163 tp = astmodulestate_global->AsyncFor_type;
6164 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006165 if (isinstance == -1) {
6166 return 1;
6167 }
6168 if (isinstance) {
6169 expr_ty target;
6170 expr_ty iter;
6171 asdl_seq* body;
6172 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006173 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006174
Dino Viehlandac46eb42019-09-11 10:16:34 -07006175 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6176 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006177 return 1;
6178 }
6179 if (tmp == NULL) {
6180 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6181 return 1;
6182 }
6183 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006184 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006185 res = obj2ast_expr(tmp, &target, arena);
6186 if (res != 0) goto failed;
6187 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006188 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006189 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006190 return 1;
6191 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006192 if (tmp == NULL) {
6193 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6194 return 1;
6195 }
6196 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006197 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006198 res = obj2ast_expr(tmp, &iter, arena);
6199 if (res != 0) goto failed;
6200 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006202 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006203 return 1;
6204 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006205 if (tmp == NULL) {
6206 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6207 return 1;
6208 }
6209 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006210 int res;
6211 Py_ssize_t len;
6212 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006213 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006214 PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04006215 goto failed;
6216 }
6217 len = PyList_GET_SIZE(tmp);
6218 body = _Py_asdl_seq_new(len, arena);
6219 if (body == NULL) goto failed;
6220 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006221 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006222 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6223 Py_INCREF(tmp2);
6224 res = obj2ast_stmt(tmp2, &val, arena);
6225 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006226 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006227 if (len != PyList_GET_SIZE(tmp)) {
6228 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6229 goto failed;
6230 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006231 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006232 }
6233 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006235 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6236 {
Yury Selivanov75445082015-05-11 22:57:16 -04006237 return 1;
6238 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006239 if (tmp == NULL) {
6240 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6241 return 1;
6242 }
6243 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006244 int res;
6245 Py_ssize_t len;
6246 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006247 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006248 PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04006249 goto failed;
6250 }
6251 len = PyList_GET_SIZE(tmp);
6252 orelse = _Py_asdl_seq_new(len, arena);
6253 if (orelse == NULL) goto failed;
6254 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006255 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006256 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6257 Py_INCREF(tmp2);
6258 res = obj2ast_stmt(tmp2, &val, arena);
6259 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006260 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006261 if (len != PyList_GET_SIZE(tmp)) {
6262 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6263 goto failed;
6264 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006265 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006266 }
6267 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006269 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6270 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006271 return 1;
6272 }
6273 if (tmp == NULL || tmp == Py_None) {
6274 Py_CLEAR(tmp);
6275 type_comment = NULL;
6276 }
6277 else {
6278 int res;
6279 res = obj2ast_string(tmp, &type_comment, arena);
6280 if (res != 0) goto failed;
6281 Py_CLEAR(tmp);
6282 }
6283 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6284 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006285 if (*out == NULL) goto failed;
6286 return 0;
6287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006288 tp = astmodulestate_global->While_type;
6289 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006290 if (isinstance == -1) {
6291 return 1;
6292 }
6293 if (isinstance) {
6294 expr_ty test;
6295 asdl_seq* body;
6296 asdl_seq* orelse;
6297
Dino Viehlandac46eb42019-09-11 10:16:34 -07006298 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006299 return 1;
6300 }
6301 if (tmp == NULL) {
6302 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6303 return 1;
6304 }
6305 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006306 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006307 res = obj2ast_expr(tmp, &test, arena);
6308 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006309 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006310 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006311 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006312 return 1;
6313 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006314 if (tmp == NULL) {
6315 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6316 return 1;
6317 }
6318 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006319 int res;
6320 Py_ssize_t len;
6321 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006322 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006323 PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006324 goto failed;
6325 }
6326 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006327 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006328 if (body == NULL) goto failed;
6329 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006330 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006331 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6332 Py_INCREF(tmp2);
6333 res = obj2ast_stmt(tmp2, &val, arena);
6334 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006335 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006336 if (len != PyList_GET_SIZE(tmp)) {
6337 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6338 goto failed;
6339 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006340 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006341 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006342 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006343 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006344 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6345 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006346 return 1;
6347 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006348 if (tmp == NULL) {
6349 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6350 return 1;
6351 }
6352 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006353 int res;
6354 Py_ssize_t len;
6355 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006356 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006357 PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006358 goto failed;
6359 }
6360 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006361 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006362 if (orelse == NULL) goto failed;
6363 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006364 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006365 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6366 Py_INCREF(tmp2);
6367 res = obj2ast_stmt(tmp2, &val, arena);
6368 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006369 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006370 if (len != PyList_GET_SIZE(tmp)) {
6371 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6372 goto failed;
6373 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006374 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006375 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006376 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006377 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006378 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6379 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006380 if (*out == NULL) goto failed;
6381 return 0;
6382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006383 tp = astmodulestate_global->If_type;
6384 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006385 if (isinstance == -1) {
6386 return 1;
6387 }
6388 if (isinstance) {
6389 expr_ty test;
6390 asdl_seq* body;
6391 asdl_seq* orelse;
6392
Dino Viehlandac46eb42019-09-11 10:16:34 -07006393 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006394 return 1;
6395 }
6396 if (tmp == NULL) {
6397 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6398 return 1;
6399 }
6400 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006401 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006402 res = obj2ast_expr(tmp, &test, arena);
6403 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006404 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006405 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006406 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006407 return 1;
6408 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006409 if (tmp == NULL) {
6410 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6411 return 1;
6412 }
6413 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006414 int res;
6415 Py_ssize_t len;
6416 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006417 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006418 PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006419 goto failed;
6420 }
6421 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006422 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006423 if (body == NULL) goto failed;
6424 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006425 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006426 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6427 Py_INCREF(tmp2);
6428 res = obj2ast_stmt(tmp2, &val, arena);
6429 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006430 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006431 if (len != PyList_GET_SIZE(tmp)) {
6432 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6433 goto failed;
6434 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006435 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006436 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006437 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006438 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006439 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6440 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006441 return 1;
6442 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006443 if (tmp == NULL) {
6444 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6445 return 1;
6446 }
6447 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006448 int res;
6449 Py_ssize_t len;
6450 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006451 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006452 PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006453 goto failed;
6454 }
6455 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006456 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006457 if (orelse == NULL) goto failed;
6458 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006459 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006460 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6461 Py_INCREF(tmp2);
6462 res = obj2ast_stmt(tmp2, &val, arena);
6463 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006464 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006465 if (len != PyList_GET_SIZE(tmp)) {
6466 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6467 goto failed;
6468 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006469 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006470 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006471 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006472 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006473 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6474 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006475 if (*out == NULL) goto failed;
6476 return 0;
6477 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006478 tp = astmodulestate_global->With_type;
6479 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006480 if (isinstance == -1) {
6481 return 1;
6482 }
6483 if (isinstance) {
6484 asdl_seq* items;
6485 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006486 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006487
Dino Viehlandac46eb42019-09-11 10:16:34 -07006488 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006489 return 1;
6490 }
6491 if (tmp == NULL) {
6492 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6493 return 1;
6494 }
6495 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006496 int res;
6497 Py_ssize_t len;
6498 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006499 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006500 PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006501 goto failed;
6502 }
6503 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006504 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006505 if (items == NULL) goto failed;
6506 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006507 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006508 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6509 Py_INCREF(tmp2);
6510 res = obj2ast_withitem(tmp2, &val, arena);
6511 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006512 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006513 if (len != PyList_GET_SIZE(tmp)) {
6514 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6515 goto failed;
6516 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006517 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006518 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006519 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006520 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006521 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006522 return 1;
6523 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006524 if (tmp == NULL) {
6525 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6526 return 1;
6527 }
6528 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006529 int res;
6530 Py_ssize_t len;
6531 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006532 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006533 PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006534 goto failed;
6535 }
6536 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006537 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006538 if (body == NULL) goto failed;
6539 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006540 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006541 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6542 Py_INCREF(tmp2);
6543 res = obj2ast_stmt(tmp2, &val, arena);
6544 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006545 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006546 if (len != PyList_GET_SIZE(tmp)) {
6547 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6548 goto failed;
6549 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006550 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006551 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006552 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006553 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006554 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6555 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006556 return 1;
6557 }
6558 if (tmp == NULL || tmp == Py_None) {
6559 Py_CLEAR(tmp);
6560 type_comment = NULL;
6561 }
6562 else {
6563 int res;
6564 res = obj2ast_string(tmp, &type_comment, arena);
6565 if (res != 0) goto failed;
6566 Py_CLEAR(tmp);
6567 }
6568 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006569 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006570 if (*out == NULL) goto failed;
6571 return 0;
6572 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006573 tp = astmodulestate_global->AsyncWith_type;
6574 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006575 if (isinstance == -1) {
6576 return 1;
6577 }
6578 if (isinstance) {
6579 asdl_seq* items;
6580 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006581 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006582
Dino Viehlandac46eb42019-09-11 10:16:34 -07006583 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006584 return 1;
6585 }
6586 if (tmp == NULL) {
6587 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6588 return 1;
6589 }
6590 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006591 int res;
6592 Py_ssize_t len;
6593 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006594 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006595 PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04006596 goto failed;
6597 }
6598 len = PyList_GET_SIZE(tmp);
6599 items = _Py_asdl_seq_new(len, arena);
6600 if (items == NULL) goto failed;
6601 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006602 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006603 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6604 Py_INCREF(tmp2);
6605 res = obj2ast_withitem(tmp2, &val, arena);
6606 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006607 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006608 if (len != PyList_GET_SIZE(tmp)) {
6609 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6610 goto failed;
6611 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006612 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006613 }
6614 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006615 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006616 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006617 return 1;
6618 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006619 if (tmp == NULL) {
6620 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6621 return 1;
6622 }
6623 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006624 int res;
6625 Py_ssize_t len;
6626 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006627 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006628 PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Yury Selivanov75445082015-05-11 22:57:16 -04006629 goto failed;
6630 }
6631 len = PyList_GET_SIZE(tmp);
6632 body = _Py_asdl_seq_new(len, arena);
6633 if (body == NULL) goto failed;
6634 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006635 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006636 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6637 Py_INCREF(tmp2);
6638 res = obj2ast_stmt(tmp2, &val, arena);
6639 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006640 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006641 if (len != PyList_GET_SIZE(tmp)) {
6642 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6643 goto failed;
6644 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006645 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006646 }
6647 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006648 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006649 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6650 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006651 return 1;
6652 }
6653 if (tmp == NULL || tmp == Py_None) {
6654 Py_CLEAR(tmp);
6655 type_comment = NULL;
6656 }
6657 else {
6658 int res;
6659 res = obj2ast_string(tmp, &type_comment, arena);
6660 if (res != 0) goto failed;
6661 Py_CLEAR(tmp);
6662 }
6663 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6664 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006665 if (*out == NULL) goto failed;
6666 return 0;
6667 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006668 tp = astmodulestate_global->Raise_type;
6669 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006670 if (isinstance == -1) {
6671 return 1;
6672 }
6673 if (isinstance) {
6674 expr_ty exc;
6675 expr_ty cause;
6676
Dino Viehlandac46eb42019-09-11 10:16:34 -07006677 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006678 return 1;
6679 }
6680 if (tmp == NULL || tmp == Py_None) {
6681 Py_CLEAR(tmp);
6682 exc = NULL;
6683 }
6684 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006685 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006686 res = obj2ast_expr(tmp, &exc, arena);
6687 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006688 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006689 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006690 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006691 return 1;
6692 }
6693 if (tmp == NULL || tmp == Py_None) {
6694 Py_CLEAR(tmp);
6695 cause = NULL;
6696 }
6697 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006698 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006699 res = obj2ast_expr(tmp, &cause, arena);
6700 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006701 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006702 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006703 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6704 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006705 if (*out == NULL) goto failed;
6706 return 0;
6707 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006708 tp = astmodulestate_global->Try_type;
6709 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006710 if (isinstance == -1) {
6711 return 1;
6712 }
6713 if (isinstance) {
6714 asdl_seq* body;
6715 asdl_seq* handlers;
6716 asdl_seq* orelse;
6717 asdl_seq* finalbody;
6718
Dino Viehlandac46eb42019-09-11 10:16:34 -07006719 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006720 return 1;
6721 }
6722 if (tmp == NULL) {
6723 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6724 return 1;
6725 }
6726 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006727 int res;
6728 Py_ssize_t len;
6729 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006730 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006731 PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006732 goto failed;
6733 }
6734 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006735 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006736 if (body == NULL) goto failed;
6737 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006738 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006739 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6740 Py_INCREF(tmp2);
6741 res = obj2ast_stmt(tmp2, &val, arena);
6742 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006743 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006744 if (len != PyList_GET_SIZE(tmp)) {
6745 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6746 goto failed;
6747 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006748 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006749 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006750 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006751 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006752 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6753 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006754 return 1;
6755 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006756 if (tmp == NULL) {
6757 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6758 return 1;
6759 }
6760 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006761 int res;
6762 Py_ssize_t len;
6763 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006764 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006765 PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006766 goto failed;
6767 }
6768 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006769 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006770 if (handlers == NULL) goto failed;
6771 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006772 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006773 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6774 Py_INCREF(tmp2);
6775 res = obj2ast_excepthandler(tmp2, &val, arena);
6776 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006777 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006778 if (len != PyList_GET_SIZE(tmp)) {
6779 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6780 goto failed;
6781 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006782 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006783 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006784 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006785 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006786 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6787 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006788 return 1;
6789 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006790 if (tmp == NULL) {
6791 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6792 return 1;
6793 }
6794 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006795 int res;
6796 Py_ssize_t len;
6797 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006798 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006799 PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006800 goto failed;
6801 }
6802 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006803 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006804 if (orelse == NULL) goto failed;
6805 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006806 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006807 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6808 Py_INCREF(tmp2);
6809 res = obj2ast_stmt(tmp2, &val, arena);
6810 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006811 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006812 if (len != PyList_GET_SIZE(tmp)) {
6813 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6814 goto failed;
6815 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006816 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006817 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006818 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006819 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006820 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6821 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006822 return 1;
6823 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006824 if (tmp == NULL) {
6825 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6826 return 1;
6827 }
6828 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006829 int res;
6830 Py_ssize_t len;
6831 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006832 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006833 PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006834 goto failed;
6835 }
6836 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006837 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006838 if (finalbody == NULL) goto failed;
6839 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006840 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006841 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6842 Py_INCREF(tmp2);
6843 res = obj2ast_stmt(tmp2, &val, arena);
6844 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006845 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006846 if (len != PyList_GET_SIZE(tmp)) {
6847 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6848 goto failed;
6849 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006850 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006851 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006852 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006853 }
6854 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006855 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006856 if (*out == NULL) goto failed;
6857 return 0;
6858 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006859 tp = astmodulestate_global->Assert_type;
6860 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006861 if (isinstance == -1) {
6862 return 1;
6863 }
6864 if (isinstance) {
6865 expr_ty test;
6866 expr_ty msg;
6867
Dino Viehlandac46eb42019-09-11 10:16:34 -07006868 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006869 return 1;
6870 }
6871 if (tmp == NULL) {
6872 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6873 return 1;
6874 }
6875 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006876 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006877 res = obj2ast_expr(tmp, &test, arena);
6878 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006879 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006880 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006881 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006882 return 1;
6883 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006884 if (tmp == NULL || tmp == Py_None) {
6885 Py_CLEAR(tmp);
6886 msg = NULL;
6887 }
6888 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006889 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006890 res = obj2ast_expr(tmp, &msg, arena);
6891 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006892 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006893 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006894 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6895 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006896 if (*out == NULL) goto failed;
6897 return 0;
6898 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006899 tp = astmodulestate_global->Import_type;
6900 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006901 if (isinstance == -1) {
6902 return 1;
6903 }
6904 if (isinstance) {
6905 asdl_seq* names;
6906
Dino Viehlandac46eb42019-09-11 10:16:34 -07006907 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006908 return 1;
6909 }
6910 if (tmp == NULL) {
6911 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6912 return 1;
6913 }
6914 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006915 int res;
6916 Py_ssize_t len;
6917 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006918 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006919 PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006920 goto failed;
6921 }
6922 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006923 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006924 if (names == NULL) goto failed;
6925 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006926 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006927 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6928 Py_INCREF(tmp2);
6929 res = obj2ast_alias(tmp2, &val, arena);
6930 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006931 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006932 if (len != PyList_GET_SIZE(tmp)) {
6933 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6934 goto failed;
6935 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006936 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006937 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006938 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006939 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006940 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6941 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006942 if (*out == NULL) goto failed;
6943 return 0;
6944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006945 tp = astmodulestate_global->ImportFrom_type;
6946 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006947 if (isinstance == -1) {
6948 return 1;
6949 }
6950 if (isinstance) {
6951 identifier module;
6952 asdl_seq* names;
6953 int level;
6954
Dino Viehlandac46eb42019-09-11 10:16:34 -07006955 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6956 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006957 return 1;
6958 }
6959 if (tmp == NULL || tmp == Py_None) {
6960 Py_CLEAR(tmp);
6961 module = NULL;
6962 }
6963 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006964 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006965 res = obj2ast_identifier(tmp, &module, arena);
6966 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006967 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006968 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006969 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006970 return 1;
6971 }
6972 if (tmp == NULL) {
6973 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6974 return 1;
6975 }
6976 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006977 int res;
6978 Py_ssize_t len;
6979 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006980 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006981 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 goto failed;
6983 }
6984 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006985 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006986 if (names == NULL) goto failed;
6987 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006988 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006989 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6990 Py_INCREF(tmp2);
6991 res = obj2ast_alias(tmp2, &val, arena);
6992 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006993 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006994 if (len != PyList_GET_SIZE(tmp)) {
6995 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
6996 goto failed;
6997 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006998 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006999 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007000 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007001 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007002 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007003 return 1;
7004 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007005 if (tmp == NULL || tmp == Py_None) {
7006 Py_CLEAR(tmp);
7007 level = 0;
7008 }
7009 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007010 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007011 res = obj2ast_int(tmp, &level, arena);
7012 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007013 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007014 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007015 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7016 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007017 if (*out == NULL) goto failed;
7018 return 0;
7019 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007020 tp = astmodulestate_global->Global_type;
7021 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007022 if (isinstance == -1) {
7023 return 1;
7024 }
7025 if (isinstance) {
7026 asdl_seq* names;
7027
Dino Viehlandac46eb42019-09-11 10:16:34 -07007028 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007029 return 1;
7030 }
7031 if (tmp == NULL) {
7032 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7033 return 1;
7034 }
7035 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007036 int res;
7037 Py_ssize_t len;
7038 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007039 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007040 PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007041 goto failed;
7042 }
7043 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007044 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007045 if (names == NULL) goto failed;
7046 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007047 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007048 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7049 Py_INCREF(tmp2);
7050 res = obj2ast_identifier(tmp2, &val, arena);
7051 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007052 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007053 if (len != PyList_GET_SIZE(tmp)) {
7054 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7055 goto failed;
7056 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007057 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007058 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007059 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007060 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007061 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7062 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007063 if (*out == NULL) goto failed;
7064 return 0;
7065 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007066 tp = astmodulestate_global->Nonlocal_type;
7067 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007068 if (isinstance == -1) {
7069 return 1;
7070 }
7071 if (isinstance) {
7072 asdl_seq* names;
7073
Dino Viehlandac46eb42019-09-11 10:16:34 -07007074 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007075 return 1;
7076 }
7077 if (tmp == NULL) {
7078 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7079 return 1;
7080 }
7081 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007082 int res;
7083 Py_ssize_t len;
7084 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007085 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007086 PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007087 goto failed;
7088 }
7089 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007090 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007091 if (names == NULL) goto failed;
7092 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007093 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007094 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7095 Py_INCREF(tmp2);
7096 res = obj2ast_identifier(tmp2, &val, arena);
7097 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007098 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007099 if (len != PyList_GET_SIZE(tmp)) {
7100 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7101 goto failed;
7102 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007103 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007104 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007105 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007106 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007107 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7108 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007109 if (*out == NULL) goto failed;
7110 return 0;
7111 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007112 tp = astmodulestate_global->Expr_type;
7113 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007114 if (isinstance == -1) {
7115 return 1;
7116 }
7117 if (isinstance) {
7118 expr_ty value;
7119
Dino Viehlandac46eb42019-09-11 10:16:34 -07007120 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007121 return 1;
7122 }
7123 if (tmp == NULL) {
7124 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7125 return 1;
7126 }
7127 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007128 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007129 res = obj2ast_expr(tmp, &value, arena);
7130 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007131 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007132 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007133 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7134 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007135 if (*out == NULL) goto failed;
7136 return 0;
7137 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007138 tp = astmodulestate_global->Pass_type;
7139 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007140 if (isinstance == -1) {
7141 return 1;
7142 }
7143 if (isinstance) {
7144
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007145 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007146 if (*out == NULL) goto failed;
7147 return 0;
7148 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007149 tp = astmodulestate_global->Break_type;
7150 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007151 if (isinstance == -1) {
7152 return 1;
7153 }
7154 if (isinstance) {
7155
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007156 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007157 if (*out == NULL) goto failed;
7158 return 0;
7159 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007160 tp = astmodulestate_global->Continue_type;
7161 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007162 if (isinstance == -1) {
7163 return 1;
7164 }
7165 if (isinstance) {
7166
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007167 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007168 if (*out == NULL) goto failed;
7169 return 0;
7170 }
7171
7172 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7173 failed:
7174 Py_XDECREF(tmp);
7175 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007176}
7177
7178int
7179obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7180{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007181 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007182
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007183 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007184 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007185 int lineno;
7186 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007187 int end_lineno;
7188 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007189
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007190 if (obj == Py_None) {
7191 *out = NULL;
7192 return 0;
7193 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007194 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007195 return 1;
7196 }
7197 if (tmp == NULL) {
7198 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7199 return 1;
7200 }
7201 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007202 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007203 res = obj2ast_int(tmp, &lineno, arena);
7204 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007205 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007206 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007207 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7208 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007209 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007210 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007211 if (tmp == NULL) {
7212 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7213 return 1;
7214 }
7215 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007216 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007217 res = obj2ast_int(tmp, &col_offset, arena);
7218 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007219 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007221 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7222 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007223 return 1;
7224 }
7225 if (tmp == NULL || tmp == Py_None) {
7226 Py_CLEAR(tmp);
7227 end_lineno = 0;
7228 }
7229 else {
7230 int res;
7231 res = obj2ast_int(tmp, &end_lineno, arena);
7232 if (res != 0) goto failed;
7233 Py_CLEAR(tmp);
7234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007235 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7236 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007237 return 1;
7238 }
7239 if (tmp == NULL || tmp == Py_None) {
7240 Py_CLEAR(tmp);
7241 end_col_offset = 0;
7242 }
7243 else {
7244 int res;
7245 res = obj2ast_int(tmp, &end_col_offset, arena);
7246 if (res != 0) goto failed;
7247 Py_CLEAR(tmp);
7248 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007249 tp = astmodulestate_global->BoolOp_type;
7250 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007251 if (isinstance == -1) {
7252 return 1;
7253 }
7254 if (isinstance) {
7255 boolop_ty op;
7256 asdl_seq* values;
7257
Dino Viehlandac46eb42019-09-11 10:16:34 -07007258 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007259 return 1;
7260 }
7261 if (tmp == NULL) {
7262 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7263 return 1;
7264 }
7265 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007266 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007267 res = obj2ast_boolop(tmp, &op, arena);
7268 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007269 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007270 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007271 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7272 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007273 return 1;
7274 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007275 if (tmp == NULL) {
7276 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7277 return 1;
7278 }
7279 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007280 int res;
7281 Py_ssize_t len;
7282 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007283 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007284 PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007285 goto failed;
7286 }
7287 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007288 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007289 if (values == NULL) goto failed;
7290 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007291 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007292 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7293 Py_INCREF(tmp2);
7294 res = obj2ast_expr(tmp2, &val, arena);
7295 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007296 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007297 if (len != PyList_GET_SIZE(tmp)) {
7298 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7299 goto failed;
7300 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007301 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007302 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007303 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007304 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007305 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7306 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007307 if (*out == NULL) goto failed;
7308 return 0;
7309 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007310 tp = astmodulestate_global->NamedExpr_type;
7311 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007312 if (isinstance == -1) {
7313 return 1;
7314 }
7315 if (isinstance) {
7316 expr_ty target;
7317 expr_ty value;
7318
Dino Viehlandac46eb42019-09-11 10:16:34 -07007319 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7320 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007321 return 1;
7322 }
7323 if (tmp == NULL) {
7324 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7325 return 1;
7326 }
7327 else {
7328 int res;
7329 res = obj2ast_expr(tmp, &target, arena);
7330 if (res != 0) goto failed;
7331 Py_CLEAR(tmp);
7332 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007333 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007334 return 1;
7335 }
7336 if (tmp == NULL) {
7337 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7338 return 1;
7339 }
7340 else {
7341 int res;
7342 res = obj2ast_expr(tmp, &value, arena);
7343 if (res != 0) goto failed;
7344 Py_CLEAR(tmp);
7345 }
7346 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7347 end_col_offset, arena);
7348 if (*out == NULL) goto failed;
7349 return 0;
7350 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007351 tp = astmodulestate_global->BinOp_type;
7352 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007353 if (isinstance == -1) {
7354 return 1;
7355 }
7356 if (isinstance) {
7357 expr_ty left;
7358 operator_ty op;
7359 expr_ty right;
7360
Dino Viehlandac46eb42019-09-11 10:16:34 -07007361 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007362 return 1;
7363 }
7364 if (tmp == NULL) {
7365 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7366 return 1;
7367 }
7368 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007369 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007370 res = obj2ast_expr(tmp, &left, arena);
7371 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007372 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007374 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007375 return 1;
7376 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007377 if (tmp == NULL) {
7378 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7379 return 1;
7380 }
7381 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007382 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007383 res = obj2ast_operator(tmp, &op, arena);
7384 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007385 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007386 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007387 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007388 return 1;
7389 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007390 if (tmp == NULL) {
7391 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7392 return 1;
7393 }
7394 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007395 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007396 res = obj2ast_expr(tmp, &right, arena);
7397 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007398 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007399 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007400 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7401 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007402 if (*out == NULL) goto failed;
7403 return 0;
7404 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007405 tp = astmodulestate_global->UnaryOp_type;
7406 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007407 if (isinstance == -1) {
7408 return 1;
7409 }
7410 if (isinstance) {
7411 unaryop_ty op;
7412 expr_ty operand;
7413
Dino Viehlandac46eb42019-09-11 10:16:34 -07007414 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007415 return 1;
7416 }
7417 if (tmp == NULL) {
7418 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7419 return 1;
7420 }
7421 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007422 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007423 res = obj2ast_unaryop(tmp, &op, arena);
7424 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007425 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007426 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007427 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7428 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007429 return 1;
7430 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007431 if (tmp == NULL) {
7432 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7433 return 1;
7434 }
7435 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007436 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007437 res = obj2ast_expr(tmp, &operand, arena);
7438 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007439 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007440 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007441 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7442 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007443 if (*out == NULL) goto failed;
7444 return 0;
7445 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007446 tp = astmodulestate_global->Lambda_type;
7447 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007448 if (isinstance == -1) {
7449 return 1;
7450 }
7451 if (isinstance) {
7452 arguments_ty args;
7453 expr_ty body;
7454
Dino Viehlandac46eb42019-09-11 10:16:34 -07007455 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007456 return 1;
7457 }
7458 if (tmp == NULL) {
7459 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7460 return 1;
7461 }
7462 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007463 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007464 res = obj2ast_arguments(tmp, &args, arena);
7465 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007466 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007467 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007468 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007469 return 1;
7470 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007471 if (tmp == NULL) {
7472 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7473 return 1;
7474 }
7475 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007476 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007477 res = obj2ast_expr(tmp, &body, arena);
7478 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007479 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007480 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007481 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7482 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007483 if (*out == NULL) goto failed;
7484 return 0;
7485 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007486 tp = astmodulestate_global->IfExp_type;
7487 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007488 if (isinstance == -1) {
7489 return 1;
7490 }
7491 if (isinstance) {
7492 expr_ty test;
7493 expr_ty body;
7494 expr_ty orelse;
7495
Dino Viehlandac46eb42019-09-11 10:16:34 -07007496 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007497 return 1;
7498 }
7499 if (tmp == NULL) {
7500 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7501 return 1;
7502 }
7503 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007504 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007505 res = obj2ast_expr(tmp, &test, arena);
7506 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007507 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007508 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007509 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007510 return 1;
7511 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007512 if (tmp == NULL) {
7513 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7514 return 1;
7515 }
7516 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007517 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007518 res = obj2ast_expr(tmp, &body, arena);
7519 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007520 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007521 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007522 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7523 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007524 return 1;
7525 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007526 if (tmp == NULL) {
7527 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7528 return 1;
7529 }
7530 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007531 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007532 res = obj2ast_expr(tmp, &orelse, arena);
7533 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007534 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007535 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007536 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7537 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007538 if (*out == NULL) goto failed;
7539 return 0;
7540 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007541 tp = astmodulestate_global->Dict_type;
7542 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007543 if (isinstance == -1) {
7544 return 1;
7545 }
7546 if (isinstance) {
7547 asdl_seq* keys;
7548 asdl_seq* values;
7549
Dino Viehlandac46eb42019-09-11 10:16:34 -07007550 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007551 return 1;
7552 }
7553 if (tmp == NULL) {
7554 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7555 return 1;
7556 }
7557 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007558 int res;
7559 Py_ssize_t len;
7560 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007561 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007562 PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007563 goto failed;
7564 }
7565 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007566 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007567 if (keys == NULL) goto failed;
7568 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007569 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007570 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7571 Py_INCREF(tmp2);
7572 res = obj2ast_expr(tmp2, &val, arena);
7573 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007574 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007575 if (len != PyList_GET_SIZE(tmp)) {
7576 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7577 goto failed;
7578 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007579 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007580 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007581 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007582 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007583 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7584 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007585 return 1;
7586 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007587 if (tmp == NULL) {
7588 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7589 return 1;
7590 }
7591 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007592 int res;
7593 Py_ssize_t len;
7594 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007595 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007596 PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007597 goto failed;
7598 }
7599 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007600 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007601 if (values == NULL) goto failed;
7602 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007603 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007604 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7605 Py_INCREF(tmp2);
7606 res = obj2ast_expr(tmp2, &val, arena);
7607 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007608 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007609 if (len != PyList_GET_SIZE(tmp)) {
7610 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7611 goto failed;
7612 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007613 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007614 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007615 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007616 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007617 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7618 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007619 if (*out == NULL) goto failed;
7620 return 0;
7621 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007622 tp = astmodulestate_global->Set_type;
7623 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007624 if (isinstance == -1) {
7625 return 1;
7626 }
7627 if (isinstance) {
7628 asdl_seq* elts;
7629
Dino Viehlandac46eb42019-09-11 10:16:34 -07007630 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007631 return 1;
7632 }
7633 if (tmp == NULL) {
7634 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7635 return 1;
7636 }
7637 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007638 int res;
7639 Py_ssize_t len;
7640 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007641 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007642 PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007643 goto failed;
7644 }
7645 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007646 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007647 if (elts == NULL) goto failed;
7648 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007649 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007650 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7651 Py_INCREF(tmp2);
7652 res = obj2ast_expr(tmp2, &val, arena);
7653 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007654 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007655 if (len != PyList_GET_SIZE(tmp)) {
7656 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7657 goto failed;
7658 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007659 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007660 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007661 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007662 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007663 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007664 if (*out == NULL) goto failed;
7665 return 0;
7666 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007667 tp = astmodulestate_global->ListComp_type;
7668 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007669 if (isinstance == -1) {
7670 return 1;
7671 }
7672 if (isinstance) {
7673 expr_ty elt;
7674 asdl_seq* generators;
7675
Dino Viehlandac46eb42019-09-11 10:16:34 -07007676 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007677 return 1;
7678 }
7679 if (tmp == NULL) {
7680 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7681 return 1;
7682 }
7683 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007684 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007685 res = obj2ast_expr(tmp, &elt, arena);
7686 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007687 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007688 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007689 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7690 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007691 return 1;
7692 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007693 if (tmp == NULL) {
7694 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7695 return 1;
7696 }
7697 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007698 int res;
7699 Py_ssize_t len;
7700 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007701 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007702 PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007703 goto failed;
7704 }
7705 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007706 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007707 if (generators == NULL) goto failed;
7708 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007709 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007710 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7711 Py_INCREF(tmp2);
7712 res = obj2ast_comprehension(tmp2, &val, arena);
7713 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007714 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007715 if (len != PyList_GET_SIZE(tmp)) {
7716 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7717 goto failed;
7718 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007719 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007720 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007721 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007722 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007723 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7724 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007725 if (*out == NULL) goto failed;
7726 return 0;
7727 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007728 tp = astmodulestate_global->SetComp_type;
7729 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007730 if (isinstance == -1) {
7731 return 1;
7732 }
7733 if (isinstance) {
7734 expr_ty elt;
7735 asdl_seq* generators;
7736
Dino Viehlandac46eb42019-09-11 10:16:34 -07007737 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007738 return 1;
7739 }
7740 if (tmp == NULL) {
7741 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7742 return 1;
7743 }
7744 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007745 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007746 res = obj2ast_expr(tmp, &elt, arena);
7747 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007748 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007749 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007750 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7751 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007752 return 1;
7753 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007754 if (tmp == NULL) {
7755 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7756 return 1;
7757 }
7758 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007759 int res;
7760 Py_ssize_t len;
7761 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007762 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007763 PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007764 goto failed;
7765 }
7766 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007767 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007768 if (generators == NULL) goto failed;
7769 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007770 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007771 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7772 Py_INCREF(tmp2);
7773 res = obj2ast_comprehension(tmp2, &val, arena);
7774 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007775 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007776 if (len != PyList_GET_SIZE(tmp)) {
7777 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7778 goto failed;
7779 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007780 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007781 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007782 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007783 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007784 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7785 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007786 if (*out == NULL) goto failed;
7787 return 0;
7788 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007789 tp = astmodulestate_global->DictComp_type;
7790 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007791 if (isinstance == -1) {
7792 return 1;
7793 }
7794 if (isinstance) {
7795 expr_ty key;
7796 expr_ty value;
7797 asdl_seq* generators;
7798
Dino Viehlandac46eb42019-09-11 10:16:34 -07007799 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007800 return 1;
7801 }
7802 if (tmp == NULL) {
7803 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7804 return 1;
7805 }
7806 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007807 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007808 res = obj2ast_expr(tmp, &key, arena);
7809 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007810 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007811 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007812 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007813 return 1;
7814 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007815 if (tmp == NULL) {
7816 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7817 return 1;
7818 }
7819 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007820 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007821 res = obj2ast_expr(tmp, &value, arena);
7822 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007823 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007824 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007825 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7826 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007827 return 1;
7828 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007829 if (tmp == NULL) {
7830 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7831 return 1;
7832 }
7833 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007834 int res;
7835 Py_ssize_t len;
7836 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007837 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007838 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007839 goto failed;
7840 }
7841 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007842 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007843 if (generators == NULL) goto failed;
7844 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007845 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007846 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7847 Py_INCREF(tmp2);
7848 res = obj2ast_comprehension(tmp2, &val, arena);
7849 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007850 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007851 if (len != PyList_GET_SIZE(tmp)) {
7852 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7853 goto failed;
7854 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007855 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007856 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007857 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007858 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007859 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7860 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007861 if (*out == NULL) goto failed;
7862 return 0;
7863 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007864 tp = astmodulestate_global->GeneratorExp_type;
7865 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007866 if (isinstance == -1) {
7867 return 1;
7868 }
7869 if (isinstance) {
7870 expr_ty elt;
7871 asdl_seq* generators;
7872
Dino Viehlandac46eb42019-09-11 10:16:34 -07007873 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007874 return 1;
7875 }
7876 if (tmp == NULL) {
7877 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7878 return 1;
7879 }
7880 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007881 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007882 res = obj2ast_expr(tmp, &elt, arena);
7883 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007884 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007885 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007886 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7887 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007888 return 1;
7889 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007890 if (tmp == NULL) {
7891 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7892 return 1;
7893 }
7894 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007895 int res;
7896 Py_ssize_t len;
7897 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007898 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007899 PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007900 goto failed;
7901 }
7902 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007903 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007904 if (generators == NULL) goto failed;
7905 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007906 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007907 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7908 Py_INCREF(tmp2);
7909 res = obj2ast_comprehension(tmp2, &val, arena);
7910 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007911 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007912 if (len != PyList_GET_SIZE(tmp)) {
7913 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7914 goto failed;
7915 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007916 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007917 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007918 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007919 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007920 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7921 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007922 if (*out == NULL) goto failed;
7923 return 0;
7924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007925 tp = astmodulestate_global->Await_type;
7926 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007927 if (isinstance == -1) {
7928 return 1;
7929 }
7930 if (isinstance) {
7931 expr_ty value;
7932
Dino Viehlandac46eb42019-09-11 10:16:34 -07007933 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007934 return 1;
7935 }
7936 if (tmp == NULL) {
7937 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7938 return 1;
7939 }
7940 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007941 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007942 res = obj2ast_expr(tmp, &value, arena);
7943 if (res != 0) goto failed;
7944 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007945 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007946 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7947 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007948 if (*out == NULL) goto failed;
7949 return 0;
7950 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007951 tp = astmodulestate_global->Yield_type;
7952 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007953 if (isinstance == -1) {
7954 return 1;
7955 }
7956 if (isinstance) {
7957 expr_ty value;
7958
Dino Viehlandac46eb42019-09-11 10:16:34 -07007959 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007960 return 1;
7961 }
7962 if (tmp == NULL || tmp == Py_None) {
7963 Py_CLEAR(tmp);
7964 value = NULL;
7965 }
7966 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007967 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007968 res = obj2ast_expr(tmp, &value, arena);
7969 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007970 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007971 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007972 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
7973 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007974 if (*out == NULL) goto failed;
7975 return 0;
7976 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007977 tp = astmodulestate_global->YieldFrom_type;
7978 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007979 if (isinstance == -1) {
7980 return 1;
7981 }
7982 if (isinstance) {
7983 expr_ty value;
7984
Dino Viehlandac46eb42019-09-11 10:16:34 -07007985 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007986 return 1;
7987 }
7988 if (tmp == NULL) {
7989 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
7990 return 1;
7991 }
7992 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007993 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007994 res = obj2ast_expr(tmp, &value, arena);
7995 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007996 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007997 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007998 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
7999 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008000 if (*out == NULL) goto failed;
8001 return 0;
8002 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008003 tp = astmodulestate_global->Compare_type;
8004 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008005 if (isinstance == -1) {
8006 return 1;
8007 }
8008 if (isinstance) {
8009 expr_ty left;
8010 asdl_int_seq* ops;
8011 asdl_seq* comparators;
8012
Dino Viehlandac46eb42019-09-11 10:16:34 -07008013 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008014 return 1;
8015 }
8016 if (tmp == NULL) {
8017 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8018 return 1;
8019 }
8020 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008021 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008022 res = obj2ast_expr(tmp, &left, arena);
8023 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008024 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008025 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008026 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008027 return 1;
8028 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008029 if (tmp == NULL) {
8030 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8031 return 1;
8032 }
8033 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008034 int res;
8035 Py_ssize_t len;
8036 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008037 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008038 PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008039 goto failed;
8040 }
8041 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008042 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008043 if (ops == NULL) goto failed;
8044 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008045 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008046 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8047 Py_INCREF(tmp2);
8048 res = obj2ast_cmpop(tmp2, &val, arena);
8049 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008050 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008051 if (len != PyList_GET_SIZE(tmp)) {
8052 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8053 goto failed;
8054 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008055 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008056 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008057 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008058 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008059 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8060 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008061 return 1;
8062 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008063 if (tmp == NULL) {
8064 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8065 return 1;
8066 }
8067 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008068 int res;
8069 Py_ssize_t len;
8070 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008071 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008072 PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008073 goto failed;
8074 }
8075 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008076 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008077 if (comparators == NULL) goto failed;
8078 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008079 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008080 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8081 Py_INCREF(tmp2);
8082 res = obj2ast_expr(tmp2, &val, arena);
8083 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008084 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008085 if (len != PyList_GET_SIZE(tmp)) {
8086 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8087 goto failed;
8088 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008089 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008090 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008091 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008092 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008093 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8094 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008095 if (*out == NULL) goto failed;
8096 return 0;
8097 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008098 tp = astmodulestate_global->Call_type;
8099 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008100 if (isinstance == -1) {
8101 return 1;
8102 }
8103 if (isinstance) {
8104 expr_ty func;
8105 asdl_seq* args;
8106 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008107
Dino Viehlandac46eb42019-09-11 10:16:34 -07008108 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008109 return 1;
8110 }
8111 if (tmp == NULL) {
8112 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8113 return 1;
8114 }
8115 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008116 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008117 res = obj2ast_expr(tmp, &func, arena);
8118 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008119 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008120 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008121 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008122 return 1;
8123 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008124 if (tmp == NULL) {
8125 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8126 return 1;
8127 }
8128 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008129 int res;
8130 Py_ssize_t len;
8131 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008132 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008133 PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008134 goto failed;
8135 }
8136 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008137 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008138 if (args == NULL) goto failed;
8139 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008140 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008141 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8142 Py_INCREF(tmp2);
8143 res = obj2ast_expr(tmp2, &val, arena);
8144 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008145 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008146 if (len != PyList_GET_SIZE(tmp)) {
8147 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8148 goto failed;
8149 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008150 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008151 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008152 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008154 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8155 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008156 return 1;
8157 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008158 if (tmp == NULL) {
8159 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8160 return 1;
8161 }
8162 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008163 int res;
8164 Py_ssize_t len;
8165 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008166 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008167 PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008168 goto failed;
8169 }
8170 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008171 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008172 if (keywords == NULL) goto failed;
8173 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008174 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008175 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8176 Py_INCREF(tmp2);
8177 res = obj2ast_keyword(tmp2, &val, arena);
8178 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008179 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008180 if (len != PyList_GET_SIZE(tmp)) {
8181 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8182 goto failed;
8183 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008184 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008185 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008186 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008187 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008188 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8189 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008190 if (*out == NULL) goto failed;
8191 return 0;
8192 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008193 tp = astmodulestate_global->FormattedValue_type;
8194 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008195 if (isinstance == -1) {
8196 return 1;
8197 }
8198 if (isinstance) {
8199 expr_ty value;
8200 int conversion;
8201 expr_ty format_spec;
8202
Dino Viehlandac46eb42019-09-11 10:16:34 -07008203 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008204 return 1;
8205 }
8206 if (tmp == NULL) {
8207 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8208 return 1;
8209 }
8210 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008211 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008212 res = obj2ast_expr(tmp, &value, arena);
8213 if (res != 0) goto failed;
8214 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008215 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008216 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8217 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008218 return 1;
8219 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008220 if (tmp == NULL || tmp == Py_None) {
8221 Py_CLEAR(tmp);
8222 conversion = 0;
8223 }
8224 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008225 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008226 res = obj2ast_int(tmp, &conversion, arena);
8227 if (res != 0) goto failed;
8228 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008230 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8231 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008232 return 1;
8233 }
8234 if (tmp == NULL || tmp == Py_None) {
8235 Py_CLEAR(tmp);
8236 format_spec = NULL;
8237 }
8238 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008239 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008240 res = obj2ast_expr(tmp, &format_spec, arena);
8241 if (res != 0) goto failed;
8242 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008243 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008244 *out = FormattedValue(value, conversion, format_spec, lineno,
8245 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008246 if (*out == NULL) goto failed;
8247 return 0;
8248 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008249 tp = astmodulestate_global->JoinedStr_type;
8250 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008251 if (isinstance == -1) {
8252 return 1;
8253 }
8254 if (isinstance) {
8255 asdl_seq* values;
8256
Dino Viehlandac46eb42019-09-11 10:16:34 -07008257 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8258 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008259 return 1;
8260 }
8261 if (tmp == NULL) {
8262 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8263 return 1;
8264 }
8265 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008266 int res;
8267 Py_ssize_t len;
8268 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008269 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008270 PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Eric V. Smith235a6f02015-09-19 14:51:32 -04008271 goto failed;
8272 }
8273 len = PyList_GET_SIZE(tmp);
8274 values = _Py_asdl_seq_new(len, arena);
8275 if (values == NULL) goto failed;
8276 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008277 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008278 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8279 Py_INCREF(tmp2);
8280 res = obj2ast_expr(tmp2, &val, arena);
8281 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008282 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008283 if (len != PyList_GET_SIZE(tmp)) {
8284 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8285 goto failed;
8286 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008287 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008288 }
8289 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008290 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008291 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8292 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008293 if (*out == NULL) goto failed;
8294 return 0;
8295 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008296 tp = astmodulestate_global->Constant_type;
8297 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008298 if (isinstance == -1) {
8299 return 1;
8300 }
8301 if (isinstance) {
8302 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008303 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008304
Dino Viehlandac46eb42019-09-11 10:16:34 -07008305 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008306 return 1;
8307 }
8308 if (tmp == NULL) {
8309 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8310 return 1;
8311 }
8312 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008313 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008314 res = obj2ast_constant(tmp, &value, arena);
8315 if (res != 0) goto failed;
8316 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008318 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008319 return 1;
8320 }
8321 if (tmp == NULL || tmp == Py_None) {
8322 Py_CLEAR(tmp);
8323 kind = NULL;
8324 }
8325 else {
8326 int res;
8327 res = obj2ast_string(tmp, &kind, arena);
8328 if (res != 0) goto failed;
8329 Py_CLEAR(tmp);
8330 }
8331 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8332 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008333 if (*out == NULL) goto failed;
8334 return 0;
8335 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008336 tp = astmodulestate_global->Attribute_type;
8337 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008338 if (isinstance == -1) {
8339 return 1;
8340 }
8341 if (isinstance) {
8342 expr_ty value;
8343 identifier attr;
8344 expr_context_ty ctx;
8345
Dino Viehlandac46eb42019-09-11 10:16:34 -07008346 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008347 return 1;
8348 }
8349 if (tmp == NULL) {
8350 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8351 return 1;
8352 }
8353 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008354 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008355 res = obj2ast_expr(tmp, &value, arena);
8356 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008357 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008358 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008359 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008360 return 1;
8361 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008362 if (tmp == NULL) {
8363 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8364 return 1;
8365 }
8366 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008367 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008368 res = obj2ast_identifier(tmp, &attr, arena);
8369 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008370 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008371 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008372 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008373 return 1;
8374 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008375 if (tmp == NULL) {
8376 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8377 return 1;
8378 }
8379 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008380 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008381 res = obj2ast_expr_context(tmp, &ctx, arena);
8382 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008383 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008384 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008385 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8386 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008387 if (*out == NULL) goto failed;
8388 return 0;
8389 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008390 tp = astmodulestate_global->Subscript_type;
8391 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008392 if (isinstance == -1) {
8393 return 1;
8394 }
8395 if (isinstance) {
8396 expr_ty value;
8397 slice_ty slice;
8398 expr_context_ty ctx;
8399
Dino Viehlandac46eb42019-09-11 10:16:34 -07008400 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008401 return 1;
8402 }
8403 if (tmp == NULL) {
8404 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8405 return 1;
8406 }
8407 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008408 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008409 res = obj2ast_expr(tmp, &value, arena);
8410 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008411 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008412 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008413 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008414 return 1;
8415 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008416 if (tmp == NULL) {
8417 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8418 return 1;
8419 }
8420 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008421 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008422 res = obj2ast_slice(tmp, &slice, arena);
8423 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008424 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008425 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008426 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008427 return 1;
8428 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008429 if (tmp == NULL) {
8430 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8431 return 1;
8432 }
8433 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008434 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008435 res = obj2ast_expr_context(tmp, &ctx, arena);
8436 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008437 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008438 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008439 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8440 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008441 if (*out == NULL) goto failed;
8442 return 0;
8443 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008444 tp = astmodulestate_global->Starred_type;
8445 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008446 if (isinstance == -1) {
8447 return 1;
8448 }
8449 if (isinstance) {
8450 expr_ty value;
8451 expr_context_ty ctx;
8452
Dino Viehlandac46eb42019-09-11 10:16:34 -07008453 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008454 return 1;
8455 }
8456 if (tmp == NULL) {
8457 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8458 return 1;
8459 }
8460 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008461 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008462 res = obj2ast_expr(tmp, &value, arena);
8463 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008464 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008465 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008466 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008467 return 1;
8468 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008469 if (tmp == NULL) {
8470 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8471 return 1;
8472 }
8473 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008474 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008475 res = obj2ast_expr_context(tmp, &ctx, arena);
8476 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008477 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008478 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008479 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8480 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008481 if (*out == NULL) goto failed;
8482 return 0;
8483 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008484 tp = astmodulestate_global->Name_type;
8485 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008486 if (isinstance == -1) {
8487 return 1;
8488 }
8489 if (isinstance) {
8490 identifier id;
8491 expr_context_ty ctx;
8492
Dino Viehlandac46eb42019-09-11 10:16:34 -07008493 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008494 return 1;
8495 }
8496 if (tmp == NULL) {
8497 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8498 return 1;
8499 }
8500 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008501 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008502 res = obj2ast_identifier(tmp, &id, arena);
8503 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008504 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008505 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008506 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008507 return 1;
8508 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008509 if (tmp == NULL) {
8510 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8511 return 1;
8512 }
8513 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008514 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008515 res = obj2ast_expr_context(tmp, &ctx, arena);
8516 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008517 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008518 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008519 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8520 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008521 if (*out == NULL) goto failed;
8522 return 0;
8523 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008524 tp = astmodulestate_global->List_type;
8525 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008526 if (isinstance == -1) {
8527 return 1;
8528 }
8529 if (isinstance) {
8530 asdl_seq* elts;
8531 expr_context_ty ctx;
8532
Dino Viehlandac46eb42019-09-11 10:16:34 -07008533 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008534 return 1;
8535 }
8536 if (tmp == NULL) {
8537 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8538 return 1;
8539 }
8540 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008541 int res;
8542 Py_ssize_t len;
8543 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008544 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008545 PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008546 goto failed;
8547 }
8548 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008549 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008550 if (elts == NULL) goto failed;
8551 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008552 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008553 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8554 Py_INCREF(tmp2);
8555 res = obj2ast_expr(tmp2, &val, arena);
8556 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008557 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008558 if (len != PyList_GET_SIZE(tmp)) {
8559 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8560 goto failed;
8561 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008562 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008563 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008564 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008565 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008566 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008567 return 1;
8568 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008569 if (tmp == NULL) {
8570 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8571 return 1;
8572 }
8573 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008574 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008575 res = obj2ast_expr_context(tmp, &ctx, arena);
8576 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008577 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008578 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008579 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8580 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008581 if (*out == NULL) goto failed;
8582 return 0;
8583 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008584 tp = astmodulestate_global->Tuple_type;
8585 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008586 if (isinstance == -1) {
8587 return 1;
8588 }
8589 if (isinstance) {
8590 asdl_seq* elts;
8591 expr_context_ty ctx;
8592
Dino Viehlandac46eb42019-09-11 10:16:34 -07008593 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008594 return 1;
8595 }
8596 if (tmp == NULL) {
8597 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8598 return 1;
8599 }
8600 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008601 int res;
8602 Py_ssize_t len;
8603 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008604 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008605 PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008606 goto failed;
8607 }
8608 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008609 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008610 if (elts == NULL) goto failed;
8611 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008612 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008613 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8614 Py_INCREF(tmp2);
8615 res = obj2ast_expr(tmp2, &val, arena);
8616 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008617 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008618 if (len != PyList_GET_SIZE(tmp)) {
8619 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8620 goto failed;
8621 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008622 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008623 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008624 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008625 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008626 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008627 return 1;
8628 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008629 if (tmp == NULL) {
8630 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8631 return 1;
8632 }
8633 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008634 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008635 res = obj2ast_expr_context(tmp, &ctx, arena);
8636 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008637 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008638 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008639 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8640 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008641 if (*out == NULL) goto failed;
8642 return 0;
8643 }
8644
8645 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8646 failed:
8647 Py_XDECREF(tmp);
8648 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008649}
8650
8651int
8652obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8653{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008654 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008655
Dino Viehlandac46eb42019-09-11 10:16:34 -07008656 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008657 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008658 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008659 }
8660 if (isinstance) {
8661 *out = Load;
8662 return 0;
8663 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008664 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008665 if (isinstance == -1) {
8666 return 1;
8667 }
8668 if (isinstance) {
8669 *out = Store;
8670 return 0;
8671 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008672 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008673 if (isinstance == -1) {
8674 return 1;
8675 }
8676 if (isinstance) {
8677 *out = Del;
8678 return 0;
8679 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008680 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008681 if (isinstance == -1) {
8682 return 1;
8683 }
8684 if (isinstance) {
8685 *out = AugLoad;
8686 return 0;
8687 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008688 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008689 if (isinstance == -1) {
8690 return 1;
8691 }
8692 if (isinstance) {
8693 *out = AugStore;
8694 return 0;
8695 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008696 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008697 if (isinstance == -1) {
8698 return 1;
8699 }
8700 if (isinstance) {
8701 *out = Param;
8702 return 0;
8703 }
8704
8705 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8706 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008707}
8708
8709int
8710obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
8711{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008712 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008713
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008714 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008715 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008716
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008717 if (obj == Py_None) {
8718 *out = NULL;
8719 return 0;
8720 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008721 tp = astmodulestate_global->Slice_type;
8722 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008723 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008724 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008725 }
8726 if (isinstance) {
8727 expr_ty lower;
8728 expr_ty upper;
8729 expr_ty step;
8730
Dino Viehlandac46eb42019-09-11 10:16:34 -07008731 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008732 return 1;
8733 }
8734 if (tmp == NULL || tmp == Py_None) {
8735 Py_CLEAR(tmp);
8736 lower = NULL;
8737 }
8738 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008739 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008740 res = obj2ast_expr(tmp, &lower, arena);
8741 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008742 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008743 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008744 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008745 return 1;
8746 }
8747 if (tmp == NULL || tmp == Py_None) {
8748 Py_CLEAR(tmp);
8749 upper = NULL;
8750 }
8751 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008752 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008753 res = obj2ast_expr(tmp, &upper, arena);
8754 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008755 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008756 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008757 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008758 return 1;
8759 }
8760 if (tmp == NULL || tmp == Py_None) {
8761 Py_CLEAR(tmp);
8762 step = NULL;
8763 }
8764 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008765 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008766 res = obj2ast_expr(tmp, &step, arena);
8767 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008768 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008769 }
8770 *out = Slice(lower, upper, step, arena);
8771 if (*out == NULL) goto failed;
8772 return 0;
8773 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008774 tp = astmodulestate_global->ExtSlice_type;
8775 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008776 if (isinstance == -1) {
8777 return 1;
8778 }
8779 if (isinstance) {
8780 asdl_seq* dims;
8781
Dino Viehlandac46eb42019-09-11 10:16:34 -07008782 if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008783 return 1;
8784 }
8785 if (tmp == NULL) {
8786 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
8787 return 1;
8788 }
8789 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008790 int res;
8791 Py_ssize_t len;
8792 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008793 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008794 PyErr_Format(PyExc_TypeError, "ExtSlice field \"dims\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008795 goto failed;
8796 }
8797 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008798 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008799 if (dims == NULL) goto failed;
8800 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008801 slice_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008802 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8803 Py_INCREF(tmp2);
8804 res = obj2ast_slice(tmp2, &val, arena);
8805 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008806 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008807 if (len != PyList_GET_SIZE(tmp)) {
8808 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
8809 goto failed;
8810 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008811 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008812 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008813 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008814 }
8815 *out = ExtSlice(dims, arena);
8816 if (*out == NULL) goto failed;
8817 return 0;
8818 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008819 tp = astmodulestate_global->Index_type;
8820 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008821 if (isinstance == -1) {
8822 return 1;
8823 }
8824 if (isinstance) {
8825 expr_ty value;
8826
Dino Viehlandac46eb42019-09-11 10:16:34 -07008827 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008828 return 1;
8829 }
8830 if (tmp == NULL) {
8831 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
8832 return 1;
8833 }
8834 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008835 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008836 res = obj2ast_expr(tmp, &value, arena);
8837 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008838 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008839 }
8840 *out = Index(value, arena);
8841 if (*out == NULL) goto failed;
8842 return 0;
8843 }
8844
8845 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
8846 failed:
8847 Py_XDECREF(tmp);
8848 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008849}
8850
8851int
8852obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8853{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008854 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008855
Dino Viehlandac46eb42019-09-11 10:16:34 -07008856 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008857 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008858 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008859 }
8860 if (isinstance) {
8861 *out = And;
8862 return 0;
8863 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008864 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008865 if (isinstance == -1) {
8866 return 1;
8867 }
8868 if (isinstance) {
8869 *out = Or;
8870 return 0;
8871 }
8872
8873 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8874 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008875}
8876
8877int
8878obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8879{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008880 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008881
Dino Viehlandac46eb42019-09-11 10:16:34 -07008882 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008883 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008884 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008885 }
8886 if (isinstance) {
8887 *out = Add;
8888 return 0;
8889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008890 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008891 if (isinstance == -1) {
8892 return 1;
8893 }
8894 if (isinstance) {
8895 *out = Sub;
8896 return 0;
8897 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008898 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008899 if (isinstance == -1) {
8900 return 1;
8901 }
8902 if (isinstance) {
8903 *out = Mult;
8904 return 0;
8905 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008906 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008907 if (isinstance == -1) {
8908 return 1;
8909 }
8910 if (isinstance) {
8911 *out = MatMult;
8912 return 0;
8913 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008914 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008915 if (isinstance == -1) {
8916 return 1;
8917 }
8918 if (isinstance) {
8919 *out = Div;
8920 return 0;
8921 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008922 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008923 if (isinstance == -1) {
8924 return 1;
8925 }
8926 if (isinstance) {
8927 *out = Mod;
8928 return 0;
8929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008930 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008931 if (isinstance == -1) {
8932 return 1;
8933 }
8934 if (isinstance) {
8935 *out = Pow;
8936 return 0;
8937 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008938 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008939 if (isinstance == -1) {
8940 return 1;
8941 }
8942 if (isinstance) {
8943 *out = LShift;
8944 return 0;
8945 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008946 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008947 if (isinstance == -1) {
8948 return 1;
8949 }
8950 if (isinstance) {
8951 *out = RShift;
8952 return 0;
8953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008954 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008955 if (isinstance == -1) {
8956 return 1;
8957 }
8958 if (isinstance) {
8959 *out = BitOr;
8960 return 0;
8961 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008962 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008963 if (isinstance == -1) {
8964 return 1;
8965 }
8966 if (isinstance) {
8967 *out = BitXor;
8968 return 0;
8969 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008970 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008971 if (isinstance == -1) {
8972 return 1;
8973 }
8974 if (isinstance) {
8975 *out = BitAnd;
8976 return 0;
8977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008978 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008979 if (isinstance == -1) {
8980 return 1;
8981 }
8982 if (isinstance) {
8983 *out = FloorDiv;
8984 return 0;
8985 }
8986
8987 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8988 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008989}
8990
8991int
8992obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8993{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008994 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008995
Dino Viehlandac46eb42019-09-11 10:16:34 -07008996 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008997 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008998 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008999 }
9000 if (isinstance) {
9001 *out = Invert;
9002 return 0;
9003 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009004 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009005 if (isinstance == -1) {
9006 return 1;
9007 }
9008 if (isinstance) {
9009 *out = Not;
9010 return 0;
9011 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009012 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009013 if (isinstance == -1) {
9014 return 1;
9015 }
9016 if (isinstance) {
9017 *out = UAdd;
9018 return 0;
9019 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009020 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009021 if (isinstance == -1) {
9022 return 1;
9023 }
9024 if (isinstance) {
9025 *out = USub;
9026 return 0;
9027 }
9028
9029 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9030 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009031}
9032
9033int
9034obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9035{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009036 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009037
Dino Viehlandac46eb42019-09-11 10:16:34 -07009038 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009039 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009040 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009041 }
9042 if (isinstance) {
9043 *out = Eq;
9044 return 0;
9045 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009046 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009047 if (isinstance == -1) {
9048 return 1;
9049 }
9050 if (isinstance) {
9051 *out = NotEq;
9052 return 0;
9053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009054 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009055 if (isinstance == -1) {
9056 return 1;
9057 }
9058 if (isinstance) {
9059 *out = Lt;
9060 return 0;
9061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009062 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009063 if (isinstance == -1) {
9064 return 1;
9065 }
9066 if (isinstance) {
9067 *out = LtE;
9068 return 0;
9069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009070 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009071 if (isinstance == -1) {
9072 return 1;
9073 }
9074 if (isinstance) {
9075 *out = Gt;
9076 return 0;
9077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009078 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009079 if (isinstance == -1) {
9080 return 1;
9081 }
9082 if (isinstance) {
9083 *out = GtE;
9084 return 0;
9085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009086 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009087 if (isinstance == -1) {
9088 return 1;
9089 }
9090 if (isinstance) {
9091 *out = Is;
9092 return 0;
9093 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009094 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009095 if (isinstance == -1) {
9096 return 1;
9097 }
9098 if (isinstance) {
9099 *out = IsNot;
9100 return 0;
9101 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009102 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009103 if (isinstance == -1) {
9104 return 1;
9105 }
9106 if (isinstance) {
9107 *out = In;
9108 return 0;
9109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009110 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009111 if (isinstance == -1) {
9112 return 1;
9113 }
9114 if (isinstance) {
9115 *out = NotIn;
9116 return 0;
9117 }
9118
9119 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9120 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009121}
9122
9123int
9124obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9125{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009126 PyObject* tmp = NULL;
9127 expr_ty target;
9128 expr_ty iter;
9129 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009130 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009131
Dino Viehlandac46eb42019-09-11 10:16:34 -07009132 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009133 return 1;
9134 }
9135 if (tmp == NULL) {
9136 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9137 return 1;
9138 }
9139 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009140 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009141 res = obj2ast_expr(tmp, &target, arena);
9142 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009143 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009144 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009145 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009146 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009147 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009148 if (tmp == NULL) {
9149 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9150 return 1;
9151 }
9152 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009153 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009154 res = obj2ast_expr(tmp, &iter, arena);
9155 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009156 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009158 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009159 return 1;
9160 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009161 if (tmp == NULL) {
9162 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9163 return 1;
9164 }
9165 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009166 int res;
9167 Py_ssize_t len;
9168 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009169 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009170 PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009171 goto failed;
9172 }
9173 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009174 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009175 if (ifs == NULL) goto failed;
9176 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009177 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009178 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9179 Py_INCREF(tmp2);
9180 res = obj2ast_expr(tmp2, &val, arena);
9181 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009182 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009183 if (len != PyList_GET_SIZE(tmp)) {
9184 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9185 goto failed;
9186 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009187 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009188 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009189 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009191 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009192 return 1;
9193 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009194 if (tmp == NULL) {
9195 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9196 return 1;
9197 }
9198 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009199 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009200 res = obj2ast_int(tmp, &is_async, arena);
9201 if (res != 0) goto failed;
9202 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009203 }
9204 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009205 return 0;
9206failed:
9207 Py_XDECREF(tmp);
9208 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009209}
9210
9211int
9212obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9213{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009214 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009215
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009216 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009217 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009218 int lineno;
9219 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009220 int end_lineno;
9221 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009222
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009223 if (obj == Py_None) {
9224 *out = NULL;
9225 return 0;
9226 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009227 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009228 return 1;
9229 }
9230 if (tmp == NULL) {
9231 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9232 return 1;
9233 }
9234 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009235 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009236 res = obj2ast_int(tmp, &lineno, arena);
9237 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009238 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009239 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009240 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9241 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009242 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009243 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009244 if (tmp == NULL) {
9245 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9246 return 1;
9247 }
9248 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009249 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009250 res = obj2ast_int(tmp, &col_offset, arena);
9251 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009252 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009253 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009254 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9255 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009256 return 1;
9257 }
9258 if (tmp == NULL || tmp == Py_None) {
9259 Py_CLEAR(tmp);
9260 end_lineno = 0;
9261 }
9262 else {
9263 int res;
9264 res = obj2ast_int(tmp, &end_lineno, arena);
9265 if (res != 0) goto failed;
9266 Py_CLEAR(tmp);
9267 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009268 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9269 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009270 return 1;
9271 }
9272 if (tmp == NULL || tmp == Py_None) {
9273 Py_CLEAR(tmp);
9274 end_col_offset = 0;
9275 }
9276 else {
9277 int res;
9278 res = obj2ast_int(tmp, &end_col_offset, arena);
9279 if (res != 0) goto failed;
9280 Py_CLEAR(tmp);
9281 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009282 tp = astmodulestate_global->ExceptHandler_type;
9283 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009284 if (isinstance == -1) {
9285 return 1;
9286 }
9287 if (isinstance) {
9288 expr_ty type;
9289 identifier name;
9290 asdl_seq* body;
9291
Dino Viehlandac46eb42019-09-11 10:16:34 -07009292 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009293 return 1;
9294 }
9295 if (tmp == NULL || tmp == Py_None) {
9296 Py_CLEAR(tmp);
9297 type = NULL;
9298 }
9299 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009300 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009301 res = obj2ast_expr(tmp, &type, arena);
9302 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009303 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009305 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009306 return 1;
9307 }
9308 if (tmp == NULL || tmp == Py_None) {
9309 Py_CLEAR(tmp);
9310 name = NULL;
9311 }
9312 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009313 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009314 res = obj2ast_identifier(tmp, &name, arena);
9315 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009316 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009318 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009319 return 1;
9320 }
9321 if (tmp == NULL) {
9322 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9323 return 1;
9324 }
9325 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009326 int res;
9327 Py_ssize_t len;
9328 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009329 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009330 PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009331 goto failed;
9332 }
9333 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009334 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009335 if (body == NULL) goto failed;
9336 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009337 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009338 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9339 Py_INCREF(tmp2);
9340 res = obj2ast_stmt(tmp2, &val, arena);
9341 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009342 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009343 if (len != PyList_GET_SIZE(tmp)) {
9344 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9345 goto failed;
9346 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009347 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009348 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009349 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009350 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009351 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9352 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009353 if (*out == NULL) goto failed;
9354 return 0;
9355 }
9356
9357 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9358 failed:
9359 Py_XDECREF(tmp);
9360 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009361}
9362
9363int
9364obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9365{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009366 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009367 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009368 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009369 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009370 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009371 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009372 arg_ty kwarg;
9373 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009374
Dino Viehlandac46eb42019-09-11 10:16:34 -07009375 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9376 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009377 return 1;
9378 }
9379 if (tmp == NULL) {
9380 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9381 return 1;
9382 }
9383 else {
9384 int res;
9385 Py_ssize_t len;
9386 Py_ssize_t i;
9387 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009388 PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009389 goto failed;
9390 }
9391 len = PyList_GET_SIZE(tmp);
9392 posonlyargs = _Py_asdl_seq_new(len, arena);
9393 if (posonlyargs == NULL) goto failed;
9394 for (i = 0; i < len; i++) {
9395 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009396 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9397 Py_INCREF(tmp2);
9398 res = obj2ast_arg(tmp2, &val, arena);
9399 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009400 if (res != 0) goto failed;
9401 if (len != PyList_GET_SIZE(tmp)) {
9402 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9403 goto failed;
9404 }
9405 asdl_seq_SET(posonlyargs, i, val);
9406 }
9407 Py_CLEAR(tmp);
9408 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009409 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009410 return 1;
9411 }
9412 if (tmp == NULL) {
9413 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9414 return 1;
9415 }
9416 else {
9417 int res;
9418 Py_ssize_t len;
9419 Py_ssize_t i;
9420 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009421 PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009422 goto failed;
9423 }
9424 len = PyList_GET_SIZE(tmp);
9425 args = _Py_asdl_seq_new(len, arena);
9426 if (args == NULL) goto failed;
9427 for (i = 0; i < len; i++) {
9428 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009429 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9430 Py_INCREF(tmp2);
9431 res = obj2ast_arg(tmp2, &val, arena);
9432 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009433 if (res != 0) goto failed;
9434 if (len != PyList_GET_SIZE(tmp)) {
9435 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9436 goto failed;
9437 }
9438 asdl_seq_SET(args, i, val);
9439 }
9440 Py_CLEAR(tmp);
9441 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009442 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009443 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009444 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009445 if (tmp == NULL || tmp == Py_None) {
9446 Py_CLEAR(tmp);
9447 vararg = NULL;
9448 }
9449 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009450 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009451 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009452 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009453 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009454 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009455 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9456 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009457 return 1;
9458 }
9459 if (tmp == NULL) {
9460 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9461 return 1;
9462 }
9463 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009464 int res;
9465 Py_ssize_t len;
9466 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009467 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009468 PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009469 goto failed;
9470 }
9471 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009472 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009473 if (kwonlyargs == NULL) goto failed;
9474 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009475 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009476 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9477 Py_INCREF(tmp2);
9478 res = obj2ast_arg(tmp2, &val, arena);
9479 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009480 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009481 if (len != PyList_GET_SIZE(tmp)) {
9482 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9483 goto failed;
9484 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009485 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009486 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009487 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009488 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009489 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9490 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009491 return 1;
9492 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009493 if (tmp == NULL) {
9494 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9495 return 1;
9496 }
9497 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009498 int res;
9499 Py_ssize_t len;
9500 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009501 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009502 PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009503 goto failed;
9504 }
9505 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009506 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009507 if (kw_defaults == NULL) goto failed;
9508 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009509 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009510 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9511 Py_INCREF(tmp2);
9512 res = obj2ast_expr(tmp2, &val, arena);
9513 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009514 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009515 if (len != PyList_GET_SIZE(tmp)) {
9516 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9517 goto failed;
9518 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009519 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009520 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009521 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009522 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009523 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009524 return 1;
9525 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009526 if (tmp == NULL || tmp == Py_None) {
9527 Py_CLEAR(tmp);
9528 kwarg = NULL;
9529 }
9530 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009531 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009532 res = obj2ast_arg(tmp, &kwarg, arena);
9533 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009534 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009535 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009536 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009537 return 1;
9538 }
9539 if (tmp == NULL) {
9540 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9541 return 1;
9542 }
9543 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009544 int res;
9545 Py_ssize_t len;
9546 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009547 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009548 PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinneree4b59c2013-07-27 00:01:35 +02009549 goto failed;
9550 }
9551 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009552 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009553 if (defaults == NULL) goto failed;
9554 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009555 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009556 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9557 Py_INCREF(tmp2);
9558 res = obj2ast_expr(tmp2, &val, arena);
9559 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009560 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009561 if (len != PyList_GET_SIZE(tmp)) {
9562 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9563 goto failed;
9564 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009565 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009566 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009567 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009568 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009569 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009570 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009571 return 0;
9572failed:
9573 Py_XDECREF(tmp);
9574 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009575}
9576
9577int
9578obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9579{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009580 PyObject* tmp = NULL;
9581 identifier arg;
9582 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009583 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009584 int lineno;
9585 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009586 int end_lineno;
9587 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009588
Dino Viehlandac46eb42019-09-11 10:16:34 -07009589 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009590 return 1;
9591 }
9592 if (tmp == NULL) {
9593 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9594 return 1;
9595 }
9596 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009597 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009598 res = obj2ast_identifier(tmp, &arg, arena);
9599 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009600 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009601 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009602 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9603 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009604 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009605 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009606 if (tmp == NULL || tmp == Py_None) {
9607 Py_CLEAR(tmp);
9608 annotation = NULL;
9609 }
9610 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009611 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009612 res = obj2ast_expr(tmp, &annotation, arena);
9613 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009614 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009615 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009616 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9617 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009618 return 1;
9619 }
9620 if (tmp == NULL || tmp == Py_None) {
9621 Py_CLEAR(tmp);
9622 type_comment = NULL;
9623 }
9624 else {
9625 int res;
9626 res = obj2ast_string(tmp, &type_comment, arena);
9627 if (res != 0) goto failed;
9628 Py_CLEAR(tmp);
9629 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009630 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009631 return 1;
9632 }
9633 if (tmp == NULL) {
9634 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9635 return 1;
9636 }
9637 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009638 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009639 res = obj2ast_int(tmp, &lineno, arena);
9640 if (res != 0) goto failed;
9641 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009643 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9644 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009645 return 1;
9646 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009647 if (tmp == NULL) {
9648 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9649 return 1;
9650 }
9651 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009652 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009653 res = obj2ast_int(tmp, &col_offset, arena);
9654 if (res != 0) goto failed;
9655 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009656 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009657 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9658 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009659 return 1;
9660 }
9661 if (tmp == NULL || tmp == Py_None) {
9662 Py_CLEAR(tmp);
9663 end_lineno = 0;
9664 }
9665 else {
9666 int res;
9667 res = obj2ast_int(tmp, &end_lineno, arena);
9668 if (res != 0) goto failed;
9669 Py_CLEAR(tmp);
9670 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009671 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9672 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009673 return 1;
9674 }
9675 if (tmp == NULL || tmp == Py_None) {
9676 Py_CLEAR(tmp);
9677 end_col_offset = 0;
9678 }
9679 else {
9680 int res;
9681 res = obj2ast_int(tmp, &end_col_offset, arena);
9682 if (res != 0) goto failed;
9683 Py_CLEAR(tmp);
9684 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009685 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9686 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009687 return 0;
9688failed:
9689 Py_XDECREF(tmp);
9690 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009691}
9692
9693int
9694obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9695{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009696 PyObject* tmp = NULL;
9697 identifier arg;
9698 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009699
Dino Viehlandac46eb42019-09-11 10:16:34 -07009700 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009701 return 1;
9702 }
9703 if (tmp == NULL || tmp == Py_None) {
9704 Py_CLEAR(tmp);
9705 arg = NULL;
9706 }
9707 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009708 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009709 res = obj2ast_identifier(tmp, &arg, arena);
9710 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009711 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009712 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009713 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009714 return 1;
9715 }
9716 if (tmp == NULL) {
9717 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9718 return 1;
9719 }
9720 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009721 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009722 res = obj2ast_expr(tmp, &value, arena);
9723 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009724 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009725 }
9726 *out = keyword(arg, value, arena);
9727 return 0;
9728failed:
9729 Py_XDECREF(tmp);
9730 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009731}
9732
9733int
9734obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9735{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009736 PyObject* tmp = NULL;
9737 identifier name;
9738 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009739
Dino Viehlandac46eb42019-09-11 10:16:34 -07009740 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009741 return 1;
9742 }
9743 if (tmp == NULL) {
9744 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9745 return 1;
9746 }
9747 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009748 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009749 res = obj2ast_identifier(tmp, &name, arena);
9750 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009751 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009753 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009754 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009755 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009756 if (tmp == NULL || tmp == Py_None) {
9757 Py_CLEAR(tmp);
9758 asname = NULL;
9759 }
9760 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009761 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009762 res = obj2ast_identifier(tmp, &asname, arena);
9763 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009764 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009765 }
9766 *out = alias(name, asname, arena);
9767 return 0;
9768failed:
9769 Py_XDECREF(tmp);
9770 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009771}
9772
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009773int
9774obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9775{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009776 PyObject* tmp = NULL;
9777 expr_ty context_expr;
9778 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009779
Dino Viehlandac46eb42019-09-11 10:16:34 -07009780 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9781 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009782 return 1;
9783 }
9784 if (tmp == NULL) {
9785 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9786 return 1;
9787 }
9788 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009789 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009790 res = obj2ast_expr(tmp, &context_expr, arena);
9791 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009792 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009793 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009794 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9795 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009796 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009797 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009798 if (tmp == NULL || tmp == Py_None) {
9799 Py_CLEAR(tmp);
9800 optional_vars = NULL;
9801 }
9802 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009803 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009804 res = obj2ast_expr(tmp, &optional_vars, arena);
9805 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009806 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009807 }
9808 *out = withitem(context_expr, optional_vars, arena);
9809 return 0;
9810failed:
9811 Py_XDECREF(tmp);
9812 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009813}
9814
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009815int
9816obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9817{
9818 int isinstance;
9819
9820 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009821 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009822
9823 if (obj == Py_None) {
9824 *out = NULL;
9825 return 0;
9826 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009827 tp = astmodulestate_global->TypeIgnore_type;
9828 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009829 if (isinstance == -1) {
9830 return 1;
9831 }
9832 if (isinstance) {
9833 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009834 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009835
Dino Viehlandac46eb42019-09-11 10:16:34 -07009836 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9837 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009838 return 1;
9839 }
9840 if (tmp == NULL) {
9841 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9842 return 1;
9843 }
9844 else {
9845 int res;
9846 res = obj2ast_int(tmp, &lineno, arena);
9847 if (res != 0) goto failed;
9848 Py_CLEAR(tmp);
9849 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009850 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009851 return 1;
9852 }
9853 if (tmp == NULL) {
9854 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9855 return 1;
9856 }
9857 else {
9858 int res;
9859 res = obj2ast_string(tmp, &tag, arena);
9860 if (res != 0) goto failed;
9861 Py_CLEAR(tmp);
9862 }
9863 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009864 if (*out == NULL) goto failed;
9865 return 0;
9866 }
9867
9868 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9869 failed:
9870 Py_XDECREF(tmp);
9871 return 1;
9872}
9873
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009874
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009875PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009876PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009877{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009878 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009879 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009880 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009881 if (!m) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009882 Py_INCREF(astmodulestate(m)->AST_type);
9883 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0)
9884 return NULL;
Matthias Bussonnier565b4f12019-05-21 13:12:03 -07009885 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0)
9886 return NULL;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009887 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009888 return NULL;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009889 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)
9890 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009891 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0)
9892 return NULL;
9893 Py_INCREF(astmodulestate(m)->mod_type);
9894 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009895 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009896 Py_INCREF(astmodulestate(m)->Module_type);
9897 if (PyModule_AddObject(m, "Interactive",
9898 astmodulestate_global->Interactive_type) < 0) return NULL;
9899 Py_INCREF(astmodulestate(m)->Interactive_type);
9900 if (PyModule_AddObject(m, "Expression",
9901 astmodulestate_global->Expression_type) < 0) return NULL;
9902 Py_INCREF(astmodulestate(m)->Expression_type);
9903 if (PyModule_AddObject(m, "FunctionType",
9904 astmodulestate_global->FunctionType_type) < 0) return NULL;
9905 Py_INCREF(astmodulestate(m)->FunctionType_type);
9906 if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009907 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009908 Py_INCREF(astmodulestate(m)->Suite_type);
9909 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009910 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009911 Py_INCREF(astmodulestate(m)->stmt_type);
9912 if (PyModule_AddObject(m, "FunctionDef",
9913 astmodulestate_global->FunctionDef_type) < 0) return NULL;
9914 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9915 if (PyModule_AddObject(m, "AsyncFunctionDef",
9916 astmodulestate_global->AsyncFunctionDef_type) < 0) return NULL;
9917 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9918 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009919 < 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009920 Py_INCREF(astmodulestate(m)->ClassDef_type);
9921 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009922 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009923 Py_INCREF(astmodulestate(m)->Return_type);
9924 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
9925 0) return NULL;
9926 Py_INCREF(astmodulestate(m)->Delete_type);
9927 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
9928 0) return NULL;
9929 Py_INCREF(astmodulestate(m)->Assign_type);
9930 if (PyModule_AddObject(m, "AugAssign",
9931 astmodulestate_global->AugAssign_type) < 0) return NULL;
9932 Py_INCREF(astmodulestate(m)->AugAssign_type);
9933 if (PyModule_AddObject(m, "AnnAssign",
9934 astmodulestate_global->AnnAssign_type) < 0) return NULL;
9935 Py_INCREF(astmodulestate(m)->AnnAssign_type);
9936 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009937 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009938 Py_INCREF(astmodulestate(m)->For_type);
9939 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
9940 < 0) return NULL;
9941 Py_INCREF(astmodulestate(m)->AsyncFor_type);
9942 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0)
9943 return NULL;
9944 Py_INCREF(astmodulestate(m)->While_type);
9945 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) return
9946 NULL;
9947 Py_INCREF(astmodulestate(m)->If_type);
9948 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0)
9949 return NULL;
9950 Py_INCREF(astmodulestate(m)->With_type);
9951 if (PyModule_AddObject(m, "AsyncWith",
9952 astmodulestate_global->AsyncWith_type) < 0) return NULL;
9953 Py_INCREF(astmodulestate(m)->AsyncWith_type);
9954 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0)
9955 return NULL;
9956 Py_INCREF(astmodulestate(m)->Raise_type);
9957 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0)
9958 return NULL;
9959 Py_INCREF(astmodulestate(m)->Try_type);
9960 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
9961 0) return NULL;
9962 Py_INCREF(astmodulestate(m)->Assert_type);
9963 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
9964 0) return NULL;
9965 Py_INCREF(astmodulestate(m)->Import_type);
9966 if (PyModule_AddObject(m, "ImportFrom",
9967 astmodulestate_global->ImportFrom_type) < 0) return NULL;
9968 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9969 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
9970 0) return NULL;
9971 Py_INCREF(astmodulestate(m)->Global_type);
9972 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
9973 < 0) return NULL;
9974 Py_INCREF(astmodulestate(m)->Nonlocal_type);
9975 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0)
9976 return NULL;
9977 Py_INCREF(astmodulestate(m)->Expr_type);
9978 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0)
9979 return NULL;
9980 Py_INCREF(astmodulestate(m)->Pass_type);
9981 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0)
9982 return NULL;
9983 Py_INCREF(astmodulestate(m)->Break_type);
9984 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
9985 < 0) return NULL;
9986 Py_INCREF(astmodulestate(m)->Continue_type);
9987 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0)
9988 return NULL;
9989 Py_INCREF(astmodulestate(m)->expr_type);
9990 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
9991 0) return NULL;
9992 Py_INCREF(astmodulestate(m)->BoolOp_type);
9993 if (PyModule_AddObject(m, "NamedExpr",
9994 astmodulestate_global->NamedExpr_type) < 0) return NULL;
9995 Py_INCREF(astmodulestate(m)->NamedExpr_type);
9996 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0)
9997 return NULL;
9998 Py_INCREF(astmodulestate(m)->BinOp_type);
9999 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
10000 0) return NULL;
10001 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10002 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
10003 0) return NULL;
10004 Py_INCREF(astmodulestate(m)->Lambda_type);
10005 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0)
10006 return NULL;
10007 Py_INCREF(astmodulestate(m)->IfExp_type);
10008 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0)
10009 return NULL;
10010 Py_INCREF(astmodulestate(m)->Dict_type);
10011 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0)
10012 return NULL;
10013 Py_INCREF(astmodulestate(m)->Set_type);
10014 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
10015 < 0) return NULL;
10016 Py_INCREF(astmodulestate(m)->ListComp_type);
10017 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
10018 0) return NULL;
10019 Py_INCREF(astmodulestate(m)->SetComp_type);
10020 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
10021 < 0) return NULL;
10022 Py_INCREF(astmodulestate(m)->DictComp_type);
10023 if (PyModule_AddObject(m, "GeneratorExp",
10024 astmodulestate_global->GeneratorExp_type) < 0) return NULL;
10025 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
10026 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0)
10027 return NULL;
10028 Py_INCREF(astmodulestate(m)->Await_type);
10029 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0)
10030 return NULL;
10031 Py_INCREF(astmodulestate(m)->Yield_type);
10032 if (PyModule_AddObject(m, "YieldFrom",
10033 astmodulestate_global->YieldFrom_type) < 0) return NULL;
10034 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10035 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
10036 0) return NULL;
10037 Py_INCREF(astmodulestate(m)->Compare_type);
10038 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0)
10039 return NULL;
10040 Py_INCREF(astmodulestate(m)->Call_type);
10041 if (PyModule_AddObject(m, "FormattedValue",
10042 astmodulestate_global->FormattedValue_type) < 0) return NULL;
10043 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10044 if (PyModule_AddObject(m, "JoinedStr",
10045 astmodulestate_global->JoinedStr_type) < 0) return NULL;
10046 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10047 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
10048 < 0) return NULL;
10049 Py_INCREF(astmodulestate(m)->Constant_type);
10050 if (PyModule_AddObject(m, "Attribute",
10051 astmodulestate_global->Attribute_type) < 0) return NULL;
10052 Py_INCREF(astmodulestate(m)->Attribute_type);
10053 if (PyModule_AddObject(m, "Subscript",
10054 astmodulestate_global->Subscript_type) < 0) return NULL;
10055 Py_INCREF(astmodulestate(m)->Subscript_type);
10056 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
10057 0) return NULL;
10058 Py_INCREF(astmodulestate(m)->Starred_type);
10059 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0)
10060 return NULL;
10061 Py_INCREF(astmodulestate(m)->Name_type);
10062 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0)
10063 return NULL;
10064 Py_INCREF(astmodulestate(m)->List_type);
10065 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0)
10066 return NULL;
10067 Py_INCREF(astmodulestate(m)->Tuple_type);
10068 if (PyModule_AddObject(m, "expr_context",
10069 astmodulestate_global->expr_context_type) < 0) return NULL;
10070 Py_INCREF(astmodulestate(m)->expr_context_type);
10071 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0)
10072 return NULL;
10073 Py_INCREF(astmodulestate(m)->Load_type);
10074 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0)
10075 return NULL;
10076 Py_INCREF(astmodulestate(m)->Store_type);
10077 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0)
10078 return NULL;
10079 Py_INCREF(astmodulestate(m)->Del_type);
10080 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
10081 0) return NULL;
10082 Py_INCREF(astmodulestate(m)->AugLoad_type);
10083 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
10084 < 0) return NULL;
10085 Py_INCREF(astmodulestate(m)->AugStore_type);
10086 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0)
10087 return NULL;
10088 Py_INCREF(astmodulestate(m)->Param_type);
10089 if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0)
10090 return NULL;
10091 Py_INCREF(astmodulestate(m)->slice_type);
10092 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0)
10093 return NULL;
10094 Py_INCREF(astmodulestate(m)->Slice_type);
10095 if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type)
10096 < 0) return NULL;
10097 Py_INCREF(astmodulestate(m)->ExtSlice_type);
10098 if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0)
10099 return NULL;
10100 Py_INCREF(astmodulestate(m)->Index_type);
10101 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
10102 0) return NULL;
10103 Py_INCREF(astmodulestate(m)->boolop_type);
10104 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0)
10105 return NULL;
10106 Py_INCREF(astmodulestate(m)->And_type);
10107 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) return
10108 NULL;
10109 Py_INCREF(astmodulestate(m)->Or_type);
10110 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
10111 < 0) return NULL;
10112 Py_INCREF(astmodulestate(m)->operator_type);
10113 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0)
10114 return NULL;
10115 Py_INCREF(astmodulestate(m)->Add_type);
10116 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0)
10117 return NULL;
10118 Py_INCREF(astmodulestate(m)->Sub_type);
10119 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0)
10120 return NULL;
10121 Py_INCREF(astmodulestate(m)->Mult_type);
10122 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
10123 0) return NULL;
10124 Py_INCREF(astmodulestate(m)->MatMult_type);
10125 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0)
10126 return NULL;
10127 Py_INCREF(astmodulestate(m)->Div_type);
10128 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0)
10129 return NULL;
10130 Py_INCREF(astmodulestate(m)->Mod_type);
10131 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0)
10132 return NULL;
10133 Py_INCREF(astmodulestate(m)->Pow_type);
10134 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
10135 0) return NULL;
10136 Py_INCREF(astmodulestate(m)->LShift_type);
10137 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
10138 0) return NULL;
10139 Py_INCREF(astmodulestate(m)->RShift_type);
10140 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0)
10141 return NULL;
10142 Py_INCREF(astmodulestate(m)->BitOr_type);
10143 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
10144 0) return NULL;
10145 Py_INCREF(astmodulestate(m)->BitXor_type);
10146 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
10147 0) return NULL;
10148 Py_INCREF(astmodulestate(m)->BitAnd_type);
10149 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
10150 < 0) return NULL;
10151 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10152 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
10153 0) return NULL;
10154 Py_INCREF(astmodulestate(m)->unaryop_type);
10155 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
10156 0) return NULL;
10157 Py_INCREF(astmodulestate(m)->Invert_type);
10158 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0)
10159 return NULL;
10160 Py_INCREF(astmodulestate(m)->Not_type);
10161 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0)
10162 return NULL;
10163 Py_INCREF(astmodulestate(m)->UAdd_type);
10164 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0)
10165 return NULL;
10166 Py_INCREF(astmodulestate(m)->USub_type);
10167 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0)
10168 return NULL;
10169 Py_INCREF(astmodulestate(m)->cmpop_type);
10170 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) return
10171 NULL;
10172 Py_INCREF(astmodulestate(m)->Eq_type);
10173 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0)
10174 return NULL;
10175 Py_INCREF(astmodulestate(m)->NotEq_type);
10176 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) return
10177 NULL;
10178 Py_INCREF(astmodulestate(m)->Lt_type);
10179 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0)
10180 return NULL;
10181 Py_INCREF(astmodulestate(m)->LtE_type);
10182 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) return
10183 NULL;
10184 Py_INCREF(astmodulestate(m)->Gt_type);
10185 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0)
10186 return NULL;
10187 Py_INCREF(astmodulestate(m)->GtE_type);
10188 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) return
10189 NULL;
10190 Py_INCREF(astmodulestate(m)->Is_type);
10191 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0)
10192 return NULL;
10193 Py_INCREF(astmodulestate(m)->IsNot_type);
10194 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) return
10195 NULL;
10196 Py_INCREF(astmodulestate(m)->In_type);
10197 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0)
10198 return NULL;
10199 Py_INCREF(astmodulestate(m)->NotIn_type);
10200 if (PyModule_AddObject(m, "comprehension",
10201 astmodulestate_global->comprehension_type) < 0) return NULL;
10202 Py_INCREF(astmodulestate(m)->comprehension_type);
10203 if (PyModule_AddObject(m, "excepthandler",
10204 astmodulestate_global->excepthandler_type) < 0) return NULL;
10205 Py_INCREF(astmodulestate(m)->excepthandler_type);
10206 if (PyModule_AddObject(m, "ExceptHandler",
10207 astmodulestate_global->ExceptHandler_type) < 0) return NULL;
10208 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10209 if (PyModule_AddObject(m, "arguments",
10210 astmodulestate_global->arguments_type) < 0) return NULL;
10211 Py_INCREF(astmodulestate(m)->arguments_type);
10212 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0)
10213 return NULL;
10214 Py_INCREF(astmodulestate(m)->arg_type);
10215 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
10216 0) return NULL;
10217 Py_INCREF(astmodulestate(m)->keyword_type);
10218 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0)
10219 return NULL;
10220 Py_INCREF(astmodulestate(m)->alias_type);
10221 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
10222 < 0) return NULL;
10223 Py_INCREF(astmodulestate(m)->withitem_type);
10224 if (PyModule_AddObject(m, "type_ignore",
10225 astmodulestate_global->type_ignore_type) < 0) return NULL;
10226 Py_INCREF(astmodulestate(m)->type_ignore_type);
10227 if (PyModule_AddObject(m, "TypeIgnore",
10228 astmodulestate_global->TypeIgnore_type) < 0) return NULL;
10229 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010230 return m;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010231}
10232
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010233
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010234PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010235{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010236 if (!init_types())
10237 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010238 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010239}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010240
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010241/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10242mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010243{
10244 mod_ty res;
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010245 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010246 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010247 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010248
Steve Dowerb82e17e2019-05-23 08:45:22 -070010249 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10250 return NULL;
10251 }
10252
Dino Viehlandac46eb42019-09-11 10:16:34 -070010253 req_type[0] = astmodulestate_global->Module_type;
10254 req_type[1] = astmodulestate_global->Expression_type;
10255 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010256
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010257 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010258
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010259 if (!init_types())
10260 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010261
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010262 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10263 if (isinstance == -1)
10264 return NULL;
10265 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010266 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010267 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010268 return NULL;
10269 }
10270 if (obj2ast_mod(ast, &res, arena) != 0)
10271 return NULL;
10272 else
10273 return res;
10274}
10275
10276int PyAST_Check(PyObject* obj)
10277{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010278 if (!init_types())
10279 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010280 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010281}
10282
Martin v. Löwis5b222132007-06-10 09:51:05 +000010283