blob: 7a38e98c435ac43e4fb65dc366400ab76506bf16 [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 */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001133 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001134 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001135 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001136 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1137 assert(free_func != NULL);
1138 free_func(self);
1139 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001140}
1141
Neal Norwitz207c9f32008-03-31 04:42:11 +00001142static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001143ast_traverse(AST_object *self, visitproc visit, void *arg)
1144{
1145 Py_VISIT(self->dict);
1146 return 0;
1147}
1148
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001149static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001150ast_clear(AST_object *self)
1151{
1152 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001153 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001154}
1155
1156static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001157ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1158{
1159 Py_ssize_t i, numfields = 0;
1160 int res = -1;
1161 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001162 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001163 goto cleanup;
1164 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001165 if (fields) {
1166 numfields = PySequence_Size(fields);
1167 if (numfields == -1)
1168 goto cleanup;
1169 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001170
Neal Norwitz207c9f32008-03-31 04:42:11 +00001171 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001172 if (numfields < PyTuple_GET_SIZE(args)) {
1173 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1174 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001175 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001176 numfields, numfields == 1 ? "" : "s");
1177 res = -1;
1178 goto cleanup;
1179 }
1180 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1181 /* cannot be reached when fields is NULL */
1182 PyObject *name = PySequence_GetItem(fields, i);
1183 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001184 res = -1;
1185 goto cleanup;
1186 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001187 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1188 Py_DECREF(name);
1189 if (res < 0)
1190 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001191 }
1192 if (kw) {
1193 i = 0; /* needed by PyDict_Next */
1194 while (PyDict_Next(kw, &i, &key, &value)) {
1195 res = PyObject_SetAttr(self, key, value);
1196 if (res < 0)
1197 goto cleanup;
1198 }
1199 }
1200 cleanup:
1201 Py_XDECREF(fields);
1202 return res;
1203}
1204
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001205/* Pickling support */
1206static PyObject *
1207ast_type_reduce(PyObject *self, PyObject *unused)
1208{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001209 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001210 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001211 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001212 }
1213 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001214 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001215 }
1216 return Py_BuildValue("O()", Py_TYPE(self));
1217}
1218
1219static PyMethodDef ast_type_methods[] = {
1220 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1221 {NULL}
1222};
1223
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001224static PyGetSetDef ast_type_getsets[] = {
1225 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1226 {NULL}
1227};
1228
Dino Viehlandac46eb42019-09-11 10:16:34 -07001229static PyType_Slot AST_type_slots[] = {
1230 {Py_tp_dealloc, ast_dealloc},
1231 {Py_tp_getattro, PyObject_GenericGetAttr},
1232 {Py_tp_setattro, PyObject_GenericSetAttr},
1233 {Py_tp_traverse, ast_traverse},
1234 {Py_tp_clear, ast_clear},
1235 {Py_tp_methods, ast_type_methods},
1236 {Py_tp_getset, ast_type_getsets},
1237 {Py_tp_init, ast_type_init},
1238 {Py_tp_alloc, PyType_GenericAlloc},
1239 {Py_tp_new, PyType_GenericNew},
1240 {Py_tp_free, PyType_GenericNew},
1241 {Py_tp_free, PyObject_GC_Del},
1242 {0, 0},
1243};
1244
1245static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001246 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001247 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001248 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001249 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1250 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001251};
1252
Dino Viehlandac46eb42019-09-11 10:16:34 -07001253static PyObject *
1254make_type(const char *type, PyObject* base, const char* const* fields, int num_fields)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001255{
1256 PyObject *fnames, *result;
1257 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001258 fnames = PyTuple_New(num_fields);
1259 if (!fnames) return NULL;
1260 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001261 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001262 if (!field) {
1263 Py_DECREF(fnames);
1264 return NULL;
1265 }
1266 PyTuple_SET_ITEM(fnames, i, field);
1267 }
INADA Naokifc489082017-01-25 22:33:43 +09001268 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
1269 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001270 astmodulestate_global->_fields, fnames,
1271 astmodulestate_global->__module__,
1272 astmodulestate_global->_ast);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001273 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001274 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001275}
1276
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001277static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001278add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001279{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001280 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001281 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001282 if (!l)
1283 return 0;
1284 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001285 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001286 if (!s) {
1287 Py_DECREF(l);
1288 return 0;
1289 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001290 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001292 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001293 Py_DECREF(l);
1294 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001295}
1296
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001297/* Conversion AST -> Python */
1298
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001299static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1300{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001301 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001302 PyObject *result = PyList_New(n);
1303 PyObject *value;
1304 if (!result)
1305 return NULL;
1306 for (i = 0; i < n; i++) {
1307 value = func(asdl_seq_GET(seq, i));
1308 if (!value) {
1309 Py_DECREF(result);
1310 return NULL;
1311 }
1312 PyList_SET_ITEM(result, i, value);
1313 }
1314 return result;
1315}
1316
1317static PyObject* ast2obj_object(void *o)
1318{
1319 if (!o)
1320 o = Py_None;
1321 Py_INCREF((PyObject*)o);
1322 return (PyObject*)o;
1323}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001324#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001325#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001326#define ast2obj_identifier ast2obj_object
1327#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001328#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001329
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001330static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001331{
Christian Heimes217cfd12007-12-02 14:31:20 +00001332 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001333}
1334
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001335/* Conversion Python -> AST */
1336
1337static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1338{
1339 if (obj == Py_None)
1340 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001341 if (obj) {
1342 if (PyArena_AddPyObject(arena, obj) < 0) {
1343 *out = NULL;
1344 return -1;
1345 }
1346 Py_INCREF(obj);
1347 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001348 *out = obj;
1349 return 0;
1350}
1351
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001352static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1353{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001354 if (PyArena_AddPyObject(arena, obj) < 0) {
1355 *out = NULL;
1356 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001357 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001358 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001359 *out = obj;
1360 return 0;
1361}
1362
Benjamin Peterson180e6352011-07-22 11:09:07 -05001363static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001364{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001365 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1366 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001367 return 1;
1368 }
1369 return obj2ast_object(obj, out, arena);
1370}
1371
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001372static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1373{
1374 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1375 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1376 return 1;
1377 }
1378 return obj2ast_object(obj, out, arena);
1379}
1380
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001381static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1382{
1383 int i;
1384 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001385 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001386 return 1;
1387 }
1388
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001389 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001390 if (i == -1 && PyErr_Occurred())
1391 return 1;
1392 *out = i;
1393 return 0;
1394}
1395
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001396static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001397{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001398 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001399 empty_tuple = PyTuple_New(0);
1400 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001401 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1402 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001403 Py_XDECREF(empty_tuple);
1404 return -1;
1405 }
1406 Py_DECREF(empty_tuple);
1407 return 0;
1408}
1409
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001410
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001411static int init_types(void)
1412{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001413 PyObject *m;
1414 if (PyState_FindModule(&_astmodule) == NULL) {
1415 m = PyModule_Create(&_astmodule);
1416 if (!m) return 0;
1417 PyState_AddModule(m, &_astmodule);
1418 }
1419 astmodulestate *state = astmodulestate_global;
1420 if (state->initialized) return 1;
1421 if (init_identifiers() < 0) return 0;
1422 state->AST_type = PyType_FromSpec(&AST_type_spec);
1423 if (!state->AST_type) return 0;
1424 ((PyTypeObject*)state->AST_type)->tp_dictoffset = offsetof(AST_object,
1425 dict);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001426 if (add_ast_fields() < 0) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001427 state->mod_type = make_type("mod", state->AST_type, NULL, 0);
1428 if (!state->mod_type) return 0;
1429 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
1430 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2);
1431 if (!state->Module_type) return 0;
1432 state->Interactive_type = make_type("Interactive", state->mod_type,
1433 Interactive_fields, 1);
1434 if (!state->Interactive_type) return 0;
1435 state->Expression_type = make_type("Expression", state->mod_type,
1436 Expression_fields, 1);
1437 if (!state->Expression_type) return 0;
1438 state->FunctionType_type = make_type("FunctionType", state->mod_type,
1439 FunctionType_fields, 2);
1440 if (!state->FunctionType_type) return 0;
1441 state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1);
1442 if (!state->Suite_type) return 0;
1443 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
1444 if (!state->stmt_type) return 0;
1445 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
1446 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1447 FunctionDef_fields, 6);
1448 if (!state->FunctionDef_type) return 0;
1449 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1450 state->stmt_type,
1451 AsyncFunctionDef_fields, 6);
1452 if (!state->AsyncFunctionDef_type) return 0;
1453 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1454 ClassDef_fields, 5);
1455 if (!state->ClassDef_type) return 0;
1456 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1457 1);
1458 if (!state->Return_type) return 0;
1459 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1460 1);
1461 if (!state->Delete_type) return 0;
1462 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1463 3);
1464 if (!state->Assign_type) return 0;
1465 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1466 AugAssign_fields, 3);
1467 if (!state->AugAssign_type) return 0;
1468 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1469 AnnAssign_fields, 4);
1470 if (!state->AnnAssign_type) return 0;
1471 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1472 if (!state->For_type) return 0;
1473 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1474 AsyncFor_fields, 5);
1475 if (!state->AsyncFor_type) return 0;
1476 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1477 if (!state->While_type) return 0;
1478 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1479 if (!state->If_type) return 0;
1480 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1481 if (!state->With_type) return 0;
1482 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1483 AsyncWith_fields, 3);
1484 if (!state->AsyncWith_type) return 0;
1485 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1486 if (!state->Raise_type) return 0;
1487 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1488 if (!state->Try_type) return 0;
1489 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1490 2);
1491 if (!state->Assert_type) return 0;
1492 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1493 1);
1494 if (!state->Import_type) return 0;
1495 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1496 ImportFrom_fields, 3);
1497 if (!state->ImportFrom_type) return 0;
1498 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1499 1);
1500 if (!state->Global_type) return 0;
1501 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1502 Nonlocal_fields, 1);
1503 if (!state->Nonlocal_type) return 0;
1504 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1505 if (!state->Expr_type) return 0;
1506 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1507 if (!state->Pass_type) return 0;
1508 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1509 if (!state->Break_type) return 0;
1510 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1511 if (!state->Continue_type) return 0;
1512 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1513 if (!state->expr_type) return 0;
1514 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
1515 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1516 2);
1517 if (!state->BoolOp_type) return 0;
1518 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1519 NamedExpr_fields, 2);
1520 if (!state->NamedExpr_type) return 0;
1521 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1522 if (!state->BinOp_type) return 0;
1523 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1524 UnaryOp_fields, 2);
1525 if (!state->UnaryOp_type) return 0;
1526 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1527 2);
1528 if (!state->Lambda_type) return 0;
1529 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1530 if (!state->IfExp_type) return 0;
1531 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1532 if (!state->Dict_type) return 0;
1533 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1534 if (!state->Set_type) return 0;
1535 state->ListComp_type = make_type("ListComp", state->expr_type,
1536 ListComp_fields, 2);
1537 if (!state->ListComp_type) return 0;
1538 state->SetComp_type = make_type("SetComp", state->expr_type,
1539 SetComp_fields, 2);
1540 if (!state->SetComp_type) return 0;
1541 state->DictComp_type = make_type("DictComp", state->expr_type,
1542 DictComp_fields, 3);
1543 if (!state->DictComp_type) return 0;
1544 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1545 GeneratorExp_fields, 2);
1546 if (!state->GeneratorExp_type) return 0;
1547 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1548 if (!state->Await_type) return 0;
1549 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1550 if (!state->Yield_type) return 0;
1551 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1552 YieldFrom_fields, 1);
1553 if (!state->YieldFrom_type) return 0;
1554 state->Compare_type = make_type("Compare", state->expr_type,
1555 Compare_fields, 3);
1556 if (!state->Compare_type) return 0;
1557 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1558 if (!state->Call_type) return 0;
1559 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1560 FormattedValue_fields, 3);
1561 if (!state->FormattedValue_type) return 0;
1562 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1563 JoinedStr_fields, 1);
1564 if (!state->JoinedStr_type) return 0;
1565 state->Constant_type = make_type("Constant", state->expr_type,
1566 Constant_fields, 2);
1567 if (!state->Constant_type) return 0;
1568 state->Attribute_type = make_type("Attribute", state->expr_type,
1569 Attribute_fields, 3);
1570 if (!state->Attribute_type) return 0;
1571 state->Subscript_type = make_type("Subscript", state->expr_type,
1572 Subscript_fields, 3);
1573 if (!state->Subscript_type) return 0;
1574 state->Starred_type = make_type("Starred", state->expr_type,
1575 Starred_fields, 2);
1576 if (!state->Starred_type) return 0;
1577 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1578 if (!state->Name_type) return 0;
1579 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1580 if (!state->List_type) return 0;
1581 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1582 if (!state->Tuple_type) return 0;
1583 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1584 0);
1585 if (!state->expr_context_type) return 0;
1586 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1587 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1588 if (!state->Load_type) return 0;
1589 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1590 NULL, NULL);
1591 if (!state->Load_singleton) return 0;
1592 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1593 if (!state->Store_type) return 0;
1594 state->Store_singleton = PyType_GenericNew((PyTypeObject
1595 *)state->Store_type, NULL, NULL);
1596 if (!state->Store_singleton) return 0;
1597 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1598 if (!state->Del_type) return 0;
1599 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1600 NULL, NULL);
1601 if (!state->Del_singleton) return 0;
1602 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1603 0);
1604 if (!state->AugLoad_type) return 0;
1605 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1606 *)state->AugLoad_type, NULL,
1607 NULL);
1608 if (!state->AugLoad_singleton) return 0;
1609 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1610 NULL, 0);
1611 if (!state->AugStore_type) return 0;
1612 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1613 *)state->AugStore_type, NULL,
1614 NULL);
1615 if (!state->AugStore_singleton) return 0;
1616 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1617 if (!state->Param_type) return 0;
1618 state->Param_singleton = PyType_GenericNew((PyTypeObject
1619 *)state->Param_type, NULL, NULL);
1620 if (!state->Param_singleton) return 0;
1621 state->slice_type = make_type("slice", state->AST_type, NULL, 0);
1622 if (!state->slice_type) return 0;
1623 if (!add_attributes(state->slice_type, NULL, 0)) return 0;
1624 state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3);
1625 if (!state->Slice_type) return 0;
1626 state->ExtSlice_type = make_type("ExtSlice", state->slice_type,
1627 ExtSlice_fields, 1);
1628 if (!state->ExtSlice_type) return 0;
1629 state->Index_type = make_type("Index", state->slice_type, Index_fields, 1);
1630 if (!state->Index_type) return 0;
1631 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1632 if (!state->boolop_type) return 0;
1633 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1634 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1635 if (!state->And_type) return 0;
1636 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1637 NULL, NULL);
1638 if (!state->And_singleton) return 0;
1639 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1640 if (!state->Or_type) return 0;
1641 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1642 NULL, NULL);
1643 if (!state->Or_singleton) return 0;
1644 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1645 if (!state->operator_type) return 0;
1646 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1647 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1648 if (!state->Add_type) return 0;
1649 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1650 NULL, NULL);
1651 if (!state->Add_singleton) return 0;
1652 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1653 if (!state->Sub_type) return 0;
1654 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1655 NULL, NULL);
1656 if (!state->Sub_singleton) return 0;
1657 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1658 if (!state->Mult_type) return 0;
1659 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1660 NULL, NULL);
1661 if (!state->Mult_singleton) return 0;
1662 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1663 if (!state->MatMult_type) return 0;
1664 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1665 *)state->MatMult_type, NULL,
1666 NULL);
1667 if (!state->MatMult_singleton) return 0;
1668 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1669 if (!state->Div_type) return 0;
1670 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1671 NULL, NULL);
1672 if (!state->Div_singleton) return 0;
1673 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1674 if (!state->Mod_type) return 0;
1675 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1676 NULL, NULL);
1677 if (!state->Mod_singleton) return 0;
1678 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1679 if (!state->Pow_type) return 0;
1680 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1681 NULL, NULL);
1682 if (!state->Pow_singleton) return 0;
1683 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1684 if (!state->LShift_type) return 0;
1685 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1686 *)state->LShift_type, NULL,
1687 NULL);
1688 if (!state->LShift_singleton) return 0;
1689 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1690 if (!state->RShift_type) return 0;
1691 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1692 *)state->RShift_type, NULL,
1693 NULL);
1694 if (!state->RShift_singleton) return 0;
1695 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1696 if (!state->BitOr_type) return 0;
1697 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1698 *)state->BitOr_type, NULL, NULL);
1699 if (!state->BitOr_singleton) return 0;
1700 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1701 if (!state->BitXor_type) return 0;
1702 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1703 *)state->BitXor_type, NULL,
1704 NULL);
1705 if (!state->BitXor_singleton) return 0;
1706 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1707 if (!state->BitAnd_type) return 0;
1708 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1709 *)state->BitAnd_type, NULL,
1710 NULL);
1711 if (!state->BitAnd_singleton) return 0;
1712 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1713 if (!state->FloorDiv_type) return 0;
1714 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1715 *)state->FloorDiv_type, NULL,
1716 NULL);
1717 if (!state->FloorDiv_singleton) return 0;
1718 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1719 if (!state->unaryop_type) return 0;
1720 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1721 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1722 if (!state->Invert_type) return 0;
1723 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1724 *)state->Invert_type, NULL,
1725 NULL);
1726 if (!state->Invert_singleton) return 0;
1727 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1728 if (!state->Not_type) return 0;
1729 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1730 NULL, NULL);
1731 if (!state->Not_singleton) return 0;
1732 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1733 if (!state->UAdd_type) return 0;
1734 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1735 NULL, NULL);
1736 if (!state->UAdd_singleton) return 0;
1737 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1738 if (!state->USub_type) return 0;
1739 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1740 NULL, NULL);
1741 if (!state->USub_singleton) return 0;
1742 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1743 if (!state->cmpop_type) return 0;
1744 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1745 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1746 if (!state->Eq_type) return 0;
1747 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1748 NULL, NULL);
1749 if (!state->Eq_singleton) return 0;
1750 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1751 if (!state->NotEq_type) return 0;
1752 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1753 *)state->NotEq_type, NULL, NULL);
1754 if (!state->NotEq_singleton) return 0;
1755 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1756 if (!state->Lt_type) return 0;
1757 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1758 NULL, NULL);
1759 if (!state->Lt_singleton) return 0;
1760 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1761 if (!state->LtE_type) return 0;
1762 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1763 NULL, NULL);
1764 if (!state->LtE_singleton) return 0;
1765 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1766 if (!state->Gt_type) return 0;
1767 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1768 NULL, NULL);
1769 if (!state->Gt_singleton) return 0;
1770 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1771 if (!state->GtE_type) return 0;
1772 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1773 NULL, NULL);
1774 if (!state->GtE_singleton) return 0;
1775 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1776 if (!state->Is_type) return 0;
1777 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1778 NULL, NULL);
1779 if (!state->Is_singleton) return 0;
1780 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1781 if (!state->IsNot_type) return 0;
1782 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1783 *)state->IsNot_type, NULL, NULL);
1784 if (!state->IsNot_singleton) return 0;
1785 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1786 if (!state->In_type) return 0;
1787 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1788 NULL, NULL);
1789 if (!state->In_singleton) return 0;
1790 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1791 if (!state->NotIn_type) return 0;
1792 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1793 *)state->NotIn_type, NULL, NULL);
1794 if (!state->NotIn_singleton) return 0;
1795 state->comprehension_type = make_type("comprehension", state->AST_type,
1796 comprehension_fields, 4);
1797 if (!state->comprehension_type) return 0;
1798 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1799 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1800 NULL, 0);
1801 if (!state->excepthandler_type) return 0;
1802 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1803 4)) return 0;
1804 state->ExceptHandler_type = make_type("ExceptHandler",
1805 state->excepthandler_type,
1806 ExceptHandler_fields, 3);
1807 if (!state->ExceptHandler_type) return 0;
1808 state->arguments_type = make_type("arguments", state->AST_type,
1809 arguments_fields, 7);
1810 if (!state->arguments_type) return 0;
1811 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
1812 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1813 if (!state->arg_type) return 0;
1814 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
1815 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1816 2);
1817 if (!state->keyword_type) return 0;
1818 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
1819 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1820 if (!state->alias_type) return 0;
1821 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
1822 state->withitem_type = make_type("withitem", state->AST_type,
1823 withitem_fields, 2);
1824 if (!state->withitem_type) return 0;
1825 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
1826 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1827 0);
1828 if (!state->type_ignore_type) return 0;
1829 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1830 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1831 TypeIgnore_fields, 2);
1832 if (!state->TypeIgnore_type) return 0;
1833 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001834 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001835}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001836
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001837static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1838static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1839static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1840static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1841 arena);
1842static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1843static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1844static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1845static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1846static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1847static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1848 arena);
1849static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1850 arena);
1851static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1852static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1853static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1854static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001855static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001856static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1857 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001858
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001859mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001860Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001861{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001862 mod_ty p;
1863 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1864 if (!p)
1865 return NULL;
1866 p->kind = Module_kind;
1867 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001868 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001869 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870}
1871
1872mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001873Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001874{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001875 mod_ty p;
1876 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1877 if (!p)
1878 return NULL;
1879 p->kind = Interactive_kind;
1880 p->v.Interactive.body = body;
1881 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882}
1883
1884mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001885Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001886{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001887 mod_ty p;
1888 if (!body) {
1889 PyErr_SetString(PyExc_ValueError,
1890 "field body is required for Expression");
1891 return NULL;
1892 }
1893 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1894 if (!p)
1895 return NULL;
1896 p->kind = Expression_kind;
1897 p->v.Expression.body = body;
1898 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001899}
1900
1901mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001902FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1903{
1904 mod_ty p;
1905 if (!returns) {
1906 PyErr_SetString(PyExc_ValueError,
1907 "field returns is required for FunctionType");
1908 return NULL;
1909 }
1910 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1911 if (!p)
1912 return NULL;
1913 p->kind = FunctionType_kind;
1914 p->v.FunctionType.argtypes = argtypes;
1915 p->v.FunctionType.returns = returns;
1916 return p;
1917}
1918
1919mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001920Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001921{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001922 mod_ty p;
1923 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1924 if (!p)
1925 return NULL;
1926 p->kind = Suite_kind;
1927 p->v.Suite.body = body;
1928 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001929}
1930
1931stmt_ty
1932FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001933 decorator_list, expr_ty returns, string type_comment, int lineno,
1934 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001935{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001936 stmt_ty p;
1937 if (!name) {
1938 PyErr_SetString(PyExc_ValueError,
1939 "field name is required for FunctionDef");
1940 return NULL;
1941 }
1942 if (!args) {
1943 PyErr_SetString(PyExc_ValueError,
1944 "field args is required for FunctionDef");
1945 return NULL;
1946 }
1947 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1948 if (!p)
1949 return NULL;
1950 p->kind = FunctionDef_kind;
1951 p->v.FunctionDef.name = name;
1952 p->v.FunctionDef.args = args;
1953 p->v.FunctionDef.body = body;
1954 p->v.FunctionDef.decorator_list = decorator_list;
1955 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001956 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001957 p->lineno = lineno;
1958 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001959 p->end_lineno = end_lineno;
1960 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001961 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001962}
1963
1964stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001965AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001966 * decorator_list, expr_ty returns, string type_comment, int
1967 lineno, int col_offset, int end_lineno, int end_col_offset,
1968 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001969{
1970 stmt_ty p;
1971 if (!name) {
1972 PyErr_SetString(PyExc_ValueError,
1973 "field name is required for AsyncFunctionDef");
1974 return NULL;
1975 }
1976 if (!args) {
1977 PyErr_SetString(PyExc_ValueError,
1978 "field args is required for AsyncFunctionDef");
1979 return NULL;
1980 }
1981 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1982 if (!p)
1983 return NULL;
1984 p->kind = AsyncFunctionDef_kind;
1985 p->v.AsyncFunctionDef.name = name;
1986 p->v.AsyncFunctionDef.args = args;
1987 p->v.AsyncFunctionDef.body = body;
1988 p->v.AsyncFunctionDef.decorator_list = decorator_list;
1989 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001990 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04001991 p->lineno = lineno;
1992 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001993 p->end_lineno = end_lineno;
1994 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04001995 return p;
1996}
1997
1998stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04001999ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002000 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2001 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002002{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002003 stmt_ty p;
2004 if (!name) {
2005 PyErr_SetString(PyExc_ValueError,
2006 "field name is required for ClassDef");
2007 return NULL;
2008 }
2009 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2010 if (!p)
2011 return NULL;
2012 p->kind = ClassDef_kind;
2013 p->v.ClassDef.name = name;
2014 p->v.ClassDef.bases = bases;
2015 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002016 p->v.ClassDef.body = body;
2017 p->v.ClassDef.decorator_list = decorator_list;
2018 p->lineno = lineno;
2019 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002020 p->end_lineno = end_lineno;
2021 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002022 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002023}
2024
2025stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002026Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2027 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002028{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002029 stmt_ty p;
2030 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2031 if (!p)
2032 return NULL;
2033 p->kind = Return_kind;
2034 p->v.Return.value = value;
2035 p->lineno = lineno;
2036 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002037 p->end_lineno = end_lineno;
2038 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002039 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002040}
2041
2042stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002043Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2044 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002045{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002046 stmt_ty p;
2047 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2048 if (!p)
2049 return NULL;
2050 p->kind = Delete_kind;
2051 p->v.Delete.targets = targets;
2052 p->lineno = lineno;
2053 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002054 p->end_lineno = end_lineno;
2055 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002056 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002057}
2058
2059stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002060Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2061 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002062{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002063 stmt_ty p;
2064 if (!value) {
2065 PyErr_SetString(PyExc_ValueError,
2066 "field value is required for Assign");
2067 return NULL;
2068 }
2069 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2070 if (!p)
2071 return NULL;
2072 p->kind = Assign_kind;
2073 p->v.Assign.targets = targets;
2074 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002075 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002076 p->lineno = lineno;
2077 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002078 p->end_lineno = end_lineno;
2079 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002080 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002081}
2082
2083stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002084AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002085 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002086{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002087 stmt_ty p;
2088 if (!target) {
2089 PyErr_SetString(PyExc_ValueError,
2090 "field target is required for AugAssign");
2091 return NULL;
2092 }
2093 if (!op) {
2094 PyErr_SetString(PyExc_ValueError,
2095 "field op is required for AugAssign");
2096 return NULL;
2097 }
2098 if (!value) {
2099 PyErr_SetString(PyExc_ValueError,
2100 "field value is required for AugAssign");
2101 return NULL;
2102 }
2103 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2104 if (!p)
2105 return NULL;
2106 p->kind = AugAssign_kind;
2107 p->v.AugAssign.target = target;
2108 p->v.AugAssign.op = op;
2109 p->v.AugAssign.value = value;
2110 p->lineno = lineno;
2111 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002112 p->end_lineno = end_lineno;
2113 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002114 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002115}
2116
2117stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002118AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002119 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2120 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002121{
2122 stmt_ty p;
2123 if (!target) {
2124 PyErr_SetString(PyExc_ValueError,
2125 "field target is required for AnnAssign");
2126 return NULL;
2127 }
2128 if (!annotation) {
2129 PyErr_SetString(PyExc_ValueError,
2130 "field annotation is required for AnnAssign");
2131 return NULL;
2132 }
2133 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2134 if (!p)
2135 return NULL;
2136 p->kind = AnnAssign_kind;
2137 p->v.AnnAssign.target = target;
2138 p->v.AnnAssign.annotation = annotation;
2139 p->v.AnnAssign.value = value;
2140 p->v.AnnAssign.simple = simple;
2141 p->lineno = lineno;
2142 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002143 p->end_lineno = end_lineno;
2144 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002145 return p;
2146}
2147
2148stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002149For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2150 type_comment, int lineno, int col_offset, int end_lineno, int
2151 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002152{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002153 stmt_ty p;
2154 if (!target) {
2155 PyErr_SetString(PyExc_ValueError,
2156 "field target is required for For");
2157 return NULL;
2158 }
2159 if (!iter) {
2160 PyErr_SetString(PyExc_ValueError,
2161 "field iter is required for For");
2162 return NULL;
2163 }
2164 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2165 if (!p)
2166 return NULL;
2167 p->kind = For_kind;
2168 p->v.For.target = target;
2169 p->v.For.iter = iter;
2170 p->v.For.body = body;
2171 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002172 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002173 p->lineno = lineno;
2174 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002175 p->end_lineno = end_lineno;
2176 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002177 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002178}
2179
2180stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002181AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2182 string type_comment, int lineno, int col_offset, int end_lineno, int
2183 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002184{
2185 stmt_ty p;
2186 if (!target) {
2187 PyErr_SetString(PyExc_ValueError,
2188 "field target is required for AsyncFor");
2189 return NULL;
2190 }
2191 if (!iter) {
2192 PyErr_SetString(PyExc_ValueError,
2193 "field iter is required for AsyncFor");
2194 return NULL;
2195 }
2196 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2197 if (!p)
2198 return NULL;
2199 p->kind = AsyncFor_kind;
2200 p->v.AsyncFor.target = target;
2201 p->v.AsyncFor.iter = iter;
2202 p->v.AsyncFor.body = body;
2203 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002204 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002205 p->lineno = lineno;
2206 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002207 p->end_lineno = end_lineno;
2208 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002209 return p;
2210}
2211
2212stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002213While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002214 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002215{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002216 stmt_ty p;
2217 if (!test) {
2218 PyErr_SetString(PyExc_ValueError,
2219 "field test is required for While");
2220 return NULL;
2221 }
2222 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2223 if (!p)
2224 return NULL;
2225 p->kind = While_kind;
2226 p->v.While.test = test;
2227 p->v.While.body = body;
2228 p->v.While.orelse = orelse;
2229 p->lineno = lineno;
2230 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002231 p->end_lineno = end_lineno;
2232 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002233 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002234}
2235
2236stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002237If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002238 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002239{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002240 stmt_ty p;
2241 if (!test) {
2242 PyErr_SetString(PyExc_ValueError,
2243 "field test is required for If");
2244 return NULL;
2245 }
2246 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2247 if (!p)
2248 return NULL;
2249 p->kind = If_kind;
2250 p->v.If.test = test;
2251 p->v.If.body = body;
2252 p->v.If.orelse = orelse;
2253 p->lineno = lineno;
2254 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002255 p->end_lineno = end_lineno;
2256 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002257 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002258}
2259
2260stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002261With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2262 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002263{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002264 stmt_ty p;
2265 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2266 if (!p)
2267 return NULL;
2268 p->kind = With_kind;
2269 p->v.With.items = items;
2270 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002271 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002272 p->lineno = lineno;
2273 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002274 p->end_lineno = end_lineno;
2275 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002276 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002277}
2278
2279stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002280AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2281 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002282{
2283 stmt_ty p;
2284 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2285 if (!p)
2286 return NULL;
2287 p->kind = AsyncWith_kind;
2288 p->v.AsyncWith.items = items;
2289 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002290 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002291 p->lineno = lineno;
2292 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002293 p->end_lineno = end_lineno;
2294 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002295 return p;
2296}
2297
2298stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002299Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2300 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002301{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002302 stmt_ty p;
2303 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2304 if (!p)
2305 return NULL;
2306 p->kind = Raise_kind;
2307 p->v.Raise.exc = exc;
2308 p->v.Raise.cause = cause;
2309 p->lineno = lineno;
2310 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002311 p->end_lineno = end_lineno;
2312 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002313 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002314}
2315
2316stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002317Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002318 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2319 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002320{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002321 stmt_ty p;
2322 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2323 if (!p)
2324 return NULL;
2325 p->kind = Try_kind;
2326 p->v.Try.body = body;
2327 p->v.Try.handlers = handlers;
2328 p->v.Try.orelse = orelse;
2329 p->v.Try.finalbody = finalbody;
2330 p->lineno = lineno;
2331 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002332 p->end_lineno = end_lineno;
2333 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002334 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002335}
2336
2337stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002338Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2339 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002340{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002341 stmt_ty p;
2342 if (!test) {
2343 PyErr_SetString(PyExc_ValueError,
2344 "field test is required for Assert");
2345 return NULL;
2346 }
2347 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2348 if (!p)
2349 return NULL;
2350 p->kind = Assert_kind;
2351 p->v.Assert.test = test;
2352 p->v.Assert.msg = msg;
2353 p->lineno = lineno;
2354 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002355 p->end_lineno = end_lineno;
2356 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002357 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002358}
2359
2360stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002361Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2362 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002363{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002364 stmt_ty p;
2365 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2366 if (!p)
2367 return NULL;
2368 p->kind = Import_kind;
2369 p->v.Import.names = names;
2370 p->lineno = lineno;
2371 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002372 p->end_lineno = end_lineno;
2373 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002374 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002375}
2376
2377stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002378ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002379 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002380{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002381 stmt_ty p;
2382 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2383 if (!p)
2384 return NULL;
2385 p->kind = ImportFrom_kind;
2386 p->v.ImportFrom.module = module;
2387 p->v.ImportFrom.names = names;
2388 p->v.ImportFrom.level = level;
2389 p->lineno = lineno;
2390 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002391 p->end_lineno = end_lineno;
2392 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002393 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002394}
2395
2396stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002397Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2398 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002399{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002400 stmt_ty p;
2401 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2402 if (!p)
2403 return NULL;
2404 p->kind = Global_kind;
2405 p->v.Global.names = names;
2406 p->lineno = lineno;
2407 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002408 p->end_lineno = end_lineno;
2409 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002410 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002411}
2412
2413stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002414Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2415 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002416{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002417 stmt_ty p;
2418 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2419 if (!p)
2420 return NULL;
2421 p->kind = Nonlocal_kind;
2422 p->v.Nonlocal.names = names;
2423 p->lineno = lineno;
2424 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002425 p->end_lineno = end_lineno;
2426 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002427 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002428}
2429
2430stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002431Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2432 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002433{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002434 stmt_ty p;
2435 if (!value) {
2436 PyErr_SetString(PyExc_ValueError,
2437 "field value is required for Expr");
2438 return NULL;
2439 }
2440 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2441 if (!p)
2442 return NULL;
2443 p->kind = Expr_kind;
2444 p->v.Expr.value = value;
2445 p->lineno = lineno;
2446 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002447 p->end_lineno = end_lineno;
2448 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002449 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002450}
2451
2452stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002453Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2454 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002455{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002456 stmt_ty p;
2457 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2458 if (!p)
2459 return NULL;
2460 p->kind = Pass_kind;
2461 p->lineno = lineno;
2462 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002463 p->end_lineno = end_lineno;
2464 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002465 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002466}
2467
2468stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002469Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2470 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002472 stmt_ty p;
2473 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2474 if (!p)
2475 return NULL;
2476 p->kind = Break_kind;
2477 p->lineno = lineno;
2478 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002479 p->end_lineno = end_lineno;
2480 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002481 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002482}
2483
2484stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002485Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2486 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002488 stmt_ty p;
2489 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2490 if (!p)
2491 return NULL;
2492 p->kind = Continue_kind;
2493 p->lineno = lineno;
2494 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002495 p->end_lineno = end_lineno;
2496 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002497 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002498}
2499
2500expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002501BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2502 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002503{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002504 expr_ty p;
2505 if (!op) {
2506 PyErr_SetString(PyExc_ValueError,
2507 "field op is required for BoolOp");
2508 return NULL;
2509 }
2510 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2511 if (!p)
2512 return NULL;
2513 p->kind = BoolOp_kind;
2514 p->v.BoolOp.op = op;
2515 p->v.BoolOp.values = values;
2516 p->lineno = lineno;
2517 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002518 p->end_lineno = end_lineno;
2519 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002520 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002521}
2522
2523expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002524NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2525 end_lineno, int end_col_offset, PyArena *arena)
2526{
2527 expr_ty p;
2528 if (!target) {
2529 PyErr_SetString(PyExc_ValueError,
2530 "field target is required for NamedExpr");
2531 return NULL;
2532 }
2533 if (!value) {
2534 PyErr_SetString(PyExc_ValueError,
2535 "field value is required for NamedExpr");
2536 return NULL;
2537 }
2538 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2539 if (!p)
2540 return NULL;
2541 p->kind = NamedExpr_kind;
2542 p->v.NamedExpr.target = target;
2543 p->v.NamedExpr.value = value;
2544 p->lineno = lineno;
2545 p->col_offset = col_offset;
2546 p->end_lineno = end_lineno;
2547 p->end_col_offset = end_col_offset;
2548 return p;
2549}
2550
2551expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002552BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002553 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002554{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002555 expr_ty p;
2556 if (!left) {
2557 PyErr_SetString(PyExc_ValueError,
2558 "field left is required for BinOp");
2559 return NULL;
2560 }
2561 if (!op) {
2562 PyErr_SetString(PyExc_ValueError,
2563 "field op is required for BinOp");
2564 return NULL;
2565 }
2566 if (!right) {
2567 PyErr_SetString(PyExc_ValueError,
2568 "field right is required for BinOp");
2569 return NULL;
2570 }
2571 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2572 if (!p)
2573 return NULL;
2574 p->kind = BinOp_kind;
2575 p->v.BinOp.left = left;
2576 p->v.BinOp.op = op;
2577 p->v.BinOp.right = right;
2578 p->lineno = lineno;
2579 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002580 p->end_lineno = end_lineno;
2581 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002582 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002583}
2584
2585expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002586UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2587 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002588{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002589 expr_ty p;
2590 if (!op) {
2591 PyErr_SetString(PyExc_ValueError,
2592 "field op is required for UnaryOp");
2593 return NULL;
2594 }
2595 if (!operand) {
2596 PyErr_SetString(PyExc_ValueError,
2597 "field operand is required for UnaryOp");
2598 return NULL;
2599 }
2600 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2601 if (!p)
2602 return NULL;
2603 p->kind = UnaryOp_kind;
2604 p->v.UnaryOp.op = op;
2605 p->v.UnaryOp.operand = operand;
2606 p->lineno = lineno;
2607 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002608 p->end_lineno = end_lineno;
2609 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002610 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002611}
2612
2613expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002614Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2615 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002616{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002617 expr_ty p;
2618 if (!args) {
2619 PyErr_SetString(PyExc_ValueError,
2620 "field args is required for Lambda");
2621 return NULL;
2622 }
2623 if (!body) {
2624 PyErr_SetString(PyExc_ValueError,
2625 "field body is required for Lambda");
2626 return NULL;
2627 }
2628 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2629 if (!p)
2630 return NULL;
2631 p->kind = Lambda_kind;
2632 p->v.Lambda.args = args;
2633 p->v.Lambda.body = body;
2634 p->lineno = lineno;
2635 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002636 p->end_lineno = end_lineno;
2637 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002638 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002639}
2640
2641expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002642IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002643 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002644{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002645 expr_ty p;
2646 if (!test) {
2647 PyErr_SetString(PyExc_ValueError,
2648 "field test is required for IfExp");
2649 return NULL;
2650 }
2651 if (!body) {
2652 PyErr_SetString(PyExc_ValueError,
2653 "field body is required for IfExp");
2654 return NULL;
2655 }
2656 if (!orelse) {
2657 PyErr_SetString(PyExc_ValueError,
2658 "field orelse is required for IfExp");
2659 return NULL;
2660 }
2661 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2662 if (!p)
2663 return NULL;
2664 p->kind = IfExp_kind;
2665 p->v.IfExp.test = test;
2666 p->v.IfExp.body = body;
2667 p->v.IfExp.orelse = orelse;
2668 p->lineno = lineno;
2669 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002670 p->end_lineno = end_lineno;
2671 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002672 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002673}
2674
2675expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002676Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2677 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002678{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002679 expr_ty p;
2680 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2681 if (!p)
2682 return NULL;
2683 p->kind = Dict_kind;
2684 p->v.Dict.keys = keys;
2685 p->v.Dict.values = values;
2686 p->lineno = lineno;
2687 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002688 p->end_lineno = end_lineno;
2689 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002690 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002691}
2692
2693expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002694Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2695 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002696{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002697 expr_ty p;
2698 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2699 if (!p)
2700 return NULL;
2701 p->kind = Set_kind;
2702 p->v.Set.elts = elts;
2703 p->lineno = lineno;
2704 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002705 p->end_lineno = end_lineno;
2706 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002707 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002708}
2709
2710expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002711ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2712 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002713{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002714 expr_ty p;
2715 if (!elt) {
2716 PyErr_SetString(PyExc_ValueError,
2717 "field elt is required for ListComp");
2718 return NULL;
2719 }
2720 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2721 if (!p)
2722 return NULL;
2723 p->kind = ListComp_kind;
2724 p->v.ListComp.elt = elt;
2725 p->v.ListComp.generators = generators;
2726 p->lineno = lineno;
2727 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002728 p->end_lineno = end_lineno;
2729 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002730 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002731}
2732
2733expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002734SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2735 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002736{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002737 expr_ty p;
2738 if (!elt) {
2739 PyErr_SetString(PyExc_ValueError,
2740 "field elt is required for SetComp");
2741 return NULL;
2742 }
2743 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2744 if (!p)
2745 return NULL;
2746 p->kind = SetComp_kind;
2747 p->v.SetComp.elt = elt;
2748 p->v.SetComp.generators = generators;
2749 p->lineno = lineno;
2750 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002751 p->end_lineno = end_lineno;
2752 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002753 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002754}
2755
2756expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002757DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002758 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002759{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002760 expr_ty p;
2761 if (!key) {
2762 PyErr_SetString(PyExc_ValueError,
2763 "field key is required for DictComp");
2764 return NULL;
2765 }
2766 if (!value) {
2767 PyErr_SetString(PyExc_ValueError,
2768 "field value is required for DictComp");
2769 return NULL;
2770 }
2771 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2772 if (!p)
2773 return NULL;
2774 p->kind = DictComp_kind;
2775 p->v.DictComp.key = key;
2776 p->v.DictComp.value = value;
2777 p->v.DictComp.generators = generators;
2778 p->lineno = lineno;
2779 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002780 p->end_lineno = end_lineno;
2781 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002782 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002783}
2784
2785expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002786GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002787 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002788{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002789 expr_ty p;
2790 if (!elt) {
2791 PyErr_SetString(PyExc_ValueError,
2792 "field elt is required for GeneratorExp");
2793 return NULL;
2794 }
2795 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2796 if (!p)
2797 return NULL;
2798 p->kind = GeneratorExp_kind;
2799 p->v.GeneratorExp.elt = elt;
2800 p->v.GeneratorExp.generators = generators;
2801 p->lineno = lineno;
2802 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002803 p->end_lineno = end_lineno;
2804 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002805 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002806}
2807
2808expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002809Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2810 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002811{
2812 expr_ty p;
2813 if (!value) {
2814 PyErr_SetString(PyExc_ValueError,
2815 "field value is required for Await");
2816 return NULL;
2817 }
2818 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2819 if (!p)
2820 return NULL;
2821 p->kind = Await_kind;
2822 p->v.Await.value = value;
2823 p->lineno = lineno;
2824 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002825 p->end_lineno = end_lineno;
2826 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002827 return p;
2828}
2829
2830expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002831Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2832 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002833{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002834 expr_ty p;
2835 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2836 if (!p)
2837 return NULL;
2838 p->kind = Yield_kind;
2839 p->v.Yield.value = value;
2840 p->lineno = lineno;
2841 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002842 p->end_lineno = end_lineno;
2843 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002844 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002845}
2846
2847expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002848YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2849 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002850{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002851 expr_ty p;
2852 if (!value) {
2853 PyErr_SetString(PyExc_ValueError,
2854 "field value is required for YieldFrom");
2855 return NULL;
2856 }
2857 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2858 if (!p)
2859 return NULL;
2860 p->kind = YieldFrom_kind;
2861 p->v.YieldFrom.value = value;
2862 p->lineno = lineno;
2863 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002864 p->end_lineno = end_lineno;
2865 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002866 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002867}
2868
2869expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002870Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002871 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002872{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002873 expr_ty p;
2874 if (!left) {
2875 PyErr_SetString(PyExc_ValueError,
2876 "field left is required for Compare");
2877 return NULL;
2878 }
2879 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2880 if (!p)
2881 return NULL;
2882 p->kind = Compare_kind;
2883 p->v.Compare.left = left;
2884 p->v.Compare.ops = ops;
2885 p->v.Compare.comparators = comparators;
2886 p->lineno = lineno;
2887 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002888 p->end_lineno = end_lineno;
2889 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002890 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002891}
2892
2893expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002894Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002895 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002896{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002897 expr_ty p;
2898 if (!func) {
2899 PyErr_SetString(PyExc_ValueError,
2900 "field func is required for Call");
2901 return NULL;
2902 }
2903 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2904 if (!p)
2905 return NULL;
2906 p->kind = Call_kind;
2907 p->v.Call.func = func;
2908 p->v.Call.args = args;
2909 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002910 p->lineno = lineno;
2911 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002912 p->end_lineno = end_lineno;
2913 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002914 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002915}
2916
2917expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002918FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2919 int col_offset, int end_lineno, int end_col_offset, PyArena
2920 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002921{
2922 expr_ty p;
2923 if (!value) {
2924 PyErr_SetString(PyExc_ValueError,
2925 "field value is required for FormattedValue");
2926 return NULL;
2927 }
2928 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2929 if (!p)
2930 return NULL;
2931 p->kind = FormattedValue_kind;
2932 p->v.FormattedValue.value = value;
2933 p->v.FormattedValue.conversion = conversion;
2934 p->v.FormattedValue.format_spec = format_spec;
2935 p->lineno = lineno;
2936 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002937 p->end_lineno = end_lineno;
2938 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002939 return p;
2940}
2941
2942expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002943JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2944 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002945{
2946 expr_ty p;
2947 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2948 if (!p)
2949 return NULL;
2950 p->kind = JoinedStr_kind;
2951 p->v.JoinedStr.values = values;
2952 p->lineno = lineno;
2953 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002954 p->end_lineno = end_lineno;
2955 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002956 return p;
2957}
2958
2959expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002960Constant(constant value, string kind, int lineno, int col_offset, int
2961 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002962{
2963 expr_ty p;
2964 if (!value) {
2965 PyErr_SetString(PyExc_ValueError,
2966 "field value is required for Constant");
2967 return NULL;
2968 }
2969 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2970 if (!p)
2971 return NULL;
2972 p->kind = Constant_kind;
2973 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002974 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002975 p->lineno = lineno;
2976 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002977 p->end_lineno = end_lineno;
2978 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002979 return p;
2980}
2981
2982expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002983Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002984 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002985{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002986 expr_ty p;
2987 if (!value) {
2988 PyErr_SetString(PyExc_ValueError,
2989 "field value is required for Attribute");
2990 return NULL;
2991 }
2992 if (!attr) {
2993 PyErr_SetString(PyExc_ValueError,
2994 "field attr is required for Attribute");
2995 return NULL;
2996 }
2997 if (!ctx) {
2998 PyErr_SetString(PyExc_ValueError,
2999 "field ctx is required for Attribute");
3000 return NULL;
3001 }
3002 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3003 if (!p)
3004 return NULL;
3005 p->kind = Attribute_kind;
3006 p->v.Attribute.value = value;
3007 p->v.Attribute.attr = attr;
3008 p->v.Attribute.ctx = ctx;
3009 p->lineno = lineno;
3010 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003011 p->end_lineno = end_lineno;
3012 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003013 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003014}
3015
3016expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003017Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003018 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003019{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003020 expr_ty p;
3021 if (!value) {
3022 PyErr_SetString(PyExc_ValueError,
3023 "field value is required for Subscript");
3024 return NULL;
3025 }
3026 if (!slice) {
3027 PyErr_SetString(PyExc_ValueError,
3028 "field slice is required for Subscript");
3029 return NULL;
3030 }
3031 if (!ctx) {
3032 PyErr_SetString(PyExc_ValueError,
3033 "field ctx is required for Subscript");
3034 return NULL;
3035 }
3036 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3037 if (!p)
3038 return NULL;
3039 p->kind = Subscript_kind;
3040 p->v.Subscript.value = value;
3041 p->v.Subscript.slice = slice;
3042 p->v.Subscript.ctx = ctx;
3043 p->lineno = lineno;
3044 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003045 p->end_lineno = end_lineno;
3046 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003047 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003048}
3049
3050expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003051Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3052 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003053{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003054 expr_ty p;
3055 if (!value) {
3056 PyErr_SetString(PyExc_ValueError,
3057 "field value is required for Starred");
3058 return NULL;
3059 }
3060 if (!ctx) {
3061 PyErr_SetString(PyExc_ValueError,
3062 "field ctx is required for Starred");
3063 return NULL;
3064 }
3065 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3066 if (!p)
3067 return NULL;
3068 p->kind = Starred_kind;
3069 p->v.Starred.value = value;
3070 p->v.Starred.ctx = ctx;
3071 p->lineno = lineno;
3072 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003073 p->end_lineno = end_lineno;
3074 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003075 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003076}
3077
3078expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003079Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3080 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003081{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003082 expr_ty p;
3083 if (!id) {
3084 PyErr_SetString(PyExc_ValueError,
3085 "field id is required for Name");
3086 return NULL;
3087 }
3088 if (!ctx) {
3089 PyErr_SetString(PyExc_ValueError,
3090 "field ctx is required for Name");
3091 return NULL;
3092 }
3093 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3094 if (!p)
3095 return NULL;
3096 p->kind = Name_kind;
3097 p->v.Name.id = id;
3098 p->v.Name.ctx = ctx;
3099 p->lineno = lineno;
3100 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003101 p->end_lineno = end_lineno;
3102 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003103 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003104}
3105
3106expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003107List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3108 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003109{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003110 expr_ty p;
3111 if (!ctx) {
3112 PyErr_SetString(PyExc_ValueError,
3113 "field ctx is required for List");
3114 return NULL;
3115 }
3116 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3117 if (!p)
3118 return NULL;
3119 p->kind = List_kind;
3120 p->v.List.elts = elts;
3121 p->v.List.ctx = ctx;
3122 p->lineno = lineno;
3123 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003124 p->end_lineno = end_lineno;
3125 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003126 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003127}
3128
3129expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003130Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3131 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003132{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003133 expr_ty p;
3134 if (!ctx) {
3135 PyErr_SetString(PyExc_ValueError,
3136 "field ctx is required for Tuple");
3137 return NULL;
3138 }
3139 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3140 if (!p)
3141 return NULL;
3142 p->kind = Tuple_kind;
3143 p->v.Tuple.elts = elts;
3144 p->v.Tuple.ctx = ctx;
3145 p->lineno = lineno;
3146 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003147 p->end_lineno = end_lineno;
3148 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003149 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003150}
3151
3152slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003153Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003154{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003155 slice_ty p;
3156 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3157 if (!p)
3158 return NULL;
3159 p->kind = Slice_kind;
3160 p->v.Slice.lower = lower;
3161 p->v.Slice.upper = upper;
3162 p->v.Slice.step = step;
3163 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003164}
3165
3166slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003167ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003168{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003169 slice_ty p;
3170 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3171 if (!p)
3172 return NULL;
3173 p->kind = ExtSlice_kind;
3174 p->v.ExtSlice.dims = dims;
3175 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003176}
3177
3178slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003179Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003180{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003181 slice_ty p;
3182 if (!value) {
3183 PyErr_SetString(PyExc_ValueError,
3184 "field value is required for Index");
3185 return NULL;
3186 }
3187 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3188 if (!p)
3189 return NULL;
3190 p->kind = Index_kind;
3191 p->v.Index.value = value;
3192 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003193}
3194
3195comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003196comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3197 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003198{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003199 comprehension_ty p;
3200 if (!target) {
3201 PyErr_SetString(PyExc_ValueError,
3202 "field target is required for comprehension");
3203 return NULL;
3204 }
3205 if (!iter) {
3206 PyErr_SetString(PyExc_ValueError,
3207 "field iter is required for comprehension");
3208 return NULL;
3209 }
3210 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3211 if (!p)
3212 return NULL;
3213 p->target = target;
3214 p->iter = iter;
3215 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003216 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003217 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003218}
3219
3220excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003221ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003222 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003223{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003224 excepthandler_ty p;
3225 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3226 if (!p)
3227 return NULL;
3228 p->kind = ExceptHandler_kind;
3229 p->v.ExceptHandler.type = type;
3230 p->v.ExceptHandler.name = name;
3231 p->v.ExceptHandler.body = body;
3232 p->lineno = lineno;
3233 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003234 p->end_lineno = end_lineno;
3235 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003236 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003237}
3238
3239arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003240arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003241 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3242 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003243{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003244 arguments_ty p;
3245 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3246 if (!p)
3247 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003248 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003249 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003250 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003251 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003252 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003253 p->kwarg = kwarg;
3254 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003255 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003256}
3257
Neal Norwitzc1505362006-12-28 06:47:50 +00003258arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003259arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3260 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003261{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003262 arg_ty p;
3263 if (!arg) {
3264 PyErr_SetString(PyExc_ValueError,
3265 "field arg is required for arg");
3266 return NULL;
3267 }
3268 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3269 if (!p)
3270 return NULL;
3271 p->arg = arg;
3272 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003273 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003274 p->lineno = lineno;
3275 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003276 p->end_lineno = end_lineno;
3277 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003278 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003279}
3280
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003281keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003282keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003283{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003284 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003285 if (!value) {
3286 PyErr_SetString(PyExc_ValueError,
3287 "field value is required for keyword");
3288 return NULL;
3289 }
3290 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3291 if (!p)
3292 return NULL;
3293 p->arg = arg;
3294 p->value = value;
3295 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003296}
3297
3298alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003299alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003300{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003301 alias_ty p;
3302 if (!name) {
3303 PyErr_SetString(PyExc_ValueError,
3304 "field name is required for alias");
3305 return NULL;
3306 }
3307 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3308 if (!p)
3309 return NULL;
3310 p->name = name;
3311 p->asname = asname;
3312 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003313}
3314
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003315withitem_ty
3316withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3317{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003318 withitem_ty p;
3319 if (!context_expr) {
3320 PyErr_SetString(PyExc_ValueError,
3321 "field context_expr is required for withitem");
3322 return NULL;
3323 }
3324 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3325 if (!p)
3326 return NULL;
3327 p->context_expr = context_expr;
3328 p->optional_vars = optional_vars;
3329 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003330}
3331
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003332type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003333TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003334{
3335 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003336 if (!tag) {
3337 PyErr_SetString(PyExc_ValueError,
3338 "field tag is required for TypeIgnore");
3339 return NULL;
3340 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003341 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3342 if (!p)
3343 return NULL;
3344 p->kind = TypeIgnore_kind;
3345 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003346 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003347 return p;
3348}
3349
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003350
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003351PyObject*
3352ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003353{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003354 mod_ty o = (mod_ty)_o;
3355 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003356 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003357 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003358 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003359 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003360
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003361 switch (o->kind) {
3362 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003363 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3364 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003365 if (!result) goto failed;
3366 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3367 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003368 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003369 goto failed;
3370 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003371 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3372 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003373 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3374 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003375 goto failed;
3376 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003377 break;
3378 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003379 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3380 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003381 if (!result) goto failed;
3382 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3383 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003384 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003385 goto failed;
3386 Py_DECREF(value);
3387 break;
3388 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003389 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3390 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003391 if (!result) goto failed;
3392 value = ast2obj_expr(o->v.Expression.body);
3393 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003394 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003395 goto failed;
3396 Py_DECREF(value);
3397 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003398 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003399 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3400 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003401 if (!result) goto failed;
3402 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3403 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003404 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3405 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003406 goto failed;
3407 Py_DECREF(value);
3408 value = ast2obj_expr(o->v.FunctionType.returns);
3409 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003410 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3411 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003412 goto failed;
3413 Py_DECREF(value);
3414 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003415 case Suite_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003416 tp = (PyTypeObject *)astmodulestate_global->Suite_type;
3417 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003418 if (!result) goto failed;
3419 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
3420 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003421 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003422 goto failed;
3423 Py_DECREF(value);
3424 break;
3425 }
3426 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003427failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003428 Py_XDECREF(value);
3429 Py_XDECREF(result);
3430 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003431}
3432
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003433PyObject*
3434ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003435{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003436 stmt_ty o = (stmt_ty)_o;
3437 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003438 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003439 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003440 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003441 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003442
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003443 switch (o->kind) {
3444 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003445 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3446 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003447 if (!result) goto failed;
3448 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003449 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003450 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003451 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003452 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003453 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003454 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003455 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003456 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003457 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003458 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3459 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003460 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003461 goto failed;
3462 Py_DECREF(value);
3463 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3464 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003465 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3466 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003467 goto failed;
3468 Py_DECREF(value);
3469 value = ast2obj_expr(o->v.FunctionDef.returns);
3470 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003471 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3472 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003473 goto failed;
3474 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003475 value = ast2obj_string(o->v.FunctionDef.type_comment);
3476 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003477 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3478 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003479 goto failed;
3480 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003481 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003482 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003483 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3484 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003485 if (!result) goto failed;
3486 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3487 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003488 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003489 goto failed;
3490 Py_DECREF(value);
3491 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3492 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003493 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003494 goto failed;
3495 Py_DECREF(value);
3496 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3497 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003498 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003499 goto failed;
3500 Py_DECREF(value);
3501 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3502 ast2obj_expr);
3503 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003504 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3505 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003506 goto failed;
3507 Py_DECREF(value);
3508 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3509 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003510 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3511 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003512 goto failed;
3513 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003514 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3515 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003516 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3517 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003518 goto failed;
3519 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003520 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003521 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003522 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3523 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003524 if (!result) goto failed;
3525 value = ast2obj_identifier(o->v.ClassDef.name);
3526 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003527 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003528 goto failed;
3529 Py_DECREF(value);
3530 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3531 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003532 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003533 goto failed;
3534 Py_DECREF(value);
3535 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3536 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003537 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3538 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003539 goto failed;
3540 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003541 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3542 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003543 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003544 goto failed;
3545 Py_DECREF(value);
3546 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3547 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003548 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3549 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003550 goto failed;
3551 Py_DECREF(value);
3552 break;
3553 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003554 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3555 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003556 if (!result) goto failed;
3557 value = ast2obj_expr(o->v.Return.value);
3558 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003559 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003560 goto failed;
3561 Py_DECREF(value);
3562 break;
3563 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003564 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3565 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003566 if (!result) goto failed;
3567 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3568 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003569 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3570 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003571 goto failed;
3572 Py_DECREF(value);
3573 break;
3574 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003575 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3576 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003577 if (!result) goto failed;
3578 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3579 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003580 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3581 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003582 goto failed;
3583 Py_DECREF(value);
3584 value = ast2obj_expr(o->v.Assign.value);
3585 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003586 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003587 goto failed;
3588 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003589 value = ast2obj_string(o->v.Assign.type_comment);
3590 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003591 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3592 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003593 goto failed;
3594 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003595 break;
3596 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003597 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3598 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003599 if (!result) goto failed;
3600 value = ast2obj_expr(o->v.AugAssign.target);
3601 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003602 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3603 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003604 goto failed;
3605 Py_DECREF(value);
3606 value = ast2obj_operator(o->v.AugAssign.op);
3607 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003608 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003609 goto failed;
3610 Py_DECREF(value);
3611 value = ast2obj_expr(o->v.AugAssign.value);
3612 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003613 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 goto failed;
3615 Py_DECREF(value);
3616 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003617 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003618 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3619 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003620 if (!result) goto failed;
3621 value = ast2obj_expr(o->v.AnnAssign.target);
3622 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003623 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3624 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003625 goto failed;
3626 Py_DECREF(value);
3627 value = ast2obj_expr(o->v.AnnAssign.annotation);
3628 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003629 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3630 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003631 goto failed;
3632 Py_DECREF(value);
3633 value = ast2obj_expr(o->v.AnnAssign.value);
3634 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003635 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003636 goto failed;
3637 Py_DECREF(value);
3638 value = ast2obj_int(o->v.AnnAssign.simple);
3639 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003640 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3641 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003642 goto failed;
3643 Py_DECREF(value);
3644 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003645 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003646 tp = (PyTypeObject *)astmodulestate_global->For_type;
3647 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003648 if (!result) goto failed;
3649 value = ast2obj_expr(o->v.For.target);
3650 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003651 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3652 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003653 goto failed;
3654 Py_DECREF(value);
3655 value = ast2obj_expr(o->v.For.iter);
3656 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003657 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003658 goto failed;
3659 Py_DECREF(value);
3660 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3661 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003662 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003663 goto failed;
3664 Py_DECREF(value);
3665 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3666 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003667 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3668 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003669 goto failed;
3670 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003671 value = ast2obj_string(o->v.For.type_comment);
3672 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003673 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3674 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003675 goto failed;
3676 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003677 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003678 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003679 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3680 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003681 if (!result) goto failed;
3682 value = ast2obj_expr(o->v.AsyncFor.target);
3683 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003684 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3685 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003686 goto failed;
3687 Py_DECREF(value);
3688 value = ast2obj_expr(o->v.AsyncFor.iter);
3689 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003690 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003691 goto failed;
3692 Py_DECREF(value);
3693 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3694 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003695 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003696 goto failed;
3697 Py_DECREF(value);
3698 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3699 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003700 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3701 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003702 goto failed;
3703 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003704 value = ast2obj_string(o->v.AsyncFor.type_comment);
3705 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003706 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3707 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003708 goto failed;
3709 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003710 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003711 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003712 tp = (PyTypeObject *)astmodulestate_global->While_type;
3713 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003714 if (!result) goto failed;
3715 value = ast2obj_expr(o->v.While.test);
3716 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003717 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003718 goto failed;
3719 Py_DECREF(value);
3720 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3721 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003722 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003723 goto failed;
3724 Py_DECREF(value);
3725 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3726 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003727 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3728 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003729 goto failed;
3730 Py_DECREF(value);
3731 break;
3732 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003733 tp = (PyTypeObject *)astmodulestate_global->If_type;
3734 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003735 if (!result) goto failed;
3736 value = ast2obj_expr(o->v.If.test);
3737 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003738 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003739 goto failed;
3740 Py_DECREF(value);
3741 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3742 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003743 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003744 goto failed;
3745 Py_DECREF(value);
3746 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3747 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003748 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3749 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003750 goto failed;
3751 Py_DECREF(value);
3752 break;
3753 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003754 tp = (PyTypeObject *)astmodulestate_global->With_type;
3755 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003756 if (!result) goto failed;
3757 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003759 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003760 goto failed;
3761 Py_DECREF(value);
3762 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003764 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003765 goto failed;
3766 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003767 value = ast2obj_string(o->v.With.type_comment);
3768 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003769 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3770 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003771 goto failed;
3772 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003773 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003774 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003775 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3776 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003777 if (!result) goto failed;
3778 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3779 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003780 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003781 goto failed;
3782 Py_DECREF(value);
3783 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003785 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003786 goto failed;
3787 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003788 value = ast2obj_string(o->v.AsyncWith.type_comment);
3789 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003790 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3791 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003792 goto failed;
3793 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003794 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003795 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003796 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3797 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003798 if (!result) goto failed;
3799 value = ast2obj_expr(o->v.Raise.exc);
3800 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003801 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003802 goto failed;
3803 Py_DECREF(value);
3804 value = ast2obj_expr(o->v.Raise.cause);
3805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003806 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003807 goto failed;
3808 Py_DECREF(value);
3809 break;
3810 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003811 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3812 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003813 if (!result) goto failed;
3814 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3815 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003816 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003817 goto failed;
3818 Py_DECREF(value);
3819 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3820 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003821 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3822 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003823 goto failed;
3824 Py_DECREF(value);
3825 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3826 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003827 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3828 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003829 goto failed;
3830 Py_DECREF(value);
3831 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003833 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3834 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003835 goto failed;
3836 Py_DECREF(value);
3837 break;
3838 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003839 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3840 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003841 if (!result) goto failed;
3842 value = ast2obj_expr(o->v.Assert.test);
3843 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003844 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003845 goto failed;
3846 Py_DECREF(value);
3847 value = ast2obj_expr(o->v.Assert.msg);
3848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003849 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003850 goto failed;
3851 Py_DECREF(value);
3852 break;
3853 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003854 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3855 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003856 if (!result) goto failed;
3857 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3858 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003859 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003860 goto failed;
3861 Py_DECREF(value);
3862 break;
3863 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003864 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3865 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003866 if (!result) goto failed;
3867 value = ast2obj_identifier(o->v.ImportFrom.module);
3868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3870 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003871 goto failed;
3872 Py_DECREF(value);
3873 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3874 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003875 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003876 goto failed;
3877 Py_DECREF(value);
3878 value = ast2obj_int(o->v.ImportFrom.level);
3879 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003880 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003881 goto failed;
3882 Py_DECREF(value);
3883 break;
3884 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003885 tp = (PyTypeObject *)astmodulestate_global->Global_type;
3886 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003887 if (!result) goto failed;
3888 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3889 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003890 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003891 goto failed;
3892 Py_DECREF(value);
3893 break;
3894 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003895 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3896 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003897 if (!result) goto failed;
3898 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3899 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003900 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003901 goto failed;
3902 Py_DECREF(value);
3903 break;
3904 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003905 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3906 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003907 if (!result) goto failed;
3908 value = ast2obj_expr(o->v.Expr.value);
3909 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003910 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003911 goto failed;
3912 Py_DECREF(value);
3913 break;
3914 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003915 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3916 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003917 if (!result) goto failed;
3918 break;
3919 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003920 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3921 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003922 if (!result) goto failed;
3923 break;
3924 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003925 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3926 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003927 if (!result) goto failed;
3928 break;
3929 }
3930 value = ast2obj_int(o->lineno);
3931 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003932 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003933 goto failed;
3934 Py_DECREF(value);
3935 value = ast2obj_int(o->col_offset);
3936 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003937 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003938 goto failed;
3939 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003940 value = ast2obj_int(o->end_lineno);
3941 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003942 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003943 goto failed;
3944 Py_DECREF(value);
3945 value = ast2obj_int(o->end_col_offset);
3946 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003947 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
3948 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003949 goto failed;
3950 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003951 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003952failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003953 Py_XDECREF(value);
3954 Py_XDECREF(result);
3955 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003956}
3957
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003958PyObject*
3959ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003960{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003961 expr_ty o = (expr_ty)_o;
3962 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003963 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003964 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003965 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003966 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003967
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 switch (o->kind) {
3969 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003970 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
3971 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003972 if (!result) goto failed;
3973 value = ast2obj_boolop(o->v.BoolOp.op);
3974 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003975 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003976 goto failed;
3977 Py_DECREF(value);
3978 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3979 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003980 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
3981 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003982 goto failed;
3983 Py_DECREF(value);
3984 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003985 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003986 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
3987 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003988 if (!result) goto failed;
3989 value = ast2obj_expr(o->v.NamedExpr.target);
3990 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003991 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3992 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003993 goto failed;
3994 Py_DECREF(value);
3995 value = ast2obj_expr(o->v.NamedExpr.value);
3996 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003997 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003998 goto failed;
3999 Py_DECREF(value);
4000 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004001 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004002 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4003 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004004 if (!result) goto failed;
4005 value = ast2obj_expr(o->v.BinOp.left);
4006 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004007 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004008 goto failed;
4009 Py_DECREF(value);
4010 value = ast2obj_operator(o->v.BinOp.op);
4011 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004012 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004013 goto failed;
4014 Py_DECREF(value);
4015 value = ast2obj_expr(o->v.BinOp.right);
4016 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004017 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004018 goto failed;
4019 Py_DECREF(value);
4020 break;
4021 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004022 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4023 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004024 if (!result) goto failed;
4025 value = ast2obj_unaryop(o->v.UnaryOp.op);
4026 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004028 goto failed;
4029 Py_DECREF(value);
4030 value = ast2obj_expr(o->v.UnaryOp.operand);
4031 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004032 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4033 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004034 goto failed;
4035 Py_DECREF(value);
4036 break;
4037 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004038 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4039 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 if (!result) goto failed;
4041 value = ast2obj_arguments(o->v.Lambda.args);
4042 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004043 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 goto failed;
4045 Py_DECREF(value);
4046 value = ast2obj_expr(o->v.Lambda.body);
4047 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004048 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004049 goto failed;
4050 Py_DECREF(value);
4051 break;
4052 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004053 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4054 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004055 if (!result) goto failed;
4056 value = ast2obj_expr(o->v.IfExp.test);
4057 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004058 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004059 goto failed;
4060 Py_DECREF(value);
4061 value = ast2obj_expr(o->v.IfExp.body);
4062 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004063 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004064 goto failed;
4065 Py_DECREF(value);
4066 value = ast2obj_expr(o->v.IfExp.orelse);
4067 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004068 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4069 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 goto failed;
4071 Py_DECREF(value);
4072 break;
4073 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004074 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4075 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004076 if (!result) goto failed;
4077 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4078 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004079 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004080 goto failed;
4081 Py_DECREF(value);
4082 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4083 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004084 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4085 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004086 goto failed;
4087 Py_DECREF(value);
4088 break;
4089 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004090 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4091 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004092 if (!result) goto failed;
4093 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4094 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004095 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004096 goto failed;
4097 Py_DECREF(value);
4098 break;
4099 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004100 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4101 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 if (!result) goto failed;
4103 value = ast2obj_expr(o->v.ListComp.elt);
4104 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004105 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004106 goto failed;
4107 Py_DECREF(value);
4108 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4109 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004110 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4111 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004112 goto failed;
4113 Py_DECREF(value);
4114 break;
4115 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004116 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4117 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004118 if (!result) goto failed;
4119 value = ast2obj_expr(o->v.SetComp.elt);
4120 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004121 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004122 goto failed;
4123 Py_DECREF(value);
4124 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4125 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004126 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4127 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004128 goto failed;
4129 Py_DECREF(value);
4130 break;
4131 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004132 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4133 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004134 if (!result) goto failed;
4135 value = ast2obj_expr(o->v.DictComp.key);
4136 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004137 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004138 goto failed;
4139 Py_DECREF(value);
4140 value = ast2obj_expr(o->v.DictComp.value);
4141 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004142 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004143 goto failed;
4144 Py_DECREF(value);
4145 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4146 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004147 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4148 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004149 goto failed;
4150 Py_DECREF(value);
4151 break;
4152 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004153 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4154 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004155 if (!result) goto failed;
4156 value = ast2obj_expr(o->v.GeneratorExp.elt);
4157 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004158 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004159 goto failed;
4160 Py_DECREF(value);
4161 value = ast2obj_list(o->v.GeneratorExp.generators,
4162 ast2obj_comprehension);
4163 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004164 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4165 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004166 goto failed;
4167 Py_DECREF(value);
4168 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004169 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004170 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4171 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004172 if (!result) goto failed;
4173 value = ast2obj_expr(o->v.Await.value);
4174 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004175 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004176 goto failed;
4177 Py_DECREF(value);
4178 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004179 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004180 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4181 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004182 if (!result) goto failed;
4183 value = ast2obj_expr(o->v.Yield.value);
4184 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004185 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004186 goto failed;
4187 Py_DECREF(value);
4188 break;
4189 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004190 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4191 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004192 if (!result) goto failed;
4193 value = ast2obj_expr(o->v.YieldFrom.value);
4194 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004195 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004196 goto failed;
4197 Py_DECREF(value);
4198 break;
4199 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004200 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4201 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004202 if (!result) goto failed;
4203 value = ast2obj_expr(o->v.Compare.left);
4204 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004205 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004206 goto failed;
4207 Py_DECREF(value);
4208 {
4209 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4210 value = PyList_New(n);
4211 if (!value) goto failed;
4212 for(i = 0; i < n; i++)
4213 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004214 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004215 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004216 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004217 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004218 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004219 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004220 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004221 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4222 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004223 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004224 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004225 break;
4226 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004227 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4228 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004229 if (!result) goto failed;
4230 value = ast2obj_expr(o->v.Call.func);
4231 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004232 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004233 goto failed;
4234 Py_DECREF(value);
4235 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4236 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004237 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004238 goto failed;
4239 Py_DECREF(value);
4240 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4241 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004242 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4243 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004244 goto failed;
4245 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004246 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004247 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004248 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4249 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004250 if (!result) goto failed;
4251 value = ast2obj_expr(o->v.FormattedValue.value);
4252 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004253 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004254 goto failed;
4255 Py_DECREF(value);
4256 value = ast2obj_int(o->v.FormattedValue.conversion);
4257 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004258 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4259 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004260 goto failed;
4261 Py_DECREF(value);
4262 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4263 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004264 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4265 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004266 goto failed;
4267 Py_DECREF(value);
4268 break;
4269 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004270 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4271 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004272 if (!result) goto failed;
4273 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4274 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004275 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4276 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004277 goto failed;
4278 Py_DECREF(value);
4279 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004280 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004281 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4282 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004283 if (!result) goto failed;
4284 value = ast2obj_constant(o->v.Constant.value);
4285 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004286 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004287 goto failed;
4288 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004289 value = ast2obj_string(o->v.Constant.kind);
4290 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004291 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004292 goto failed;
4293 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004294 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004295 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004296 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4297 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004298 if (!result) goto failed;
4299 value = ast2obj_expr(o->v.Attribute.value);
4300 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004301 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004302 goto failed;
4303 Py_DECREF(value);
4304 value = ast2obj_identifier(o->v.Attribute.attr);
4305 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004306 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004307 goto failed;
4308 Py_DECREF(value);
4309 value = ast2obj_expr_context(o->v.Attribute.ctx);
4310 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004311 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 goto failed;
4313 Py_DECREF(value);
4314 break;
4315 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004316 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4317 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004318 if (!result) goto failed;
4319 value = ast2obj_expr(o->v.Subscript.value);
4320 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004321 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004322 goto failed;
4323 Py_DECREF(value);
4324 value = ast2obj_slice(o->v.Subscript.slice);
4325 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004326 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004327 goto failed;
4328 Py_DECREF(value);
4329 value = ast2obj_expr_context(o->v.Subscript.ctx);
4330 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004331 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004332 goto failed;
4333 Py_DECREF(value);
4334 break;
4335 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004336 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4337 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004338 if (!result) goto failed;
4339 value = ast2obj_expr(o->v.Starred.value);
4340 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004341 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004342 goto failed;
4343 Py_DECREF(value);
4344 value = ast2obj_expr_context(o->v.Starred.ctx);
4345 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004346 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004347 goto failed;
4348 Py_DECREF(value);
4349 break;
4350 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004351 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4352 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004353 if (!result) goto failed;
4354 value = ast2obj_identifier(o->v.Name.id);
4355 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004356 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004357 goto failed;
4358 Py_DECREF(value);
4359 value = ast2obj_expr_context(o->v.Name.ctx);
4360 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004361 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004362 goto failed;
4363 Py_DECREF(value);
4364 break;
4365 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004366 tp = (PyTypeObject *)astmodulestate_global->List_type;
4367 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004368 if (!result) goto failed;
4369 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4370 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004371 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004372 goto failed;
4373 Py_DECREF(value);
4374 value = ast2obj_expr_context(o->v.List.ctx);
4375 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004376 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004377 goto failed;
4378 Py_DECREF(value);
4379 break;
4380 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004381 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4382 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004383 if (!result) goto failed;
4384 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4385 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004386 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004387 goto failed;
4388 Py_DECREF(value);
4389 value = ast2obj_expr_context(o->v.Tuple.ctx);
4390 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004391 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004392 goto failed;
4393 Py_DECREF(value);
4394 break;
4395 }
4396 value = ast2obj_int(o->lineno);
4397 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004398 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004399 goto failed;
4400 Py_DECREF(value);
4401 value = ast2obj_int(o->col_offset);
4402 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004403 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004404 goto failed;
4405 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004406 value = ast2obj_int(o->end_lineno);
4407 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004408 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004409 goto failed;
4410 Py_DECREF(value);
4411 value = ast2obj_int(o->end_col_offset);
4412 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004413 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4414 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004415 goto failed;
4416 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004417 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004418failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004419 Py_XDECREF(value);
4420 Py_XDECREF(result);
4421 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004422}
4423
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004424PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004425{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004426 switch(o) {
4427 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004428 Py_INCREF(astmodulestate_global->Load_singleton);
4429 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004430 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004431 Py_INCREF(astmodulestate_global->Store_singleton);
4432 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004433 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004434 Py_INCREF(astmodulestate_global->Del_singleton);
4435 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004436 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004437 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4438 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004439 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004440 Py_INCREF(astmodulestate_global->AugStore_singleton);
4441 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004442 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004443 Py_INCREF(astmodulestate_global->Param_singleton);
4444 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004445 default:
4446 /* should never happen, but just in case ... */
4447 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4448 return NULL;
4449 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004450}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004451PyObject*
4452ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004453{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004454 slice_ty o = (slice_ty)_o;
4455 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004456 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004457 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004458 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004459 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004460
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004461 switch (o->kind) {
4462 case Slice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004463 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4464 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004465 if (!result) goto failed;
4466 value = ast2obj_expr(o->v.Slice.lower);
4467 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004468 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004469 goto failed;
4470 Py_DECREF(value);
4471 value = ast2obj_expr(o->v.Slice.upper);
4472 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004473 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004474 goto failed;
4475 Py_DECREF(value);
4476 value = ast2obj_expr(o->v.Slice.step);
4477 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004478 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004479 goto failed;
4480 Py_DECREF(value);
4481 break;
4482 case ExtSlice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004483 tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type;
4484 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004485 if (!result) goto failed;
4486 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
4487 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004488 if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004489 goto failed;
4490 Py_DECREF(value);
4491 break;
4492 case Index_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004493 tp = (PyTypeObject *)astmodulestate_global->Index_type;
4494 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004495 if (!result) goto failed;
4496 value = ast2obj_expr(o->v.Index.value);
4497 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004498 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004499 goto failed;
4500 Py_DECREF(value);
4501 break;
4502 }
4503 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004504failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004505 Py_XDECREF(value);
4506 Py_XDECREF(result);
4507 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004508}
4509
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004510PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004511{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004512 switch(o) {
4513 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004514 Py_INCREF(astmodulestate_global->And_singleton);
4515 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004516 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004517 Py_INCREF(astmodulestate_global->Or_singleton);
4518 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004519 default:
4520 /* should never happen, but just in case ... */
4521 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4522 return NULL;
4523 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004524}
4525PyObject* ast2obj_operator(operator_ty o)
4526{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004527 switch(o) {
4528 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004529 Py_INCREF(astmodulestate_global->Add_singleton);
4530 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004531 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004532 Py_INCREF(astmodulestate_global->Sub_singleton);
4533 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004534 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004535 Py_INCREF(astmodulestate_global->Mult_singleton);
4536 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004537 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004538 Py_INCREF(astmodulestate_global->MatMult_singleton);
4539 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004540 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004541 Py_INCREF(astmodulestate_global->Div_singleton);
4542 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004543 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004544 Py_INCREF(astmodulestate_global->Mod_singleton);
4545 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004546 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004547 Py_INCREF(astmodulestate_global->Pow_singleton);
4548 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004549 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004550 Py_INCREF(astmodulestate_global->LShift_singleton);
4551 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004552 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004553 Py_INCREF(astmodulestate_global->RShift_singleton);
4554 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004555 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004556 Py_INCREF(astmodulestate_global->BitOr_singleton);
4557 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004558 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004559 Py_INCREF(astmodulestate_global->BitXor_singleton);
4560 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004561 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004562 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4563 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004564 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004565 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4566 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004567 default:
4568 /* should never happen, but just in case ... */
4569 PyErr_Format(PyExc_SystemError, "unknown operator found");
4570 return NULL;
4571 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004572}
4573PyObject* ast2obj_unaryop(unaryop_ty o)
4574{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004575 switch(o) {
4576 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004577 Py_INCREF(astmodulestate_global->Invert_singleton);
4578 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004579 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004580 Py_INCREF(astmodulestate_global->Not_singleton);
4581 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004582 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004583 Py_INCREF(astmodulestate_global->UAdd_singleton);
4584 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004585 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004586 Py_INCREF(astmodulestate_global->USub_singleton);
4587 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004588 default:
4589 /* should never happen, but just in case ... */
4590 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4591 return NULL;
4592 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004593}
4594PyObject* ast2obj_cmpop(cmpop_ty o)
4595{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004596 switch(o) {
4597 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004598 Py_INCREF(astmodulestate_global->Eq_singleton);
4599 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004600 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004601 Py_INCREF(astmodulestate_global->NotEq_singleton);
4602 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004603 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004604 Py_INCREF(astmodulestate_global->Lt_singleton);
4605 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004606 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004607 Py_INCREF(astmodulestate_global->LtE_singleton);
4608 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004609 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004610 Py_INCREF(astmodulestate_global->Gt_singleton);
4611 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004612 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004613 Py_INCREF(astmodulestate_global->GtE_singleton);
4614 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004615 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004616 Py_INCREF(astmodulestate_global->Is_singleton);
4617 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004618 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004619 Py_INCREF(astmodulestate_global->IsNot_singleton);
4620 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004621 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004622 Py_INCREF(astmodulestate_global->In_singleton);
4623 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004624 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004625 Py_INCREF(astmodulestate_global->NotIn_singleton);
4626 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004627 default:
4628 /* should never happen, but just in case ... */
4629 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4630 return NULL;
4631 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004632}
4633PyObject*
4634ast2obj_comprehension(void* _o)
4635{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004636 comprehension_ty o = (comprehension_ty)_o;
4637 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004638 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004639 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004640 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004641 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004642
Dino Viehlandac46eb42019-09-11 10:16:34 -07004643 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4644 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004645 if (!result) return NULL;
4646 value = ast2obj_expr(o->target);
4647 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004648 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004649 goto failed;
4650 Py_DECREF(value);
4651 value = ast2obj_expr(o->iter);
4652 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004653 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004654 goto failed;
4655 Py_DECREF(value);
4656 value = ast2obj_list(o->ifs, ast2obj_expr);
4657 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004658 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004659 goto failed;
4660 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004661 value = ast2obj_int(o->is_async);
4662 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004663 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004664 goto failed;
4665 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004666 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004667failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004668 Py_XDECREF(value);
4669 Py_XDECREF(result);
4670 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004671}
4672
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004673PyObject*
4674ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004675{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004676 excepthandler_ty o = (excepthandler_ty)_o;
4677 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004678 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004679 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004680 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004681 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004682
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 switch (o->kind) {
4684 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004685 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4686 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 if (!result) goto failed;
4688 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004689 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004690 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004691 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004692 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004693 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004694 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004695 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004696 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004697 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004698 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4699 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004700 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004701 goto failed;
4702 Py_DECREF(value);
4703 break;
4704 }
4705 value = ast2obj_int(o->lineno);
4706 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004707 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004708 goto failed;
4709 Py_DECREF(value);
4710 value = ast2obj_int(o->col_offset);
4711 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004712 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004713 goto failed;
4714 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004715 value = ast2obj_int(o->end_lineno);
4716 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004717 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004718 goto failed;
4719 Py_DECREF(value);
4720 value = ast2obj_int(o->end_col_offset);
4721 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004722 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4723 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004724 goto failed;
4725 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004726 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004727failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004728 Py_XDECREF(value);
4729 Py_XDECREF(result);
4730 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004731}
4732
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004733PyObject*
4734ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004735{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004736 arguments_ty o = (arguments_ty)_o;
4737 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004738 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004739 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004740 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004741 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004742
Dino Viehlandac46eb42019-09-11 10:16:34 -07004743 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4744 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004745 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004746 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4747 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004748 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4749 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004750 goto failed;
4751 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004752 value = ast2obj_list(o->args, ast2obj_arg);
4753 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004754 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004755 goto failed;
4756 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004757 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004759 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 goto failed;
4761 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004762 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004764 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4765 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004766 goto failed;
4767 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004768 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004769 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004770 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4771 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004772 goto failed;
4773 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004774 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004775 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004776 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 goto failed;
4778 Py_DECREF(value);
4779 value = ast2obj_list(o->defaults, ast2obj_expr);
4780 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004781 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 goto failed;
4783 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004784 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004785failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004786 Py_XDECREF(value);
4787 Py_XDECREF(result);
4788 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004789}
4790
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004791PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004792ast2obj_arg(void* _o)
4793{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004794 arg_ty o = (arg_ty)_o;
4795 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004796 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004798 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004799 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004800
Dino Viehlandac46eb42019-09-11 10:16:34 -07004801 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4802 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004803 if (!result) return NULL;
4804 value = ast2obj_identifier(o->arg);
4805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004806 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004807 goto failed;
4808 Py_DECREF(value);
4809 value = ast2obj_expr(o->annotation);
4810 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004811 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4812 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004813 goto failed;
4814 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004815 value = ast2obj_string(o->type_comment);
4816 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004817 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4818 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004819 goto failed;
4820 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004821 value = ast2obj_int(o->lineno);
4822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004823 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004824 goto failed;
4825 Py_DECREF(value);
4826 value = ast2obj_int(o->col_offset);
4827 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004828 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004829 goto failed;
4830 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004831 value = ast2obj_int(o->end_lineno);
4832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004833 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004834 goto failed;
4835 Py_DECREF(value);
4836 value = ast2obj_int(o->end_col_offset);
4837 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004838 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4839 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004840 goto failed;
4841 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004842 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004843failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004844 Py_XDECREF(value);
4845 Py_XDECREF(result);
4846 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004847}
4848
4849PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004850ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004851{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004852 keyword_ty o = (keyword_ty)_o;
4853 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004854 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004855 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004856 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004857 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004858
Dino Viehlandac46eb42019-09-11 10:16:34 -07004859 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4860 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 if (!result) return NULL;
4862 value = ast2obj_identifier(o->arg);
4863 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004864 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004865 goto failed;
4866 Py_DECREF(value);
4867 value = ast2obj_expr(o->value);
4868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004869 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004870 goto failed;
4871 Py_DECREF(value);
4872 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004873failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004874 Py_XDECREF(value);
4875 Py_XDECREF(result);
4876 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004877}
4878
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004879PyObject*
4880ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004881{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004882 alias_ty o = (alias_ty)_o;
4883 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004884 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004885 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004886 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004887 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004888
Dino Viehlandac46eb42019-09-11 10:16:34 -07004889 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4890 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 if (!result) return NULL;
4892 value = ast2obj_identifier(o->name);
4893 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004894 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004895 goto failed;
4896 Py_DECREF(value);
4897 value = ast2obj_identifier(o->asname);
4898 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004899 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 goto failed;
4901 Py_DECREF(value);
4902 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004903failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004904 Py_XDECREF(value);
4905 Py_XDECREF(result);
4906 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004907}
4908
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004909PyObject*
4910ast2obj_withitem(void* _o)
4911{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004912 withitem_ty o = (withitem_ty)_o;
4913 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004914 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004915 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004916 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004917 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004918
Dino Viehlandac46eb42019-09-11 10:16:34 -07004919 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4920 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004921 if (!result) return NULL;
4922 value = ast2obj_expr(o->context_expr);
4923 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004924 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4925 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004926 goto failed;
4927 Py_DECREF(value);
4928 value = ast2obj_expr(o->optional_vars);
4929 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004930 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4931 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004932 goto failed;
4933 Py_DECREF(value);
4934 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004935failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004936 Py_XDECREF(value);
4937 Py_XDECREF(result);
4938 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004939}
4940
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004941PyObject*
4942ast2obj_type_ignore(void* _o)
4943{
4944 type_ignore_ty o = (type_ignore_ty)_o;
4945 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004946 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004947 if (!o) {
4948 Py_RETURN_NONE;
4949 }
4950
4951 switch (o->kind) {
4952 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004953 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
4954 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004955 if (!result) goto failed;
4956 value = ast2obj_int(o->v.TypeIgnore.lineno);
4957 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004958 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
4959 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004960 goto failed;
4961 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004962 value = ast2obj_string(o->v.TypeIgnore.tag);
4963 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004964 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004965 goto failed;
4966 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004967 break;
4968 }
4969 return result;
4970failed:
4971 Py_XDECREF(value);
4972 Py_XDECREF(result);
4973 return NULL;
4974}
4975
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004976
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004977int
4978obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4979{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004980 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004981
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004982 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004983 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004984
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004985 if (obj == Py_None) {
4986 *out = NULL;
4987 return 0;
4988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07004989 tp = astmodulestate_global->Module_type;
4990 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004991 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004992 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004993 }
4994 if (isinstance) {
4995 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004996 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004997
Dino Viehlandac46eb42019-09-11 10:16:34 -07004998 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02004999 return 1;
5000 }
5001 if (tmp == NULL) {
5002 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5003 return 1;
5004 }
5005 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005006 int res;
5007 Py_ssize_t len;
5008 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005009 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005010 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 +02005011 goto failed;
5012 }
5013 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005014 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005015 if (body == NULL) goto failed;
5016 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005017 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005018 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5019 Py_INCREF(tmp2);
5020 res = obj2ast_stmt(tmp2, &val, arena);
5021 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005022 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005023 if (len != PyList_GET_SIZE(tmp)) {
5024 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5025 goto failed;
5026 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005027 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005028 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005029 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005031 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5032 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005033 return 1;
5034 }
5035 if (tmp == NULL) {
5036 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5037 return 1;
5038 }
5039 else {
5040 int res;
5041 Py_ssize_t len;
5042 Py_ssize_t i;
5043 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005044 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 -08005045 goto failed;
5046 }
5047 len = PyList_GET_SIZE(tmp);
5048 type_ignores = _Py_asdl_seq_new(len, arena);
5049 if (type_ignores == NULL) goto failed;
5050 for (i = 0; i < len; i++) {
5051 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005052 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5053 Py_INCREF(tmp2);
5054 res = obj2ast_type_ignore(tmp2, &val, arena);
5055 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005056 if (res != 0) goto failed;
5057 if (len != PyList_GET_SIZE(tmp)) {
5058 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5059 goto failed;
5060 }
5061 asdl_seq_SET(type_ignores, i, val);
5062 }
5063 Py_CLEAR(tmp);
5064 }
5065 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005066 if (*out == NULL) goto failed;
5067 return 0;
5068 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005069 tp = astmodulestate_global->Interactive_type;
5070 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005071 if (isinstance == -1) {
5072 return 1;
5073 }
5074 if (isinstance) {
5075 asdl_seq* body;
5076
Dino Viehlandac46eb42019-09-11 10:16:34 -07005077 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005078 return 1;
5079 }
5080 if (tmp == NULL) {
5081 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5082 return 1;
5083 }
5084 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005085 int res;
5086 Py_ssize_t len;
5087 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005088 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005089 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 +02005090 goto failed;
5091 }
5092 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005093 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005094 if (body == NULL) goto failed;
5095 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005096 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005097 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5098 Py_INCREF(tmp2);
5099 res = obj2ast_stmt(tmp2, &val, arena);
5100 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005101 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005102 if (len != PyList_GET_SIZE(tmp)) {
5103 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5104 goto failed;
5105 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005106 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005107 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005108 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005109 }
5110 *out = Interactive(body, arena);
5111 if (*out == NULL) goto failed;
5112 return 0;
5113 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005114 tp = astmodulestate_global->Expression_type;
5115 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005116 if (isinstance == -1) {
5117 return 1;
5118 }
5119 if (isinstance) {
5120 expr_ty body;
5121
Dino Viehlandac46eb42019-09-11 10:16:34 -07005122 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005123 return 1;
5124 }
5125 if (tmp == NULL) {
5126 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5127 return 1;
5128 }
5129 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005130 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005131 res = obj2ast_expr(tmp, &body, arena);
5132 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005133 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005134 }
5135 *out = Expression(body, arena);
5136 if (*out == NULL) goto failed;
5137 return 0;
5138 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005139 tp = astmodulestate_global->FunctionType_type;
5140 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005141 if (isinstance == -1) {
5142 return 1;
5143 }
5144 if (isinstance) {
5145 asdl_seq* argtypes;
5146 expr_ty returns;
5147
Dino Viehlandac46eb42019-09-11 10:16:34 -07005148 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5149 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005150 return 1;
5151 }
5152 if (tmp == NULL) {
5153 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5154 return 1;
5155 }
5156 else {
5157 int res;
5158 Py_ssize_t len;
5159 Py_ssize_t i;
5160 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005161 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 -08005162 goto failed;
5163 }
5164 len = PyList_GET_SIZE(tmp);
5165 argtypes = _Py_asdl_seq_new(len, arena);
5166 if (argtypes == NULL) goto failed;
5167 for (i = 0; i < len; i++) {
5168 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005169 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5170 Py_INCREF(tmp2);
5171 res = obj2ast_expr(tmp2, &val, arena);
5172 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005173 if (res != 0) goto failed;
5174 if (len != PyList_GET_SIZE(tmp)) {
5175 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5176 goto failed;
5177 }
5178 asdl_seq_SET(argtypes, i, val);
5179 }
5180 Py_CLEAR(tmp);
5181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005182 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5183 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005184 return 1;
5185 }
5186 if (tmp == NULL) {
5187 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5188 return 1;
5189 }
5190 else {
5191 int res;
5192 res = obj2ast_expr(tmp, &returns, arena);
5193 if (res != 0) goto failed;
5194 Py_CLEAR(tmp);
5195 }
5196 *out = FunctionType(argtypes, returns, arena);
5197 if (*out == NULL) goto failed;
5198 return 0;
5199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005200 tp = astmodulestate_global->Suite_type;
5201 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005202 if (isinstance == -1) {
5203 return 1;
5204 }
5205 if (isinstance) {
5206 asdl_seq* body;
5207
Dino Viehlandac46eb42019-09-11 10:16:34 -07005208 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005209 return 1;
5210 }
5211 if (tmp == NULL) {
5212 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
5213 return 1;
5214 }
5215 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005216 int res;
5217 Py_ssize_t len;
5218 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005219 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005220 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 +02005221 goto failed;
5222 }
5223 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005224 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005225 if (body == NULL) goto failed;
5226 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005227 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005228 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5229 Py_INCREF(tmp2);
5230 res = obj2ast_stmt(tmp2, &val, arena);
5231 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005232 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005233 if (len != PyList_GET_SIZE(tmp)) {
5234 PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
5235 goto failed;
5236 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005237 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005238 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005239 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005240 }
5241 *out = Suite(body, arena);
5242 if (*out == NULL) goto failed;
5243 return 0;
5244 }
5245
5246 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5247 failed:
5248 Py_XDECREF(tmp);
5249 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005250}
5251
5252int
5253obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5254{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005255 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005256
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005257 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005258 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005259 int lineno;
5260 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005261 int end_lineno;
5262 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005263
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005264 if (obj == Py_None) {
5265 *out = NULL;
5266 return 0;
5267 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005268 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005269 return 1;
5270 }
5271 if (tmp == NULL) {
5272 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5273 return 1;
5274 }
5275 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005276 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005277 res = obj2ast_int(tmp, &lineno, arena);
5278 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005279 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005280 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005281 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5282 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005283 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005284 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005285 if (tmp == NULL) {
5286 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5287 return 1;
5288 }
5289 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005290 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005291 res = obj2ast_int(tmp, &col_offset, arena);
5292 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005293 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005294 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005295 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5296 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005297 return 1;
5298 }
5299 if (tmp == NULL || tmp == Py_None) {
5300 Py_CLEAR(tmp);
5301 end_lineno = 0;
5302 }
5303 else {
5304 int res;
5305 res = obj2ast_int(tmp, &end_lineno, arena);
5306 if (res != 0) goto failed;
5307 Py_CLEAR(tmp);
5308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005309 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5310 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005311 return 1;
5312 }
5313 if (tmp == NULL || tmp == Py_None) {
5314 Py_CLEAR(tmp);
5315 end_col_offset = 0;
5316 }
5317 else {
5318 int res;
5319 res = obj2ast_int(tmp, &end_col_offset, arena);
5320 if (res != 0) goto failed;
5321 Py_CLEAR(tmp);
5322 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005323 tp = astmodulestate_global->FunctionDef_type;
5324 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005325 if (isinstance == -1) {
5326 return 1;
5327 }
5328 if (isinstance) {
5329 identifier name;
5330 arguments_ty args;
5331 asdl_seq* body;
5332 asdl_seq* decorator_list;
5333 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005334 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005335
Dino Viehlandac46eb42019-09-11 10:16:34 -07005336 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005337 return 1;
5338 }
5339 if (tmp == NULL) {
5340 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5341 return 1;
5342 }
5343 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005344 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005345 res = obj2ast_identifier(tmp, &name, arena);
5346 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005347 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005348 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005349 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005350 return 1;
5351 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005352 if (tmp == NULL) {
5353 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5354 return 1;
5355 }
5356 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005357 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005358 res = obj2ast_arguments(tmp, &args, arena);
5359 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005360 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005361 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005362 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005363 return 1;
5364 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005365 if (tmp == NULL) {
5366 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5367 return 1;
5368 }
5369 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005370 int res;
5371 Py_ssize_t len;
5372 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005373 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005374 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 +02005375 goto failed;
5376 }
5377 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005378 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005379 if (body == NULL) goto failed;
5380 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005381 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005382 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5383 Py_INCREF(tmp2);
5384 res = obj2ast_stmt(tmp2, &val, arena);
5385 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005386 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005387 if (len != PyList_GET_SIZE(tmp)) {
5388 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5389 goto failed;
5390 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005391 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005392 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005393 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005394 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005395 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5396 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005397 return 1;
5398 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005399 if (tmp == NULL) {
5400 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5401 return 1;
5402 }
5403 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005404 int res;
5405 Py_ssize_t len;
5406 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005407 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005408 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 +02005409 goto failed;
5410 }
5411 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005412 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005413 if (decorator_list == NULL) goto failed;
5414 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005415 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005416 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5417 Py_INCREF(tmp2);
5418 res = obj2ast_expr(tmp2, &val, arena);
5419 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005420 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005421 if (len != PyList_GET_SIZE(tmp)) {
5422 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5423 goto failed;
5424 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005425 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005426 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005427 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005428 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005429 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5430 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005431 return 1;
5432 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005433 if (tmp == NULL || tmp == Py_None) {
5434 Py_CLEAR(tmp);
5435 returns = NULL;
5436 }
5437 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005438 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005439 res = obj2ast_expr(tmp, &returns, arena);
5440 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005441 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005442 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005443 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5444 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005445 return 1;
5446 }
5447 if (tmp == NULL || tmp == Py_None) {
5448 Py_CLEAR(tmp);
5449 type_comment = NULL;
5450 }
5451 else {
5452 int res;
5453 res = obj2ast_string(tmp, &type_comment, arena);
5454 if (res != 0) goto failed;
5455 Py_CLEAR(tmp);
5456 }
5457 *out = FunctionDef(name, args, body, decorator_list, returns,
5458 type_comment, lineno, col_offset, end_lineno,
5459 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005460 if (*out == NULL) goto failed;
5461 return 0;
5462 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005463 tp = astmodulestate_global->AsyncFunctionDef_type;
5464 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005465 if (isinstance == -1) {
5466 return 1;
5467 }
5468 if (isinstance) {
5469 identifier name;
5470 arguments_ty args;
5471 asdl_seq* body;
5472 asdl_seq* decorator_list;
5473 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005474 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005475
Dino Viehlandac46eb42019-09-11 10:16:34 -07005476 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005477 return 1;
5478 }
5479 if (tmp == NULL) {
5480 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5481 return 1;
5482 }
5483 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005484 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005485 res = obj2ast_identifier(tmp, &name, arena);
5486 if (res != 0) goto failed;
5487 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005488 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005489 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005490 return 1;
5491 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005492 if (tmp == NULL) {
5493 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5494 return 1;
5495 }
5496 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005497 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005498 res = obj2ast_arguments(tmp, &args, arena);
5499 if (res != 0) goto failed;
5500 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005501 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005502 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005503 return 1;
5504 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005505 if (tmp == NULL) {
5506 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5507 return 1;
5508 }
5509 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005510 int res;
5511 Py_ssize_t len;
5512 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005513 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005514 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 -04005515 goto failed;
5516 }
5517 len = PyList_GET_SIZE(tmp);
5518 body = _Py_asdl_seq_new(len, arena);
5519 if (body == NULL) goto failed;
5520 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005521 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005522 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5523 Py_INCREF(tmp2);
5524 res = obj2ast_stmt(tmp2, &val, arena);
5525 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005526 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005527 if (len != PyList_GET_SIZE(tmp)) {
5528 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5529 goto failed;
5530 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005531 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005532 }
5533 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005534 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005535 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5536 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005537 return 1;
5538 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005539 if (tmp == NULL) {
5540 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5541 return 1;
5542 }
5543 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005544 int res;
5545 Py_ssize_t len;
5546 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005547 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005548 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 -04005549 goto failed;
5550 }
5551 len = PyList_GET_SIZE(tmp);
5552 decorator_list = _Py_asdl_seq_new(len, arena);
5553 if (decorator_list == NULL) goto failed;
5554 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005555 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005556 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5557 Py_INCREF(tmp2);
5558 res = obj2ast_expr(tmp2, &val, arena);
5559 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005560 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005561 if (len != PyList_GET_SIZE(tmp)) {
5562 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5563 goto failed;
5564 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005565 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005566 }
5567 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005568 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005569 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5570 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005571 return 1;
5572 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005573 if (tmp == NULL || tmp == Py_None) {
5574 Py_CLEAR(tmp);
5575 returns = NULL;
5576 }
5577 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005578 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005579 res = obj2ast_expr(tmp, &returns, arena);
5580 if (res != 0) goto failed;
5581 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005582 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005583 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5584 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005585 return 1;
5586 }
5587 if (tmp == NULL || tmp == Py_None) {
5588 Py_CLEAR(tmp);
5589 type_comment = NULL;
5590 }
5591 else {
5592 int res;
5593 res = obj2ast_string(tmp, &type_comment, arena);
5594 if (res != 0) goto failed;
5595 Py_CLEAR(tmp);
5596 }
Yury Selivanov75445082015-05-11 22:57:16 -04005597 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005598 type_comment, lineno, col_offset, end_lineno,
5599 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005600 if (*out == NULL) goto failed;
5601 return 0;
5602 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005603 tp = astmodulestate_global->ClassDef_type;
5604 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005605 if (isinstance == -1) {
5606 return 1;
5607 }
5608 if (isinstance) {
5609 identifier name;
5610 asdl_seq* bases;
5611 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005612 asdl_seq* body;
5613 asdl_seq* decorator_list;
5614
Dino Viehlandac46eb42019-09-11 10:16:34 -07005615 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005616 return 1;
5617 }
5618 if (tmp == NULL) {
5619 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5620 return 1;
5621 }
5622 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005623 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005624 res = obj2ast_identifier(tmp, &name, arena);
5625 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005626 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005627 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005628 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005629 return 1;
5630 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005631 if (tmp == NULL) {
5632 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5633 return 1;
5634 }
5635 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005636 int res;
5637 Py_ssize_t len;
5638 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005639 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005640 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 +02005641 goto failed;
5642 }
5643 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005644 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005645 if (bases == NULL) goto failed;
5646 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005647 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005648 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5649 Py_INCREF(tmp2);
5650 res = obj2ast_expr(tmp2, &val, arena);
5651 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005652 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005653 if (len != PyList_GET_SIZE(tmp)) {
5654 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5655 goto failed;
5656 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005657 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005658 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005659 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005660 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005661 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5662 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005663 return 1;
5664 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005665 if (tmp == NULL) {
5666 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5667 return 1;
5668 }
5669 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005670 int res;
5671 Py_ssize_t len;
5672 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005673 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005674 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 +02005675 goto failed;
5676 }
5677 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005678 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005679 if (keywords == NULL) goto failed;
5680 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005681 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005682 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5683 Py_INCREF(tmp2);
5684 res = obj2ast_keyword(tmp2, &val, arena);
5685 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005686 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005687 if (len != PyList_GET_SIZE(tmp)) {
5688 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5689 goto failed;
5690 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005691 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005692 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005693 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005694 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005695 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005696 return 1;
5697 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005698 if (tmp == NULL) {
5699 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5700 return 1;
5701 }
5702 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005703 int res;
5704 Py_ssize_t len;
5705 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005706 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005707 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 +02005708 goto failed;
5709 }
5710 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005711 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005712 if (body == NULL) goto failed;
5713 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005714 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005715 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5716 Py_INCREF(tmp2);
5717 res = obj2ast_stmt(tmp2, &val, arena);
5718 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005719 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005720 if (len != PyList_GET_SIZE(tmp)) {
5721 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5722 goto failed;
5723 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005724 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005725 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005726 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005727 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005728 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5729 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005730 return 1;
5731 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005732 if (tmp == NULL) {
5733 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5734 return 1;
5735 }
5736 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005737 int res;
5738 Py_ssize_t len;
5739 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005740 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005741 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 +02005742 goto failed;
5743 }
5744 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005745 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005746 if (decorator_list == NULL) goto failed;
5747 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005748 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005749 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5750 Py_INCREF(tmp2);
5751 res = obj2ast_expr(tmp2, &val, arena);
5752 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005753 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005754 if (len != PyList_GET_SIZE(tmp)) {
5755 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5756 goto failed;
5757 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005758 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005759 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005760 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005761 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005762 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005763 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005764 if (*out == NULL) goto failed;
5765 return 0;
5766 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005767 tp = astmodulestate_global->Return_type;
5768 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005769 if (isinstance == -1) {
5770 return 1;
5771 }
5772 if (isinstance) {
5773 expr_ty value;
5774
Dino Viehlandac46eb42019-09-11 10:16:34 -07005775 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005776 return 1;
5777 }
5778 if (tmp == NULL || tmp == Py_None) {
5779 Py_CLEAR(tmp);
5780 value = NULL;
5781 }
5782 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005783 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005784 res = obj2ast_expr(tmp, &value, arena);
5785 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005786 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005787 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005788 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5789 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005790 if (*out == NULL) goto failed;
5791 return 0;
5792 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005793 tp = astmodulestate_global->Delete_type;
5794 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005795 if (isinstance == -1) {
5796 return 1;
5797 }
5798 if (isinstance) {
5799 asdl_seq* targets;
5800
Dino Viehlandac46eb42019-09-11 10:16:34 -07005801 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5802 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005803 return 1;
5804 }
5805 if (tmp == NULL) {
5806 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5807 return 1;
5808 }
5809 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005810 int res;
5811 Py_ssize_t len;
5812 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005813 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005814 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 +02005815 goto failed;
5816 }
5817 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005818 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005819 if (targets == NULL) goto failed;
5820 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005821 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005822 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5823 Py_INCREF(tmp2);
5824 res = obj2ast_expr(tmp2, &val, arena);
5825 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005826 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005827 if (len != PyList_GET_SIZE(tmp)) {
5828 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5829 goto failed;
5830 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005831 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005832 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005833 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005834 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005835 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5836 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005837 if (*out == NULL) goto failed;
5838 return 0;
5839 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005840 tp = astmodulestate_global->Assign_type;
5841 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005842 if (isinstance == -1) {
5843 return 1;
5844 }
5845 if (isinstance) {
5846 asdl_seq* targets;
5847 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005848 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005849
Dino Viehlandac46eb42019-09-11 10:16:34 -07005850 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5851 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005852 return 1;
5853 }
5854 if (tmp == NULL) {
5855 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5856 return 1;
5857 }
5858 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005859 int res;
5860 Py_ssize_t len;
5861 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005862 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005863 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 +02005864 goto failed;
5865 }
5866 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005867 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005868 if (targets == NULL) goto failed;
5869 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005870 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005871 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5872 Py_INCREF(tmp2);
5873 res = obj2ast_expr(tmp2, &val, arena);
5874 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005875 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005876 if (len != PyList_GET_SIZE(tmp)) {
5877 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5878 goto failed;
5879 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005880 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005881 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005882 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005883 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005884 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005885 return 1;
5886 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005887 if (tmp == NULL) {
5888 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5889 return 1;
5890 }
5891 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005892 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005893 res = obj2ast_expr(tmp, &value, arena);
5894 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005895 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005896 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005897 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5898 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005899 return 1;
5900 }
5901 if (tmp == NULL || tmp == Py_None) {
5902 Py_CLEAR(tmp);
5903 type_comment = NULL;
5904 }
5905 else {
5906 int res;
5907 res = obj2ast_string(tmp, &type_comment, arena);
5908 if (res != 0) goto failed;
5909 Py_CLEAR(tmp);
5910 }
5911 *out = Assign(targets, value, type_comment, lineno, col_offset,
5912 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005913 if (*out == NULL) goto failed;
5914 return 0;
5915 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005916 tp = astmodulestate_global->AugAssign_type;
5917 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005918 if (isinstance == -1) {
5919 return 1;
5920 }
5921 if (isinstance) {
5922 expr_ty target;
5923 operator_ty op;
5924 expr_ty value;
5925
Dino Viehlandac46eb42019-09-11 10:16:34 -07005926 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5927 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005928 return 1;
5929 }
5930 if (tmp == NULL) {
5931 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5932 return 1;
5933 }
5934 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005935 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005936 res = obj2ast_expr(tmp, &target, arena);
5937 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005938 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005939 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005940 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005941 return 1;
5942 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005943 if (tmp == NULL) {
5944 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5945 return 1;
5946 }
5947 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005948 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005949 res = obj2ast_operator(tmp, &op, arena);
5950 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005951 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005952 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005953 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005954 return 1;
5955 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005956 if (tmp == NULL) {
5957 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5958 return 1;
5959 }
5960 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005961 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005962 res = obj2ast_expr(tmp, &value, arena);
5963 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005964 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005965 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005966 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5967 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005968 if (*out == NULL) goto failed;
5969 return 0;
5970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005971 tp = astmodulestate_global->AnnAssign_type;
5972 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005973 if (isinstance == -1) {
5974 return 1;
5975 }
5976 if (isinstance) {
5977 expr_ty target;
5978 expr_ty annotation;
5979 expr_ty value;
5980 int simple;
5981
Dino Viehlandac46eb42019-09-11 10:16:34 -07005982 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5983 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005984 return 1;
5985 }
5986 if (tmp == NULL) {
5987 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5988 return 1;
5989 }
5990 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005991 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005992 res = obj2ast_expr(tmp, &target, arena);
5993 if (res != 0) goto failed;
5994 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005995 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005996 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
5997 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005998 return 1;
5999 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006000 if (tmp == NULL) {
6001 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6002 return 1;
6003 }
6004 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006005 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006006 res = obj2ast_expr(tmp, &annotation, arena);
6007 if (res != 0) goto failed;
6008 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006010 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006011 return 1;
6012 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006013 if (tmp == NULL || tmp == Py_None) {
6014 Py_CLEAR(tmp);
6015 value = NULL;
6016 }
6017 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006018 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006019 res = obj2ast_expr(tmp, &value, arena);
6020 if (res != 0) goto failed;
6021 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006022 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006023 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6024 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006025 return 1;
6026 }
6027 if (tmp == NULL) {
6028 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6029 return 1;
6030 }
6031 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006032 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006033 res = obj2ast_int(tmp, &simple, arena);
6034 if (res != 0) goto failed;
6035 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006036 }
6037 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006038 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006039 if (*out == NULL) goto failed;
6040 return 0;
6041 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006042 tp = astmodulestate_global->For_type;
6043 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006044 if (isinstance == -1) {
6045 return 1;
6046 }
6047 if (isinstance) {
6048 expr_ty target;
6049 expr_ty iter;
6050 asdl_seq* body;
6051 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006052 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006053
Dino Viehlandac46eb42019-09-11 10:16:34 -07006054 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6055 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006056 return 1;
6057 }
6058 if (tmp == NULL) {
6059 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6060 return 1;
6061 }
6062 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006063 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006064 res = obj2ast_expr(tmp, &target, arena);
6065 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006066 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006068 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006069 return 1;
6070 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006071 if (tmp == NULL) {
6072 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6073 return 1;
6074 }
6075 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006076 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006077 res = obj2ast_expr(tmp, &iter, arena);
6078 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006079 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006080 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006081 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006082 return 1;
6083 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006084 if (tmp == NULL) {
6085 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6086 return 1;
6087 }
6088 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006089 int res;
6090 Py_ssize_t len;
6091 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006092 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006093 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 +02006094 goto failed;
6095 }
6096 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006097 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006098 if (body == NULL) goto failed;
6099 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006100 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006101 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6102 Py_INCREF(tmp2);
6103 res = obj2ast_stmt(tmp2, &val, arena);
6104 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006105 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006106 if (len != PyList_GET_SIZE(tmp)) {
6107 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6108 goto failed;
6109 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006110 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006111 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006112 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006113 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006114 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6115 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006116 return 1;
6117 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006118 if (tmp == NULL) {
6119 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6120 return 1;
6121 }
6122 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006123 int res;
6124 Py_ssize_t len;
6125 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006126 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006127 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 +02006128 goto failed;
6129 }
6130 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006131 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006132 if (orelse == NULL) goto failed;
6133 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006134 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006135 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6136 Py_INCREF(tmp2);
6137 res = obj2ast_stmt(tmp2, &val, arena);
6138 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006139 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006140 if (len != PyList_GET_SIZE(tmp)) {
6141 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6142 goto failed;
6143 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006144 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006145 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006146 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006147 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006148 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6149 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006150 return 1;
6151 }
6152 if (tmp == NULL || tmp == Py_None) {
6153 Py_CLEAR(tmp);
6154 type_comment = NULL;
6155 }
6156 else {
6157 int res;
6158 res = obj2ast_string(tmp, &type_comment, arena);
6159 if (res != 0) goto failed;
6160 Py_CLEAR(tmp);
6161 }
6162 *out = For(target, iter, body, orelse, type_comment, lineno,
6163 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006164 if (*out == NULL) goto failed;
6165 return 0;
6166 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006167 tp = astmodulestate_global->AsyncFor_type;
6168 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006169 if (isinstance == -1) {
6170 return 1;
6171 }
6172 if (isinstance) {
6173 expr_ty target;
6174 expr_ty iter;
6175 asdl_seq* body;
6176 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006177 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006178
Dino Viehlandac46eb42019-09-11 10:16:34 -07006179 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6180 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006181 return 1;
6182 }
6183 if (tmp == NULL) {
6184 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6185 return 1;
6186 }
6187 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006188 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006189 res = obj2ast_expr(tmp, &target, arena);
6190 if (res != 0) goto failed;
6191 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006192 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006193 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006194 return 1;
6195 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006196 if (tmp == NULL) {
6197 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6198 return 1;
6199 }
6200 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006201 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006202 res = obj2ast_expr(tmp, &iter, arena);
6203 if (res != 0) goto failed;
6204 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006205 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006206 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006207 return 1;
6208 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006209 if (tmp == NULL) {
6210 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6211 return 1;
6212 }
6213 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006214 int res;
6215 Py_ssize_t len;
6216 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006217 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006218 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 -04006219 goto failed;
6220 }
6221 len = PyList_GET_SIZE(tmp);
6222 body = _Py_asdl_seq_new(len, arena);
6223 if (body == NULL) goto failed;
6224 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006225 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006226 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6227 Py_INCREF(tmp2);
6228 res = obj2ast_stmt(tmp2, &val, arena);
6229 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006230 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006231 if (len != PyList_GET_SIZE(tmp)) {
6232 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6233 goto failed;
6234 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006235 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006236 }
6237 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006238 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006239 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6240 {
Yury Selivanov75445082015-05-11 22:57:16 -04006241 return 1;
6242 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006243 if (tmp == NULL) {
6244 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6245 return 1;
6246 }
6247 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006248 int res;
6249 Py_ssize_t len;
6250 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006251 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006252 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 -04006253 goto failed;
6254 }
6255 len = PyList_GET_SIZE(tmp);
6256 orelse = _Py_asdl_seq_new(len, arena);
6257 if (orelse == NULL) goto failed;
6258 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006259 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006260 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6261 Py_INCREF(tmp2);
6262 res = obj2ast_stmt(tmp2, &val, arena);
6263 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006264 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006265 if (len != PyList_GET_SIZE(tmp)) {
6266 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6267 goto failed;
6268 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006269 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006270 }
6271 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006272 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006273 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6274 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006275 return 1;
6276 }
6277 if (tmp == NULL || tmp == Py_None) {
6278 Py_CLEAR(tmp);
6279 type_comment = NULL;
6280 }
6281 else {
6282 int res;
6283 res = obj2ast_string(tmp, &type_comment, arena);
6284 if (res != 0) goto failed;
6285 Py_CLEAR(tmp);
6286 }
6287 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6288 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006289 if (*out == NULL) goto failed;
6290 return 0;
6291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006292 tp = astmodulestate_global->While_type;
6293 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006294 if (isinstance == -1) {
6295 return 1;
6296 }
6297 if (isinstance) {
6298 expr_ty test;
6299 asdl_seq* body;
6300 asdl_seq* orelse;
6301
Dino Viehlandac46eb42019-09-11 10:16:34 -07006302 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006303 return 1;
6304 }
6305 if (tmp == NULL) {
6306 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6307 return 1;
6308 }
6309 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006310 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006311 res = obj2ast_expr(tmp, &test, arena);
6312 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006313 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006314 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006315 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006316 return 1;
6317 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006318 if (tmp == NULL) {
6319 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6320 return 1;
6321 }
6322 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006323 int res;
6324 Py_ssize_t len;
6325 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006326 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006327 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 +02006328 goto failed;
6329 }
6330 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006331 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006332 if (body == NULL) goto failed;
6333 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006334 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006335 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6336 Py_INCREF(tmp2);
6337 res = obj2ast_stmt(tmp2, &val, arena);
6338 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006339 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006340 if (len != PyList_GET_SIZE(tmp)) {
6341 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6342 goto failed;
6343 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006344 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006345 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006346 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006347 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006348 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6349 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006350 return 1;
6351 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006352 if (tmp == NULL) {
6353 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6354 return 1;
6355 }
6356 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006357 int res;
6358 Py_ssize_t len;
6359 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006360 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006361 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 +02006362 goto failed;
6363 }
6364 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006365 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006366 if (orelse == NULL) goto failed;
6367 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006368 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006369 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6370 Py_INCREF(tmp2);
6371 res = obj2ast_stmt(tmp2, &val, arena);
6372 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006373 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006374 if (len != PyList_GET_SIZE(tmp)) {
6375 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6376 goto failed;
6377 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006378 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006379 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006380 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006381 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006382 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6383 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006384 if (*out == NULL) goto failed;
6385 return 0;
6386 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006387 tp = astmodulestate_global->If_type;
6388 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006389 if (isinstance == -1) {
6390 return 1;
6391 }
6392 if (isinstance) {
6393 expr_ty test;
6394 asdl_seq* body;
6395 asdl_seq* orelse;
6396
Dino Viehlandac46eb42019-09-11 10:16:34 -07006397 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006398 return 1;
6399 }
6400 if (tmp == NULL) {
6401 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6402 return 1;
6403 }
6404 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006405 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006406 res = obj2ast_expr(tmp, &test, arena);
6407 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006408 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006409 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006410 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006411 return 1;
6412 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006413 if (tmp == NULL) {
6414 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6415 return 1;
6416 }
6417 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006418 int res;
6419 Py_ssize_t len;
6420 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006421 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006422 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 +02006423 goto failed;
6424 }
6425 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006426 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006427 if (body == NULL) goto failed;
6428 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006429 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006430 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6431 Py_INCREF(tmp2);
6432 res = obj2ast_stmt(tmp2, &val, arena);
6433 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006434 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006435 if (len != PyList_GET_SIZE(tmp)) {
6436 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6437 goto failed;
6438 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006439 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006440 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006441 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006442 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006443 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6444 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006445 return 1;
6446 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006447 if (tmp == NULL) {
6448 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6449 return 1;
6450 }
6451 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006452 int res;
6453 Py_ssize_t len;
6454 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006455 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006456 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 +02006457 goto failed;
6458 }
6459 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006460 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006461 if (orelse == NULL) goto failed;
6462 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006463 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006464 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6465 Py_INCREF(tmp2);
6466 res = obj2ast_stmt(tmp2, &val, arena);
6467 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006468 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006469 if (len != PyList_GET_SIZE(tmp)) {
6470 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6471 goto failed;
6472 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006473 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006474 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006475 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006476 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006477 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6478 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006479 if (*out == NULL) goto failed;
6480 return 0;
6481 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006482 tp = astmodulestate_global->With_type;
6483 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006484 if (isinstance == -1) {
6485 return 1;
6486 }
6487 if (isinstance) {
6488 asdl_seq* items;
6489 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006490 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006491
Dino Viehlandac46eb42019-09-11 10:16:34 -07006492 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006493 return 1;
6494 }
6495 if (tmp == NULL) {
6496 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6497 return 1;
6498 }
6499 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006500 int res;
6501 Py_ssize_t len;
6502 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006503 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006504 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 +02006505 goto failed;
6506 }
6507 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006508 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006509 if (items == NULL) goto failed;
6510 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006511 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006512 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6513 Py_INCREF(tmp2);
6514 res = obj2ast_withitem(tmp2, &val, arena);
6515 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006516 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006517 if (len != PyList_GET_SIZE(tmp)) {
6518 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6519 goto failed;
6520 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006521 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006522 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006523 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006524 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006525 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006526 return 1;
6527 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006528 if (tmp == NULL) {
6529 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6530 return 1;
6531 }
6532 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006533 int res;
6534 Py_ssize_t len;
6535 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006536 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006537 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 +02006538 goto failed;
6539 }
6540 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006541 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006542 if (body == NULL) goto failed;
6543 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006544 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006545 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6546 Py_INCREF(tmp2);
6547 res = obj2ast_stmt(tmp2, &val, arena);
6548 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006549 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006550 if (len != PyList_GET_SIZE(tmp)) {
6551 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6552 goto failed;
6553 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006554 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006555 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006556 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006557 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006558 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6559 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006560 return 1;
6561 }
6562 if (tmp == NULL || tmp == Py_None) {
6563 Py_CLEAR(tmp);
6564 type_comment = NULL;
6565 }
6566 else {
6567 int res;
6568 res = obj2ast_string(tmp, &type_comment, arena);
6569 if (res != 0) goto failed;
6570 Py_CLEAR(tmp);
6571 }
6572 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006573 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006574 if (*out == NULL) goto failed;
6575 return 0;
6576 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006577 tp = astmodulestate_global->AsyncWith_type;
6578 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006579 if (isinstance == -1) {
6580 return 1;
6581 }
6582 if (isinstance) {
6583 asdl_seq* items;
6584 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006585 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006586
Dino Viehlandac46eb42019-09-11 10:16:34 -07006587 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006588 return 1;
6589 }
6590 if (tmp == NULL) {
6591 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6592 return 1;
6593 }
6594 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006595 int res;
6596 Py_ssize_t len;
6597 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006598 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006599 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 -04006600 goto failed;
6601 }
6602 len = PyList_GET_SIZE(tmp);
6603 items = _Py_asdl_seq_new(len, arena);
6604 if (items == NULL) goto failed;
6605 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006606 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006607 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6608 Py_INCREF(tmp2);
6609 res = obj2ast_withitem(tmp2, &val, arena);
6610 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006611 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006612 if (len != PyList_GET_SIZE(tmp)) {
6613 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6614 goto failed;
6615 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006616 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006617 }
6618 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006619 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006620 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006621 return 1;
6622 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006623 if (tmp == NULL) {
6624 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6625 return 1;
6626 }
6627 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006628 int res;
6629 Py_ssize_t len;
6630 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006631 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006632 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 -04006633 goto failed;
6634 }
6635 len = PyList_GET_SIZE(tmp);
6636 body = _Py_asdl_seq_new(len, arena);
6637 if (body == NULL) goto failed;
6638 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006639 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006640 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6641 Py_INCREF(tmp2);
6642 res = obj2ast_stmt(tmp2, &val, arena);
6643 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006644 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006645 if (len != PyList_GET_SIZE(tmp)) {
6646 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6647 goto failed;
6648 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006649 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006650 }
6651 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006652 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006653 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6654 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006655 return 1;
6656 }
6657 if (tmp == NULL || tmp == Py_None) {
6658 Py_CLEAR(tmp);
6659 type_comment = NULL;
6660 }
6661 else {
6662 int res;
6663 res = obj2ast_string(tmp, &type_comment, arena);
6664 if (res != 0) goto failed;
6665 Py_CLEAR(tmp);
6666 }
6667 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6668 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006669 if (*out == NULL) goto failed;
6670 return 0;
6671 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006672 tp = astmodulestate_global->Raise_type;
6673 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006674 if (isinstance == -1) {
6675 return 1;
6676 }
6677 if (isinstance) {
6678 expr_ty exc;
6679 expr_ty cause;
6680
Dino Viehlandac46eb42019-09-11 10:16:34 -07006681 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006682 return 1;
6683 }
6684 if (tmp == NULL || tmp == Py_None) {
6685 Py_CLEAR(tmp);
6686 exc = NULL;
6687 }
6688 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006689 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006690 res = obj2ast_expr(tmp, &exc, arena);
6691 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006692 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006693 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006694 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006695 return 1;
6696 }
6697 if (tmp == NULL || tmp == Py_None) {
6698 Py_CLEAR(tmp);
6699 cause = NULL;
6700 }
6701 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006702 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006703 res = obj2ast_expr(tmp, &cause, arena);
6704 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006705 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006706 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006707 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6708 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006709 if (*out == NULL) goto failed;
6710 return 0;
6711 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006712 tp = astmodulestate_global->Try_type;
6713 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006714 if (isinstance == -1) {
6715 return 1;
6716 }
6717 if (isinstance) {
6718 asdl_seq* body;
6719 asdl_seq* handlers;
6720 asdl_seq* orelse;
6721 asdl_seq* finalbody;
6722
Dino Viehlandac46eb42019-09-11 10:16:34 -07006723 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006724 return 1;
6725 }
6726 if (tmp == NULL) {
6727 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6728 return 1;
6729 }
6730 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006731 int res;
6732 Py_ssize_t len;
6733 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006734 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006735 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 +02006736 goto failed;
6737 }
6738 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006739 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006740 if (body == NULL) goto failed;
6741 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006742 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006743 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6744 Py_INCREF(tmp2);
6745 res = obj2ast_stmt(tmp2, &val, arena);
6746 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006747 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006748 if (len != PyList_GET_SIZE(tmp)) {
6749 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6750 goto failed;
6751 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006752 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006753 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006754 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006755 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006756 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6757 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006758 return 1;
6759 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006760 if (tmp == NULL) {
6761 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6762 return 1;
6763 }
6764 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006765 int res;
6766 Py_ssize_t len;
6767 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006768 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006769 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 +02006770 goto failed;
6771 }
6772 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006773 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006774 if (handlers == NULL) goto failed;
6775 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006776 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006777 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6778 Py_INCREF(tmp2);
6779 res = obj2ast_excepthandler(tmp2, &val, arena);
6780 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006781 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006782 if (len != PyList_GET_SIZE(tmp)) {
6783 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6784 goto failed;
6785 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006786 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006787 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006788 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006789 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006790 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6791 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006792 return 1;
6793 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006794 if (tmp == NULL) {
6795 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6796 return 1;
6797 }
6798 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006799 int res;
6800 Py_ssize_t len;
6801 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006802 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006803 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 +02006804 goto failed;
6805 }
6806 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006807 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006808 if (orelse == NULL) goto failed;
6809 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006810 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006811 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6812 Py_INCREF(tmp2);
6813 res = obj2ast_stmt(tmp2, &val, arena);
6814 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006815 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006816 if (len != PyList_GET_SIZE(tmp)) {
6817 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6818 goto failed;
6819 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006820 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006821 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006822 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006823 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006824 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6825 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006826 return 1;
6827 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006828 if (tmp == NULL) {
6829 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6830 return 1;
6831 }
6832 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006833 int res;
6834 Py_ssize_t len;
6835 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006836 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006837 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 +02006838 goto failed;
6839 }
6840 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006841 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006842 if (finalbody == NULL) goto failed;
6843 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006844 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006845 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6846 Py_INCREF(tmp2);
6847 res = obj2ast_stmt(tmp2, &val, arena);
6848 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006849 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006850 if (len != PyList_GET_SIZE(tmp)) {
6851 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6852 goto failed;
6853 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006854 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006855 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006856 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006857 }
6858 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006859 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006860 if (*out == NULL) goto failed;
6861 return 0;
6862 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006863 tp = astmodulestate_global->Assert_type;
6864 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006865 if (isinstance == -1) {
6866 return 1;
6867 }
6868 if (isinstance) {
6869 expr_ty test;
6870 expr_ty msg;
6871
Dino Viehlandac46eb42019-09-11 10:16:34 -07006872 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006873 return 1;
6874 }
6875 if (tmp == NULL) {
6876 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6877 return 1;
6878 }
6879 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006880 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006881 res = obj2ast_expr(tmp, &test, arena);
6882 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006883 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006884 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006885 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006886 return 1;
6887 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006888 if (tmp == NULL || tmp == Py_None) {
6889 Py_CLEAR(tmp);
6890 msg = NULL;
6891 }
6892 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006893 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006894 res = obj2ast_expr(tmp, &msg, arena);
6895 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006896 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006897 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006898 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6899 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006900 if (*out == NULL) goto failed;
6901 return 0;
6902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006903 tp = astmodulestate_global->Import_type;
6904 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006905 if (isinstance == -1) {
6906 return 1;
6907 }
6908 if (isinstance) {
6909 asdl_seq* names;
6910
Dino Viehlandac46eb42019-09-11 10:16:34 -07006911 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006912 return 1;
6913 }
6914 if (tmp == NULL) {
6915 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6916 return 1;
6917 }
6918 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006919 int res;
6920 Py_ssize_t len;
6921 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006922 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006923 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 +02006924 goto failed;
6925 }
6926 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006927 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006928 if (names == NULL) goto failed;
6929 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006930 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006931 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6932 Py_INCREF(tmp2);
6933 res = obj2ast_alias(tmp2, &val, arena);
6934 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006935 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006936 if (len != PyList_GET_SIZE(tmp)) {
6937 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6938 goto failed;
6939 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006940 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006941 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006942 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006943 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006944 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6945 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006946 if (*out == NULL) goto failed;
6947 return 0;
6948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006949 tp = astmodulestate_global->ImportFrom_type;
6950 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006951 if (isinstance == -1) {
6952 return 1;
6953 }
6954 if (isinstance) {
6955 identifier module;
6956 asdl_seq* names;
6957 int level;
6958
Dino Viehlandac46eb42019-09-11 10:16:34 -07006959 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6960 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006961 return 1;
6962 }
6963 if (tmp == NULL || tmp == Py_None) {
6964 Py_CLEAR(tmp);
6965 module = NULL;
6966 }
6967 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006968 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006969 res = obj2ast_identifier(tmp, &module, arena);
6970 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006971 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006972 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006973 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006974 return 1;
6975 }
6976 if (tmp == NULL) {
6977 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6978 return 1;
6979 }
6980 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006981 int res;
6982 Py_ssize_t len;
6983 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006984 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006985 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 +02006986 goto failed;
6987 }
6988 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006989 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006990 if (names == NULL) goto failed;
6991 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006992 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006993 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6994 Py_INCREF(tmp2);
6995 res = obj2ast_alias(tmp2, &val, arena);
6996 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006997 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006998 if (len != PyList_GET_SIZE(tmp)) {
6999 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7000 goto failed;
7001 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007002 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007003 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007004 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007005 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007006 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007007 return 1;
7008 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007009 if (tmp == NULL || tmp == Py_None) {
7010 Py_CLEAR(tmp);
7011 level = 0;
7012 }
7013 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007014 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007015 res = obj2ast_int(tmp, &level, arena);
7016 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007017 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007018 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007019 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7020 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007021 if (*out == NULL) goto failed;
7022 return 0;
7023 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007024 tp = astmodulestate_global->Global_type;
7025 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007026 if (isinstance == -1) {
7027 return 1;
7028 }
7029 if (isinstance) {
7030 asdl_seq* names;
7031
Dino Viehlandac46eb42019-09-11 10:16:34 -07007032 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007033 return 1;
7034 }
7035 if (tmp == NULL) {
7036 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7037 return 1;
7038 }
7039 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007040 int res;
7041 Py_ssize_t len;
7042 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007043 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007044 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 +02007045 goto failed;
7046 }
7047 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007048 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007049 if (names == NULL) goto failed;
7050 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007051 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007052 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7053 Py_INCREF(tmp2);
7054 res = obj2ast_identifier(tmp2, &val, arena);
7055 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007056 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007057 if (len != PyList_GET_SIZE(tmp)) {
7058 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7059 goto failed;
7060 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007061 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007062 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007063 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007064 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007065 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7066 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007067 if (*out == NULL) goto failed;
7068 return 0;
7069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007070 tp = astmodulestate_global->Nonlocal_type;
7071 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007072 if (isinstance == -1) {
7073 return 1;
7074 }
7075 if (isinstance) {
7076 asdl_seq* names;
7077
Dino Viehlandac46eb42019-09-11 10:16:34 -07007078 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007079 return 1;
7080 }
7081 if (tmp == NULL) {
7082 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7083 return 1;
7084 }
7085 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007086 int res;
7087 Py_ssize_t len;
7088 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007089 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007090 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 +02007091 goto failed;
7092 }
7093 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007094 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007095 if (names == NULL) goto failed;
7096 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007097 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007098 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7099 Py_INCREF(tmp2);
7100 res = obj2ast_identifier(tmp2, &val, arena);
7101 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007102 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007103 if (len != PyList_GET_SIZE(tmp)) {
7104 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7105 goto failed;
7106 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007107 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007108 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007109 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007110 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007111 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7112 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007113 if (*out == NULL) goto failed;
7114 return 0;
7115 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007116 tp = astmodulestate_global->Expr_type;
7117 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007118 if (isinstance == -1) {
7119 return 1;
7120 }
7121 if (isinstance) {
7122 expr_ty value;
7123
Dino Viehlandac46eb42019-09-11 10:16:34 -07007124 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007125 return 1;
7126 }
7127 if (tmp == NULL) {
7128 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7129 return 1;
7130 }
7131 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007132 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007133 res = obj2ast_expr(tmp, &value, arena);
7134 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007135 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007136 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007137 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7138 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007139 if (*out == NULL) goto failed;
7140 return 0;
7141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007142 tp = astmodulestate_global->Pass_type;
7143 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007144 if (isinstance == -1) {
7145 return 1;
7146 }
7147 if (isinstance) {
7148
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007149 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007150 if (*out == NULL) goto failed;
7151 return 0;
7152 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007153 tp = astmodulestate_global->Break_type;
7154 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007155 if (isinstance == -1) {
7156 return 1;
7157 }
7158 if (isinstance) {
7159
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007160 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007161 if (*out == NULL) goto failed;
7162 return 0;
7163 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007164 tp = astmodulestate_global->Continue_type;
7165 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007166 if (isinstance == -1) {
7167 return 1;
7168 }
7169 if (isinstance) {
7170
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007171 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007172 if (*out == NULL) goto failed;
7173 return 0;
7174 }
7175
7176 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7177 failed:
7178 Py_XDECREF(tmp);
7179 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007180}
7181
7182int
7183obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7184{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007185 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007186
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007187 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007188 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007189 int lineno;
7190 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007191 int end_lineno;
7192 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007193
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007194 if (obj == Py_None) {
7195 *out = NULL;
7196 return 0;
7197 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007198 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007199 return 1;
7200 }
7201 if (tmp == NULL) {
7202 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7203 return 1;
7204 }
7205 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007206 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007207 res = obj2ast_int(tmp, &lineno, arena);
7208 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007209 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007210 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007211 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7212 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007213 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007214 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007215 if (tmp == NULL) {
7216 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7217 return 1;
7218 }
7219 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007220 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007221 res = obj2ast_int(tmp, &col_offset, arena);
7222 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007223 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007225 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7226 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007227 return 1;
7228 }
7229 if (tmp == NULL || tmp == Py_None) {
7230 Py_CLEAR(tmp);
7231 end_lineno = 0;
7232 }
7233 else {
7234 int res;
7235 res = obj2ast_int(tmp, &end_lineno, arena);
7236 if (res != 0) goto failed;
7237 Py_CLEAR(tmp);
7238 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007239 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7240 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007241 return 1;
7242 }
7243 if (tmp == NULL || tmp == Py_None) {
7244 Py_CLEAR(tmp);
7245 end_col_offset = 0;
7246 }
7247 else {
7248 int res;
7249 res = obj2ast_int(tmp, &end_col_offset, arena);
7250 if (res != 0) goto failed;
7251 Py_CLEAR(tmp);
7252 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007253 tp = astmodulestate_global->BoolOp_type;
7254 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007255 if (isinstance == -1) {
7256 return 1;
7257 }
7258 if (isinstance) {
7259 boolop_ty op;
7260 asdl_seq* values;
7261
Dino Viehlandac46eb42019-09-11 10:16:34 -07007262 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007263 return 1;
7264 }
7265 if (tmp == NULL) {
7266 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7267 return 1;
7268 }
7269 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007270 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007271 res = obj2ast_boolop(tmp, &op, arena);
7272 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007273 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007274 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007275 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7276 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007277 return 1;
7278 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007279 if (tmp == NULL) {
7280 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7281 return 1;
7282 }
7283 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007284 int res;
7285 Py_ssize_t len;
7286 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007287 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007288 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 +02007289 goto failed;
7290 }
7291 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007292 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007293 if (values == NULL) goto failed;
7294 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007295 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007296 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7297 Py_INCREF(tmp2);
7298 res = obj2ast_expr(tmp2, &val, arena);
7299 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007300 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007301 if (len != PyList_GET_SIZE(tmp)) {
7302 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7303 goto failed;
7304 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007305 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007306 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007307 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007308 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007309 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7310 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007311 if (*out == NULL) goto failed;
7312 return 0;
7313 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007314 tp = astmodulestate_global->NamedExpr_type;
7315 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007316 if (isinstance == -1) {
7317 return 1;
7318 }
7319 if (isinstance) {
7320 expr_ty target;
7321 expr_ty value;
7322
Dino Viehlandac46eb42019-09-11 10:16:34 -07007323 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7324 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007325 return 1;
7326 }
7327 if (tmp == NULL) {
7328 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7329 return 1;
7330 }
7331 else {
7332 int res;
7333 res = obj2ast_expr(tmp, &target, arena);
7334 if (res != 0) goto failed;
7335 Py_CLEAR(tmp);
7336 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007337 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007338 return 1;
7339 }
7340 if (tmp == NULL) {
7341 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7342 return 1;
7343 }
7344 else {
7345 int res;
7346 res = obj2ast_expr(tmp, &value, arena);
7347 if (res != 0) goto failed;
7348 Py_CLEAR(tmp);
7349 }
7350 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7351 end_col_offset, arena);
7352 if (*out == NULL) goto failed;
7353 return 0;
7354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007355 tp = astmodulestate_global->BinOp_type;
7356 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007357 if (isinstance == -1) {
7358 return 1;
7359 }
7360 if (isinstance) {
7361 expr_ty left;
7362 operator_ty op;
7363 expr_ty right;
7364
Dino Viehlandac46eb42019-09-11 10:16:34 -07007365 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007366 return 1;
7367 }
7368 if (tmp == NULL) {
7369 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7370 return 1;
7371 }
7372 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007373 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007374 res = obj2ast_expr(tmp, &left, arena);
7375 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007376 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007377 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007378 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007379 return 1;
7380 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007381 if (tmp == NULL) {
7382 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7383 return 1;
7384 }
7385 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007386 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007387 res = obj2ast_operator(tmp, &op, arena);
7388 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007389 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007391 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007392 return 1;
7393 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007394 if (tmp == NULL) {
7395 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7396 return 1;
7397 }
7398 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007399 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007400 res = obj2ast_expr(tmp, &right, arena);
7401 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007402 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007403 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007404 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7405 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007406 if (*out == NULL) goto failed;
7407 return 0;
7408 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007409 tp = astmodulestate_global->UnaryOp_type;
7410 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007411 if (isinstance == -1) {
7412 return 1;
7413 }
7414 if (isinstance) {
7415 unaryop_ty op;
7416 expr_ty operand;
7417
Dino Viehlandac46eb42019-09-11 10:16:34 -07007418 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007419 return 1;
7420 }
7421 if (tmp == NULL) {
7422 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7423 return 1;
7424 }
7425 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007426 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007427 res = obj2ast_unaryop(tmp, &op, arena);
7428 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007429 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007430 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007431 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7432 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007433 return 1;
7434 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007435 if (tmp == NULL) {
7436 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7437 return 1;
7438 }
7439 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007440 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007441 res = obj2ast_expr(tmp, &operand, arena);
7442 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007443 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007444 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007445 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7446 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007447 if (*out == NULL) goto failed;
7448 return 0;
7449 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007450 tp = astmodulestate_global->Lambda_type;
7451 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007452 if (isinstance == -1) {
7453 return 1;
7454 }
7455 if (isinstance) {
7456 arguments_ty args;
7457 expr_ty body;
7458
Dino Viehlandac46eb42019-09-11 10:16:34 -07007459 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007460 return 1;
7461 }
7462 if (tmp == NULL) {
7463 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7464 return 1;
7465 }
7466 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007467 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007468 res = obj2ast_arguments(tmp, &args, arena);
7469 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007470 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007471 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007472 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007473 return 1;
7474 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007475 if (tmp == NULL) {
7476 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7477 return 1;
7478 }
7479 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007480 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007481 res = obj2ast_expr(tmp, &body, arena);
7482 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007483 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007484 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007485 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7486 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007487 if (*out == NULL) goto failed;
7488 return 0;
7489 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007490 tp = astmodulestate_global->IfExp_type;
7491 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007492 if (isinstance == -1) {
7493 return 1;
7494 }
7495 if (isinstance) {
7496 expr_ty test;
7497 expr_ty body;
7498 expr_ty orelse;
7499
Dino Viehlandac46eb42019-09-11 10:16:34 -07007500 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007501 return 1;
7502 }
7503 if (tmp == NULL) {
7504 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7505 return 1;
7506 }
7507 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007508 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007509 res = obj2ast_expr(tmp, &test, arena);
7510 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007511 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007512 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007513 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007514 return 1;
7515 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007516 if (tmp == NULL) {
7517 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7518 return 1;
7519 }
7520 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007521 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007522 res = obj2ast_expr(tmp, &body, arena);
7523 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007524 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007525 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007526 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7527 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007528 return 1;
7529 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007530 if (tmp == NULL) {
7531 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7532 return 1;
7533 }
7534 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007535 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007536 res = obj2ast_expr(tmp, &orelse, arena);
7537 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007538 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007539 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007540 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7541 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007542 if (*out == NULL) goto failed;
7543 return 0;
7544 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007545 tp = astmodulestate_global->Dict_type;
7546 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007547 if (isinstance == -1) {
7548 return 1;
7549 }
7550 if (isinstance) {
7551 asdl_seq* keys;
7552 asdl_seq* values;
7553
Dino Viehlandac46eb42019-09-11 10:16:34 -07007554 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007555 return 1;
7556 }
7557 if (tmp == NULL) {
7558 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7559 return 1;
7560 }
7561 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007562 int res;
7563 Py_ssize_t len;
7564 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007565 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007566 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 +02007567 goto failed;
7568 }
7569 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007570 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007571 if (keys == NULL) goto failed;
7572 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007573 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007574 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7575 Py_INCREF(tmp2);
7576 res = obj2ast_expr(tmp2, &val, arena);
7577 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007578 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007579 if (len != PyList_GET_SIZE(tmp)) {
7580 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7581 goto failed;
7582 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007583 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007584 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007585 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007586 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007587 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7588 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007589 return 1;
7590 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007591 if (tmp == NULL) {
7592 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7593 return 1;
7594 }
7595 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007596 int res;
7597 Py_ssize_t len;
7598 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007599 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007600 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 +02007601 goto failed;
7602 }
7603 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007604 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007605 if (values == NULL) goto failed;
7606 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007607 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007608 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7609 Py_INCREF(tmp2);
7610 res = obj2ast_expr(tmp2, &val, arena);
7611 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007612 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007613 if (len != PyList_GET_SIZE(tmp)) {
7614 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7615 goto failed;
7616 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007617 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007618 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007619 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007620 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007621 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7622 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007623 if (*out == NULL) goto failed;
7624 return 0;
7625 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007626 tp = astmodulestate_global->Set_type;
7627 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007628 if (isinstance == -1) {
7629 return 1;
7630 }
7631 if (isinstance) {
7632 asdl_seq* elts;
7633
Dino Viehlandac46eb42019-09-11 10:16:34 -07007634 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007635 return 1;
7636 }
7637 if (tmp == NULL) {
7638 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7639 return 1;
7640 }
7641 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007642 int res;
7643 Py_ssize_t len;
7644 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007645 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007646 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 +02007647 goto failed;
7648 }
7649 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007650 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007651 if (elts == NULL) goto failed;
7652 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007653 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007654 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7655 Py_INCREF(tmp2);
7656 res = obj2ast_expr(tmp2, &val, arena);
7657 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007658 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007659 if (len != PyList_GET_SIZE(tmp)) {
7660 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7661 goto failed;
7662 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007663 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007664 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007665 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007666 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007667 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007668 if (*out == NULL) goto failed;
7669 return 0;
7670 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007671 tp = astmodulestate_global->ListComp_type;
7672 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007673 if (isinstance == -1) {
7674 return 1;
7675 }
7676 if (isinstance) {
7677 expr_ty elt;
7678 asdl_seq* generators;
7679
Dino Viehlandac46eb42019-09-11 10:16:34 -07007680 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007681 return 1;
7682 }
7683 if (tmp == NULL) {
7684 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7685 return 1;
7686 }
7687 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007688 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007689 res = obj2ast_expr(tmp, &elt, arena);
7690 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007691 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007692 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007693 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7694 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007695 return 1;
7696 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007697 if (tmp == NULL) {
7698 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7699 return 1;
7700 }
7701 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007702 int res;
7703 Py_ssize_t len;
7704 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007705 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007706 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 +02007707 goto failed;
7708 }
7709 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007710 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007711 if (generators == NULL) goto failed;
7712 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007713 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007714 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7715 Py_INCREF(tmp2);
7716 res = obj2ast_comprehension(tmp2, &val, arena);
7717 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007718 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007719 if (len != PyList_GET_SIZE(tmp)) {
7720 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7721 goto failed;
7722 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007723 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007724 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007725 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007726 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007727 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7728 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007729 if (*out == NULL) goto failed;
7730 return 0;
7731 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007732 tp = astmodulestate_global->SetComp_type;
7733 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007734 if (isinstance == -1) {
7735 return 1;
7736 }
7737 if (isinstance) {
7738 expr_ty elt;
7739 asdl_seq* generators;
7740
Dino Viehlandac46eb42019-09-11 10:16:34 -07007741 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007742 return 1;
7743 }
7744 if (tmp == NULL) {
7745 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7746 return 1;
7747 }
7748 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007749 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007750 res = obj2ast_expr(tmp, &elt, arena);
7751 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007752 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007753 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007754 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7755 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007756 return 1;
7757 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007758 if (tmp == NULL) {
7759 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7760 return 1;
7761 }
7762 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007763 int res;
7764 Py_ssize_t len;
7765 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007766 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007767 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 +02007768 goto failed;
7769 }
7770 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007771 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007772 if (generators == NULL) goto failed;
7773 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007774 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007775 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7776 Py_INCREF(tmp2);
7777 res = obj2ast_comprehension(tmp2, &val, arena);
7778 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007779 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007780 if (len != PyList_GET_SIZE(tmp)) {
7781 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7782 goto failed;
7783 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007784 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007785 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007786 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007787 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007788 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7789 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007790 if (*out == NULL) goto failed;
7791 return 0;
7792 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007793 tp = astmodulestate_global->DictComp_type;
7794 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007795 if (isinstance == -1) {
7796 return 1;
7797 }
7798 if (isinstance) {
7799 expr_ty key;
7800 expr_ty value;
7801 asdl_seq* generators;
7802
Dino Viehlandac46eb42019-09-11 10:16:34 -07007803 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007804 return 1;
7805 }
7806 if (tmp == NULL) {
7807 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7808 return 1;
7809 }
7810 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007811 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007812 res = obj2ast_expr(tmp, &key, arena);
7813 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007814 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007815 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007816 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007817 return 1;
7818 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007819 if (tmp == NULL) {
7820 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7821 return 1;
7822 }
7823 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007824 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007825 res = obj2ast_expr(tmp, &value, arena);
7826 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007827 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007828 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007829 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7830 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007831 return 1;
7832 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007833 if (tmp == NULL) {
7834 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7835 return 1;
7836 }
7837 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007838 int res;
7839 Py_ssize_t len;
7840 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007841 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007842 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 +02007843 goto failed;
7844 }
7845 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007846 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007847 if (generators == NULL) goto failed;
7848 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007849 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007850 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7851 Py_INCREF(tmp2);
7852 res = obj2ast_comprehension(tmp2, &val, arena);
7853 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007854 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007855 if (len != PyList_GET_SIZE(tmp)) {
7856 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7857 goto failed;
7858 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007859 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007860 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007861 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007862 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007863 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7864 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007865 if (*out == NULL) goto failed;
7866 return 0;
7867 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007868 tp = astmodulestate_global->GeneratorExp_type;
7869 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007870 if (isinstance == -1) {
7871 return 1;
7872 }
7873 if (isinstance) {
7874 expr_ty elt;
7875 asdl_seq* generators;
7876
Dino Viehlandac46eb42019-09-11 10:16:34 -07007877 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007878 return 1;
7879 }
7880 if (tmp == NULL) {
7881 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7882 return 1;
7883 }
7884 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007885 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007886 res = obj2ast_expr(tmp, &elt, arena);
7887 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007888 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007890 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7891 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007892 return 1;
7893 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007894 if (tmp == NULL) {
7895 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7896 return 1;
7897 }
7898 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007899 int res;
7900 Py_ssize_t len;
7901 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007902 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007903 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 +02007904 goto failed;
7905 }
7906 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007907 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007908 if (generators == NULL) goto failed;
7909 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007910 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007911 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7912 Py_INCREF(tmp2);
7913 res = obj2ast_comprehension(tmp2, &val, arena);
7914 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007915 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007916 if (len != PyList_GET_SIZE(tmp)) {
7917 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7918 goto failed;
7919 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007920 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007921 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007922 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007923 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007924 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7925 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007926 if (*out == NULL) goto failed;
7927 return 0;
7928 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007929 tp = astmodulestate_global->Await_type;
7930 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007931 if (isinstance == -1) {
7932 return 1;
7933 }
7934 if (isinstance) {
7935 expr_ty value;
7936
Dino Viehlandac46eb42019-09-11 10:16:34 -07007937 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007938 return 1;
7939 }
7940 if (tmp == NULL) {
7941 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7942 return 1;
7943 }
7944 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007945 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007946 res = obj2ast_expr(tmp, &value, arena);
7947 if (res != 0) goto failed;
7948 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007949 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007950 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7951 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007952 if (*out == NULL) goto failed;
7953 return 0;
7954 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007955 tp = astmodulestate_global->Yield_type;
7956 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007957 if (isinstance == -1) {
7958 return 1;
7959 }
7960 if (isinstance) {
7961 expr_ty value;
7962
Dino Viehlandac46eb42019-09-11 10:16:34 -07007963 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007964 return 1;
7965 }
7966 if (tmp == NULL || tmp == Py_None) {
7967 Py_CLEAR(tmp);
7968 value = NULL;
7969 }
7970 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007971 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007972 res = obj2ast_expr(tmp, &value, arena);
7973 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007974 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007975 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007976 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
7977 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007978 if (*out == NULL) goto failed;
7979 return 0;
7980 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007981 tp = astmodulestate_global->YieldFrom_type;
7982 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007983 if (isinstance == -1) {
7984 return 1;
7985 }
7986 if (isinstance) {
7987 expr_ty value;
7988
Dino Viehlandac46eb42019-09-11 10:16:34 -07007989 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007990 return 1;
7991 }
7992 if (tmp == NULL) {
7993 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
7994 return 1;
7995 }
7996 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007997 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007998 res = obj2ast_expr(tmp, &value, arena);
7999 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008000 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008001 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008002 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8003 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008004 if (*out == NULL) goto failed;
8005 return 0;
8006 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008007 tp = astmodulestate_global->Compare_type;
8008 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008009 if (isinstance == -1) {
8010 return 1;
8011 }
8012 if (isinstance) {
8013 expr_ty left;
8014 asdl_int_seq* ops;
8015 asdl_seq* comparators;
8016
Dino Viehlandac46eb42019-09-11 10:16:34 -07008017 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008018 return 1;
8019 }
8020 if (tmp == NULL) {
8021 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8022 return 1;
8023 }
8024 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008025 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008026 res = obj2ast_expr(tmp, &left, arena);
8027 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008028 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008030 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008031 return 1;
8032 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008033 if (tmp == NULL) {
8034 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8035 return 1;
8036 }
8037 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008038 int res;
8039 Py_ssize_t len;
8040 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008041 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008042 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 +02008043 goto failed;
8044 }
8045 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008046 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008047 if (ops == NULL) goto failed;
8048 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008049 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008050 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8051 Py_INCREF(tmp2);
8052 res = obj2ast_cmpop(tmp2, &val, arena);
8053 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008054 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008055 if (len != PyList_GET_SIZE(tmp)) {
8056 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8057 goto failed;
8058 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008059 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008060 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008061 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008063 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8064 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008065 return 1;
8066 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008067 if (tmp == NULL) {
8068 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8069 return 1;
8070 }
8071 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008072 int res;
8073 Py_ssize_t len;
8074 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008075 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008076 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 +02008077 goto failed;
8078 }
8079 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008080 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008081 if (comparators == NULL) goto failed;
8082 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008083 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008084 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8085 Py_INCREF(tmp2);
8086 res = obj2ast_expr(tmp2, &val, arena);
8087 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008088 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008089 if (len != PyList_GET_SIZE(tmp)) {
8090 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8091 goto failed;
8092 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008093 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008094 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008095 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008096 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008097 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8098 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008099 if (*out == NULL) goto failed;
8100 return 0;
8101 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008102 tp = astmodulestate_global->Call_type;
8103 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008104 if (isinstance == -1) {
8105 return 1;
8106 }
8107 if (isinstance) {
8108 expr_ty func;
8109 asdl_seq* args;
8110 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008111
Dino Viehlandac46eb42019-09-11 10:16:34 -07008112 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008113 return 1;
8114 }
8115 if (tmp == NULL) {
8116 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8117 return 1;
8118 }
8119 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008120 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008121 res = obj2ast_expr(tmp, &func, arena);
8122 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008123 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008124 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008125 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008126 return 1;
8127 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008128 if (tmp == NULL) {
8129 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8130 return 1;
8131 }
8132 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008133 int res;
8134 Py_ssize_t len;
8135 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008136 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008137 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 +02008138 goto failed;
8139 }
8140 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008141 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008142 if (args == NULL) goto failed;
8143 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008144 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008145 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8146 Py_INCREF(tmp2);
8147 res = obj2ast_expr(tmp2, &val, arena);
8148 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008149 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008150 if (len != PyList_GET_SIZE(tmp)) {
8151 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8152 goto failed;
8153 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008154 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008155 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008156 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008158 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8159 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008160 return 1;
8161 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008162 if (tmp == NULL) {
8163 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8164 return 1;
8165 }
8166 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008167 int res;
8168 Py_ssize_t len;
8169 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008170 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008171 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 +02008172 goto failed;
8173 }
8174 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008175 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008176 if (keywords == NULL) goto failed;
8177 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008178 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008179 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8180 Py_INCREF(tmp2);
8181 res = obj2ast_keyword(tmp2, &val, arena);
8182 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008183 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008184 if (len != PyList_GET_SIZE(tmp)) {
8185 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8186 goto failed;
8187 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008188 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008189 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008190 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008191 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008192 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8193 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008194 if (*out == NULL) goto failed;
8195 return 0;
8196 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008197 tp = astmodulestate_global->FormattedValue_type;
8198 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008199 if (isinstance == -1) {
8200 return 1;
8201 }
8202 if (isinstance) {
8203 expr_ty value;
8204 int conversion;
8205 expr_ty format_spec;
8206
Dino Viehlandac46eb42019-09-11 10:16:34 -07008207 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008208 return 1;
8209 }
8210 if (tmp == NULL) {
8211 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8212 return 1;
8213 }
8214 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008215 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008216 res = obj2ast_expr(tmp, &value, arena);
8217 if (res != 0) goto failed;
8218 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008219 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008220 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8221 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008222 return 1;
8223 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008224 if (tmp == NULL || tmp == Py_None) {
8225 Py_CLEAR(tmp);
8226 conversion = 0;
8227 }
8228 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008229 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008230 res = obj2ast_int(tmp, &conversion, arena);
8231 if (res != 0) goto failed;
8232 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008234 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8235 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008236 return 1;
8237 }
8238 if (tmp == NULL || tmp == Py_None) {
8239 Py_CLEAR(tmp);
8240 format_spec = NULL;
8241 }
8242 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008243 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008244 res = obj2ast_expr(tmp, &format_spec, arena);
8245 if (res != 0) goto failed;
8246 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008247 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008248 *out = FormattedValue(value, conversion, format_spec, lineno,
8249 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008250 if (*out == NULL) goto failed;
8251 return 0;
8252 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008253 tp = astmodulestate_global->JoinedStr_type;
8254 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008255 if (isinstance == -1) {
8256 return 1;
8257 }
8258 if (isinstance) {
8259 asdl_seq* values;
8260
Dino Viehlandac46eb42019-09-11 10:16:34 -07008261 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8262 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008263 return 1;
8264 }
8265 if (tmp == NULL) {
8266 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8267 return 1;
8268 }
8269 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008270 int res;
8271 Py_ssize_t len;
8272 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008273 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008274 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 -04008275 goto failed;
8276 }
8277 len = PyList_GET_SIZE(tmp);
8278 values = _Py_asdl_seq_new(len, arena);
8279 if (values == NULL) goto failed;
8280 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008281 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008282 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8283 Py_INCREF(tmp2);
8284 res = obj2ast_expr(tmp2, &val, arena);
8285 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008286 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008287 if (len != PyList_GET_SIZE(tmp)) {
8288 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8289 goto failed;
8290 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008291 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008292 }
8293 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008294 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008295 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8296 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008297 if (*out == NULL) goto failed;
8298 return 0;
8299 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008300 tp = astmodulestate_global->Constant_type;
8301 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008302 if (isinstance == -1) {
8303 return 1;
8304 }
8305 if (isinstance) {
8306 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008307 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008308
Dino Viehlandac46eb42019-09-11 10:16:34 -07008309 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008310 return 1;
8311 }
8312 if (tmp == NULL) {
8313 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8314 return 1;
8315 }
8316 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008317 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008318 res = obj2ast_constant(tmp, &value, arena);
8319 if (res != 0) goto failed;
8320 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008321 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008322 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008323 return 1;
8324 }
8325 if (tmp == NULL || tmp == Py_None) {
8326 Py_CLEAR(tmp);
8327 kind = NULL;
8328 }
8329 else {
8330 int res;
8331 res = obj2ast_string(tmp, &kind, arena);
8332 if (res != 0) goto failed;
8333 Py_CLEAR(tmp);
8334 }
8335 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8336 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008337 if (*out == NULL) goto failed;
8338 return 0;
8339 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008340 tp = astmodulestate_global->Attribute_type;
8341 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008342 if (isinstance == -1) {
8343 return 1;
8344 }
8345 if (isinstance) {
8346 expr_ty value;
8347 identifier attr;
8348 expr_context_ty ctx;
8349
Dino Viehlandac46eb42019-09-11 10:16:34 -07008350 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008351 return 1;
8352 }
8353 if (tmp == NULL) {
8354 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8355 return 1;
8356 }
8357 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008358 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008359 res = obj2ast_expr(tmp, &value, arena);
8360 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008361 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008362 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008363 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008364 return 1;
8365 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008366 if (tmp == NULL) {
8367 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8368 return 1;
8369 }
8370 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008371 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008372 res = obj2ast_identifier(tmp, &attr, arena);
8373 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008374 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008375 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008376 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008377 return 1;
8378 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008379 if (tmp == NULL) {
8380 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8381 return 1;
8382 }
8383 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008384 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008385 res = obj2ast_expr_context(tmp, &ctx, arena);
8386 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008387 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008388 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008389 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8390 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008391 if (*out == NULL) goto failed;
8392 return 0;
8393 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008394 tp = astmodulestate_global->Subscript_type;
8395 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008396 if (isinstance == -1) {
8397 return 1;
8398 }
8399 if (isinstance) {
8400 expr_ty value;
8401 slice_ty slice;
8402 expr_context_ty ctx;
8403
Dino Viehlandac46eb42019-09-11 10:16:34 -07008404 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008405 return 1;
8406 }
8407 if (tmp == NULL) {
8408 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8409 return 1;
8410 }
8411 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008412 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008413 res = obj2ast_expr(tmp, &value, arena);
8414 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008415 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008416 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008417 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008418 return 1;
8419 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008420 if (tmp == NULL) {
8421 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8422 return 1;
8423 }
8424 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008425 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008426 res = obj2ast_slice(tmp, &slice, arena);
8427 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008428 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008429 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008430 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008431 return 1;
8432 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008433 if (tmp == NULL) {
8434 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8435 return 1;
8436 }
8437 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008438 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008439 res = obj2ast_expr_context(tmp, &ctx, arena);
8440 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008441 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008442 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008443 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8444 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008445 if (*out == NULL) goto failed;
8446 return 0;
8447 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008448 tp = astmodulestate_global->Starred_type;
8449 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008450 if (isinstance == -1) {
8451 return 1;
8452 }
8453 if (isinstance) {
8454 expr_ty value;
8455 expr_context_ty ctx;
8456
Dino Viehlandac46eb42019-09-11 10:16:34 -07008457 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008458 return 1;
8459 }
8460 if (tmp == NULL) {
8461 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8462 return 1;
8463 }
8464 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008465 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008466 res = obj2ast_expr(tmp, &value, arena);
8467 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008468 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008469 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008470 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008471 return 1;
8472 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008473 if (tmp == NULL) {
8474 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8475 return 1;
8476 }
8477 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008478 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008479 res = obj2ast_expr_context(tmp, &ctx, arena);
8480 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008481 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008482 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008483 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8484 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008485 if (*out == NULL) goto failed;
8486 return 0;
8487 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008488 tp = astmodulestate_global->Name_type;
8489 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008490 if (isinstance == -1) {
8491 return 1;
8492 }
8493 if (isinstance) {
8494 identifier id;
8495 expr_context_ty ctx;
8496
Dino Viehlandac46eb42019-09-11 10:16:34 -07008497 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008498 return 1;
8499 }
8500 if (tmp == NULL) {
8501 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8502 return 1;
8503 }
8504 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008505 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008506 res = obj2ast_identifier(tmp, &id, arena);
8507 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008508 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008509 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008510 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008511 return 1;
8512 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008513 if (tmp == NULL) {
8514 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8515 return 1;
8516 }
8517 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008518 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008519 res = obj2ast_expr_context(tmp, &ctx, arena);
8520 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008521 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008522 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008523 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8524 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008525 if (*out == NULL) goto failed;
8526 return 0;
8527 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008528 tp = astmodulestate_global->List_type;
8529 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008530 if (isinstance == -1) {
8531 return 1;
8532 }
8533 if (isinstance) {
8534 asdl_seq* elts;
8535 expr_context_ty ctx;
8536
Dino Viehlandac46eb42019-09-11 10:16:34 -07008537 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008538 return 1;
8539 }
8540 if (tmp == NULL) {
8541 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8542 return 1;
8543 }
8544 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008545 int res;
8546 Py_ssize_t len;
8547 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008548 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008549 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 +02008550 goto failed;
8551 }
8552 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008553 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008554 if (elts == NULL) goto failed;
8555 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008556 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008557 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8558 Py_INCREF(tmp2);
8559 res = obj2ast_expr(tmp2, &val, arena);
8560 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008561 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008562 if (len != PyList_GET_SIZE(tmp)) {
8563 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8564 goto failed;
8565 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008566 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008567 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008568 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008569 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008570 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008571 return 1;
8572 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008573 if (tmp == NULL) {
8574 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8575 return 1;
8576 }
8577 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008578 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008579 res = obj2ast_expr_context(tmp, &ctx, arena);
8580 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008581 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008582 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008583 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8584 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008585 if (*out == NULL) goto failed;
8586 return 0;
8587 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008588 tp = astmodulestate_global->Tuple_type;
8589 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008590 if (isinstance == -1) {
8591 return 1;
8592 }
8593 if (isinstance) {
8594 asdl_seq* elts;
8595 expr_context_ty ctx;
8596
Dino Viehlandac46eb42019-09-11 10:16:34 -07008597 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008598 return 1;
8599 }
8600 if (tmp == NULL) {
8601 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8602 return 1;
8603 }
8604 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008605 int res;
8606 Py_ssize_t len;
8607 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008608 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008609 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 +02008610 goto failed;
8611 }
8612 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008613 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008614 if (elts == NULL) goto failed;
8615 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008616 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008617 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8618 Py_INCREF(tmp2);
8619 res = obj2ast_expr(tmp2, &val, arena);
8620 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008621 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008622 if (len != PyList_GET_SIZE(tmp)) {
8623 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8624 goto failed;
8625 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008626 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008627 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008628 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008629 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008630 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008631 return 1;
8632 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008633 if (tmp == NULL) {
8634 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8635 return 1;
8636 }
8637 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008638 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008639 res = obj2ast_expr_context(tmp, &ctx, arena);
8640 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008641 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008642 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008643 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8644 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008645 if (*out == NULL) goto failed;
8646 return 0;
8647 }
8648
8649 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8650 failed:
8651 Py_XDECREF(tmp);
8652 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008653}
8654
8655int
8656obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8657{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008658 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008659
Dino Viehlandac46eb42019-09-11 10:16:34 -07008660 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008661 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008662 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008663 }
8664 if (isinstance) {
8665 *out = Load;
8666 return 0;
8667 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008668 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008669 if (isinstance == -1) {
8670 return 1;
8671 }
8672 if (isinstance) {
8673 *out = Store;
8674 return 0;
8675 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008676 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008677 if (isinstance == -1) {
8678 return 1;
8679 }
8680 if (isinstance) {
8681 *out = Del;
8682 return 0;
8683 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008684 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008685 if (isinstance == -1) {
8686 return 1;
8687 }
8688 if (isinstance) {
8689 *out = AugLoad;
8690 return 0;
8691 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008692 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008693 if (isinstance == -1) {
8694 return 1;
8695 }
8696 if (isinstance) {
8697 *out = AugStore;
8698 return 0;
8699 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008700 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008701 if (isinstance == -1) {
8702 return 1;
8703 }
8704 if (isinstance) {
8705 *out = Param;
8706 return 0;
8707 }
8708
8709 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8710 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008711}
8712
8713int
8714obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
8715{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008716 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008717
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008718 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008719 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008720
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008721 if (obj == Py_None) {
8722 *out = NULL;
8723 return 0;
8724 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008725 tp = astmodulestate_global->Slice_type;
8726 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008727 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008728 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008729 }
8730 if (isinstance) {
8731 expr_ty lower;
8732 expr_ty upper;
8733 expr_ty step;
8734
Dino Viehlandac46eb42019-09-11 10:16:34 -07008735 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008736 return 1;
8737 }
8738 if (tmp == NULL || tmp == Py_None) {
8739 Py_CLEAR(tmp);
8740 lower = NULL;
8741 }
8742 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008743 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008744 res = obj2ast_expr(tmp, &lower, arena);
8745 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008746 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008747 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008748 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008749 return 1;
8750 }
8751 if (tmp == NULL || tmp == Py_None) {
8752 Py_CLEAR(tmp);
8753 upper = NULL;
8754 }
8755 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008756 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008757 res = obj2ast_expr(tmp, &upper, arena);
8758 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008759 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008760 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008761 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008762 return 1;
8763 }
8764 if (tmp == NULL || tmp == Py_None) {
8765 Py_CLEAR(tmp);
8766 step = NULL;
8767 }
8768 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008769 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008770 res = obj2ast_expr(tmp, &step, arena);
8771 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008772 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008773 }
8774 *out = Slice(lower, upper, step, arena);
8775 if (*out == NULL) goto failed;
8776 return 0;
8777 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008778 tp = astmodulestate_global->ExtSlice_type;
8779 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008780 if (isinstance == -1) {
8781 return 1;
8782 }
8783 if (isinstance) {
8784 asdl_seq* dims;
8785
Dino Viehlandac46eb42019-09-11 10:16:34 -07008786 if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008787 return 1;
8788 }
8789 if (tmp == NULL) {
8790 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
8791 return 1;
8792 }
8793 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008794 int res;
8795 Py_ssize_t len;
8796 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008797 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008798 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 +02008799 goto failed;
8800 }
8801 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008802 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008803 if (dims == NULL) goto failed;
8804 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008805 slice_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008806 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8807 Py_INCREF(tmp2);
8808 res = obj2ast_slice(tmp2, &val, arena);
8809 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008810 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008811 if (len != PyList_GET_SIZE(tmp)) {
8812 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
8813 goto failed;
8814 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008815 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008816 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008817 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008818 }
8819 *out = ExtSlice(dims, arena);
8820 if (*out == NULL) goto failed;
8821 return 0;
8822 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008823 tp = astmodulestate_global->Index_type;
8824 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008825 if (isinstance == -1) {
8826 return 1;
8827 }
8828 if (isinstance) {
8829 expr_ty value;
8830
Dino Viehlandac46eb42019-09-11 10:16:34 -07008831 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008832 return 1;
8833 }
8834 if (tmp == NULL) {
8835 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
8836 return 1;
8837 }
8838 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008839 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008840 res = obj2ast_expr(tmp, &value, arena);
8841 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008842 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008843 }
8844 *out = Index(value, arena);
8845 if (*out == NULL) goto failed;
8846 return 0;
8847 }
8848
8849 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
8850 failed:
8851 Py_XDECREF(tmp);
8852 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008853}
8854
8855int
8856obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8857{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008858 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008859
Dino Viehlandac46eb42019-09-11 10:16:34 -07008860 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008861 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008862 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008863 }
8864 if (isinstance) {
8865 *out = And;
8866 return 0;
8867 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008868 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008869 if (isinstance == -1) {
8870 return 1;
8871 }
8872 if (isinstance) {
8873 *out = Or;
8874 return 0;
8875 }
8876
8877 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8878 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008879}
8880
8881int
8882obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8883{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008884 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008885
Dino Viehlandac46eb42019-09-11 10:16:34 -07008886 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008887 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008888 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008889 }
8890 if (isinstance) {
8891 *out = Add;
8892 return 0;
8893 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008894 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008895 if (isinstance == -1) {
8896 return 1;
8897 }
8898 if (isinstance) {
8899 *out = Sub;
8900 return 0;
8901 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008902 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008903 if (isinstance == -1) {
8904 return 1;
8905 }
8906 if (isinstance) {
8907 *out = Mult;
8908 return 0;
8909 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008910 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008911 if (isinstance == -1) {
8912 return 1;
8913 }
8914 if (isinstance) {
8915 *out = MatMult;
8916 return 0;
8917 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008918 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008919 if (isinstance == -1) {
8920 return 1;
8921 }
8922 if (isinstance) {
8923 *out = Div;
8924 return 0;
8925 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008926 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008927 if (isinstance == -1) {
8928 return 1;
8929 }
8930 if (isinstance) {
8931 *out = Mod;
8932 return 0;
8933 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008934 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008935 if (isinstance == -1) {
8936 return 1;
8937 }
8938 if (isinstance) {
8939 *out = Pow;
8940 return 0;
8941 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008942 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008943 if (isinstance == -1) {
8944 return 1;
8945 }
8946 if (isinstance) {
8947 *out = LShift;
8948 return 0;
8949 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008950 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008951 if (isinstance == -1) {
8952 return 1;
8953 }
8954 if (isinstance) {
8955 *out = RShift;
8956 return 0;
8957 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008958 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008959 if (isinstance == -1) {
8960 return 1;
8961 }
8962 if (isinstance) {
8963 *out = BitOr;
8964 return 0;
8965 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008966 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008967 if (isinstance == -1) {
8968 return 1;
8969 }
8970 if (isinstance) {
8971 *out = BitXor;
8972 return 0;
8973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008974 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008975 if (isinstance == -1) {
8976 return 1;
8977 }
8978 if (isinstance) {
8979 *out = BitAnd;
8980 return 0;
8981 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008982 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008983 if (isinstance == -1) {
8984 return 1;
8985 }
8986 if (isinstance) {
8987 *out = FloorDiv;
8988 return 0;
8989 }
8990
8991 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8992 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008993}
8994
8995int
8996obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8997{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008998 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008999
Dino Viehlandac46eb42019-09-11 10:16:34 -07009000 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009001 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009002 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009003 }
9004 if (isinstance) {
9005 *out = Invert;
9006 return 0;
9007 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009008 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009009 if (isinstance == -1) {
9010 return 1;
9011 }
9012 if (isinstance) {
9013 *out = Not;
9014 return 0;
9015 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009016 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009017 if (isinstance == -1) {
9018 return 1;
9019 }
9020 if (isinstance) {
9021 *out = UAdd;
9022 return 0;
9023 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009024 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009025 if (isinstance == -1) {
9026 return 1;
9027 }
9028 if (isinstance) {
9029 *out = USub;
9030 return 0;
9031 }
9032
9033 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9034 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009035}
9036
9037int
9038obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9039{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009040 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009041
Dino Viehlandac46eb42019-09-11 10:16:34 -07009042 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009043 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009044 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009045 }
9046 if (isinstance) {
9047 *out = Eq;
9048 return 0;
9049 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009050 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009051 if (isinstance == -1) {
9052 return 1;
9053 }
9054 if (isinstance) {
9055 *out = NotEq;
9056 return 0;
9057 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009058 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009059 if (isinstance == -1) {
9060 return 1;
9061 }
9062 if (isinstance) {
9063 *out = Lt;
9064 return 0;
9065 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009066 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009067 if (isinstance == -1) {
9068 return 1;
9069 }
9070 if (isinstance) {
9071 *out = LtE;
9072 return 0;
9073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009074 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009075 if (isinstance == -1) {
9076 return 1;
9077 }
9078 if (isinstance) {
9079 *out = Gt;
9080 return 0;
9081 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009082 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009083 if (isinstance == -1) {
9084 return 1;
9085 }
9086 if (isinstance) {
9087 *out = GtE;
9088 return 0;
9089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009090 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009091 if (isinstance == -1) {
9092 return 1;
9093 }
9094 if (isinstance) {
9095 *out = Is;
9096 return 0;
9097 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009098 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009099 if (isinstance == -1) {
9100 return 1;
9101 }
9102 if (isinstance) {
9103 *out = IsNot;
9104 return 0;
9105 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009106 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009107 if (isinstance == -1) {
9108 return 1;
9109 }
9110 if (isinstance) {
9111 *out = In;
9112 return 0;
9113 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009114 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009115 if (isinstance == -1) {
9116 return 1;
9117 }
9118 if (isinstance) {
9119 *out = NotIn;
9120 return 0;
9121 }
9122
9123 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9124 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009125}
9126
9127int
9128obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9129{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009130 PyObject* tmp = NULL;
9131 expr_ty target;
9132 expr_ty iter;
9133 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009134 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009135
Dino Viehlandac46eb42019-09-11 10:16:34 -07009136 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009137 return 1;
9138 }
9139 if (tmp == NULL) {
9140 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9141 return 1;
9142 }
9143 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009144 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009145 res = obj2ast_expr(tmp, &target, arena);
9146 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009147 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009148 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009149 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009150 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009151 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009152 if (tmp == NULL) {
9153 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9154 return 1;
9155 }
9156 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009157 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009158 res = obj2ast_expr(tmp, &iter, arena);
9159 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009160 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009162 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009163 return 1;
9164 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009165 if (tmp == NULL) {
9166 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9167 return 1;
9168 }
9169 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009170 int res;
9171 Py_ssize_t len;
9172 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009173 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009174 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 +02009175 goto failed;
9176 }
9177 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009178 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009179 if (ifs == NULL) goto failed;
9180 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009181 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009182 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9183 Py_INCREF(tmp2);
9184 res = obj2ast_expr(tmp2, &val, arena);
9185 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009186 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009187 if (len != PyList_GET_SIZE(tmp)) {
9188 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9189 goto failed;
9190 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009191 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009192 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009193 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009194 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009195 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009196 return 1;
9197 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009198 if (tmp == NULL) {
9199 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9200 return 1;
9201 }
9202 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009203 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009204 res = obj2ast_int(tmp, &is_async, arena);
9205 if (res != 0) goto failed;
9206 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009207 }
9208 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009209 return 0;
9210failed:
9211 Py_XDECREF(tmp);
9212 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009213}
9214
9215int
9216obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9217{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009218 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009219
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009220 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009221 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009222 int lineno;
9223 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009224 int end_lineno;
9225 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009226
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009227 if (obj == Py_None) {
9228 *out = NULL;
9229 return 0;
9230 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009231 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009232 return 1;
9233 }
9234 if (tmp == NULL) {
9235 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9236 return 1;
9237 }
9238 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009239 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009240 res = obj2ast_int(tmp, &lineno, arena);
9241 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009242 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009243 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009244 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9245 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009246 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009247 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009248 if (tmp == NULL) {
9249 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9250 return 1;
9251 }
9252 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009253 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009254 res = obj2ast_int(tmp, &col_offset, arena);
9255 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009256 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009257 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009258 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9259 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009260 return 1;
9261 }
9262 if (tmp == NULL || tmp == Py_None) {
9263 Py_CLEAR(tmp);
9264 end_lineno = 0;
9265 }
9266 else {
9267 int res;
9268 res = obj2ast_int(tmp, &end_lineno, arena);
9269 if (res != 0) goto failed;
9270 Py_CLEAR(tmp);
9271 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009272 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9273 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009274 return 1;
9275 }
9276 if (tmp == NULL || tmp == Py_None) {
9277 Py_CLEAR(tmp);
9278 end_col_offset = 0;
9279 }
9280 else {
9281 int res;
9282 res = obj2ast_int(tmp, &end_col_offset, arena);
9283 if (res != 0) goto failed;
9284 Py_CLEAR(tmp);
9285 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009286 tp = astmodulestate_global->ExceptHandler_type;
9287 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009288 if (isinstance == -1) {
9289 return 1;
9290 }
9291 if (isinstance) {
9292 expr_ty type;
9293 identifier name;
9294 asdl_seq* body;
9295
Dino Viehlandac46eb42019-09-11 10:16:34 -07009296 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009297 return 1;
9298 }
9299 if (tmp == NULL || tmp == Py_None) {
9300 Py_CLEAR(tmp);
9301 type = NULL;
9302 }
9303 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009304 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009305 res = obj2ast_expr(tmp, &type, arena);
9306 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009307 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009309 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009310 return 1;
9311 }
9312 if (tmp == NULL || tmp == Py_None) {
9313 Py_CLEAR(tmp);
9314 name = NULL;
9315 }
9316 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009317 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009318 res = obj2ast_identifier(tmp, &name, arena);
9319 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009320 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009321 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009322 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009323 return 1;
9324 }
9325 if (tmp == NULL) {
9326 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9327 return 1;
9328 }
9329 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009330 int res;
9331 Py_ssize_t len;
9332 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009333 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009334 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 +02009335 goto failed;
9336 }
9337 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009338 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009339 if (body == NULL) goto failed;
9340 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009341 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009342 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9343 Py_INCREF(tmp2);
9344 res = obj2ast_stmt(tmp2, &val, arena);
9345 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009346 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009347 if (len != PyList_GET_SIZE(tmp)) {
9348 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9349 goto failed;
9350 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009351 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009352 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009353 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009354 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009355 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9356 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009357 if (*out == NULL) goto failed;
9358 return 0;
9359 }
9360
9361 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9362 failed:
9363 Py_XDECREF(tmp);
9364 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009365}
9366
9367int
9368obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9369{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009370 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009371 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009372 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009373 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009374 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009375 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009376 arg_ty kwarg;
9377 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009378
Dino Viehlandac46eb42019-09-11 10:16:34 -07009379 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9380 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009381 return 1;
9382 }
9383 if (tmp == NULL) {
9384 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9385 return 1;
9386 }
9387 else {
9388 int res;
9389 Py_ssize_t len;
9390 Py_ssize_t i;
9391 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009392 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 +01009393 goto failed;
9394 }
9395 len = PyList_GET_SIZE(tmp);
9396 posonlyargs = _Py_asdl_seq_new(len, arena);
9397 if (posonlyargs == NULL) goto failed;
9398 for (i = 0; i < len; i++) {
9399 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009400 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9401 Py_INCREF(tmp2);
9402 res = obj2ast_arg(tmp2, &val, arena);
9403 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009404 if (res != 0) goto failed;
9405 if (len != PyList_GET_SIZE(tmp)) {
9406 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9407 goto failed;
9408 }
9409 asdl_seq_SET(posonlyargs, i, val);
9410 }
9411 Py_CLEAR(tmp);
9412 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009413 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009414 return 1;
9415 }
9416 if (tmp == NULL) {
9417 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9418 return 1;
9419 }
9420 else {
9421 int res;
9422 Py_ssize_t len;
9423 Py_ssize_t i;
9424 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009425 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 +02009426 goto failed;
9427 }
9428 len = PyList_GET_SIZE(tmp);
9429 args = _Py_asdl_seq_new(len, arena);
9430 if (args == NULL) goto failed;
9431 for (i = 0; i < len; i++) {
9432 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009433 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9434 Py_INCREF(tmp2);
9435 res = obj2ast_arg(tmp2, &val, arena);
9436 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009437 if (res != 0) goto failed;
9438 if (len != PyList_GET_SIZE(tmp)) {
9439 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9440 goto failed;
9441 }
9442 asdl_seq_SET(args, i, val);
9443 }
9444 Py_CLEAR(tmp);
9445 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009446 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009447 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009448 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009449 if (tmp == NULL || tmp == Py_None) {
9450 Py_CLEAR(tmp);
9451 vararg = NULL;
9452 }
9453 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009454 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009455 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009456 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009457 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009458 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009459 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9460 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009461 return 1;
9462 }
9463 if (tmp == NULL) {
9464 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9465 return 1;
9466 }
9467 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009468 int res;
9469 Py_ssize_t len;
9470 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009471 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009472 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 +02009473 goto failed;
9474 }
9475 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009476 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009477 if (kwonlyargs == NULL) goto failed;
9478 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009479 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009480 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9481 Py_INCREF(tmp2);
9482 res = obj2ast_arg(tmp2, &val, arena);
9483 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009484 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009485 if (len != PyList_GET_SIZE(tmp)) {
9486 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9487 goto failed;
9488 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009489 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009490 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009491 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009492 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009493 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9494 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009495 return 1;
9496 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009497 if (tmp == NULL) {
9498 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9499 return 1;
9500 }
9501 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009502 int res;
9503 Py_ssize_t len;
9504 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009505 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009506 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 +02009507 goto failed;
9508 }
9509 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009510 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009511 if (kw_defaults == NULL) goto failed;
9512 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009513 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009514 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9515 Py_INCREF(tmp2);
9516 res = obj2ast_expr(tmp2, &val, arena);
9517 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009518 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009519 if (len != PyList_GET_SIZE(tmp)) {
9520 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9521 goto failed;
9522 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009523 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009524 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009525 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009526 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009527 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009528 return 1;
9529 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009530 if (tmp == NULL || tmp == Py_None) {
9531 Py_CLEAR(tmp);
9532 kwarg = NULL;
9533 }
9534 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009535 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009536 res = obj2ast_arg(tmp, &kwarg, arena);
9537 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009538 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009539 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009540 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009541 return 1;
9542 }
9543 if (tmp == NULL) {
9544 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9545 return 1;
9546 }
9547 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009548 int res;
9549 Py_ssize_t len;
9550 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009551 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009552 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 +02009553 goto failed;
9554 }
9555 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009556 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009557 if (defaults == NULL) goto failed;
9558 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009559 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009560 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9561 Py_INCREF(tmp2);
9562 res = obj2ast_expr(tmp2, &val, arena);
9563 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009564 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009565 if (len != PyList_GET_SIZE(tmp)) {
9566 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9567 goto failed;
9568 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009569 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009570 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009571 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009572 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009573 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009574 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009575 return 0;
9576failed:
9577 Py_XDECREF(tmp);
9578 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009579}
9580
9581int
9582obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9583{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009584 PyObject* tmp = NULL;
9585 identifier arg;
9586 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009587 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009588 int lineno;
9589 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009590 int end_lineno;
9591 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009592
Dino Viehlandac46eb42019-09-11 10:16:34 -07009593 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009594 return 1;
9595 }
9596 if (tmp == NULL) {
9597 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9598 return 1;
9599 }
9600 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009601 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009602 res = obj2ast_identifier(tmp, &arg, arena);
9603 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009604 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009605 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009606 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9607 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009608 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009609 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009610 if (tmp == NULL || tmp == Py_None) {
9611 Py_CLEAR(tmp);
9612 annotation = NULL;
9613 }
9614 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009615 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009616 res = obj2ast_expr(tmp, &annotation, arena);
9617 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009618 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009619 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009620 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9621 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009622 return 1;
9623 }
9624 if (tmp == NULL || tmp == Py_None) {
9625 Py_CLEAR(tmp);
9626 type_comment = NULL;
9627 }
9628 else {
9629 int res;
9630 res = obj2ast_string(tmp, &type_comment, arena);
9631 if (res != 0) goto failed;
9632 Py_CLEAR(tmp);
9633 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009634 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009635 return 1;
9636 }
9637 if (tmp == NULL) {
9638 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9639 return 1;
9640 }
9641 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009642 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009643 res = obj2ast_int(tmp, &lineno, arena);
9644 if (res != 0) goto failed;
9645 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009646 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009647 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9648 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009649 return 1;
9650 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009651 if (tmp == NULL) {
9652 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9653 return 1;
9654 }
9655 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009656 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009657 res = obj2ast_int(tmp, &col_offset, arena);
9658 if (res != 0) goto failed;
9659 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009660 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009661 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9662 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009663 return 1;
9664 }
9665 if (tmp == NULL || tmp == Py_None) {
9666 Py_CLEAR(tmp);
9667 end_lineno = 0;
9668 }
9669 else {
9670 int res;
9671 res = obj2ast_int(tmp, &end_lineno, arena);
9672 if (res != 0) goto failed;
9673 Py_CLEAR(tmp);
9674 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009675 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9676 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009677 return 1;
9678 }
9679 if (tmp == NULL || tmp == Py_None) {
9680 Py_CLEAR(tmp);
9681 end_col_offset = 0;
9682 }
9683 else {
9684 int res;
9685 res = obj2ast_int(tmp, &end_col_offset, arena);
9686 if (res != 0) goto failed;
9687 Py_CLEAR(tmp);
9688 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009689 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9690 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009691 return 0;
9692failed:
9693 Py_XDECREF(tmp);
9694 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009695}
9696
9697int
9698obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9699{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009700 PyObject* tmp = NULL;
9701 identifier arg;
9702 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009703
Dino Viehlandac46eb42019-09-11 10:16:34 -07009704 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009705 return 1;
9706 }
9707 if (tmp == NULL || tmp == Py_None) {
9708 Py_CLEAR(tmp);
9709 arg = NULL;
9710 }
9711 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009712 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009713 res = obj2ast_identifier(tmp, &arg, arena);
9714 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009715 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009716 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009717 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009718 return 1;
9719 }
9720 if (tmp == NULL) {
9721 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9722 return 1;
9723 }
9724 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009725 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009726 res = obj2ast_expr(tmp, &value, arena);
9727 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009728 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009729 }
9730 *out = keyword(arg, value, arena);
9731 return 0;
9732failed:
9733 Py_XDECREF(tmp);
9734 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009735}
9736
9737int
9738obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9739{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009740 PyObject* tmp = NULL;
9741 identifier name;
9742 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009743
Dino Viehlandac46eb42019-09-11 10:16:34 -07009744 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009745 return 1;
9746 }
9747 if (tmp == NULL) {
9748 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9749 return 1;
9750 }
9751 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009752 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009753 res = obj2ast_identifier(tmp, &name, arena);
9754 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009755 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009756 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009757 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009758 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009759 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009760 if (tmp == NULL || tmp == Py_None) {
9761 Py_CLEAR(tmp);
9762 asname = NULL;
9763 }
9764 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009765 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009766 res = obj2ast_identifier(tmp, &asname, arena);
9767 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009768 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009769 }
9770 *out = alias(name, asname, arena);
9771 return 0;
9772failed:
9773 Py_XDECREF(tmp);
9774 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009775}
9776
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009777int
9778obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9779{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009780 PyObject* tmp = NULL;
9781 expr_ty context_expr;
9782 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009783
Dino Viehlandac46eb42019-09-11 10:16:34 -07009784 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9785 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009786 return 1;
9787 }
9788 if (tmp == NULL) {
9789 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9790 return 1;
9791 }
9792 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009793 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009794 res = obj2ast_expr(tmp, &context_expr, arena);
9795 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009796 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009797 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009798 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9799 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009800 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009801 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009802 if (tmp == NULL || tmp == Py_None) {
9803 Py_CLEAR(tmp);
9804 optional_vars = NULL;
9805 }
9806 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009807 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009808 res = obj2ast_expr(tmp, &optional_vars, arena);
9809 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009810 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009811 }
9812 *out = withitem(context_expr, optional_vars, arena);
9813 return 0;
9814failed:
9815 Py_XDECREF(tmp);
9816 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009817}
9818
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009819int
9820obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9821{
9822 int isinstance;
9823
9824 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009825 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009826
9827 if (obj == Py_None) {
9828 *out = NULL;
9829 return 0;
9830 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009831 tp = astmodulestate_global->TypeIgnore_type;
9832 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009833 if (isinstance == -1) {
9834 return 1;
9835 }
9836 if (isinstance) {
9837 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009838 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009839
Dino Viehlandac46eb42019-09-11 10:16:34 -07009840 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9841 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009842 return 1;
9843 }
9844 if (tmp == NULL) {
9845 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9846 return 1;
9847 }
9848 else {
9849 int res;
9850 res = obj2ast_int(tmp, &lineno, arena);
9851 if (res != 0) goto failed;
9852 Py_CLEAR(tmp);
9853 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009854 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009855 return 1;
9856 }
9857 if (tmp == NULL) {
9858 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9859 return 1;
9860 }
9861 else {
9862 int res;
9863 res = obj2ast_string(tmp, &tag, arena);
9864 if (res != 0) goto failed;
9865 Py_CLEAR(tmp);
9866 }
9867 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009868 if (*out == NULL) goto failed;
9869 return 0;
9870 }
9871
9872 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9873 failed:
9874 Py_XDECREF(tmp);
9875 return 1;
9876}
9877
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009878
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009879PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009880PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009881{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009882 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009883 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009884 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009885 if (!m) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009886 Py_INCREF(astmodulestate(m)->AST_type);
9887 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0)
9888 return NULL;
Matthias Bussonnier565b4f12019-05-21 13:12:03 -07009889 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0)
9890 return NULL;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009891 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009892 return NULL;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009893 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)
9894 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009895 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0)
9896 return NULL;
9897 Py_INCREF(astmodulestate(m)->mod_type);
9898 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009899 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009900 Py_INCREF(astmodulestate(m)->Module_type);
9901 if (PyModule_AddObject(m, "Interactive",
9902 astmodulestate_global->Interactive_type) < 0) return NULL;
9903 Py_INCREF(astmodulestate(m)->Interactive_type);
9904 if (PyModule_AddObject(m, "Expression",
9905 astmodulestate_global->Expression_type) < 0) return NULL;
9906 Py_INCREF(astmodulestate(m)->Expression_type);
9907 if (PyModule_AddObject(m, "FunctionType",
9908 astmodulestate_global->FunctionType_type) < 0) return NULL;
9909 Py_INCREF(astmodulestate(m)->FunctionType_type);
9910 if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009911 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009912 Py_INCREF(astmodulestate(m)->Suite_type);
9913 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009914 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009915 Py_INCREF(astmodulestate(m)->stmt_type);
9916 if (PyModule_AddObject(m, "FunctionDef",
9917 astmodulestate_global->FunctionDef_type) < 0) return NULL;
9918 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9919 if (PyModule_AddObject(m, "AsyncFunctionDef",
9920 astmodulestate_global->AsyncFunctionDef_type) < 0) return NULL;
9921 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9922 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009923 < 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009924 Py_INCREF(astmodulestate(m)->ClassDef_type);
9925 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009926 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009927 Py_INCREF(astmodulestate(m)->Return_type);
9928 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
9929 0) return NULL;
9930 Py_INCREF(astmodulestate(m)->Delete_type);
9931 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
9932 0) return NULL;
9933 Py_INCREF(astmodulestate(m)->Assign_type);
9934 if (PyModule_AddObject(m, "AugAssign",
9935 astmodulestate_global->AugAssign_type) < 0) return NULL;
9936 Py_INCREF(astmodulestate(m)->AugAssign_type);
9937 if (PyModule_AddObject(m, "AnnAssign",
9938 astmodulestate_global->AnnAssign_type) < 0) return NULL;
9939 Py_INCREF(astmodulestate(m)->AnnAssign_type);
9940 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009941 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009942 Py_INCREF(astmodulestate(m)->For_type);
9943 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
9944 < 0) return NULL;
9945 Py_INCREF(astmodulestate(m)->AsyncFor_type);
9946 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0)
9947 return NULL;
9948 Py_INCREF(astmodulestate(m)->While_type);
9949 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) return
9950 NULL;
9951 Py_INCREF(astmodulestate(m)->If_type);
9952 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0)
9953 return NULL;
9954 Py_INCREF(astmodulestate(m)->With_type);
9955 if (PyModule_AddObject(m, "AsyncWith",
9956 astmodulestate_global->AsyncWith_type) < 0) return NULL;
9957 Py_INCREF(astmodulestate(m)->AsyncWith_type);
9958 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0)
9959 return NULL;
9960 Py_INCREF(astmodulestate(m)->Raise_type);
9961 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0)
9962 return NULL;
9963 Py_INCREF(astmodulestate(m)->Try_type);
9964 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
9965 0) return NULL;
9966 Py_INCREF(astmodulestate(m)->Assert_type);
9967 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
9968 0) return NULL;
9969 Py_INCREF(astmodulestate(m)->Import_type);
9970 if (PyModule_AddObject(m, "ImportFrom",
9971 astmodulestate_global->ImportFrom_type) < 0) return NULL;
9972 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9973 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
9974 0) return NULL;
9975 Py_INCREF(astmodulestate(m)->Global_type);
9976 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
9977 < 0) return NULL;
9978 Py_INCREF(astmodulestate(m)->Nonlocal_type);
9979 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0)
9980 return NULL;
9981 Py_INCREF(astmodulestate(m)->Expr_type);
9982 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0)
9983 return NULL;
9984 Py_INCREF(astmodulestate(m)->Pass_type);
9985 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0)
9986 return NULL;
9987 Py_INCREF(astmodulestate(m)->Break_type);
9988 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
9989 < 0) return NULL;
9990 Py_INCREF(astmodulestate(m)->Continue_type);
9991 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0)
9992 return NULL;
9993 Py_INCREF(astmodulestate(m)->expr_type);
9994 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
9995 0) return NULL;
9996 Py_INCREF(astmodulestate(m)->BoolOp_type);
9997 if (PyModule_AddObject(m, "NamedExpr",
9998 astmodulestate_global->NamedExpr_type) < 0) return NULL;
9999 Py_INCREF(astmodulestate(m)->NamedExpr_type);
10000 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0)
10001 return NULL;
10002 Py_INCREF(astmodulestate(m)->BinOp_type);
10003 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
10004 0) return NULL;
10005 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10006 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
10007 0) return NULL;
10008 Py_INCREF(astmodulestate(m)->Lambda_type);
10009 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0)
10010 return NULL;
10011 Py_INCREF(astmodulestate(m)->IfExp_type);
10012 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0)
10013 return NULL;
10014 Py_INCREF(astmodulestate(m)->Dict_type);
10015 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0)
10016 return NULL;
10017 Py_INCREF(astmodulestate(m)->Set_type);
10018 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
10019 < 0) return NULL;
10020 Py_INCREF(astmodulestate(m)->ListComp_type);
10021 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
10022 0) return NULL;
10023 Py_INCREF(astmodulestate(m)->SetComp_type);
10024 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
10025 < 0) return NULL;
10026 Py_INCREF(astmodulestate(m)->DictComp_type);
10027 if (PyModule_AddObject(m, "GeneratorExp",
10028 astmodulestate_global->GeneratorExp_type) < 0) return NULL;
10029 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
10030 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0)
10031 return NULL;
10032 Py_INCREF(astmodulestate(m)->Await_type);
10033 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0)
10034 return NULL;
10035 Py_INCREF(astmodulestate(m)->Yield_type);
10036 if (PyModule_AddObject(m, "YieldFrom",
10037 astmodulestate_global->YieldFrom_type) < 0) return NULL;
10038 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10039 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
10040 0) return NULL;
10041 Py_INCREF(astmodulestate(m)->Compare_type);
10042 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0)
10043 return NULL;
10044 Py_INCREF(astmodulestate(m)->Call_type);
10045 if (PyModule_AddObject(m, "FormattedValue",
10046 astmodulestate_global->FormattedValue_type) < 0) return NULL;
10047 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10048 if (PyModule_AddObject(m, "JoinedStr",
10049 astmodulestate_global->JoinedStr_type) < 0) return NULL;
10050 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10051 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
10052 < 0) return NULL;
10053 Py_INCREF(astmodulestate(m)->Constant_type);
10054 if (PyModule_AddObject(m, "Attribute",
10055 astmodulestate_global->Attribute_type) < 0) return NULL;
10056 Py_INCREF(astmodulestate(m)->Attribute_type);
10057 if (PyModule_AddObject(m, "Subscript",
10058 astmodulestate_global->Subscript_type) < 0) return NULL;
10059 Py_INCREF(astmodulestate(m)->Subscript_type);
10060 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
10061 0) return NULL;
10062 Py_INCREF(astmodulestate(m)->Starred_type);
10063 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0)
10064 return NULL;
10065 Py_INCREF(astmodulestate(m)->Name_type);
10066 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0)
10067 return NULL;
10068 Py_INCREF(astmodulestate(m)->List_type);
10069 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0)
10070 return NULL;
10071 Py_INCREF(astmodulestate(m)->Tuple_type);
10072 if (PyModule_AddObject(m, "expr_context",
10073 astmodulestate_global->expr_context_type) < 0) return NULL;
10074 Py_INCREF(astmodulestate(m)->expr_context_type);
10075 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0)
10076 return NULL;
10077 Py_INCREF(astmodulestate(m)->Load_type);
10078 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0)
10079 return NULL;
10080 Py_INCREF(astmodulestate(m)->Store_type);
10081 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0)
10082 return NULL;
10083 Py_INCREF(astmodulestate(m)->Del_type);
10084 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
10085 0) return NULL;
10086 Py_INCREF(astmodulestate(m)->AugLoad_type);
10087 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
10088 < 0) return NULL;
10089 Py_INCREF(astmodulestate(m)->AugStore_type);
10090 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0)
10091 return NULL;
10092 Py_INCREF(astmodulestate(m)->Param_type);
10093 if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0)
10094 return NULL;
10095 Py_INCREF(astmodulestate(m)->slice_type);
10096 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0)
10097 return NULL;
10098 Py_INCREF(astmodulestate(m)->Slice_type);
10099 if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type)
10100 < 0) return NULL;
10101 Py_INCREF(astmodulestate(m)->ExtSlice_type);
10102 if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0)
10103 return NULL;
10104 Py_INCREF(astmodulestate(m)->Index_type);
10105 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
10106 0) return NULL;
10107 Py_INCREF(astmodulestate(m)->boolop_type);
10108 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0)
10109 return NULL;
10110 Py_INCREF(astmodulestate(m)->And_type);
10111 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) return
10112 NULL;
10113 Py_INCREF(astmodulestate(m)->Or_type);
10114 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
10115 < 0) return NULL;
10116 Py_INCREF(astmodulestate(m)->operator_type);
10117 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0)
10118 return NULL;
10119 Py_INCREF(astmodulestate(m)->Add_type);
10120 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0)
10121 return NULL;
10122 Py_INCREF(astmodulestate(m)->Sub_type);
10123 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0)
10124 return NULL;
10125 Py_INCREF(astmodulestate(m)->Mult_type);
10126 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
10127 0) return NULL;
10128 Py_INCREF(astmodulestate(m)->MatMult_type);
10129 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0)
10130 return NULL;
10131 Py_INCREF(astmodulestate(m)->Div_type);
10132 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0)
10133 return NULL;
10134 Py_INCREF(astmodulestate(m)->Mod_type);
10135 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0)
10136 return NULL;
10137 Py_INCREF(astmodulestate(m)->Pow_type);
10138 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
10139 0) return NULL;
10140 Py_INCREF(astmodulestate(m)->LShift_type);
10141 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
10142 0) return NULL;
10143 Py_INCREF(astmodulestate(m)->RShift_type);
10144 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0)
10145 return NULL;
10146 Py_INCREF(astmodulestate(m)->BitOr_type);
10147 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
10148 0) return NULL;
10149 Py_INCREF(astmodulestate(m)->BitXor_type);
10150 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
10151 0) return NULL;
10152 Py_INCREF(astmodulestate(m)->BitAnd_type);
10153 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
10154 < 0) return NULL;
10155 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10156 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
10157 0) return NULL;
10158 Py_INCREF(astmodulestate(m)->unaryop_type);
10159 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
10160 0) return NULL;
10161 Py_INCREF(astmodulestate(m)->Invert_type);
10162 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0)
10163 return NULL;
10164 Py_INCREF(astmodulestate(m)->Not_type);
10165 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0)
10166 return NULL;
10167 Py_INCREF(astmodulestate(m)->UAdd_type);
10168 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0)
10169 return NULL;
10170 Py_INCREF(astmodulestate(m)->USub_type);
10171 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0)
10172 return NULL;
10173 Py_INCREF(astmodulestate(m)->cmpop_type);
10174 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) return
10175 NULL;
10176 Py_INCREF(astmodulestate(m)->Eq_type);
10177 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0)
10178 return NULL;
10179 Py_INCREF(astmodulestate(m)->NotEq_type);
10180 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) return
10181 NULL;
10182 Py_INCREF(astmodulestate(m)->Lt_type);
10183 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0)
10184 return NULL;
10185 Py_INCREF(astmodulestate(m)->LtE_type);
10186 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) return
10187 NULL;
10188 Py_INCREF(astmodulestate(m)->Gt_type);
10189 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0)
10190 return NULL;
10191 Py_INCREF(astmodulestate(m)->GtE_type);
10192 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) return
10193 NULL;
10194 Py_INCREF(astmodulestate(m)->Is_type);
10195 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0)
10196 return NULL;
10197 Py_INCREF(astmodulestate(m)->IsNot_type);
10198 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) return
10199 NULL;
10200 Py_INCREF(astmodulestate(m)->In_type);
10201 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0)
10202 return NULL;
10203 Py_INCREF(astmodulestate(m)->NotIn_type);
10204 if (PyModule_AddObject(m, "comprehension",
10205 astmodulestate_global->comprehension_type) < 0) return NULL;
10206 Py_INCREF(astmodulestate(m)->comprehension_type);
10207 if (PyModule_AddObject(m, "excepthandler",
10208 astmodulestate_global->excepthandler_type) < 0) return NULL;
10209 Py_INCREF(astmodulestate(m)->excepthandler_type);
10210 if (PyModule_AddObject(m, "ExceptHandler",
10211 astmodulestate_global->ExceptHandler_type) < 0) return NULL;
10212 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10213 if (PyModule_AddObject(m, "arguments",
10214 astmodulestate_global->arguments_type) < 0) return NULL;
10215 Py_INCREF(astmodulestate(m)->arguments_type);
10216 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0)
10217 return NULL;
10218 Py_INCREF(astmodulestate(m)->arg_type);
10219 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
10220 0) return NULL;
10221 Py_INCREF(astmodulestate(m)->keyword_type);
10222 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0)
10223 return NULL;
10224 Py_INCREF(astmodulestate(m)->alias_type);
10225 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
10226 < 0) return NULL;
10227 Py_INCREF(astmodulestate(m)->withitem_type);
10228 if (PyModule_AddObject(m, "type_ignore",
10229 astmodulestate_global->type_ignore_type) < 0) return NULL;
10230 Py_INCREF(astmodulestate(m)->type_ignore_type);
10231 if (PyModule_AddObject(m, "TypeIgnore",
10232 astmodulestate_global->TypeIgnore_type) < 0) return NULL;
10233 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010234 return m;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010235}
10236
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010237
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010238PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010239{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010240 if (!init_types())
10241 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010242 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010243}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010244
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010245/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10246mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010247{
10248 mod_ty res;
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010249 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010250 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010251 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010252
Steve Dowerb82e17e2019-05-23 08:45:22 -070010253 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10254 return NULL;
10255 }
10256
Dino Viehlandac46eb42019-09-11 10:16:34 -070010257 req_type[0] = astmodulestate_global->Module_type;
10258 req_type[1] = astmodulestate_global->Expression_type;
10259 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010260
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010261 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010262
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010263 if (!init_types())
10264 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010265
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010266 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10267 if (isinstance == -1)
10268 return NULL;
10269 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010270 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010271 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010272 return NULL;
10273 }
10274 if (obj2ast_mod(ast, &res, arena) != 0)
10275 return NULL;
10276 else
10277 return res;
10278}
10279
10280int PyAST_Check(PyObject* obj)
10281{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010282 if (!init_types())
10283 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010284 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010285}
10286
Martin v. Löwis5b222132007-06-10 09:51:05 +000010287