blob: e9925e742e733a26344f5d3d3a96672e31037493 [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"
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07007#include "structmember.h"
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00008
Dino Viehlandac46eb42019-09-11 10:16:34 -07009typedef struct {
10 int initialized;
11 PyObject *AST_type;
12 PyObject *Add_singleton;
13 PyObject *Add_type;
14 PyObject *And_singleton;
15 PyObject *And_type;
16 PyObject *AnnAssign_type;
17 PyObject *Assert_type;
18 PyObject *Assign_type;
19 PyObject *AsyncFor_type;
20 PyObject *AsyncFunctionDef_type;
21 PyObject *AsyncWith_type;
22 PyObject *Attribute_type;
23 PyObject *AugAssign_type;
24 PyObject *AugLoad_singleton;
25 PyObject *AugLoad_type;
26 PyObject *AugStore_singleton;
27 PyObject *AugStore_type;
28 PyObject *Await_type;
29 PyObject *BinOp_type;
30 PyObject *BitAnd_singleton;
31 PyObject *BitAnd_type;
32 PyObject *BitOr_singleton;
33 PyObject *BitOr_type;
34 PyObject *BitXor_singleton;
35 PyObject *BitXor_type;
36 PyObject *BoolOp_type;
37 PyObject *Break_type;
38 PyObject *Call_type;
39 PyObject *ClassDef_type;
40 PyObject *Compare_type;
41 PyObject *Constant_type;
42 PyObject *Continue_type;
43 PyObject *Del_singleton;
44 PyObject *Del_type;
45 PyObject *Delete_type;
46 PyObject *DictComp_type;
47 PyObject *Dict_type;
48 PyObject *Div_singleton;
49 PyObject *Div_type;
50 PyObject *Eq_singleton;
51 PyObject *Eq_type;
52 PyObject *ExceptHandler_type;
53 PyObject *Expr_type;
54 PyObject *Expression_type;
55 PyObject *ExtSlice_type;
56 PyObject *FloorDiv_singleton;
57 PyObject *FloorDiv_type;
58 PyObject *For_type;
59 PyObject *FormattedValue_type;
60 PyObject *FunctionDef_type;
61 PyObject *FunctionType_type;
62 PyObject *GeneratorExp_type;
63 PyObject *Global_type;
64 PyObject *GtE_singleton;
65 PyObject *GtE_type;
66 PyObject *Gt_singleton;
67 PyObject *Gt_type;
68 PyObject *IfExp_type;
69 PyObject *If_type;
70 PyObject *ImportFrom_type;
71 PyObject *Import_type;
72 PyObject *In_singleton;
73 PyObject *In_type;
74 PyObject *Index_type;
75 PyObject *Interactive_type;
76 PyObject *Invert_singleton;
77 PyObject *Invert_type;
78 PyObject *IsNot_singleton;
79 PyObject *IsNot_type;
80 PyObject *Is_singleton;
81 PyObject *Is_type;
82 PyObject *JoinedStr_type;
83 PyObject *LShift_singleton;
84 PyObject *LShift_type;
85 PyObject *Lambda_type;
86 PyObject *ListComp_type;
87 PyObject *List_type;
88 PyObject *Load_singleton;
89 PyObject *Load_type;
90 PyObject *LtE_singleton;
91 PyObject *LtE_type;
92 PyObject *Lt_singleton;
93 PyObject *Lt_type;
94 PyObject *MatMult_singleton;
95 PyObject *MatMult_type;
96 PyObject *Mod_singleton;
97 PyObject *Mod_type;
98 PyObject *Module_type;
99 PyObject *Mult_singleton;
100 PyObject *Mult_type;
101 PyObject *Name_type;
102 PyObject *NamedExpr_type;
103 PyObject *Nonlocal_type;
104 PyObject *NotEq_singleton;
105 PyObject *NotEq_type;
106 PyObject *NotIn_singleton;
107 PyObject *NotIn_type;
108 PyObject *Not_singleton;
109 PyObject *Not_type;
110 PyObject *Or_singleton;
111 PyObject *Or_type;
112 PyObject *Param_singleton;
113 PyObject *Param_type;
114 PyObject *Pass_type;
115 PyObject *Pow_singleton;
116 PyObject *Pow_type;
117 PyObject *RShift_singleton;
118 PyObject *RShift_type;
119 PyObject *Raise_type;
120 PyObject *Return_type;
121 PyObject *SetComp_type;
122 PyObject *Set_type;
123 PyObject *Slice_type;
124 PyObject *Starred_type;
125 PyObject *Store_singleton;
126 PyObject *Store_type;
127 PyObject *Sub_singleton;
128 PyObject *Sub_type;
129 PyObject *Subscript_type;
130 PyObject *Suite_type;
131 PyObject *Try_type;
132 PyObject *Tuple_type;
133 PyObject *TypeIgnore_type;
134 PyObject *UAdd_singleton;
135 PyObject *UAdd_type;
136 PyObject *USub_singleton;
137 PyObject *USub_type;
138 PyObject *UnaryOp_type;
139 PyObject *While_type;
140 PyObject *With_type;
141 PyObject *YieldFrom_type;
142 PyObject *Yield_type;
143 PyObject *__dict__;
144 PyObject *__module__;
145 PyObject *_ast;
146 PyObject *_attributes;
147 PyObject *_fields;
148 PyObject *alias_type;
149 PyObject *annotation;
150 PyObject *arg;
151 PyObject *arg_type;
152 PyObject *args;
153 PyObject *argtypes;
154 PyObject *arguments_type;
155 PyObject *asname;
156 PyObject *attr;
157 PyObject *bases;
158 PyObject *body;
159 PyObject *boolop_type;
160 PyObject *cause;
161 PyObject *cmpop_type;
162 PyObject *col_offset;
163 PyObject *comparators;
164 PyObject *comprehension_type;
165 PyObject *context_expr;
166 PyObject *conversion;
167 PyObject *ctx;
168 PyObject *decorator_list;
169 PyObject *defaults;
170 PyObject *dims;
171 PyObject *elt;
172 PyObject *elts;
173 PyObject *end_col_offset;
174 PyObject *end_lineno;
175 PyObject *exc;
176 PyObject *excepthandler_type;
177 PyObject *expr_context_type;
178 PyObject *expr_type;
179 PyObject *finalbody;
180 PyObject *format_spec;
181 PyObject *func;
182 PyObject *generators;
183 PyObject *handlers;
184 PyObject *id;
185 PyObject *ifs;
186 PyObject *is_async;
187 PyObject *items;
188 PyObject *iter;
189 PyObject *key;
190 PyObject *keys;
191 PyObject *keyword_type;
192 PyObject *keywords;
193 PyObject *kind;
194 PyObject *kw_defaults;
195 PyObject *kwarg;
196 PyObject *kwonlyargs;
197 PyObject *left;
198 PyObject *level;
199 PyObject *lineno;
200 PyObject *lower;
201 PyObject *mod_type;
202 PyObject *module;
203 PyObject *msg;
204 PyObject *name;
205 PyObject *names;
206 PyObject *op;
207 PyObject *operand;
208 PyObject *operator_type;
209 PyObject *ops;
210 PyObject *optional_vars;
211 PyObject *orelse;
212 PyObject *posonlyargs;
213 PyObject *returns;
214 PyObject *right;
215 PyObject *simple;
216 PyObject *slice;
217 PyObject *slice_type;
218 PyObject *step;
219 PyObject *stmt_type;
220 PyObject *tag;
221 PyObject *target;
222 PyObject *targets;
223 PyObject *test;
224 PyObject *type;
225 PyObject *type_comment;
226 PyObject *type_ignore_type;
227 PyObject *type_ignores;
228 PyObject *unaryop_type;
229 PyObject *upper;
230 PyObject *value;
231 PyObject *values;
232 PyObject *vararg;
233 PyObject *withitem_type;
234} astmodulestate;
235
236
237#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
238
239static int astmodule_clear(PyObject *module)
240{
241 Py_CLEAR(astmodulestate(module)->AST_type);
242 Py_CLEAR(astmodulestate(module)->Add_singleton);
243 Py_CLEAR(astmodulestate(module)->Add_type);
244 Py_CLEAR(astmodulestate(module)->And_singleton);
245 Py_CLEAR(astmodulestate(module)->And_type);
246 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
247 Py_CLEAR(astmodulestate(module)->Assert_type);
248 Py_CLEAR(astmodulestate(module)->Assign_type);
249 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
250 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
251 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
252 Py_CLEAR(astmodulestate(module)->Attribute_type);
253 Py_CLEAR(astmodulestate(module)->AugAssign_type);
254 Py_CLEAR(astmodulestate(module)->AugLoad_singleton);
255 Py_CLEAR(astmodulestate(module)->AugLoad_type);
256 Py_CLEAR(astmodulestate(module)->AugStore_singleton);
257 Py_CLEAR(astmodulestate(module)->AugStore_type);
258 Py_CLEAR(astmodulestate(module)->Await_type);
259 Py_CLEAR(astmodulestate(module)->BinOp_type);
260 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
261 Py_CLEAR(astmodulestate(module)->BitAnd_type);
262 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
263 Py_CLEAR(astmodulestate(module)->BitOr_type);
264 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
265 Py_CLEAR(astmodulestate(module)->BitXor_type);
266 Py_CLEAR(astmodulestate(module)->BoolOp_type);
267 Py_CLEAR(astmodulestate(module)->Break_type);
268 Py_CLEAR(astmodulestate(module)->Call_type);
269 Py_CLEAR(astmodulestate(module)->ClassDef_type);
270 Py_CLEAR(astmodulestate(module)->Compare_type);
271 Py_CLEAR(astmodulestate(module)->Constant_type);
272 Py_CLEAR(astmodulestate(module)->Continue_type);
273 Py_CLEAR(astmodulestate(module)->Del_singleton);
274 Py_CLEAR(astmodulestate(module)->Del_type);
275 Py_CLEAR(astmodulestate(module)->Delete_type);
276 Py_CLEAR(astmodulestate(module)->DictComp_type);
277 Py_CLEAR(astmodulestate(module)->Dict_type);
278 Py_CLEAR(astmodulestate(module)->Div_singleton);
279 Py_CLEAR(astmodulestate(module)->Div_type);
280 Py_CLEAR(astmodulestate(module)->Eq_singleton);
281 Py_CLEAR(astmodulestate(module)->Eq_type);
282 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
283 Py_CLEAR(astmodulestate(module)->Expr_type);
284 Py_CLEAR(astmodulestate(module)->Expression_type);
285 Py_CLEAR(astmodulestate(module)->ExtSlice_type);
286 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
287 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
288 Py_CLEAR(astmodulestate(module)->For_type);
289 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
290 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
291 Py_CLEAR(astmodulestate(module)->FunctionType_type);
292 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
293 Py_CLEAR(astmodulestate(module)->Global_type);
294 Py_CLEAR(astmodulestate(module)->GtE_singleton);
295 Py_CLEAR(astmodulestate(module)->GtE_type);
296 Py_CLEAR(astmodulestate(module)->Gt_singleton);
297 Py_CLEAR(astmodulestate(module)->Gt_type);
298 Py_CLEAR(astmodulestate(module)->IfExp_type);
299 Py_CLEAR(astmodulestate(module)->If_type);
300 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
301 Py_CLEAR(astmodulestate(module)->Import_type);
302 Py_CLEAR(astmodulestate(module)->In_singleton);
303 Py_CLEAR(astmodulestate(module)->In_type);
304 Py_CLEAR(astmodulestate(module)->Index_type);
305 Py_CLEAR(astmodulestate(module)->Interactive_type);
306 Py_CLEAR(astmodulestate(module)->Invert_singleton);
307 Py_CLEAR(astmodulestate(module)->Invert_type);
308 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
309 Py_CLEAR(astmodulestate(module)->IsNot_type);
310 Py_CLEAR(astmodulestate(module)->Is_singleton);
311 Py_CLEAR(astmodulestate(module)->Is_type);
312 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
313 Py_CLEAR(astmodulestate(module)->LShift_singleton);
314 Py_CLEAR(astmodulestate(module)->LShift_type);
315 Py_CLEAR(astmodulestate(module)->Lambda_type);
316 Py_CLEAR(astmodulestate(module)->ListComp_type);
317 Py_CLEAR(astmodulestate(module)->List_type);
318 Py_CLEAR(astmodulestate(module)->Load_singleton);
319 Py_CLEAR(astmodulestate(module)->Load_type);
320 Py_CLEAR(astmodulestate(module)->LtE_singleton);
321 Py_CLEAR(astmodulestate(module)->LtE_type);
322 Py_CLEAR(astmodulestate(module)->Lt_singleton);
323 Py_CLEAR(astmodulestate(module)->Lt_type);
324 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
325 Py_CLEAR(astmodulestate(module)->MatMult_type);
326 Py_CLEAR(astmodulestate(module)->Mod_singleton);
327 Py_CLEAR(astmodulestate(module)->Mod_type);
328 Py_CLEAR(astmodulestate(module)->Module_type);
329 Py_CLEAR(astmodulestate(module)->Mult_singleton);
330 Py_CLEAR(astmodulestate(module)->Mult_type);
331 Py_CLEAR(astmodulestate(module)->Name_type);
332 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
333 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
334 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
335 Py_CLEAR(astmodulestate(module)->NotEq_type);
336 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
337 Py_CLEAR(astmodulestate(module)->NotIn_type);
338 Py_CLEAR(astmodulestate(module)->Not_singleton);
339 Py_CLEAR(astmodulestate(module)->Not_type);
340 Py_CLEAR(astmodulestate(module)->Or_singleton);
341 Py_CLEAR(astmodulestate(module)->Or_type);
342 Py_CLEAR(astmodulestate(module)->Param_singleton);
343 Py_CLEAR(astmodulestate(module)->Param_type);
344 Py_CLEAR(astmodulestate(module)->Pass_type);
345 Py_CLEAR(astmodulestate(module)->Pow_singleton);
346 Py_CLEAR(astmodulestate(module)->Pow_type);
347 Py_CLEAR(astmodulestate(module)->RShift_singleton);
348 Py_CLEAR(astmodulestate(module)->RShift_type);
349 Py_CLEAR(astmodulestate(module)->Raise_type);
350 Py_CLEAR(astmodulestate(module)->Return_type);
351 Py_CLEAR(astmodulestate(module)->SetComp_type);
352 Py_CLEAR(astmodulestate(module)->Set_type);
353 Py_CLEAR(astmodulestate(module)->Slice_type);
354 Py_CLEAR(astmodulestate(module)->Starred_type);
355 Py_CLEAR(astmodulestate(module)->Store_singleton);
356 Py_CLEAR(astmodulestate(module)->Store_type);
357 Py_CLEAR(astmodulestate(module)->Sub_singleton);
358 Py_CLEAR(astmodulestate(module)->Sub_type);
359 Py_CLEAR(astmodulestate(module)->Subscript_type);
360 Py_CLEAR(astmodulestate(module)->Suite_type);
361 Py_CLEAR(astmodulestate(module)->Try_type);
362 Py_CLEAR(astmodulestate(module)->Tuple_type);
363 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
364 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
365 Py_CLEAR(astmodulestate(module)->UAdd_type);
366 Py_CLEAR(astmodulestate(module)->USub_singleton);
367 Py_CLEAR(astmodulestate(module)->USub_type);
368 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
369 Py_CLEAR(astmodulestate(module)->While_type);
370 Py_CLEAR(astmodulestate(module)->With_type);
371 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
372 Py_CLEAR(astmodulestate(module)->Yield_type);
373 Py_CLEAR(astmodulestate(module)->__dict__);
374 Py_CLEAR(astmodulestate(module)->__module__);
375 Py_CLEAR(astmodulestate(module)->_ast);
376 Py_CLEAR(astmodulestate(module)->_attributes);
377 Py_CLEAR(astmodulestate(module)->_fields);
378 Py_CLEAR(astmodulestate(module)->alias_type);
379 Py_CLEAR(astmodulestate(module)->annotation);
380 Py_CLEAR(astmodulestate(module)->arg);
381 Py_CLEAR(astmodulestate(module)->arg_type);
382 Py_CLEAR(astmodulestate(module)->args);
383 Py_CLEAR(astmodulestate(module)->argtypes);
384 Py_CLEAR(astmodulestate(module)->arguments_type);
385 Py_CLEAR(astmodulestate(module)->asname);
386 Py_CLEAR(astmodulestate(module)->attr);
387 Py_CLEAR(astmodulestate(module)->bases);
388 Py_CLEAR(astmodulestate(module)->body);
389 Py_CLEAR(astmodulestate(module)->boolop_type);
390 Py_CLEAR(astmodulestate(module)->cause);
391 Py_CLEAR(astmodulestate(module)->cmpop_type);
392 Py_CLEAR(astmodulestate(module)->col_offset);
393 Py_CLEAR(astmodulestate(module)->comparators);
394 Py_CLEAR(astmodulestate(module)->comprehension_type);
395 Py_CLEAR(astmodulestate(module)->context_expr);
396 Py_CLEAR(astmodulestate(module)->conversion);
397 Py_CLEAR(astmodulestate(module)->ctx);
398 Py_CLEAR(astmodulestate(module)->decorator_list);
399 Py_CLEAR(astmodulestate(module)->defaults);
400 Py_CLEAR(astmodulestate(module)->dims);
401 Py_CLEAR(astmodulestate(module)->elt);
402 Py_CLEAR(astmodulestate(module)->elts);
403 Py_CLEAR(astmodulestate(module)->end_col_offset);
404 Py_CLEAR(astmodulestate(module)->end_lineno);
405 Py_CLEAR(astmodulestate(module)->exc);
406 Py_CLEAR(astmodulestate(module)->excepthandler_type);
407 Py_CLEAR(astmodulestate(module)->expr_context_type);
408 Py_CLEAR(astmodulestate(module)->expr_type);
409 Py_CLEAR(astmodulestate(module)->finalbody);
410 Py_CLEAR(astmodulestate(module)->format_spec);
411 Py_CLEAR(astmodulestate(module)->func);
412 Py_CLEAR(astmodulestate(module)->generators);
413 Py_CLEAR(astmodulestate(module)->handlers);
414 Py_CLEAR(astmodulestate(module)->id);
415 Py_CLEAR(astmodulestate(module)->ifs);
416 Py_CLEAR(astmodulestate(module)->is_async);
417 Py_CLEAR(astmodulestate(module)->items);
418 Py_CLEAR(astmodulestate(module)->iter);
419 Py_CLEAR(astmodulestate(module)->key);
420 Py_CLEAR(astmodulestate(module)->keys);
421 Py_CLEAR(astmodulestate(module)->keyword_type);
422 Py_CLEAR(astmodulestate(module)->keywords);
423 Py_CLEAR(astmodulestate(module)->kind);
424 Py_CLEAR(astmodulestate(module)->kw_defaults);
425 Py_CLEAR(astmodulestate(module)->kwarg);
426 Py_CLEAR(astmodulestate(module)->kwonlyargs);
427 Py_CLEAR(astmodulestate(module)->left);
428 Py_CLEAR(astmodulestate(module)->level);
429 Py_CLEAR(astmodulestate(module)->lineno);
430 Py_CLEAR(astmodulestate(module)->lower);
431 Py_CLEAR(astmodulestate(module)->mod_type);
432 Py_CLEAR(astmodulestate(module)->module);
433 Py_CLEAR(astmodulestate(module)->msg);
434 Py_CLEAR(astmodulestate(module)->name);
435 Py_CLEAR(astmodulestate(module)->names);
436 Py_CLEAR(astmodulestate(module)->op);
437 Py_CLEAR(astmodulestate(module)->operand);
438 Py_CLEAR(astmodulestate(module)->operator_type);
439 Py_CLEAR(astmodulestate(module)->ops);
440 Py_CLEAR(astmodulestate(module)->optional_vars);
441 Py_CLEAR(astmodulestate(module)->orelse);
442 Py_CLEAR(astmodulestate(module)->posonlyargs);
443 Py_CLEAR(astmodulestate(module)->returns);
444 Py_CLEAR(astmodulestate(module)->right);
445 Py_CLEAR(astmodulestate(module)->simple);
446 Py_CLEAR(astmodulestate(module)->slice);
447 Py_CLEAR(astmodulestate(module)->slice_type);
448 Py_CLEAR(astmodulestate(module)->step);
449 Py_CLEAR(astmodulestate(module)->stmt_type);
450 Py_CLEAR(astmodulestate(module)->tag);
451 Py_CLEAR(astmodulestate(module)->target);
452 Py_CLEAR(astmodulestate(module)->targets);
453 Py_CLEAR(astmodulestate(module)->test);
454 Py_CLEAR(astmodulestate(module)->type);
455 Py_CLEAR(astmodulestate(module)->type_comment);
456 Py_CLEAR(astmodulestate(module)->type_ignore_type);
457 Py_CLEAR(astmodulestate(module)->type_ignores);
458 Py_CLEAR(astmodulestate(module)->unaryop_type);
459 Py_CLEAR(astmodulestate(module)->upper);
460 Py_CLEAR(astmodulestate(module)->value);
461 Py_CLEAR(astmodulestate(module)->values);
462 Py_CLEAR(astmodulestate(module)->vararg);
463 Py_CLEAR(astmodulestate(module)->withitem_type);
464
465 return 0;
466}
467
468static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
469{
470 Py_VISIT(astmodulestate(module)->AST_type);
471 Py_VISIT(astmodulestate(module)->Add_singleton);
472 Py_VISIT(astmodulestate(module)->Add_type);
473 Py_VISIT(astmodulestate(module)->And_singleton);
474 Py_VISIT(astmodulestate(module)->And_type);
475 Py_VISIT(astmodulestate(module)->AnnAssign_type);
476 Py_VISIT(astmodulestate(module)->Assert_type);
477 Py_VISIT(astmodulestate(module)->Assign_type);
478 Py_VISIT(astmodulestate(module)->AsyncFor_type);
479 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
480 Py_VISIT(astmodulestate(module)->AsyncWith_type);
481 Py_VISIT(astmodulestate(module)->Attribute_type);
482 Py_VISIT(astmodulestate(module)->AugAssign_type);
483 Py_VISIT(astmodulestate(module)->AugLoad_singleton);
484 Py_VISIT(astmodulestate(module)->AugLoad_type);
485 Py_VISIT(astmodulestate(module)->AugStore_singleton);
486 Py_VISIT(astmodulestate(module)->AugStore_type);
487 Py_VISIT(astmodulestate(module)->Await_type);
488 Py_VISIT(astmodulestate(module)->BinOp_type);
489 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
490 Py_VISIT(astmodulestate(module)->BitAnd_type);
491 Py_VISIT(astmodulestate(module)->BitOr_singleton);
492 Py_VISIT(astmodulestate(module)->BitOr_type);
493 Py_VISIT(astmodulestate(module)->BitXor_singleton);
494 Py_VISIT(astmodulestate(module)->BitXor_type);
495 Py_VISIT(astmodulestate(module)->BoolOp_type);
496 Py_VISIT(astmodulestate(module)->Break_type);
497 Py_VISIT(astmodulestate(module)->Call_type);
498 Py_VISIT(astmodulestate(module)->ClassDef_type);
499 Py_VISIT(astmodulestate(module)->Compare_type);
500 Py_VISIT(astmodulestate(module)->Constant_type);
501 Py_VISIT(astmodulestate(module)->Continue_type);
502 Py_VISIT(astmodulestate(module)->Del_singleton);
503 Py_VISIT(astmodulestate(module)->Del_type);
504 Py_VISIT(astmodulestate(module)->Delete_type);
505 Py_VISIT(astmodulestate(module)->DictComp_type);
506 Py_VISIT(astmodulestate(module)->Dict_type);
507 Py_VISIT(astmodulestate(module)->Div_singleton);
508 Py_VISIT(astmodulestate(module)->Div_type);
509 Py_VISIT(astmodulestate(module)->Eq_singleton);
510 Py_VISIT(astmodulestate(module)->Eq_type);
511 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
512 Py_VISIT(astmodulestate(module)->Expr_type);
513 Py_VISIT(astmodulestate(module)->Expression_type);
514 Py_VISIT(astmodulestate(module)->ExtSlice_type);
515 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
516 Py_VISIT(astmodulestate(module)->FloorDiv_type);
517 Py_VISIT(astmodulestate(module)->For_type);
518 Py_VISIT(astmodulestate(module)->FormattedValue_type);
519 Py_VISIT(astmodulestate(module)->FunctionDef_type);
520 Py_VISIT(astmodulestate(module)->FunctionType_type);
521 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
522 Py_VISIT(astmodulestate(module)->Global_type);
523 Py_VISIT(astmodulestate(module)->GtE_singleton);
524 Py_VISIT(astmodulestate(module)->GtE_type);
525 Py_VISIT(astmodulestate(module)->Gt_singleton);
526 Py_VISIT(astmodulestate(module)->Gt_type);
527 Py_VISIT(astmodulestate(module)->IfExp_type);
528 Py_VISIT(astmodulestate(module)->If_type);
529 Py_VISIT(astmodulestate(module)->ImportFrom_type);
530 Py_VISIT(astmodulestate(module)->Import_type);
531 Py_VISIT(astmodulestate(module)->In_singleton);
532 Py_VISIT(astmodulestate(module)->In_type);
533 Py_VISIT(astmodulestate(module)->Index_type);
534 Py_VISIT(astmodulestate(module)->Interactive_type);
535 Py_VISIT(astmodulestate(module)->Invert_singleton);
536 Py_VISIT(astmodulestate(module)->Invert_type);
537 Py_VISIT(astmodulestate(module)->IsNot_singleton);
538 Py_VISIT(astmodulestate(module)->IsNot_type);
539 Py_VISIT(astmodulestate(module)->Is_singleton);
540 Py_VISIT(astmodulestate(module)->Is_type);
541 Py_VISIT(astmodulestate(module)->JoinedStr_type);
542 Py_VISIT(astmodulestate(module)->LShift_singleton);
543 Py_VISIT(astmodulestate(module)->LShift_type);
544 Py_VISIT(astmodulestate(module)->Lambda_type);
545 Py_VISIT(astmodulestate(module)->ListComp_type);
546 Py_VISIT(astmodulestate(module)->List_type);
547 Py_VISIT(astmodulestate(module)->Load_singleton);
548 Py_VISIT(astmodulestate(module)->Load_type);
549 Py_VISIT(astmodulestate(module)->LtE_singleton);
550 Py_VISIT(astmodulestate(module)->LtE_type);
551 Py_VISIT(astmodulestate(module)->Lt_singleton);
552 Py_VISIT(astmodulestate(module)->Lt_type);
553 Py_VISIT(astmodulestate(module)->MatMult_singleton);
554 Py_VISIT(astmodulestate(module)->MatMult_type);
555 Py_VISIT(astmodulestate(module)->Mod_singleton);
556 Py_VISIT(astmodulestate(module)->Mod_type);
557 Py_VISIT(astmodulestate(module)->Module_type);
558 Py_VISIT(astmodulestate(module)->Mult_singleton);
559 Py_VISIT(astmodulestate(module)->Mult_type);
560 Py_VISIT(astmodulestate(module)->Name_type);
561 Py_VISIT(astmodulestate(module)->NamedExpr_type);
562 Py_VISIT(astmodulestate(module)->Nonlocal_type);
563 Py_VISIT(astmodulestate(module)->NotEq_singleton);
564 Py_VISIT(astmodulestate(module)->NotEq_type);
565 Py_VISIT(astmodulestate(module)->NotIn_singleton);
566 Py_VISIT(astmodulestate(module)->NotIn_type);
567 Py_VISIT(astmodulestate(module)->Not_singleton);
568 Py_VISIT(astmodulestate(module)->Not_type);
569 Py_VISIT(astmodulestate(module)->Or_singleton);
570 Py_VISIT(astmodulestate(module)->Or_type);
571 Py_VISIT(astmodulestate(module)->Param_singleton);
572 Py_VISIT(astmodulestate(module)->Param_type);
573 Py_VISIT(astmodulestate(module)->Pass_type);
574 Py_VISIT(astmodulestate(module)->Pow_singleton);
575 Py_VISIT(astmodulestate(module)->Pow_type);
576 Py_VISIT(astmodulestate(module)->RShift_singleton);
577 Py_VISIT(astmodulestate(module)->RShift_type);
578 Py_VISIT(astmodulestate(module)->Raise_type);
579 Py_VISIT(astmodulestate(module)->Return_type);
580 Py_VISIT(astmodulestate(module)->SetComp_type);
581 Py_VISIT(astmodulestate(module)->Set_type);
582 Py_VISIT(astmodulestate(module)->Slice_type);
583 Py_VISIT(astmodulestate(module)->Starred_type);
584 Py_VISIT(astmodulestate(module)->Store_singleton);
585 Py_VISIT(astmodulestate(module)->Store_type);
586 Py_VISIT(astmodulestate(module)->Sub_singleton);
587 Py_VISIT(astmodulestate(module)->Sub_type);
588 Py_VISIT(astmodulestate(module)->Subscript_type);
589 Py_VISIT(astmodulestate(module)->Suite_type);
590 Py_VISIT(astmodulestate(module)->Try_type);
591 Py_VISIT(astmodulestate(module)->Tuple_type);
592 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
593 Py_VISIT(astmodulestate(module)->UAdd_singleton);
594 Py_VISIT(astmodulestate(module)->UAdd_type);
595 Py_VISIT(astmodulestate(module)->USub_singleton);
596 Py_VISIT(astmodulestate(module)->USub_type);
597 Py_VISIT(astmodulestate(module)->UnaryOp_type);
598 Py_VISIT(astmodulestate(module)->While_type);
599 Py_VISIT(astmodulestate(module)->With_type);
600 Py_VISIT(astmodulestate(module)->YieldFrom_type);
601 Py_VISIT(astmodulestate(module)->Yield_type);
602 Py_VISIT(astmodulestate(module)->__dict__);
603 Py_VISIT(astmodulestate(module)->__module__);
604 Py_VISIT(astmodulestate(module)->_ast);
605 Py_VISIT(astmodulestate(module)->_attributes);
606 Py_VISIT(astmodulestate(module)->_fields);
607 Py_VISIT(astmodulestate(module)->alias_type);
608 Py_VISIT(astmodulestate(module)->annotation);
609 Py_VISIT(astmodulestate(module)->arg);
610 Py_VISIT(astmodulestate(module)->arg_type);
611 Py_VISIT(astmodulestate(module)->args);
612 Py_VISIT(astmodulestate(module)->argtypes);
613 Py_VISIT(astmodulestate(module)->arguments_type);
614 Py_VISIT(astmodulestate(module)->asname);
615 Py_VISIT(astmodulestate(module)->attr);
616 Py_VISIT(astmodulestate(module)->bases);
617 Py_VISIT(astmodulestate(module)->body);
618 Py_VISIT(astmodulestate(module)->boolop_type);
619 Py_VISIT(astmodulestate(module)->cause);
620 Py_VISIT(astmodulestate(module)->cmpop_type);
621 Py_VISIT(astmodulestate(module)->col_offset);
622 Py_VISIT(astmodulestate(module)->comparators);
623 Py_VISIT(astmodulestate(module)->comprehension_type);
624 Py_VISIT(astmodulestate(module)->context_expr);
625 Py_VISIT(astmodulestate(module)->conversion);
626 Py_VISIT(astmodulestate(module)->ctx);
627 Py_VISIT(astmodulestate(module)->decorator_list);
628 Py_VISIT(astmodulestate(module)->defaults);
629 Py_VISIT(astmodulestate(module)->dims);
630 Py_VISIT(astmodulestate(module)->elt);
631 Py_VISIT(astmodulestate(module)->elts);
632 Py_VISIT(astmodulestate(module)->end_col_offset);
633 Py_VISIT(astmodulestate(module)->end_lineno);
634 Py_VISIT(astmodulestate(module)->exc);
635 Py_VISIT(astmodulestate(module)->excepthandler_type);
636 Py_VISIT(astmodulestate(module)->expr_context_type);
637 Py_VISIT(astmodulestate(module)->expr_type);
638 Py_VISIT(astmodulestate(module)->finalbody);
639 Py_VISIT(astmodulestate(module)->format_spec);
640 Py_VISIT(astmodulestate(module)->func);
641 Py_VISIT(astmodulestate(module)->generators);
642 Py_VISIT(astmodulestate(module)->handlers);
643 Py_VISIT(astmodulestate(module)->id);
644 Py_VISIT(astmodulestate(module)->ifs);
645 Py_VISIT(astmodulestate(module)->is_async);
646 Py_VISIT(astmodulestate(module)->items);
647 Py_VISIT(astmodulestate(module)->iter);
648 Py_VISIT(astmodulestate(module)->key);
649 Py_VISIT(astmodulestate(module)->keys);
650 Py_VISIT(astmodulestate(module)->keyword_type);
651 Py_VISIT(astmodulestate(module)->keywords);
652 Py_VISIT(astmodulestate(module)->kind);
653 Py_VISIT(astmodulestate(module)->kw_defaults);
654 Py_VISIT(astmodulestate(module)->kwarg);
655 Py_VISIT(astmodulestate(module)->kwonlyargs);
656 Py_VISIT(astmodulestate(module)->left);
657 Py_VISIT(astmodulestate(module)->level);
658 Py_VISIT(astmodulestate(module)->lineno);
659 Py_VISIT(astmodulestate(module)->lower);
660 Py_VISIT(astmodulestate(module)->mod_type);
661 Py_VISIT(astmodulestate(module)->module);
662 Py_VISIT(astmodulestate(module)->msg);
663 Py_VISIT(astmodulestate(module)->name);
664 Py_VISIT(astmodulestate(module)->names);
665 Py_VISIT(astmodulestate(module)->op);
666 Py_VISIT(astmodulestate(module)->operand);
667 Py_VISIT(astmodulestate(module)->operator_type);
668 Py_VISIT(astmodulestate(module)->ops);
669 Py_VISIT(astmodulestate(module)->optional_vars);
670 Py_VISIT(astmodulestate(module)->orelse);
671 Py_VISIT(astmodulestate(module)->posonlyargs);
672 Py_VISIT(astmodulestate(module)->returns);
673 Py_VISIT(astmodulestate(module)->right);
674 Py_VISIT(astmodulestate(module)->simple);
675 Py_VISIT(astmodulestate(module)->slice);
676 Py_VISIT(astmodulestate(module)->slice_type);
677 Py_VISIT(astmodulestate(module)->step);
678 Py_VISIT(astmodulestate(module)->stmt_type);
679 Py_VISIT(astmodulestate(module)->tag);
680 Py_VISIT(astmodulestate(module)->target);
681 Py_VISIT(astmodulestate(module)->targets);
682 Py_VISIT(astmodulestate(module)->test);
683 Py_VISIT(astmodulestate(module)->type);
684 Py_VISIT(astmodulestate(module)->type_comment);
685 Py_VISIT(astmodulestate(module)->type_ignore_type);
686 Py_VISIT(astmodulestate(module)->type_ignores);
687 Py_VISIT(astmodulestate(module)->unaryop_type);
688 Py_VISIT(astmodulestate(module)->upper);
689 Py_VISIT(astmodulestate(module)->value);
690 Py_VISIT(astmodulestate(module)->values);
691 Py_VISIT(astmodulestate(module)->vararg);
692 Py_VISIT(astmodulestate(module)->withitem_type);
693
694 return 0;
695}
696
697static void astmodule_free(void* module) {
698 astmodule_clear((PyObject*)module);
699}
700
701static struct PyModuleDef _astmodule = {
702 PyModuleDef_HEAD_INIT,
703 "_ast",
704 NULL,
705 sizeof(astmodulestate),
706 NULL,
707 NULL,
708 astmodule_traverse,
709 astmodule_clear,
710 astmodule_free,
711};
712
713#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
714
715static int init_identifiers(void)
716{
717 astmodulestate *state = astmodulestate_global;
718 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
719 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
720 if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0;
721 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
722 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
723 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
724 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
725 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
726 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
727 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
728 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
729 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
730 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
731 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
732 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
733 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
734 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
735 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
736 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
737 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
738 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
739 if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0;
740 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
741 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
742 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
743 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
744 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
745 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
746 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
747 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
748 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
749 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
750 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
751 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
752 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
753 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
754 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
755 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
756 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
757 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
758 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
759 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
760 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
761 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
762 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
763 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
764 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
765 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
766 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
767 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
768 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
769 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
770 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
771 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
772 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
773 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
774 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
775 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
776 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
777 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
778 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
779 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
780 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
781 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
782 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
783 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
784 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
785 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
786 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
787 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
788 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
789 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
790 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
791 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
792 return 1;
793};
794
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000795static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300796static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200797 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800798 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000799};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300800static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200801 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000802};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300803static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200804 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000805};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300806static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800807 "argtypes",
808 "returns",
809};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300810static const char * const Suite_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200811 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000812};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300813static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200814 "lineno",
815 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000816 "end_lineno",
817 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000818};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000819static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300820static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200821 "name",
822 "args",
823 "body",
824 "decorator_list",
825 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800826 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000827};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300828static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400829 "name",
830 "args",
831 "body",
832 "decorator_list",
833 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800834 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400835};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300836static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200837 "name",
838 "bases",
839 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200840 "body",
841 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000842};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300843static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200844 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000845};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300846static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200847 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000848};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300849static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200850 "targets",
851 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800852 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000853};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300854static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200855 "target",
856 "op",
857 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000858};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300859static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700860 "target",
861 "annotation",
862 "value",
863 "simple",
864};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300865static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200866 "target",
867 "iter",
868 "body",
869 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800870 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000871};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300872static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400873 "target",
874 "iter",
875 "body",
876 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800877 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400878};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300879static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200880 "test",
881 "body",
882 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000883};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300884static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200885 "test",
886 "body",
887 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000888};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300889static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200890 "items",
891 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800892 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000893};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300894static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400895 "items",
896 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800897 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400898};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300899static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200900 "exc",
901 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000902};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300903static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200904 "body",
905 "handlers",
906 "orelse",
907 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000908};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300909static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200910 "test",
911 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000912};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300913static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200914 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000915};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300916static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200917 "module",
918 "names",
919 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000920};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300921static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200922 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000923};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300924static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200925 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000926};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300927static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200928 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000929};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300930static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200931 "lineno",
932 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000933 "end_lineno",
934 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000935};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000936static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300937static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200938 "op",
939 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000940};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300941static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700942 "target",
943 "value",
944};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300945static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200946 "left",
947 "op",
948 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000949};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300950static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200951 "op",
952 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000953};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300954static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200955 "args",
956 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000957};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300958static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200959 "test",
960 "body",
961 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000962};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300963static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200964 "keys",
965 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000966};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300967static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200968 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000969};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300970static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200971 "elt",
972 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000973};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300974static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200975 "elt",
976 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000977};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300978static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200979 "key",
980 "value",
981 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000982};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300983static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200984 "elt",
985 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000986};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300987static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400988 "value",
989};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300990static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200991 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500992};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300993static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200994 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000995};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300996static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200997 "left",
998 "ops",
999 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001000};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001001static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001002 "func",
1003 "args",
1004 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001005};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001006static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -04001007 "value",
1008 "conversion",
1009 "format_spec",
1010};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001011static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -04001012 "values",
1013};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001014static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001015 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -07001016 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001017};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001018static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001019 "value",
1020 "attr",
1021 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001022};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001023static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001024 "value",
1025 "slice",
1026 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001027};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001028static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001029 "value",
1030 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +00001031};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001032static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001033 "id",
1034 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001035};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001036static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001037 "elts",
1038 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001039};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001040static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001041 "elts",
1042 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001043};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001044static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001045static PyObject* ast2obj_slice(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001046static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001047 "lower",
1048 "upper",
1049 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001050};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001051static const char * const ExtSlice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001052 "dims",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001053};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001054static const char * const Index_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001055 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001056};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001057static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001058static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001059static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001060static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001061static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001062static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001063 "target",
1064 "iter",
1065 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001066 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001067};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001068static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001069 "lineno",
1070 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001071 "end_lineno",
1072 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001073};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001074static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001075static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001076 "type",
1077 "name",
1078 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001079};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001080static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001081static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001082 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001083 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001084 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001085 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001086 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001087 "kwarg",
1088 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001089};
Neal Norwitzc1505362006-12-28 06:47:50 +00001090static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001091static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001092 "lineno",
1093 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001094 "end_lineno",
1095 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001096};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001097static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001098 "arg",
1099 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001100 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001101};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001102static PyObject* ast2obj_keyword(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001103static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001104 "arg",
1105 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001106};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001107static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001108static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001109 "name",
1110 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001111};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001112static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001113static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001114 "context_expr",
1115 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001116};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001117static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001118static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001119 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001120 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001121};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001122
1123
INADA Naokifc489082017-01-25 22:33:43 +09001124
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001125typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001126 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001127 PyObject *dict;
1128} AST_object;
1129
Benjamin Peterson1767e022012-03-14 21:50:29 -05001130static void
1131ast_dealloc(AST_object *self)
1132{
INADA Naokia6296d32017-08-24 14:55:17 +09001133 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001134 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001135 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001136 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001137 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1138 assert(free_func != NULL);
1139 free_func(self);
1140 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001141}
1142
Neal Norwitz207c9f32008-03-31 04:42:11 +00001143static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001144ast_traverse(AST_object *self, visitproc visit, void *arg)
1145{
1146 Py_VISIT(self->dict);
1147 return 0;
1148}
1149
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001150static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001151ast_clear(AST_object *self)
1152{
1153 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001154 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001155}
1156
1157static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001158ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1159{
1160 Py_ssize_t i, numfields = 0;
1161 int res = -1;
1162 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001163 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001164 goto cleanup;
1165 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001166 if (fields) {
1167 numfields = PySequence_Size(fields);
1168 if (numfields == -1)
1169 goto cleanup;
1170 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001171
Neal Norwitz207c9f32008-03-31 04:42:11 +00001172 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001173 if (numfields < PyTuple_GET_SIZE(args)) {
1174 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1175 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001176 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001177 numfields, numfields == 1 ? "" : "s");
1178 res = -1;
1179 goto cleanup;
1180 }
1181 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1182 /* cannot be reached when fields is NULL */
1183 PyObject *name = PySequence_GetItem(fields, i);
1184 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001185 res = -1;
1186 goto cleanup;
1187 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001188 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1189 Py_DECREF(name);
1190 if (res < 0)
1191 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001192 }
1193 if (kw) {
1194 i = 0; /* needed by PyDict_Next */
1195 while (PyDict_Next(kw, &i, &key, &value)) {
1196 res = PyObject_SetAttr(self, key, value);
1197 if (res < 0)
1198 goto cleanup;
1199 }
1200 }
1201 cleanup:
1202 Py_XDECREF(fields);
1203 return res;
1204}
1205
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001206/* Pickling support */
1207static PyObject *
1208ast_type_reduce(PyObject *self, PyObject *unused)
1209{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001210 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001211 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001212 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001213 }
1214 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001215 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001216 }
1217 return Py_BuildValue("O()", Py_TYPE(self));
1218}
1219
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001220static PyMemberDef ast_type_members[] = {
1221 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1222 {NULL} /* Sentinel */
1223};
1224
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001225static PyMethodDef ast_type_methods[] = {
1226 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1227 {NULL}
1228};
1229
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001230static PyGetSetDef ast_type_getsets[] = {
1231 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1232 {NULL}
1233};
1234
Dino Viehlandac46eb42019-09-11 10:16:34 -07001235static PyType_Slot AST_type_slots[] = {
1236 {Py_tp_dealloc, ast_dealloc},
1237 {Py_tp_getattro, PyObject_GenericGetAttr},
1238 {Py_tp_setattro, PyObject_GenericSetAttr},
1239 {Py_tp_traverse, ast_traverse},
1240 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001241 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001242 {Py_tp_methods, ast_type_methods},
1243 {Py_tp_getset, ast_type_getsets},
1244 {Py_tp_init, ast_type_init},
1245 {Py_tp_alloc, PyType_GenericAlloc},
1246 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001247 {Py_tp_free, PyObject_GC_Del},
1248 {0, 0},
1249};
1250
1251static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001252 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001253 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001254 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001255 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1256 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001257};
1258
Dino Viehlandac46eb42019-09-11 10:16:34 -07001259static PyObject *
1260make_type(const char *type, PyObject* base, const char* const* fields, int num_fields)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001261{
1262 PyObject *fnames, *result;
1263 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001264 fnames = PyTuple_New(num_fields);
1265 if (!fnames) return NULL;
1266 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001267 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001268 if (!field) {
1269 Py_DECREF(fnames);
1270 return NULL;
1271 }
1272 PyTuple_SET_ITEM(fnames, i, field);
1273 }
INADA Naokifc489082017-01-25 22:33:43 +09001274 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
1275 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001276 astmodulestate_global->_fields, fnames,
1277 astmodulestate_global->__module__,
1278 astmodulestate_global->_ast);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001279 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001280 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001281}
1282
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001283static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001284add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001285{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001286 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001287 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001288 if (!l)
1289 return 0;
1290 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001291 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001292 if (!s) {
1293 Py_DECREF(l);
1294 return 0;
1295 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001296 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001297 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001298 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001299 Py_DECREF(l);
1300 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001301}
1302
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001303/* Conversion AST -> Python */
1304
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001305static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1306{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001307 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001308 PyObject *result = PyList_New(n);
1309 PyObject *value;
1310 if (!result)
1311 return NULL;
1312 for (i = 0; i < n; i++) {
1313 value = func(asdl_seq_GET(seq, i));
1314 if (!value) {
1315 Py_DECREF(result);
1316 return NULL;
1317 }
1318 PyList_SET_ITEM(result, i, value);
1319 }
1320 return result;
1321}
1322
1323static PyObject* ast2obj_object(void *o)
1324{
1325 if (!o)
1326 o = Py_None;
1327 Py_INCREF((PyObject*)o);
1328 return (PyObject*)o;
1329}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001330#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001331#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001332#define ast2obj_identifier ast2obj_object
1333#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001334#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001335
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001336static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001337{
Christian Heimes217cfd12007-12-02 14:31:20 +00001338 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001339}
1340
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001341/* Conversion Python -> AST */
1342
1343static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1344{
1345 if (obj == Py_None)
1346 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001347 if (obj) {
1348 if (PyArena_AddPyObject(arena, obj) < 0) {
1349 *out = NULL;
1350 return -1;
1351 }
1352 Py_INCREF(obj);
1353 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001354 *out = obj;
1355 return 0;
1356}
1357
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001358static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1359{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001360 if (PyArena_AddPyObject(arena, obj) < 0) {
1361 *out = NULL;
1362 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001363 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001364 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001365 *out = obj;
1366 return 0;
1367}
1368
Benjamin Peterson180e6352011-07-22 11:09:07 -05001369static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001370{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001371 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1372 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001373 return 1;
1374 }
1375 return obj2ast_object(obj, out, arena);
1376}
1377
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001378static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1379{
1380 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1381 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1382 return 1;
1383 }
1384 return obj2ast_object(obj, out, arena);
1385}
1386
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001387static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1388{
1389 int i;
1390 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001391 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001392 return 1;
1393 }
1394
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001395 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001396 if (i == -1 && PyErr_Occurred())
1397 return 1;
1398 *out = i;
1399 return 0;
1400}
1401
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001402static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001403{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001404 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001405 empty_tuple = PyTuple_New(0);
1406 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001407 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1408 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001409 Py_XDECREF(empty_tuple);
1410 return -1;
1411 }
1412 Py_DECREF(empty_tuple);
1413 return 0;
1414}
1415
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001416
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001417static int init_types(void)
1418{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001419 PyObject *m;
1420 if (PyState_FindModule(&_astmodule) == NULL) {
1421 m = PyModule_Create(&_astmodule);
1422 if (!m) return 0;
1423 PyState_AddModule(m, &_astmodule);
1424 }
1425 astmodulestate *state = astmodulestate_global;
1426 if (state->initialized) return 1;
1427 if (init_identifiers() < 0) return 0;
1428 state->AST_type = PyType_FromSpec(&AST_type_spec);
1429 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001430 if (add_ast_fields() < 0) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001431 state->mod_type = make_type("mod", state->AST_type, NULL, 0);
1432 if (!state->mod_type) return 0;
1433 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
1434 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2);
1435 if (!state->Module_type) return 0;
1436 state->Interactive_type = make_type("Interactive", state->mod_type,
1437 Interactive_fields, 1);
1438 if (!state->Interactive_type) return 0;
1439 state->Expression_type = make_type("Expression", state->mod_type,
1440 Expression_fields, 1);
1441 if (!state->Expression_type) return 0;
1442 state->FunctionType_type = make_type("FunctionType", state->mod_type,
1443 FunctionType_fields, 2);
1444 if (!state->FunctionType_type) return 0;
1445 state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1);
1446 if (!state->Suite_type) return 0;
1447 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
1448 if (!state->stmt_type) return 0;
1449 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
1450 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1451 FunctionDef_fields, 6);
1452 if (!state->FunctionDef_type) return 0;
1453 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1454 state->stmt_type,
1455 AsyncFunctionDef_fields, 6);
1456 if (!state->AsyncFunctionDef_type) return 0;
1457 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1458 ClassDef_fields, 5);
1459 if (!state->ClassDef_type) return 0;
1460 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1461 1);
1462 if (!state->Return_type) return 0;
1463 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1464 1);
1465 if (!state->Delete_type) return 0;
1466 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1467 3);
1468 if (!state->Assign_type) return 0;
1469 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1470 AugAssign_fields, 3);
1471 if (!state->AugAssign_type) return 0;
1472 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1473 AnnAssign_fields, 4);
1474 if (!state->AnnAssign_type) return 0;
1475 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1476 if (!state->For_type) return 0;
1477 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1478 AsyncFor_fields, 5);
1479 if (!state->AsyncFor_type) return 0;
1480 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1481 if (!state->While_type) return 0;
1482 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1483 if (!state->If_type) return 0;
1484 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1485 if (!state->With_type) return 0;
1486 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1487 AsyncWith_fields, 3);
1488 if (!state->AsyncWith_type) return 0;
1489 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1490 if (!state->Raise_type) return 0;
1491 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1492 if (!state->Try_type) return 0;
1493 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1494 2);
1495 if (!state->Assert_type) return 0;
1496 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1497 1);
1498 if (!state->Import_type) return 0;
1499 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1500 ImportFrom_fields, 3);
1501 if (!state->ImportFrom_type) return 0;
1502 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1503 1);
1504 if (!state->Global_type) return 0;
1505 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1506 Nonlocal_fields, 1);
1507 if (!state->Nonlocal_type) return 0;
1508 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1509 if (!state->Expr_type) return 0;
1510 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1511 if (!state->Pass_type) return 0;
1512 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1513 if (!state->Break_type) return 0;
1514 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1515 if (!state->Continue_type) return 0;
1516 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1517 if (!state->expr_type) return 0;
1518 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
1519 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1520 2);
1521 if (!state->BoolOp_type) return 0;
1522 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1523 NamedExpr_fields, 2);
1524 if (!state->NamedExpr_type) return 0;
1525 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1526 if (!state->BinOp_type) return 0;
1527 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1528 UnaryOp_fields, 2);
1529 if (!state->UnaryOp_type) return 0;
1530 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1531 2);
1532 if (!state->Lambda_type) return 0;
1533 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1534 if (!state->IfExp_type) return 0;
1535 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1536 if (!state->Dict_type) return 0;
1537 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1538 if (!state->Set_type) return 0;
1539 state->ListComp_type = make_type("ListComp", state->expr_type,
1540 ListComp_fields, 2);
1541 if (!state->ListComp_type) return 0;
1542 state->SetComp_type = make_type("SetComp", state->expr_type,
1543 SetComp_fields, 2);
1544 if (!state->SetComp_type) return 0;
1545 state->DictComp_type = make_type("DictComp", state->expr_type,
1546 DictComp_fields, 3);
1547 if (!state->DictComp_type) return 0;
1548 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1549 GeneratorExp_fields, 2);
1550 if (!state->GeneratorExp_type) return 0;
1551 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1552 if (!state->Await_type) return 0;
1553 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1554 if (!state->Yield_type) return 0;
1555 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1556 YieldFrom_fields, 1);
1557 if (!state->YieldFrom_type) return 0;
1558 state->Compare_type = make_type("Compare", state->expr_type,
1559 Compare_fields, 3);
1560 if (!state->Compare_type) return 0;
1561 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1562 if (!state->Call_type) return 0;
1563 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1564 FormattedValue_fields, 3);
1565 if (!state->FormattedValue_type) return 0;
1566 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1567 JoinedStr_fields, 1);
1568 if (!state->JoinedStr_type) return 0;
1569 state->Constant_type = make_type("Constant", state->expr_type,
1570 Constant_fields, 2);
1571 if (!state->Constant_type) return 0;
1572 state->Attribute_type = make_type("Attribute", state->expr_type,
1573 Attribute_fields, 3);
1574 if (!state->Attribute_type) return 0;
1575 state->Subscript_type = make_type("Subscript", state->expr_type,
1576 Subscript_fields, 3);
1577 if (!state->Subscript_type) return 0;
1578 state->Starred_type = make_type("Starred", state->expr_type,
1579 Starred_fields, 2);
1580 if (!state->Starred_type) return 0;
1581 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1582 if (!state->Name_type) return 0;
1583 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1584 if (!state->List_type) return 0;
1585 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1586 if (!state->Tuple_type) return 0;
1587 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1588 0);
1589 if (!state->expr_context_type) return 0;
1590 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1591 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1592 if (!state->Load_type) return 0;
1593 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1594 NULL, NULL);
1595 if (!state->Load_singleton) return 0;
1596 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1597 if (!state->Store_type) return 0;
1598 state->Store_singleton = PyType_GenericNew((PyTypeObject
1599 *)state->Store_type, NULL, NULL);
1600 if (!state->Store_singleton) return 0;
1601 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1602 if (!state->Del_type) return 0;
1603 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1604 NULL, NULL);
1605 if (!state->Del_singleton) return 0;
1606 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1607 0);
1608 if (!state->AugLoad_type) return 0;
1609 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1610 *)state->AugLoad_type, NULL,
1611 NULL);
1612 if (!state->AugLoad_singleton) return 0;
1613 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1614 NULL, 0);
1615 if (!state->AugStore_type) return 0;
1616 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1617 *)state->AugStore_type, NULL,
1618 NULL);
1619 if (!state->AugStore_singleton) return 0;
1620 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1621 if (!state->Param_type) return 0;
1622 state->Param_singleton = PyType_GenericNew((PyTypeObject
1623 *)state->Param_type, NULL, NULL);
1624 if (!state->Param_singleton) return 0;
1625 state->slice_type = make_type("slice", state->AST_type, NULL, 0);
1626 if (!state->slice_type) return 0;
1627 if (!add_attributes(state->slice_type, NULL, 0)) return 0;
1628 state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3);
1629 if (!state->Slice_type) return 0;
1630 state->ExtSlice_type = make_type("ExtSlice", state->slice_type,
1631 ExtSlice_fields, 1);
1632 if (!state->ExtSlice_type) return 0;
1633 state->Index_type = make_type("Index", state->slice_type, Index_fields, 1);
1634 if (!state->Index_type) return 0;
1635 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1636 if (!state->boolop_type) return 0;
1637 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1638 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1639 if (!state->And_type) return 0;
1640 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1641 NULL, NULL);
1642 if (!state->And_singleton) return 0;
1643 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1644 if (!state->Or_type) return 0;
1645 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1646 NULL, NULL);
1647 if (!state->Or_singleton) return 0;
1648 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1649 if (!state->operator_type) return 0;
1650 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1651 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1652 if (!state->Add_type) return 0;
1653 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1654 NULL, NULL);
1655 if (!state->Add_singleton) return 0;
1656 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1657 if (!state->Sub_type) return 0;
1658 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1659 NULL, NULL);
1660 if (!state->Sub_singleton) return 0;
1661 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1662 if (!state->Mult_type) return 0;
1663 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1664 NULL, NULL);
1665 if (!state->Mult_singleton) return 0;
1666 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1667 if (!state->MatMult_type) return 0;
1668 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1669 *)state->MatMult_type, NULL,
1670 NULL);
1671 if (!state->MatMult_singleton) return 0;
1672 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1673 if (!state->Div_type) return 0;
1674 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1675 NULL, NULL);
1676 if (!state->Div_singleton) return 0;
1677 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1678 if (!state->Mod_type) return 0;
1679 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1680 NULL, NULL);
1681 if (!state->Mod_singleton) return 0;
1682 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1683 if (!state->Pow_type) return 0;
1684 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1685 NULL, NULL);
1686 if (!state->Pow_singleton) return 0;
1687 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1688 if (!state->LShift_type) return 0;
1689 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1690 *)state->LShift_type, NULL,
1691 NULL);
1692 if (!state->LShift_singleton) return 0;
1693 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1694 if (!state->RShift_type) return 0;
1695 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1696 *)state->RShift_type, NULL,
1697 NULL);
1698 if (!state->RShift_singleton) return 0;
1699 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1700 if (!state->BitOr_type) return 0;
1701 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1702 *)state->BitOr_type, NULL, NULL);
1703 if (!state->BitOr_singleton) return 0;
1704 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1705 if (!state->BitXor_type) return 0;
1706 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1707 *)state->BitXor_type, NULL,
1708 NULL);
1709 if (!state->BitXor_singleton) return 0;
1710 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1711 if (!state->BitAnd_type) return 0;
1712 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1713 *)state->BitAnd_type, NULL,
1714 NULL);
1715 if (!state->BitAnd_singleton) return 0;
1716 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1717 if (!state->FloorDiv_type) return 0;
1718 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1719 *)state->FloorDiv_type, NULL,
1720 NULL);
1721 if (!state->FloorDiv_singleton) return 0;
1722 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1723 if (!state->unaryop_type) return 0;
1724 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1725 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1726 if (!state->Invert_type) return 0;
1727 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1728 *)state->Invert_type, NULL,
1729 NULL);
1730 if (!state->Invert_singleton) return 0;
1731 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1732 if (!state->Not_type) return 0;
1733 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1734 NULL, NULL);
1735 if (!state->Not_singleton) return 0;
1736 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1737 if (!state->UAdd_type) return 0;
1738 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1739 NULL, NULL);
1740 if (!state->UAdd_singleton) return 0;
1741 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1742 if (!state->USub_type) return 0;
1743 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1744 NULL, NULL);
1745 if (!state->USub_singleton) return 0;
1746 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1747 if (!state->cmpop_type) return 0;
1748 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1749 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1750 if (!state->Eq_type) return 0;
1751 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1752 NULL, NULL);
1753 if (!state->Eq_singleton) return 0;
1754 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1755 if (!state->NotEq_type) return 0;
1756 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1757 *)state->NotEq_type, NULL, NULL);
1758 if (!state->NotEq_singleton) return 0;
1759 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1760 if (!state->Lt_type) return 0;
1761 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1762 NULL, NULL);
1763 if (!state->Lt_singleton) return 0;
1764 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1765 if (!state->LtE_type) return 0;
1766 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1767 NULL, NULL);
1768 if (!state->LtE_singleton) return 0;
1769 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1770 if (!state->Gt_type) return 0;
1771 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1772 NULL, NULL);
1773 if (!state->Gt_singleton) return 0;
1774 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1775 if (!state->GtE_type) return 0;
1776 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1777 NULL, NULL);
1778 if (!state->GtE_singleton) return 0;
1779 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1780 if (!state->Is_type) return 0;
1781 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1782 NULL, NULL);
1783 if (!state->Is_singleton) return 0;
1784 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1785 if (!state->IsNot_type) return 0;
1786 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1787 *)state->IsNot_type, NULL, NULL);
1788 if (!state->IsNot_singleton) return 0;
1789 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1790 if (!state->In_type) return 0;
1791 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1792 NULL, NULL);
1793 if (!state->In_singleton) return 0;
1794 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1795 if (!state->NotIn_type) return 0;
1796 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1797 *)state->NotIn_type, NULL, NULL);
1798 if (!state->NotIn_singleton) return 0;
1799 state->comprehension_type = make_type("comprehension", state->AST_type,
1800 comprehension_fields, 4);
1801 if (!state->comprehension_type) return 0;
1802 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1803 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1804 NULL, 0);
1805 if (!state->excepthandler_type) return 0;
1806 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1807 4)) return 0;
1808 state->ExceptHandler_type = make_type("ExceptHandler",
1809 state->excepthandler_type,
1810 ExceptHandler_fields, 3);
1811 if (!state->ExceptHandler_type) return 0;
1812 state->arguments_type = make_type("arguments", state->AST_type,
1813 arguments_fields, 7);
1814 if (!state->arguments_type) return 0;
1815 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
1816 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1817 if (!state->arg_type) return 0;
1818 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
1819 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1820 2);
1821 if (!state->keyword_type) return 0;
1822 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
1823 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1824 if (!state->alias_type) return 0;
1825 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
1826 state->withitem_type = make_type("withitem", state->AST_type,
1827 withitem_fields, 2);
1828 if (!state->withitem_type) return 0;
1829 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
1830 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1831 0);
1832 if (!state->type_ignore_type) return 0;
1833 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1834 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1835 TypeIgnore_fields, 2);
1836 if (!state->TypeIgnore_type) return 0;
1837 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001838 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001839}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001840
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001841static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1842static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1843static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1844static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1845 arena);
1846static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1847static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1848static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1849static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1850static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1851static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1852 arena);
1853static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1854 arena);
1855static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1856static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1857static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1858static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001859static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001860static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1861 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001862
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001863mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001864Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001865{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001866 mod_ty p;
1867 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1868 if (!p)
1869 return NULL;
1870 p->kind = Module_kind;
1871 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001872 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001873 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001874}
1875
1876mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001877Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001878{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001879 mod_ty p;
1880 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1881 if (!p)
1882 return NULL;
1883 p->kind = Interactive_kind;
1884 p->v.Interactive.body = body;
1885 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001886}
1887
1888mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001889Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001890{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001891 mod_ty p;
1892 if (!body) {
1893 PyErr_SetString(PyExc_ValueError,
1894 "field body is required for Expression");
1895 return NULL;
1896 }
1897 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1898 if (!p)
1899 return NULL;
1900 p->kind = Expression_kind;
1901 p->v.Expression.body = body;
1902 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001903}
1904
1905mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001906FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1907{
1908 mod_ty p;
1909 if (!returns) {
1910 PyErr_SetString(PyExc_ValueError,
1911 "field returns is required for FunctionType");
1912 return NULL;
1913 }
1914 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1915 if (!p)
1916 return NULL;
1917 p->kind = FunctionType_kind;
1918 p->v.FunctionType.argtypes = argtypes;
1919 p->v.FunctionType.returns = returns;
1920 return p;
1921}
1922
1923mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001924Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001925{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001926 mod_ty p;
1927 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1928 if (!p)
1929 return NULL;
1930 p->kind = Suite_kind;
1931 p->v.Suite.body = body;
1932 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001933}
1934
1935stmt_ty
1936FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001937 decorator_list, expr_ty returns, string type_comment, int lineno,
1938 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001939{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001940 stmt_ty p;
1941 if (!name) {
1942 PyErr_SetString(PyExc_ValueError,
1943 "field name is required for FunctionDef");
1944 return NULL;
1945 }
1946 if (!args) {
1947 PyErr_SetString(PyExc_ValueError,
1948 "field args is required for FunctionDef");
1949 return NULL;
1950 }
1951 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1952 if (!p)
1953 return NULL;
1954 p->kind = FunctionDef_kind;
1955 p->v.FunctionDef.name = name;
1956 p->v.FunctionDef.args = args;
1957 p->v.FunctionDef.body = body;
1958 p->v.FunctionDef.decorator_list = decorator_list;
1959 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001960 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001961 p->lineno = lineno;
1962 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001963 p->end_lineno = end_lineno;
1964 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001965 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001966}
1967
1968stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001969AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001970 * decorator_list, expr_ty returns, string type_comment, int
1971 lineno, int col_offset, int end_lineno, int end_col_offset,
1972 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001973{
1974 stmt_ty p;
1975 if (!name) {
1976 PyErr_SetString(PyExc_ValueError,
1977 "field name is required for AsyncFunctionDef");
1978 return NULL;
1979 }
1980 if (!args) {
1981 PyErr_SetString(PyExc_ValueError,
1982 "field args is required for AsyncFunctionDef");
1983 return NULL;
1984 }
1985 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1986 if (!p)
1987 return NULL;
1988 p->kind = AsyncFunctionDef_kind;
1989 p->v.AsyncFunctionDef.name = name;
1990 p->v.AsyncFunctionDef.args = args;
1991 p->v.AsyncFunctionDef.body = body;
1992 p->v.AsyncFunctionDef.decorator_list = decorator_list;
1993 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001994 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04001995 p->lineno = lineno;
1996 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001997 p->end_lineno = end_lineno;
1998 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04001999 return p;
2000}
2001
2002stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002003ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002004 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2005 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002006{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002007 stmt_ty p;
2008 if (!name) {
2009 PyErr_SetString(PyExc_ValueError,
2010 "field name is required for ClassDef");
2011 return NULL;
2012 }
2013 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2014 if (!p)
2015 return NULL;
2016 p->kind = ClassDef_kind;
2017 p->v.ClassDef.name = name;
2018 p->v.ClassDef.bases = bases;
2019 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002020 p->v.ClassDef.body = body;
2021 p->v.ClassDef.decorator_list = decorator_list;
2022 p->lineno = lineno;
2023 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002024 p->end_lineno = end_lineno;
2025 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002026 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002027}
2028
2029stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002030Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2031 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002032{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002033 stmt_ty p;
2034 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2035 if (!p)
2036 return NULL;
2037 p->kind = Return_kind;
2038 p->v.Return.value = value;
2039 p->lineno = lineno;
2040 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002041 p->end_lineno = end_lineno;
2042 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002043 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002044}
2045
2046stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002047Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2048 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002049{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002050 stmt_ty p;
2051 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2052 if (!p)
2053 return NULL;
2054 p->kind = Delete_kind;
2055 p->v.Delete.targets = targets;
2056 p->lineno = lineno;
2057 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002058 p->end_lineno = end_lineno;
2059 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002060 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002061}
2062
2063stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002064Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2065 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002066{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002067 stmt_ty p;
2068 if (!value) {
2069 PyErr_SetString(PyExc_ValueError,
2070 "field value is required for Assign");
2071 return NULL;
2072 }
2073 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2074 if (!p)
2075 return NULL;
2076 p->kind = Assign_kind;
2077 p->v.Assign.targets = targets;
2078 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002079 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002080 p->lineno = lineno;
2081 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002082 p->end_lineno = end_lineno;
2083 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002084 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002085}
2086
2087stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002088AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002089 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002090{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002091 stmt_ty p;
2092 if (!target) {
2093 PyErr_SetString(PyExc_ValueError,
2094 "field target is required for AugAssign");
2095 return NULL;
2096 }
2097 if (!op) {
2098 PyErr_SetString(PyExc_ValueError,
2099 "field op is required for AugAssign");
2100 return NULL;
2101 }
2102 if (!value) {
2103 PyErr_SetString(PyExc_ValueError,
2104 "field value is required for AugAssign");
2105 return NULL;
2106 }
2107 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2108 if (!p)
2109 return NULL;
2110 p->kind = AugAssign_kind;
2111 p->v.AugAssign.target = target;
2112 p->v.AugAssign.op = op;
2113 p->v.AugAssign.value = value;
2114 p->lineno = lineno;
2115 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002116 p->end_lineno = end_lineno;
2117 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002118 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002119}
2120
2121stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002122AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002123 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2124 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002125{
2126 stmt_ty p;
2127 if (!target) {
2128 PyErr_SetString(PyExc_ValueError,
2129 "field target is required for AnnAssign");
2130 return NULL;
2131 }
2132 if (!annotation) {
2133 PyErr_SetString(PyExc_ValueError,
2134 "field annotation is required for AnnAssign");
2135 return NULL;
2136 }
2137 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2138 if (!p)
2139 return NULL;
2140 p->kind = AnnAssign_kind;
2141 p->v.AnnAssign.target = target;
2142 p->v.AnnAssign.annotation = annotation;
2143 p->v.AnnAssign.value = value;
2144 p->v.AnnAssign.simple = simple;
2145 p->lineno = lineno;
2146 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002147 p->end_lineno = end_lineno;
2148 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002149 return p;
2150}
2151
2152stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002153For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2154 type_comment, int lineno, int col_offset, int end_lineno, int
2155 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002156{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002157 stmt_ty p;
2158 if (!target) {
2159 PyErr_SetString(PyExc_ValueError,
2160 "field target is required for For");
2161 return NULL;
2162 }
2163 if (!iter) {
2164 PyErr_SetString(PyExc_ValueError,
2165 "field iter is required for For");
2166 return NULL;
2167 }
2168 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2169 if (!p)
2170 return NULL;
2171 p->kind = For_kind;
2172 p->v.For.target = target;
2173 p->v.For.iter = iter;
2174 p->v.For.body = body;
2175 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002176 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002177 p->lineno = lineno;
2178 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002179 p->end_lineno = end_lineno;
2180 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002181 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002182}
2183
2184stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002185AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2186 string type_comment, int lineno, int col_offset, int end_lineno, int
2187 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002188{
2189 stmt_ty p;
2190 if (!target) {
2191 PyErr_SetString(PyExc_ValueError,
2192 "field target is required for AsyncFor");
2193 return NULL;
2194 }
2195 if (!iter) {
2196 PyErr_SetString(PyExc_ValueError,
2197 "field iter is required for AsyncFor");
2198 return NULL;
2199 }
2200 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2201 if (!p)
2202 return NULL;
2203 p->kind = AsyncFor_kind;
2204 p->v.AsyncFor.target = target;
2205 p->v.AsyncFor.iter = iter;
2206 p->v.AsyncFor.body = body;
2207 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002208 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002209 p->lineno = lineno;
2210 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002211 p->end_lineno = end_lineno;
2212 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002213 return p;
2214}
2215
2216stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002217While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002218 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002219{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002220 stmt_ty p;
2221 if (!test) {
2222 PyErr_SetString(PyExc_ValueError,
2223 "field test is required for While");
2224 return NULL;
2225 }
2226 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2227 if (!p)
2228 return NULL;
2229 p->kind = While_kind;
2230 p->v.While.test = test;
2231 p->v.While.body = body;
2232 p->v.While.orelse = orelse;
2233 p->lineno = lineno;
2234 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002235 p->end_lineno = end_lineno;
2236 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002237 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002238}
2239
2240stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002241If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002242 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002243{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002244 stmt_ty p;
2245 if (!test) {
2246 PyErr_SetString(PyExc_ValueError,
2247 "field test is required for If");
2248 return NULL;
2249 }
2250 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2251 if (!p)
2252 return NULL;
2253 p->kind = If_kind;
2254 p->v.If.test = test;
2255 p->v.If.body = body;
2256 p->v.If.orelse = orelse;
2257 p->lineno = lineno;
2258 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002259 p->end_lineno = end_lineno;
2260 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002261 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002262}
2263
2264stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002265With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2266 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002267{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002268 stmt_ty p;
2269 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2270 if (!p)
2271 return NULL;
2272 p->kind = With_kind;
2273 p->v.With.items = items;
2274 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002275 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002276 p->lineno = lineno;
2277 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002278 p->end_lineno = end_lineno;
2279 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002280 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002281}
2282
2283stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002284AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2285 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002286{
2287 stmt_ty p;
2288 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2289 if (!p)
2290 return NULL;
2291 p->kind = AsyncWith_kind;
2292 p->v.AsyncWith.items = items;
2293 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002294 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002295 p->lineno = lineno;
2296 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002297 p->end_lineno = end_lineno;
2298 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002299 return p;
2300}
2301
2302stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002303Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2304 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002305{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002306 stmt_ty p;
2307 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2308 if (!p)
2309 return NULL;
2310 p->kind = Raise_kind;
2311 p->v.Raise.exc = exc;
2312 p->v.Raise.cause = cause;
2313 p->lineno = lineno;
2314 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002315 p->end_lineno = end_lineno;
2316 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002317 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002318}
2319
2320stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002321Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002322 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2323 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002325 stmt_ty p;
2326 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2327 if (!p)
2328 return NULL;
2329 p->kind = Try_kind;
2330 p->v.Try.body = body;
2331 p->v.Try.handlers = handlers;
2332 p->v.Try.orelse = orelse;
2333 p->v.Try.finalbody = finalbody;
2334 p->lineno = lineno;
2335 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002336 p->end_lineno = end_lineno;
2337 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002338 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002339}
2340
2341stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002342Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2343 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002344{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002345 stmt_ty p;
2346 if (!test) {
2347 PyErr_SetString(PyExc_ValueError,
2348 "field test is required for Assert");
2349 return NULL;
2350 }
2351 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2352 if (!p)
2353 return NULL;
2354 p->kind = Assert_kind;
2355 p->v.Assert.test = test;
2356 p->v.Assert.msg = msg;
2357 p->lineno = lineno;
2358 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002359 p->end_lineno = end_lineno;
2360 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002361 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002362}
2363
2364stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002365Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2366 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002367{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002368 stmt_ty p;
2369 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2370 if (!p)
2371 return NULL;
2372 p->kind = Import_kind;
2373 p->v.Import.names = names;
2374 p->lineno = lineno;
2375 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002376 p->end_lineno = end_lineno;
2377 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002378 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002379}
2380
2381stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002382ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002383 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002384{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002385 stmt_ty p;
2386 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2387 if (!p)
2388 return NULL;
2389 p->kind = ImportFrom_kind;
2390 p->v.ImportFrom.module = module;
2391 p->v.ImportFrom.names = names;
2392 p->v.ImportFrom.level = level;
2393 p->lineno = lineno;
2394 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002395 p->end_lineno = end_lineno;
2396 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002397 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002398}
2399
2400stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002401Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2402 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002403{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002404 stmt_ty p;
2405 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2406 if (!p)
2407 return NULL;
2408 p->kind = Global_kind;
2409 p->v.Global.names = names;
2410 p->lineno = lineno;
2411 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002412 p->end_lineno = end_lineno;
2413 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002414 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002415}
2416
2417stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002418Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2419 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002420{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002421 stmt_ty p;
2422 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2423 if (!p)
2424 return NULL;
2425 p->kind = Nonlocal_kind;
2426 p->v.Nonlocal.names = names;
2427 p->lineno = lineno;
2428 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002429 p->end_lineno = end_lineno;
2430 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002431 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002432}
2433
2434stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002435Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2436 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002437{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002438 stmt_ty p;
2439 if (!value) {
2440 PyErr_SetString(PyExc_ValueError,
2441 "field value is required for Expr");
2442 return NULL;
2443 }
2444 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2445 if (!p)
2446 return NULL;
2447 p->kind = Expr_kind;
2448 p->v.Expr.value = value;
2449 p->lineno = lineno;
2450 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002451 p->end_lineno = end_lineno;
2452 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002453 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002454}
2455
2456stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002457Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2458 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002459{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002460 stmt_ty p;
2461 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2462 if (!p)
2463 return NULL;
2464 p->kind = Pass_kind;
2465 p->lineno = lineno;
2466 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002467 p->end_lineno = end_lineno;
2468 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002469 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002470}
2471
2472stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002473Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2474 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002475{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002476 stmt_ty p;
2477 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2478 if (!p)
2479 return NULL;
2480 p->kind = Break_kind;
2481 p->lineno = lineno;
2482 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002483 p->end_lineno = end_lineno;
2484 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002485 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002486}
2487
2488stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002489Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2490 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002491{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002492 stmt_ty p;
2493 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2494 if (!p)
2495 return NULL;
2496 p->kind = Continue_kind;
2497 p->lineno = lineno;
2498 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002499 p->end_lineno = end_lineno;
2500 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002501 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002502}
2503
2504expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002505BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2506 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002507{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002508 expr_ty p;
2509 if (!op) {
2510 PyErr_SetString(PyExc_ValueError,
2511 "field op is required for BoolOp");
2512 return NULL;
2513 }
2514 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2515 if (!p)
2516 return NULL;
2517 p->kind = BoolOp_kind;
2518 p->v.BoolOp.op = op;
2519 p->v.BoolOp.values = values;
2520 p->lineno = lineno;
2521 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002522 p->end_lineno = end_lineno;
2523 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002524 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002525}
2526
2527expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002528NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2529 end_lineno, int end_col_offset, PyArena *arena)
2530{
2531 expr_ty p;
2532 if (!target) {
2533 PyErr_SetString(PyExc_ValueError,
2534 "field target is required for NamedExpr");
2535 return NULL;
2536 }
2537 if (!value) {
2538 PyErr_SetString(PyExc_ValueError,
2539 "field value is required for NamedExpr");
2540 return NULL;
2541 }
2542 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2543 if (!p)
2544 return NULL;
2545 p->kind = NamedExpr_kind;
2546 p->v.NamedExpr.target = target;
2547 p->v.NamedExpr.value = value;
2548 p->lineno = lineno;
2549 p->col_offset = col_offset;
2550 p->end_lineno = end_lineno;
2551 p->end_col_offset = end_col_offset;
2552 return p;
2553}
2554
2555expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002556BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002557 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002558{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002559 expr_ty p;
2560 if (!left) {
2561 PyErr_SetString(PyExc_ValueError,
2562 "field left is required for BinOp");
2563 return NULL;
2564 }
2565 if (!op) {
2566 PyErr_SetString(PyExc_ValueError,
2567 "field op is required for BinOp");
2568 return NULL;
2569 }
2570 if (!right) {
2571 PyErr_SetString(PyExc_ValueError,
2572 "field right is required for BinOp");
2573 return NULL;
2574 }
2575 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2576 if (!p)
2577 return NULL;
2578 p->kind = BinOp_kind;
2579 p->v.BinOp.left = left;
2580 p->v.BinOp.op = op;
2581 p->v.BinOp.right = right;
2582 p->lineno = lineno;
2583 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002584 p->end_lineno = end_lineno;
2585 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002586 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002587}
2588
2589expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002590UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2591 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002592{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002593 expr_ty p;
2594 if (!op) {
2595 PyErr_SetString(PyExc_ValueError,
2596 "field op is required for UnaryOp");
2597 return NULL;
2598 }
2599 if (!operand) {
2600 PyErr_SetString(PyExc_ValueError,
2601 "field operand is required for UnaryOp");
2602 return NULL;
2603 }
2604 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2605 if (!p)
2606 return NULL;
2607 p->kind = UnaryOp_kind;
2608 p->v.UnaryOp.op = op;
2609 p->v.UnaryOp.operand = operand;
2610 p->lineno = lineno;
2611 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002612 p->end_lineno = end_lineno;
2613 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002614 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002615}
2616
2617expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002618Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2619 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002620{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002621 expr_ty p;
2622 if (!args) {
2623 PyErr_SetString(PyExc_ValueError,
2624 "field args is required for Lambda");
2625 return NULL;
2626 }
2627 if (!body) {
2628 PyErr_SetString(PyExc_ValueError,
2629 "field body is required for Lambda");
2630 return NULL;
2631 }
2632 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2633 if (!p)
2634 return NULL;
2635 p->kind = Lambda_kind;
2636 p->v.Lambda.args = args;
2637 p->v.Lambda.body = body;
2638 p->lineno = lineno;
2639 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002640 p->end_lineno = end_lineno;
2641 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002642 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002643}
2644
2645expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002646IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002647 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002648{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002649 expr_ty p;
2650 if (!test) {
2651 PyErr_SetString(PyExc_ValueError,
2652 "field test is required for IfExp");
2653 return NULL;
2654 }
2655 if (!body) {
2656 PyErr_SetString(PyExc_ValueError,
2657 "field body is required for IfExp");
2658 return NULL;
2659 }
2660 if (!orelse) {
2661 PyErr_SetString(PyExc_ValueError,
2662 "field orelse is required for IfExp");
2663 return NULL;
2664 }
2665 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2666 if (!p)
2667 return NULL;
2668 p->kind = IfExp_kind;
2669 p->v.IfExp.test = test;
2670 p->v.IfExp.body = body;
2671 p->v.IfExp.orelse = orelse;
2672 p->lineno = lineno;
2673 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002674 p->end_lineno = end_lineno;
2675 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002676 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002677}
2678
2679expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002680Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2681 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002682{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002683 expr_ty p;
2684 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2685 if (!p)
2686 return NULL;
2687 p->kind = Dict_kind;
2688 p->v.Dict.keys = keys;
2689 p->v.Dict.values = values;
2690 p->lineno = lineno;
2691 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002692 p->end_lineno = end_lineno;
2693 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002694 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002695}
2696
2697expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002698Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2699 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002700{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002701 expr_ty p;
2702 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2703 if (!p)
2704 return NULL;
2705 p->kind = Set_kind;
2706 p->v.Set.elts = elts;
2707 p->lineno = lineno;
2708 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002709 p->end_lineno = end_lineno;
2710 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002711 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002712}
2713
2714expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002715ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2716 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002718 expr_ty p;
2719 if (!elt) {
2720 PyErr_SetString(PyExc_ValueError,
2721 "field elt is required for ListComp");
2722 return NULL;
2723 }
2724 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2725 if (!p)
2726 return NULL;
2727 p->kind = ListComp_kind;
2728 p->v.ListComp.elt = elt;
2729 p->v.ListComp.generators = generators;
2730 p->lineno = lineno;
2731 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002732 p->end_lineno = end_lineno;
2733 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002734 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002735}
2736
2737expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002738SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2739 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002740{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002741 expr_ty p;
2742 if (!elt) {
2743 PyErr_SetString(PyExc_ValueError,
2744 "field elt is required for SetComp");
2745 return NULL;
2746 }
2747 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2748 if (!p)
2749 return NULL;
2750 p->kind = SetComp_kind;
2751 p->v.SetComp.elt = elt;
2752 p->v.SetComp.generators = generators;
2753 p->lineno = lineno;
2754 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002755 p->end_lineno = end_lineno;
2756 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002757 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002758}
2759
2760expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002761DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002762 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002763{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002764 expr_ty p;
2765 if (!key) {
2766 PyErr_SetString(PyExc_ValueError,
2767 "field key is required for DictComp");
2768 return NULL;
2769 }
2770 if (!value) {
2771 PyErr_SetString(PyExc_ValueError,
2772 "field value is required for DictComp");
2773 return NULL;
2774 }
2775 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2776 if (!p)
2777 return NULL;
2778 p->kind = DictComp_kind;
2779 p->v.DictComp.key = key;
2780 p->v.DictComp.value = value;
2781 p->v.DictComp.generators = generators;
2782 p->lineno = lineno;
2783 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002784 p->end_lineno = end_lineno;
2785 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002786 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002787}
2788
2789expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002790GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002791 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002792{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002793 expr_ty p;
2794 if (!elt) {
2795 PyErr_SetString(PyExc_ValueError,
2796 "field elt is required for GeneratorExp");
2797 return NULL;
2798 }
2799 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2800 if (!p)
2801 return NULL;
2802 p->kind = GeneratorExp_kind;
2803 p->v.GeneratorExp.elt = elt;
2804 p->v.GeneratorExp.generators = generators;
2805 p->lineno = lineno;
2806 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002807 p->end_lineno = end_lineno;
2808 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002809 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002810}
2811
2812expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002813Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2814 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002815{
2816 expr_ty p;
2817 if (!value) {
2818 PyErr_SetString(PyExc_ValueError,
2819 "field value is required for Await");
2820 return NULL;
2821 }
2822 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2823 if (!p)
2824 return NULL;
2825 p->kind = Await_kind;
2826 p->v.Await.value = value;
2827 p->lineno = lineno;
2828 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002829 p->end_lineno = end_lineno;
2830 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002831 return p;
2832}
2833
2834expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002835Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2836 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002837{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002838 expr_ty p;
2839 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2840 if (!p)
2841 return NULL;
2842 p->kind = Yield_kind;
2843 p->v.Yield.value = value;
2844 p->lineno = lineno;
2845 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002846 p->end_lineno = end_lineno;
2847 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002848 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002849}
2850
2851expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002852YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2853 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002854{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002855 expr_ty p;
2856 if (!value) {
2857 PyErr_SetString(PyExc_ValueError,
2858 "field value is required for YieldFrom");
2859 return NULL;
2860 }
2861 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2862 if (!p)
2863 return NULL;
2864 p->kind = YieldFrom_kind;
2865 p->v.YieldFrom.value = value;
2866 p->lineno = lineno;
2867 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002868 p->end_lineno = end_lineno;
2869 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002870 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002871}
2872
2873expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002874Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002875 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002876{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002877 expr_ty p;
2878 if (!left) {
2879 PyErr_SetString(PyExc_ValueError,
2880 "field left is required for Compare");
2881 return NULL;
2882 }
2883 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2884 if (!p)
2885 return NULL;
2886 p->kind = Compare_kind;
2887 p->v.Compare.left = left;
2888 p->v.Compare.ops = ops;
2889 p->v.Compare.comparators = comparators;
2890 p->lineno = lineno;
2891 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002892 p->end_lineno = end_lineno;
2893 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002894 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002895}
2896
2897expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002898Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002899 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002900{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002901 expr_ty p;
2902 if (!func) {
2903 PyErr_SetString(PyExc_ValueError,
2904 "field func is required for Call");
2905 return NULL;
2906 }
2907 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2908 if (!p)
2909 return NULL;
2910 p->kind = Call_kind;
2911 p->v.Call.func = func;
2912 p->v.Call.args = args;
2913 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002914 p->lineno = lineno;
2915 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002916 p->end_lineno = end_lineno;
2917 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002918 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002919}
2920
2921expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002922FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2923 int col_offset, int end_lineno, int end_col_offset, PyArena
2924 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002925{
2926 expr_ty p;
2927 if (!value) {
2928 PyErr_SetString(PyExc_ValueError,
2929 "field value is required for FormattedValue");
2930 return NULL;
2931 }
2932 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2933 if (!p)
2934 return NULL;
2935 p->kind = FormattedValue_kind;
2936 p->v.FormattedValue.value = value;
2937 p->v.FormattedValue.conversion = conversion;
2938 p->v.FormattedValue.format_spec = format_spec;
2939 p->lineno = lineno;
2940 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002941 p->end_lineno = end_lineno;
2942 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002943 return p;
2944}
2945
2946expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002947JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2948 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002949{
2950 expr_ty p;
2951 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2952 if (!p)
2953 return NULL;
2954 p->kind = JoinedStr_kind;
2955 p->v.JoinedStr.values = values;
2956 p->lineno = lineno;
2957 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002958 p->end_lineno = end_lineno;
2959 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002960 return p;
2961}
2962
2963expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002964Constant(constant value, string kind, int lineno, int col_offset, int
2965 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002966{
2967 expr_ty p;
2968 if (!value) {
2969 PyErr_SetString(PyExc_ValueError,
2970 "field value is required for Constant");
2971 return NULL;
2972 }
2973 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2974 if (!p)
2975 return NULL;
2976 p->kind = Constant_kind;
2977 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002978 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002979 p->lineno = lineno;
2980 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002981 p->end_lineno = end_lineno;
2982 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002983 return p;
2984}
2985
2986expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002987Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002988 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002989{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002990 expr_ty p;
2991 if (!value) {
2992 PyErr_SetString(PyExc_ValueError,
2993 "field value is required for Attribute");
2994 return NULL;
2995 }
2996 if (!attr) {
2997 PyErr_SetString(PyExc_ValueError,
2998 "field attr is required for Attribute");
2999 return NULL;
3000 }
3001 if (!ctx) {
3002 PyErr_SetString(PyExc_ValueError,
3003 "field ctx is required for Attribute");
3004 return NULL;
3005 }
3006 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3007 if (!p)
3008 return NULL;
3009 p->kind = Attribute_kind;
3010 p->v.Attribute.value = value;
3011 p->v.Attribute.attr = attr;
3012 p->v.Attribute.ctx = ctx;
3013 p->lineno = lineno;
3014 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003015 p->end_lineno = end_lineno;
3016 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003017 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003018}
3019
3020expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003021Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003022 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003023{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003024 expr_ty p;
3025 if (!value) {
3026 PyErr_SetString(PyExc_ValueError,
3027 "field value is required for Subscript");
3028 return NULL;
3029 }
3030 if (!slice) {
3031 PyErr_SetString(PyExc_ValueError,
3032 "field slice is required for Subscript");
3033 return NULL;
3034 }
3035 if (!ctx) {
3036 PyErr_SetString(PyExc_ValueError,
3037 "field ctx is required for Subscript");
3038 return NULL;
3039 }
3040 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3041 if (!p)
3042 return NULL;
3043 p->kind = Subscript_kind;
3044 p->v.Subscript.value = value;
3045 p->v.Subscript.slice = slice;
3046 p->v.Subscript.ctx = ctx;
3047 p->lineno = lineno;
3048 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003049 p->end_lineno = end_lineno;
3050 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003051 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003052}
3053
3054expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003055Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3056 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003057{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003058 expr_ty p;
3059 if (!value) {
3060 PyErr_SetString(PyExc_ValueError,
3061 "field value is required for Starred");
3062 return NULL;
3063 }
3064 if (!ctx) {
3065 PyErr_SetString(PyExc_ValueError,
3066 "field ctx is required for Starred");
3067 return NULL;
3068 }
3069 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3070 if (!p)
3071 return NULL;
3072 p->kind = Starred_kind;
3073 p->v.Starred.value = value;
3074 p->v.Starred.ctx = ctx;
3075 p->lineno = lineno;
3076 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003077 p->end_lineno = end_lineno;
3078 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003079 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003080}
3081
3082expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003083Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3084 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003085{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003086 expr_ty p;
3087 if (!id) {
3088 PyErr_SetString(PyExc_ValueError,
3089 "field id is required for Name");
3090 return NULL;
3091 }
3092 if (!ctx) {
3093 PyErr_SetString(PyExc_ValueError,
3094 "field ctx is required for Name");
3095 return NULL;
3096 }
3097 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3098 if (!p)
3099 return NULL;
3100 p->kind = Name_kind;
3101 p->v.Name.id = id;
3102 p->v.Name.ctx = ctx;
3103 p->lineno = lineno;
3104 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003105 p->end_lineno = end_lineno;
3106 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003107 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003108}
3109
3110expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003111List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3112 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003113{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003114 expr_ty p;
3115 if (!ctx) {
3116 PyErr_SetString(PyExc_ValueError,
3117 "field ctx is required for List");
3118 return NULL;
3119 }
3120 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3121 if (!p)
3122 return NULL;
3123 p->kind = List_kind;
3124 p->v.List.elts = elts;
3125 p->v.List.ctx = ctx;
3126 p->lineno = lineno;
3127 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003128 p->end_lineno = end_lineno;
3129 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003130 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003131}
3132
3133expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003134Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3135 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003136{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003137 expr_ty p;
3138 if (!ctx) {
3139 PyErr_SetString(PyExc_ValueError,
3140 "field ctx is required for Tuple");
3141 return NULL;
3142 }
3143 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3144 if (!p)
3145 return NULL;
3146 p->kind = Tuple_kind;
3147 p->v.Tuple.elts = elts;
3148 p->v.Tuple.ctx = ctx;
3149 p->lineno = lineno;
3150 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003151 p->end_lineno = end_lineno;
3152 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003153 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003154}
3155
3156slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003157Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003158{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003159 slice_ty p;
3160 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3161 if (!p)
3162 return NULL;
3163 p->kind = Slice_kind;
3164 p->v.Slice.lower = lower;
3165 p->v.Slice.upper = upper;
3166 p->v.Slice.step = step;
3167 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003168}
3169
3170slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003171ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003172{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003173 slice_ty p;
3174 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3175 if (!p)
3176 return NULL;
3177 p->kind = ExtSlice_kind;
3178 p->v.ExtSlice.dims = dims;
3179 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003180}
3181
3182slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003183Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003184{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003185 slice_ty p;
3186 if (!value) {
3187 PyErr_SetString(PyExc_ValueError,
3188 "field value is required for Index");
3189 return NULL;
3190 }
3191 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3192 if (!p)
3193 return NULL;
3194 p->kind = Index_kind;
3195 p->v.Index.value = value;
3196 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003197}
3198
3199comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003200comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3201 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003202{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003203 comprehension_ty p;
3204 if (!target) {
3205 PyErr_SetString(PyExc_ValueError,
3206 "field target is required for comprehension");
3207 return NULL;
3208 }
3209 if (!iter) {
3210 PyErr_SetString(PyExc_ValueError,
3211 "field iter is required for comprehension");
3212 return NULL;
3213 }
3214 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3215 if (!p)
3216 return NULL;
3217 p->target = target;
3218 p->iter = iter;
3219 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003220 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003221 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003222}
3223
3224excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003225ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003226 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003227{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003228 excepthandler_ty p;
3229 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3230 if (!p)
3231 return NULL;
3232 p->kind = ExceptHandler_kind;
3233 p->v.ExceptHandler.type = type;
3234 p->v.ExceptHandler.name = name;
3235 p->v.ExceptHandler.body = body;
3236 p->lineno = lineno;
3237 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003238 p->end_lineno = end_lineno;
3239 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003240 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003241}
3242
3243arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003244arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003245 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3246 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003247{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003248 arguments_ty p;
3249 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3250 if (!p)
3251 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003252 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003253 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003254 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003255 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003256 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003257 p->kwarg = kwarg;
3258 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003259 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003260}
3261
Neal Norwitzc1505362006-12-28 06:47:50 +00003262arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003263arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3264 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003265{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003266 arg_ty p;
3267 if (!arg) {
3268 PyErr_SetString(PyExc_ValueError,
3269 "field arg is required for arg");
3270 return NULL;
3271 }
3272 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3273 if (!p)
3274 return NULL;
3275 p->arg = arg;
3276 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003277 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003278 p->lineno = lineno;
3279 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003280 p->end_lineno = end_lineno;
3281 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003282 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003283}
3284
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003285keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003286keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003287{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003288 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003289 if (!value) {
3290 PyErr_SetString(PyExc_ValueError,
3291 "field value is required for keyword");
3292 return NULL;
3293 }
3294 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3295 if (!p)
3296 return NULL;
3297 p->arg = arg;
3298 p->value = value;
3299 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003300}
3301
3302alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003303alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003304{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003305 alias_ty p;
3306 if (!name) {
3307 PyErr_SetString(PyExc_ValueError,
3308 "field name is required for alias");
3309 return NULL;
3310 }
3311 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3312 if (!p)
3313 return NULL;
3314 p->name = name;
3315 p->asname = asname;
3316 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003317}
3318
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003319withitem_ty
3320withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3321{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003322 withitem_ty p;
3323 if (!context_expr) {
3324 PyErr_SetString(PyExc_ValueError,
3325 "field context_expr is required for withitem");
3326 return NULL;
3327 }
3328 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3329 if (!p)
3330 return NULL;
3331 p->context_expr = context_expr;
3332 p->optional_vars = optional_vars;
3333 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003334}
3335
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003336type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003337TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003338{
3339 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003340 if (!tag) {
3341 PyErr_SetString(PyExc_ValueError,
3342 "field tag is required for TypeIgnore");
3343 return NULL;
3344 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003345 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3346 if (!p)
3347 return NULL;
3348 p->kind = TypeIgnore_kind;
3349 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003350 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003351 return p;
3352}
3353
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003354
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003355PyObject*
3356ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003357{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003358 mod_ty o = (mod_ty)_o;
3359 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003360 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003361 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003362 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003363 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003364
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003365 switch (o->kind) {
3366 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003367 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3368 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003369 if (!result) goto failed;
3370 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3371 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003372 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003373 goto failed;
3374 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003375 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3376 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003377 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3378 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003379 goto failed;
3380 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003381 break;
3382 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003383 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3384 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003385 if (!result) goto failed;
3386 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3387 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003388 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003389 goto failed;
3390 Py_DECREF(value);
3391 break;
3392 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003393 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3394 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003395 if (!result) goto failed;
3396 value = ast2obj_expr(o->v.Expression.body);
3397 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003398 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003399 goto failed;
3400 Py_DECREF(value);
3401 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003402 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003403 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3404 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003405 if (!result) goto failed;
3406 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3407 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003408 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3409 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003410 goto failed;
3411 Py_DECREF(value);
3412 value = ast2obj_expr(o->v.FunctionType.returns);
3413 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003414 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3415 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003416 goto failed;
3417 Py_DECREF(value);
3418 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003419 case Suite_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003420 tp = (PyTypeObject *)astmodulestate_global->Suite_type;
3421 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003422 if (!result) goto failed;
3423 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
3424 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003425 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003426 goto failed;
3427 Py_DECREF(value);
3428 break;
3429 }
3430 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003431failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003432 Py_XDECREF(value);
3433 Py_XDECREF(result);
3434 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003435}
3436
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003437PyObject*
3438ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003439{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003440 stmt_ty o = (stmt_ty)_o;
3441 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003442 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003443 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003444 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003445 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003446
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003447 switch (o->kind) {
3448 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003449 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3450 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003451 if (!result) goto failed;
3452 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003453 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003454 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003455 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003456 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003457 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003458 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003459 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003460 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003461 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003462 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3463 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003464 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003465 goto failed;
3466 Py_DECREF(value);
3467 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3468 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003469 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3470 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003471 goto failed;
3472 Py_DECREF(value);
3473 value = ast2obj_expr(o->v.FunctionDef.returns);
3474 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003475 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3476 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003477 goto failed;
3478 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003479 value = ast2obj_string(o->v.FunctionDef.type_comment);
3480 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003481 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3482 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003483 goto failed;
3484 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003485 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003486 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003487 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3488 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003489 if (!result) goto failed;
3490 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3491 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003492 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003493 goto failed;
3494 Py_DECREF(value);
3495 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3496 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003497 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003498 goto failed;
3499 Py_DECREF(value);
3500 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3501 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003502 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003503 goto failed;
3504 Py_DECREF(value);
3505 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3506 ast2obj_expr);
3507 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003508 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3509 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003510 goto failed;
3511 Py_DECREF(value);
3512 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3513 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003514 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3515 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003516 goto failed;
3517 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003518 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3519 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003520 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3521 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003522 goto failed;
3523 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003524 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003525 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003526 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3527 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003528 if (!result) goto failed;
3529 value = ast2obj_identifier(o->v.ClassDef.name);
3530 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003531 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003532 goto failed;
3533 Py_DECREF(value);
3534 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3535 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003536 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003537 goto failed;
3538 Py_DECREF(value);
3539 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3540 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003541 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3542 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003543 goto failed;
3544 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003545 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3546 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003547 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003548 goto failed;
3549 Py_DECREF(value);
3550 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3551 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003552 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3553 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003554 goto failed;
3555 Py_DECREF(value);
3556 break;
3557 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003558 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3559 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003560 if (!result) goto failed;
3561 value = ast2obj_expr(o->v.Return.value);
3562 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003563 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003564 goto failed;
3565 Py_DECREF(value);
3566 break;
3567 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003568 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3569 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003570 if (!result) goto failed;
3571 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3572 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003573 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3574 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003575 goto failed;
3576 Py_DECREF(value);
3577 break;
3578 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003579 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3580 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003581 if (!result) goto failed;
3582 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3583 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003584 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3585 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003586 goto failed;
3587 Py_DECREF(value);
3588 value = ast2obj_expr(o->v.Assign.value);
3589 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003590 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003591 goto failed;
3592 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003593 value = ast2obj_string(o->v.Assign.type_comment);
3594 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003595 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3596 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003597 goto failed;
3598 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003599 break;
3600 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003601 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3602 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003603 if (!result) goto failed;
3604 value = ast2obj_expr(o->v.AugAssign.target);
3605 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003606 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3607 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003608 goto failed;
3609 Py_DECREF(value);
3610 value = ast2obj_operator(o->v.AugAssign.op);
3611 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003612 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003613 goto failed;
3614 Py_DECREF(value);
3615 value = ast2obj_expr(o->v.AugAssign.value);
3616 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003617 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003618 goto failed;
3619 Py_DECREF(value);
3620 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003621 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003622 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3623 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003624 if (!result) goto failed;
3625 value = ast2obj_expr(o->v.AnnAssign.target);
3626 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003627 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3628 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003629 goto failed;
3630 Py_DECREF(value);
3631 value = ast2obj_expr(o->v.AnnAssign.annotation);
3632 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003633 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3634 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003635 goto failed;
3636 Py_DECREF(value);
3637 value = ast2obj_expr(o->v.AnnAssign.value);
3638 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003639 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003640 goto failed;
3641 Py_DECREF(value);
3642 value = ast2obj_int(o->v.AnnAssign.simple);
3643 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003644 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3645 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003646 goto failed;
3647 Py_DECREF(value);
3648 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003649 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003650 tp = (PyTypeObject *)astmodulestate_global->For_type;
3651 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003652 if (!result) goto failed;
3653 value = ast2obj_expr(o->v.For.target);
3654 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003655 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3656 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003657 goto failed;
3658 Py_DECREF(value);
3659 value = ast2obj_expr(o->v.For.iter);
3660 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003661 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003662 goto failed;
3663 Py_DECREF(value);
3664 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3665 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003666 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003667 goto failed;
3668 Py_DECREF(value);
3669 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3670 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003671 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3672 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003673 goto failed;
3674 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003675 value = ast2obj_string(o->v.For.type_comment);
3676 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003677 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3678 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003679 goto failed;
3680 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003681 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003682 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003683 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3684 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003685 if (!result) goto failed;
3686 value = ast2obj_expr(o->v.AsyncFor.target);
3687 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003688 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3689 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003690 goto failed;
3691 Py_DECREF(value);
3692 value = ast2obj_expr(o->v.AsyncFor.iter);
3693 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003694 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003695 goto failed;
3696 Py_DECREF(value);
3697 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3698 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003699 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003700 goto failed;
3701 Py_DECREF(value);
3702 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3703 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003704 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3705 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003706 goto failed;
3707 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003708 value = ast2obj_string(o->v.AsyncFor.type_comment);
3709 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003710 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3711 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003712 goto failed;
3713 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003714 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003715 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003716 tp = (PyTypeObject *)astmodulestate_global->While_type;
3717 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003718 if (!result) goto failed;
3719 value = ast2obj_expr(o->v.While.test);
3720 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003721 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003722 goto failed;
3723 Py_DECREF(value);
3724 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3725 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003726 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003727 goto failed;
3728 Py_DECREF(value);
3729 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3730 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003731 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3732 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003733 goto failed;
3734 Py_DECREF(value);
3735 break;
3736 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003737 tp = (PyTypeObject *)astmodulestate_global->If_type;
3738 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003739 if (!result) goto failed;
3740 value = ast2obj_expr(o->v.If.test);
3741 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003742 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003743 goto failed;
3744 Py_DECREF(value);
3745 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3746 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003747 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003748 goto failed;
3749 Py_DECREF(value);
3750 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3751 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003752 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3753 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003754 goto failed;
3755 Py_DECREF(value);
3756 break;
3757 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003758 tp = (PyTypeObject *)astmodulestate_global->With_type;
3759 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003760 if (!result) goto failed;
3761 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003763 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003764 goto failed;
3765 Py_DECREF(value);
3766 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3767 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003768 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003769 goto failed;
3770 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003771 value = ast2obj_string(o->v.With.type_comment);
3772 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003773 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3774 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003775 goto failed;
3776 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003777 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003778 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003779 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3780 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003781 if (!result) goto failed;
3782 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3783 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003784 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003785 goto failed;
3786 Py_DECREF(value);
3787 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3788 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003789 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003790 goto failed;
3791 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003792 value = ast2obj_string(o->v.AsyncWith.type_comment);
3793 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003794 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3795 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003796 goto failed;
3797 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003798 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003799 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003800 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3801 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003802 if (!result) goto failed;
3803 value = ast2obj_expr(o->v.Raise.exc);
3804 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003805 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003806 goto failed;
3807 Py_DECREF(value);
3808 value = ast2obj_expr(o->v.Raise.cause);
3809 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003810 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003811 goto failed;
3812 Py_DECREF(value);
3813 break;
3814 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003815 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3816 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003817 if (!result) goto failed;
3818 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3819 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003820 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003821 goto failed;
3822 Py_DECREF(value);
3823 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3824 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003825 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3826 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003827 goto failed;
3828 Py_DECREF(value);
3829 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3830 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003831 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3832 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003833 goto failed;
3834 Py_DECREF(value);
3835 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3836 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003837 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3838 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003839 goto failed;
3840 Py_DECREF(value);
3841 break;
3842 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003843 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3844 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003845 if (!result) goto failed;
3846 value = ast2obj_expr(o->v.Assert.test);
3847 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003848 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003849 goto failed;
3850 Py_DECREF(value);
3851 value = ast2obj_expr(o->v.Assert.msg);
3852 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003853 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003854 goto failed;
3855 Py_DECREF(value);
3856 break;
3857 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003858 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3859 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003860 if (!result) goto failed;
3861 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3862 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003863 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003864 goto failed;
3865 Py_DECREF(value);
3866 break;
3867 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003868 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3869 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003870 if (!result) goto failed;
3871 value = ast2obj_identifier(o->v.ImportFrom.module);
3872 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003873 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3874 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003875 goto failed;
3876 Py_DECREF(value);
3877 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3878 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003879 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003880 goto failed;
3881 Py_DECREF(value);
3882 value = ast2obj_int(o->v.ImportFrom.level);
3883 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003884 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003885 goto failed;
3886 Py_DECREF(value);
3887 break;
3888 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003889 tp = (PyTypeObject *)astmodulestate_global->Global_type;
3890 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003891 if (!result) goto failed;
3892 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3893 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003894 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003895 goto failed;
3896 Py_DECREF(value);
3897 break;
3898 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003899 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3900 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003901 if (!result) goto failed;
3902 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3903 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003904 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003905 goto failed;
3906 Py_DECREF(value);
3907 break;
3908 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003909 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3910 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003911 if (!result) goto failed;
3912 value = ast2obj_expr(o->v.Expr.value);
3913 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003914 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003915 goto failed;
3916 Py_DECREF(value);
3917 break;
3918 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003919 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3920 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003921 if (!result) goto failed;
3922 break;
3923 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003924 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3925 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003926 if (!result) goto failed;
3927 break;
3928 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003929 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3930 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003931 if (!result) goto failed;
3932 break;
3933 }
3934 value = ast2obj_int(o->lineno);
3935 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003936 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003937 goto failed;
3938 Py_DECREF(value);
3939 value = ast2obj_int(o->col_offset);
3940 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003941 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003942 goto failed;
3943 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003944 value = ast2obj_int(o->end_lineno);
3945 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003946 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003947 goto failed;
3948 Py_DECREF(value);
3949 value = ast2obj_int(o->end_col_offset);
3950 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003951 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
3952 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003953 goto failed;
3954 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003955 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003956failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003957 Py_XDECREF(value);
3958 Py_XDECREF(result);
3959 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003960}
3961
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003962PyObject*
3963ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003964{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003965 expr_ty o = (expr_ty)_o;
3966 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003967 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003969 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003970 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003971
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003972 switch (o->kind) {
3973 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003974 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
3975 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003976 if (!result) goto failed;
3977 value = ast2obj_boolop(o->v.BoolOp.op);
3978 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003979 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003980 goto failed;
3981 Py_DECREF(value);
3982 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3983 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003984 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
3985 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003986 goto failed;
3987 Py_DECREF(value);
3988 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003989 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003990 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
3991 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003992 if (!result) goto failed;
3993 value = ast2obj_expr(o->v.NamedExpr.target);
3994 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003995 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3996 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003997 goto failed;
3998 Py_DECREF(value);
3999 value = ast2obj_expr(o->v.NamedExpr.value);
4000 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004001 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004002 goto failed;
4003 Py_DECREF(value);
4004 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004005 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004006 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4007 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004008 if (!result) goto failed;
4009 value = ast2obj_expr(o->v.BinOp.left);
4010 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004011 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004012 goto failed;
4013 Py_DECREF(value);
4014 value = ast2obj_operator(o->v.BinOp.op);
4015 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004016 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004017 goto failed;
4018 Py_DECREF(value);
4019 value = ast2obj_expr(o->v.BinOp.right);
4020 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004021 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004022 goto failed;
4023 Py_DECREF(value);
4024 break;
4025 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004026 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4027 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004028 if (!result) goto failed;
4029 value = ast2obj_unaryop(o->v.UnaryOp.op);
4030 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004031 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004032 goto failed;
4033 Py_DECREF(value);
4034 value = ast2obj_expr(o->v.UnaryOp.operand);
4035 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004036 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4037 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004038 goto failed;
4039 Py_DECREF(value);
4040 break;
4041 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004042 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4043 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 if (!result) goto failed;
4045 value = ast2obj_arguments(o->v.Lambda.args);
4046 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004047 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004048 goto failed;
4049 Py_DECREF(value);
4050 value = ast2obj_expr(o->v.Lambda.body);
4051 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004052 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004053 goto failed;
4054 Py_DECREF(value);
4055 break;
4056 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004057 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4058 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004059 if (!result) goto failed;
4060 value = ast2obj_expr(o->v.IfExp.test);
4061 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004062 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004063 goto failed;
4064 Py_DECREF(value);
4065 value = ast2obj_expr(o->v.IfExp.body);
4066 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004067 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004068 goto failed;
4069 Py_DECREF(value);
4070 value = ast2obj_expr(o->v.IfExp.orelse);
4071 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004072 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4073 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004074 goto failed;
4075 Py_DECREF(value);
4076 break;
4077 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004078 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4079 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004080 if (!result) goto failed;
4081 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4082 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004083 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004084 goto failed;
4085 Py_DECREF(value);
4086 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4087 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004088 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4089 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004090 goto failed;
4091 Py_DECREF(value);
4092 break;
4093 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004094 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4095 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004096 if (!result) goto failed;
4097 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4098 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004099 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004100 goto failed;
4101 Py_DECREF(value);
4102 break;
4103 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004104 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4105 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004106 if (!result) goto failed;
4107 value = ast2obj_expr(o->v.ListComp.elt);
4108 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004109 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004110 goto failed;
4111 Py_DECREF(value);
4112 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4113 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004114 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4115 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004116 goto failed;
4117 Py_DECREF(value);
4118 break;
4119 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004120 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4121 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004122 if (!result) goto failed;
4123 value = ast2obj_expr(o->v.SetComp.elt);
4124 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004125 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004126 goto failed;
4127 Py_DECREF(value);
4128 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4129 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004130 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4131 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004132 goto failed;
4133 Py_DECREF(value);
4134 break;
4135 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004136 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4137 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004138 if (!result) goto failed;
4139 value = ast2obj_expr(o->v.DictComp.key);
4140 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004141 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004142 goto failed;
4143 Py_DECREF(value);
4144 value = ast2obj_expr(o->v.DictComp.value);
4145 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004146 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004147 goto failed;
4148 Py_DECREF(value);
4149 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4150 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004151 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4152 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004153 goto failed;
4154 Py_DECREF(value);
4155 break;
4156 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004157 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4158 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004159 if (!result) goto failed;
4160 value = ast2obj_expr(o->v.GeneratorExp.elt);
4161 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004162 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004163 goto failed;
4164 Py_DECREF(value);
4165 value = ast2obj_list(o->v.GeneratorExp.generators,
4166 ast2obj_comprehension);
4167 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004168 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4169 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004170 goto failed;
4171 Py_DECREF(value);
4172 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004173 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004174 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4175 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004176 if (!result) goto failed;
4177 value = ast2obj_expr(o->v.Await.value);
4178 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004179 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004180 goto failed;
4181 Py_DECREF(value);
4182 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004183 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004184 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4185 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004186 if (!result) goto failed;
4187 value = ast2obj_expr(o->v.Yield.value);
4188 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004189 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004190 goto failed;
4191 Py_DECREF(value);
4192 break;
4193 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004194 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4195 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004196 if (!result) goto failed;
4197 value = ast2obj_expr(o->v.YieldFrom.value);
4198 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004199 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004200 goto failed;
4201 Py_DECREF(value);
4202 break;
4203 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004204 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4205 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004206 if (!result) goto failed;
4207 value = ast2obj_expr(o->v.Compare.left);
4208 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004209 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004210 goto failed;
4211 Py_DECREF(value);
4212 {
4213 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4214 value = PyList_New(n);
4215 if (!value) goto failed;
4216 for(i = 0; i < n; i++)
4217 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004218 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004219 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004220 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004221 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004222 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004223 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004224 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004225 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4226 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004227 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004228 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004229 break;
4230 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004231 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4232 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004233 if (!result) goto failed;
4234 value = ast2obj_expr(o->v.Call.func);
4235 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004236 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004237 goto failed;
4238 Py_DECREF(value);
4239 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4240 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004241 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004242 goto failed;
4243 Py_DECREF(value);
4244 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4245 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004246 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4247 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004248 goto failed;
4249 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004250 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004251 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004252 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4253 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004254 if (!result) goto failed;
4255 value = ast2obj_expr(o->v.FormattedValue.value);
4256 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004257 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004258 goto failed;
4259 Py_DECREF(value);
4260 value = ast2obj_int(o->v.FormattedValue.conversion);
4261 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004262 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4263 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004264 goto failed;
4265 Py_DECREF(value);
4266 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4267 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004268 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4269 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004270 goto failed;
4271 Py_DECREF(value);
4272 break;
4273 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004274 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4275 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004276 if (!result) goto failed;
4277 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4278 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004279 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4280 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004281 goto failed;
4282 Py_DECREF(value);
4283 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004284 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004285 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4286 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004287 if (!result) goto failed;
4288 value = ast2obj_constant(o->v.Constant.value);
4289 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004290 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004291 goto failed;
4292 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004293 value = ast2obj_string(o->v.Constant.kind);
4294 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004295 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004296 goto failed;
4297 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004298 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004299 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004300 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4301 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004302 if (!result) goto failed;
4303 value = ast2obj_expr(o->v.Attribute.value);
4304 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004305 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004306 goto failed;
4307 Py_DECREF(value);
4308 value = ast2obj_identifier(o->v.Attribute.attr);
4309 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004310 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004311 goto failed;
4312 Py_DECREF(value);
4313 value = ast2obj_expr_context(o->v.Attribute.ctx);
4314 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004315 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004316 goto failed;
4317 Py_DECREF(value);
4318 break;
4319 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004320 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4321 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004322 if (!result) goto failed;
4323 value = ast2obj_expr(o->v.Subscript.value);
4324 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004325 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004326 goto failed;
4327 Py_DECREF(value);
4328 value = ast2obj_slice(o->v.Subscript.slice);
4329 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004330 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004331 goto failed;
4332 Py_DECREF(value);
4333 value = ast2obj_expr_context(o->v.Subscript.ctx);
4334 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004335 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004336 goto failed;
4337 Py_DECREF(value);
4338 break;
4339 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004340 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4341 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004342 if (!result) goto failed;
4343 value = ast2obj_expr(o->v.Starred.value);
4344 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004345 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004346 goto failed;
4347 Py_DECREF(value);
4348 value = ast2obj_expr_context(o->v.Starred.ctx);
4349 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004350 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004351 goto failed;
4352 Py_DECREF(value);
4353 break;
4354 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004355 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4356 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004357 if (!result) goto failed;
4358 value = ast2obj_identifier(o->v.Name.id);
4359 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004360 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004361 goto failed;
4362 Py_DECREF(value);
4363 value = ast2obj_expr_context(o->v.Name.ctx);
4364 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004365 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 goto failed;
4367 Py_DECREF(value);
4368 break;
4369 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004370 tp = (PyTypeObject *)astmodulestate_global->List_type;
4371 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004372 if (!result) goto failed;
4373 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4374 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004375 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004376 goto failed;
4377 Py_DECREF(value);
4378 value = ast2obj_expr_context(o->v.List.ctx);
4379 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004380 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004381 goto failed;
4382 Py_DECREF(value);
4383 break;
4384 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004385 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4386 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004387 if (!result) goto failed;
4388 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4389 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004390 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004391 goto failed;
4392 Py_DECREF(value);
4393 value = ast2obj_expr_context(o->v.Tuple.ctx);
4394 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004395 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004396 goto failed;
4397 Py_DECREF(value);
4398 break;
4399 }
4400 value = ast2obj_int(o->lineno);
4401 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004402 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004403 goto failed;
4404 Py_DECREF(value);
4405 value = ast2obj_int(o->col_offset);
4406 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004407 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004408 goto failed;
4409 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004410 value = ast2obj_int(o->end_lineno);
4411 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004412 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004413 goto failed;
4414 Py_DECREF(value);
4415 value = ast2obj_int(o->end_col_offset);
4416 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004417 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4418 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004419 goto failed;
4420 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004421 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004422failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004423 Py_XDECREF(value);
4424 Py_XDECREF(result);
4425 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004426}
4427
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004428PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004429{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004430 switch(o) {
4431 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004432 Py_INCREF(astmodulestate_global->Load_singleton);
4433 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004434 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004435 Py_INCREF(astmodulestate_global->Store_singleton);
4436 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004437 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004438 Py_INCREF(astmodulestate_global->Del_singleton);
4439 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004440 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004441 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4442 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004443 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004444 Py_INCREF(astmodulestate_global->AugStore_singleton);
4445 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004446 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004447 Py_INCREF(astmodulestate_global->Param_singleton);
4448 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004449 default:
4450 /* should never happen, but just in case ... */
4451 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4452 return NULL;
4453 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004454}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004455PyObject*
4456ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004457{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004458 slice_ty o = (slice_ty)_o;
4459 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004460 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004461 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004462 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004463 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004464
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004465 switch (o->kind) {
4466 case Slice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004467 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4468 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004469 if (!result) goto failed;
4470 value = ast2obj_expr(o->v.Slice.lower);
4471 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004472 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004473 goto failed;
4474 Py_DECREF(value);
4475 value = ast2obj_expr(o->v.Slice.upper);
4476 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004477 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004478 goto failed;
4479 Py_DECREF(value);
4480 value = ast2obj_expr(o->v.Slice.step);
4481 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004482 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004483 goto failed;
4484 Py_DECREF(value);
4485 break;
4486 case ExtSlice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004487 tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type;
4488 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004489 if (!result) goto failed;
4490 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
4491 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004492 if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004493 goto failed;
4494 Py_DECREF(value);
4495 break;
4496 case Index_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004497 tp = (PyTypeObject *)astmodulestate_global->Index_type;
4498 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004499 if (!result) goto failed;
4500 value = ast2obj_expr(o->v.Index.value);
4501 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004502 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004503 goto failed;
4504 Py_DECREF(value);
4505 break;
4506 }
4507 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004508failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004509 Py_XDECREF(value);
4510 Py_XDECREF(result);
4511 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004512}
4513
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004514PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004515{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004516 switch(o) {
4517 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004518 Py_INCREF(astmodulestate_global->And_singleton);
4519 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004520 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004521 Py_INCREF(astmodulestate_global->Or_singleton);
4522 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004523 default:
4524 /* should never happen, but just in case ... */
4525 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4526 return NULL;
4527 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004528}
4529PyObject* ast2obj_operator(operator_ty o)
4530{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004531 switch(o) {
4532 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004533 Py_INCREF(astmodulestate_global->Add_singleton);
4534 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004535 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004536 Py_INCREF(astmodulestate_global->Sub_singleton);
4537 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004538 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004539 Py_INCREF(astmodulestate_global->Mult_singleton);
4540 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004541 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004542 Py_INCREF(astmodulestate_global->MatMult_singleton);
4543 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004544 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004545 Py_INCREF(astmodulestate_global->Div_singleton);
4546 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004547 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004548 Py_INCREF(astmodulestate_global->Mod_singleton);
4549 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004550 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004551 Py_INCREF(astmodulestate_global->Pow_singleton);
4552 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004553 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004554 Py_INCREF(astmodulestate_global->LShift_singleton);
4555 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004556 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004557 Py_INCREF(astmodulestate_global->RShift_singleton);
4558 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004559 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004560 Py_INCREF(astmodulestate_global->BitOr_singleton);
4561 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004562 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004563 Py_INCREF(astmodulestate_global->BitXor_singleton);
4564 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004565 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004566 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4567 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004568 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004569 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4570 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004571 default:
4572 /* should never happen, but just in case ... */
4573 PyErr_Format(PyExc_SystemError, "unknown operator found");
4574 return NULL;
4575 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004576}
4577PyObject* ast2obj_unaryop(unaryop_ty o)
4578{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004579 switch(o) {
4580 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004581 Py_INCREF(astmodulestate_global->Invert_singleton);
4582 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004583 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004584 Py_INCREF(astmodulestate_global->Not_singleton);
4585 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004586 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004587 Py_INCREF(astmodulestate_global->UAdd_singleton);
4588 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004589 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004590 Py_INCREF(astmodulestate_global->USub_singleton);
4591 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004592 default:
4593 /* should never happen, but just in case ... */
4594 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4595 return NULL;
4596 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004597}
4598PyObject* ast2obj_cmpop(cmpop_ty o)
4599{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004600 switch(o) {
4601 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004602 Py_INCREF(astmodulestate_global->Eq_singleton);
4603 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004604 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004605 Py_INCREF(astmodulestate_global->NotEq_singleton);
4606 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004607 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004608 Py_INCREF(astmodulestate_global->Lt_singleton);
4609 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004610 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004611 Py_INCREF(astmodulestate_global->LtE_singleton);
4612 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004613 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004614 Py_INCREF(astmodulestate_global->Gt_singleton);
4615 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004616 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004617 Py_INCREF(astmodulestate_global->GtE_singleton);
4618 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004619 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004620 Py_INCREF(astmodulestate_global->Is_singleton);
4621 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004622 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004623 Py_INCREF(astmodulestate_global->IsNot_singleton);
4624 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004625 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004626 Py_INCREF(astmodulestate_global->In_singleton);
4627 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004628 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004629 Py_INCREF(astmodulestate_global->NotIn_singleton);
4630 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004631 default:
4632 /* should never happen, but just in case ... */
4633 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4634 return NULL;
4635 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004636}
4637PyObject*
4638ast2obj_comprehension(void* _o)
4639{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004640 comprehension_ty o = (comprehension_ty)_o;
4641 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004642 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004643 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004644 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004645 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004646
Dino Viehlandac46eb42019-09-11 10:16:34 -07004647 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4648 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004649 if (!result) return NULL;
4650 value = ast2obj_expr(o->target);
4651 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004652 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004653 goto failed;
4654 Py_DECREF(value);
4655 value = ast2obj_expr(o->iter);
4656 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004657 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004658 goto failed;
4659 Py_DECREF(value);
4660 value = ast2obj_list(o->ifs, ast2obj_expr);
4661 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004662 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004663 goto failed;
4664 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004665 value = ast2obj_int(o->is_async);
4666 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004667 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004668 goto failed;
4669 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004670 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004671failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 Py_XDECREF(value);
4673 Py_XDECREF(result);
4674 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004675}
4676
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004677PyObject*
4678ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004679{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004680 excepthandler_ty o = (excepthandler_ty)_o;
4681 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004682 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004684 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004685 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004686
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 switch (o->kind) {
4688 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004689 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4690 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004691 if (!result) goto failed;
4692 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004693 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004694 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004695 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004696 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004697 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004698 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004699 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004700 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004701 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004702 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4703 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004704 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004705 goto failed;
4706 Py_DECREF(value);
4707 break;
4708 }
4709 value = ast2obj_int(o->lineno);
4710 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004711 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004712 goto failed;
4713 Py_DECREF(value);
4714 value = ast2obj_int(o->col_offset);
4715 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004716 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004717 goto failed;
4718 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004719 value = ast2obj_int(o->end_lineno);
4720 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004721 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004722 goto failed;
4723 Py_DECREF(value);
4724 value = ast2obj_int(o->end_col_offset);
4725 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004726 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4727 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004728 goto failed;
4729 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004730 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004731failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004732 Py_XDECREF(value);
4733 Py_XDECREF(result);
4734 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004735}
4736
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004737PyObject*
4738ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004739{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004740 arguments_ty o = (arguments_ty)_o;
4741 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004742 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004743 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004744 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004745 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004746
Dino Viehlandac46eb42019-09-11 10:16:34 -07004747 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4748 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004749 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004750 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4751 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004752 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4753 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004754 goto failed;
4755 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004756 value = ast2obj_list(o->args, ast2obj_arg);
4757 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004758 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004759 goto failed;
4760 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004761 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004763 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004764 goto failed;
4765 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004766 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4767 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004768 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4769 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004770 goto failed;
4771 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004772 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004773 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004774 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4775 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004776 goto failed;
4777 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004778 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004779 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004780 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004781 goto failed;
4782 Py_DECREF(value);
4783 value = ast2obj_list(o->defaults, ast2obj_expr);
4784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004785 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004786 goto failed;
4787 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004788 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004789failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004790 Py_XDECREF(value);
4791 Py_XDECREF(result);
4792 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004793}
4794
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004795PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004796ast2obj_arg(void* _o)
4797{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004798 arg_ty o = (arg_ty)_o;
4799 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004800 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004801 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004802 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004803 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004804
Dino Viehlandac46eb42019-09-11 10:16:34 -07004805 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4806 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004807 if (!result) return NULL;
4808 value = ast2obj_identifier(o->arg);
4809 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004810 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004811 goto failed;
4812 Py_DECREF(value);
4813 value = ast2obj_expr(o->annotation);
4814 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004815 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4816 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004817 goto failed;
4818 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004819 value = ast2obj_string(o->type_comment);
4820 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004821 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4822 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004823 goto failed;
4824 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004825 value = ast2obj_int(o->lineno);
4826 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004827 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004828 goto failed;
4829 Py_DECREF(value);
4830 value = ast2obj_int(o->col_offset);
4831 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004832 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004833 goto failed;
4834 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004835 value = ast2obj_int(o->end_lineno);
4836 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004837 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004838 goto failed;
4839 Py_DECREF(value);
4840 value = ast2obj_int(o->end_col_offset);
4841 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004842 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4843 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004844 goto failed;
4845 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004846 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004847failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004848 Py_XDECREF(value);
4849 Py_XDECREF(result);
4850 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004851}
4852
4853PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004854ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004855{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004856 keyword_ty o = (keyword_ty)_o;
4857 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004858 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004859 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004860 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004862
Dino Viehlandac46eb42019-09-11 10:16:34 -07004863 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4864 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004865 if (!result) return NULL;
4866 value = ast2obj_identifier(o->arg);
4867 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004868 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004869 goto failed;
4870 Py_DECREF(value);
4871 value = ast2obj_expr(o->value);
4872 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004873 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004874 goto failed;
4875 Py_DECREF(value);
4876 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004877failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 Py_XDECREF(value);
4879 Py_XDECREF(result);
4880 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004881}
4882
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004883PyObject*
4884ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004885{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004886 alias_ty o = (alias_ty)_o;
4887 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004888 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004889 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004890 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004892
Dino Viehlandac46eb42019-09-11 10:16:34 -07004893 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4894 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004895 if (!result) return NULL;
4896 value = ast2obj_identifier(o->name);
4897 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004898 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004899 goto failed;
4900 Py_DECREF(value);
4901 value = ast2obj_identifier(o->asname);
4902 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004903 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004904 goto failed;
4905 Py_DECREF(value);
4906 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004907failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004908 Py_XDECREF(value);
4909 Py_XDECREF(result);
4910 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004911}
4912
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004913PyObject*
4914ast2obj_withitem(void* _o)
4915{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004916 withitem_ty o = (withitem_ty)_o;
4917 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004918 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004919 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004920 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004921 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004922
Dino Viehlandac46eb42019-09-11 10:16:34 -07004923 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4924 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004925 if (!result) return NULL;
4926 value = ast2obj_expr(o->context_expr);
4927 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004928 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4929 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004930 goto failed;
4931 Py_DECREF(value);
4932 value = ast2obj_expr(o->optional_vars);
4933 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004934 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4935 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004936 goto failed;
4937 Py_DECREF(value);
4938 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004939failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004940 Py_XDECREF(value);
4941 Py_XDECREF(result);
4942 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004943}
4944
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004945PyObject*
4946ast2obj_type_ignore(void* _o)
4947{
4948 type_ignore_ty o = (type_ignore_ty)_o;
4949 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004950 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004951 if (!o) {
4952 Py_RETURN_NONE;
4953 }
4954
4955 switch (o->kind) {
4956 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004957 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
4958 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004959 if (!result) goto failed;
4960 value = ast2obj_int(o->v.TypeIgnore.lineno);
4961 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004962 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
4963 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004964 goto failed;
4965 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004966 value = ast2obj_string(o->v.TypeIgnore.tag);
4967 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004968 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004969 goto failed;
4970 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004971 break;
4972 }
4973 return result;
4974failed:
4975 Py_XDECREF(value);
4976 Py_XDECREF(result);
4977 return NULL;
4978}
4979
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004980
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004981int
4982obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4983{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004984 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004985
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004986 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004987 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004988
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 if (obj == Py_None) {
4990 *out = NULL;
4991 return 0;
4992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07004993 tp = astmodulestate_global->Module_type;
4994 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004995 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004996 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004997 }
4998 if (isinstance) {
4999 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005000 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005001
Dino Viehlandac46eb42019-09-11 10:16:34 -07005002 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005003 return 1;
5004 }
5005 if (tmp == NULL) {
5006 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5007 return 1;
5008 }
5009 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005010 int res;
5011 Py_ssize_t len;
5012 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005013 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005014 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 +02005015 goto failed;
5016 }
5017 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005018 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005019 if (body == NULL) goto failed;
5020 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005021 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005022 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5023 Py_INCREF(tmp2);
5024 res = obj2ast_stmt(tmp2, &val, arena);
5025 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005026 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005027 if (len != PyList_GET_SIZE(tmp)) {
5028 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5029 goto failed;
5030 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005031 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005032 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005033 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005035 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5036 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005037 return 1;
5038 }
5039 if (tmp == NULL) {
5040 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5041 return 1;
5042 }
5043 else {
5044 int res;
5045 Py_ssize_t len;
5046 Py_ssize_t i;
5047 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005048 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 -08005049 goto failed;
5050 }
5051 len = PyList_GET_SIZE(tmp);
5052 type_ignores = _Py_asdl_seq_new(len, arena);
5053 if (type_ignores == NULL) goto failed;
5054 for (i = 0; i < len; i++) {
5055 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005056 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5057 Py_INCREF(tmp2);
5058 res = obj2ast_type_ignore(tmp2, &val, arena);
5059 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005060 if (res != 0) goto failed;
5061 if (len != PyList_GET_SIZE(tmp)) {
5062 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5063 goto failed;
5064 }
5065 asdl_seq_SET(type_ignores, i, val);
5066 }
5067 Py_CLEAR(tmp);
5068 }
5069 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005070 if (*out == NULL) goto failed;
5071 return 0;
5072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005073 tp = astmodulestate_global->Interactive_type;
5074 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005075 if (isinstance == -1) {
5076 return 1;
5077 }
5078 if (isinstance) {
5079 asdl_seq* body;
5080
Dino Viehlandac46eb42019-09-11 10:16:34 -07005081 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005082 return 1;
5083 }
5084 if (tmp == NULL) {
5085 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5086 return 1;
5087 }
5088 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005089 int res;
5090 Py_ssize_t len;
5091 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005092 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005093 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 +02005094 goto failed;
5095 }
5096 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005097 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005098 if (body == NULL) goto failed;
5099 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005100 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005101 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5102 Py_INCREF(tmp2);
5103 res = obj2ast_stmt(tmp2, &val, arena);
5104 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005105 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005106 if (len != PyList_GET_SIZE(tmp)) {
5107 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5108 goto failed;
5109 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005110 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005111 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005112 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005113 }
5114 *out = Interactive(body, arena);
5115 if (*out == NULL) goto failed;
5116 return 0;
5117 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005118 tp = astmodulestate_global->Expression_type;
5119 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005120 if (isinstance == -1) {
5121 return 1;
5122 }
5123 if (isinstance) {
5124 expr_ty body;
5125
Dino Viehlandac46eb42019-09-11 10:16:34 -07005126 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005127 return 1;
5128 }
5129 if (tmp == NULL) {
5130 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5131 return 1;
5132 }
5133 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005134 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005135 res = obj2ast_expr(tmp, &body, arena);
5136 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005137 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005138 }
5139 *out = Expression(body, arena);
5140 if (*out == NULL) goto failed;
5141 return 0;
5142 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005143 tp = astmodulestate_global->FunctionType_type;
5144 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005145 if (isinstance == -1) {
5146 return 1;
5147 }
5148 if (isinstance) {
5149 asdl_seq* argtypes;
5150 expr_ty returns;
5151
Dino Viehlandac46eb42019-09-11 10:16:34 -07005152 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5153 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005154 return 1;
5155 }
5156 if (tmp == NULL) {
5157 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5158 return 1;
5159 }
5160 else {
5161 int res;
5162 Py_ssize_t len;
5163 Py_ssize_t i;
5164 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005165 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 -08005166 goto failed;
5167 }
5168 len = PyList_GET_SIZE(tmp);
5169 argtypes = _Py_asdl_seq_new(len, arena);
5170 if (argtypes == NULL) goto failed;
5171 for (i = 0; i < len; i++) {
5172 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005173 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5174 Py_INCREF(tmp2);
5175 res = obj2ast_expr(tmp2, &val, arena);
5176 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005177 if (res != 0) goto failed;
5178 if (len != PyList_GET_SIZE(tmp)) {
5179 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5180 goto failed;
5181 }
5182 asdl_seq_SET(argtypes, i, val);
5183 }
5184 Py_CLEAR(tmp);
5185 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005186 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5187 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005188 return 1;
5189 }
5190 if (tmp == NULL) {
5191 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5192 return 1;
5193 }
5194 else {
5195 int res;
5196 res = obj2ast_expr(tmp, &returns, arena);
5197 if (res != 0) goto failed;
5198 Py_CLEAR(tmp);
5199 }
5200 *out = FunctionType(argtypes, returns, arena);
5201 if (*out == NULL) goto failed;
5202 return 0;
5203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005204 tp = astmodulestate_global->Suite_type;
5205 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005206 if (isinstance == -1) {
5207 return 1;
5208 }
5209 if (isinstance) {
5210 asdl_seq* body;
5211
Dino Viehlandac46eb42019-09-11 10:16:34 -07005212 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005213 return 1;
5214 }
5215 if (tmp == NULL) {
5216 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
5217 return 1;
5218 }
5219 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005220 int res;
5221 Py_ssize_t len;
5222 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005223 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005224 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 +02005225 goto failed;
5226 }
5227 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005228 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005229 if (body == NULL) goto failed;
5230 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005231 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005232 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5233 Py_INCREF(tmp2);
5234 res = obj2ast_stmt(tmp2, &val, arena);
5235 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005236 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005237 if (len != PyList_GET_SIZE(tmp)) {
5238 PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
5239 goto failed;
5240 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005241 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005242 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005243 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005244 }
5245 *out = Suite(body, arena);
5246 if (*out == NULL) goto failed;
5247 return 0;
5248 }
5249
5250 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5251 failed:
5252 Py_XDECREF(tmp);
5253 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005254}
5255
5256int
5257obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5258{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005259 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005260
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005261 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005262 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005263 int lineno;
5264 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005265 int end_lineno;
5266 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005267
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005268 if (obj == Py_None) {
5269 *out = NULL;
5270 return 0;
5271 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005272 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005273 return 1;
5274 }
5275 if (tmp == NULL) {
5276 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5277 return 1;
5278 }
5279 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005280 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005281 res = obj2ast_int(tmp, &lineno, arena);
5282 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005283 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005284 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005285 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5286 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005287 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005288 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005289 if (tmp == NULL) {
5290 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5291 return 1;
5292 }
5293 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005294 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005295 res = obj2ast_int(tmp, &col_offset, arena);
5296 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005297 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005298 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005299 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5300 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005301 return 1;
5302 }
5303 if (tmp == NULL || tmp == Py_None) {
5304 Py_CLEAR(tmp);
5305 end_lineno = 0;
5306 }
5307 else {
5308 int res;
5309 res = obj2ast_int(tmp, &end_lineno, arena);
5310 if (res != 0) goto failed;
5311 Py_CLEAR(tmp);
5312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005313 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5314 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005315 return 1;
5316 }
5317 if (tmp == NULL || tmp == Py_None) {
5318 Py_CLEAR(tmp);
5319 end_col_offset = 0;
5320 }
5321 else {
5322 int res;
5323 res = obj2ast_int(tmp, &end_col_offset, arena);
5324 if (res != 0) goto failed;
5325 Py_CLEAR(tmp);
5326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005327 tp = astmodulestate_global->FunctionDef_type;
5328 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005329 if (isinstance == -1) {
5330 return 1;
5331 }
5332 if (isinstance) {
5333 identifier name;
5334 arguments_ty args;
5335 asdl_seq* body;
5336 asdl_seq* decorator_list;
5337 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005338 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005339
Dino Viehlandac46eb42019-09-11 10:16:34 -07005340 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005341 return 1;
5342 }
5343 if (tmp == NULL) {
5344 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5345 return 1;
5346 }
5347 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005348 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005349 res = obj2ast_identifier(tmp, &name, arena);
5350 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005351 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005352 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005353 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005354 return 1;
5355 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005356 if (tmp == NULL) {
5357 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5358 return 1;
5359 }
5360 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005361 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005362 res = obj2ast_arguments(tmp, &args, arena);
5363 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005364 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005365 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005366 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005367 return 1;
5368 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005369 if (tmp == NULL) {
5370 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5371 return 1;
5372 }
5373 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005374 int res;
5375 Py_ssize_t len;
5376 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005377 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005378 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 +02005379 goto failed;
5380 }
5381 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005382 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005383 if (body == NULL) goto failed;
5384 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005385 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005386 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5387 Py_INCREF(tmp2);
5388 res = obj2ast_stmt(tmp2, &val, arena);
5389 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005390 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005391 if (len != PyList_GET_SIZE(tmp)) {
5392 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5393 goto failed;
5394 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005395 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005396 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005397 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005398 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005399 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5400 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005401 return 1;
5402 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005403 if (tmp == NULL) {
5404 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5405 return 1;
5406 }
5407 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005408 int res;
5409 Py_ssize_t len;
5410 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005411 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005412 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 +02005413 goto failed;
5414 }
5415 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005416 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005417 if (decorator_list == NULL) goto failed;
5418 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005419 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005420 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5421 Py_INCREF(tmp2);
5422 res = obj2ast_expr(tmp2, &val, arena);
5423 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005424 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005425 if (len != PyList_GET_SIZE(tmp)) {
5426 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5427 goto failed;
5428 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005429 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005430 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005431 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005432 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005433 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5434 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005435 return 1;
5436 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005437 if (tmp == NULL || tmp == Py_None) {
5438 Py_CLEAR(tmp);
5439 returns = NULL;
5440 }
5441 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005442 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005443 res = obj2ast_expr(tmp, &returns, arena);
5444 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005445 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005446 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005447 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5448 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005449 return 1;
5450 }
5451 if (tmp == NULL || tmp == Py_None) {
5452 Py_CLEAR(tmp);
5453 type_comment = NULL;
5454 }
5455 else {
5456 int res;
5457 res = obj2ast_string(tmp, &type_comment, arena);
5458 if (res != 0) goto failed;
5459 Py_CLEAR(tmp);
5460 }
5461 *out = FunctionDef(name, args, body, decorator_list, returns,
5462 type_comment, lineno, col_offset, end_lineno,
5463 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005464 if (*out == NULL) goto failed;
5465 return 0;
5466 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005467 tp = astmodulestate_global->AsyncFunctionDef_type;
5468 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005469 if (isinstance == -1) {
5470 return 1;
5471 }
5472 if (isinstance) {
5473 identifier name;
5474 arguments_ty args;
5475 asdl_seq* body;
5476 asdl_seq* decorator_list;
5477 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005478 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005479
Dino Viehlandac46eb42019-09-11 10:16:34 -07005480 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005481 return 1;
5482 }
5483 if (tmp == NULL) {
5484 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5485 return 1;
5486 }
5487 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005488 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005489 res = obj2ast_identifier(tmp, &name, arena);
5490 if (res != 0) goto failed;
5491 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005492 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005493 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005494 return 1;
5495 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005496 if (tmp == NULL) {
5497 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5498 return 1;
5499 }
5500 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005501 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005502 res = obj2ast_arguments(tmp, &args, arena);
5503 if (res != 0) goto failed;
5504 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005505 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005506 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005507 return 1;
5508 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005509 if (tmp == NULL) {
5510 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5511 return 1;
5512 }
5513 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005514 int res;
5515 Py_ssize_t len;
5516 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005517 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005518 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 -04005519 goto failed;
5520 }
5521 len = PyList_GET_SIZE(tmp);
5522 body = _Py_asdl_seq_new(len, arena);
5523 if (body == NULL) goto failed;
5524 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005525 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005526 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5527 Py_INCREF(tmp2);
5528 res = obj2ast_stmt(tmp2, &val, arena);
5529 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005530 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005531 if (len != PyList_GET_SIZE(tmp)) {
5532 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5533 goto failed;
5534 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005535 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005536 }
5537 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005538 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005539 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5540 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005541 return 1;
5542 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005543 if (tmp == NULL) {
5544 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5545 return 1;
5546 }
5547 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005548 int res;
5549 Py_ssize_t len;
5550 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005551 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005552 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 -04005553 goto failed;
5554 }
5555 len = PyList_GET_SIZE(tmp);
5556 decorator_list = _Py_asdl_seq_new(len, arena);
5557 if (decorator_list == NULL) goto failed;
5558 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005559 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005560 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5561 Py_INCREF(tmp2);
5562 res = obj2ast_expr(tmp2, &val, arena);
5563 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005564 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005565 if (len != PyList_GET_SIZE(tmp)) {
5566 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5567 goto failed;
5568 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005569 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005570 }
5571 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005572 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005573 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5574 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005575 return 1;
5576 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005577 if (tmp == NULL || tmp == Py_None) {
5578 Py_CLEAR(tmp);
5579 returns = NULL;
5580 }
5581 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005582 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005583 res = obj2ast_expr(tmp, &returns, arena);
5584 if (res != 0) goto failed;
5585 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005586 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005587 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5588 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005589 return 1;
5590 }
5591 if (tmp == NULL || tmp == Py_None) {
5592 Py_CLEAR(tmp);
5593 type_comment = NULL;
5594 }
5595 else {
5596 int res;
5597 res = obj2ast_string(tmp, &type_comment, arena);
5598 if (res != 0) goto failed;
5599 Py_CLEAR(tmp);
5600 }
Yury Selivanov75445082015-05-11 22:57:16 -04005601 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005602 type_comment, lineno, col_offset, end_lineno,
5603 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005604 if (*out == NULL) goto failed;
5605 return 0;
5606 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005607 tp = astmodulestate_global->ClassDef_type;
5608 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005609 if (isinstance == -1) {
5610 return 1;
5611 }
5612 if (isinstance) {
5613 identifier name;
5614 asdl_seq* bases;
5615 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005616 asdl_seq* body;
5617 asdl_seq* decorator_list;
5618
Dino Viehlandac46eb42019-09-11 10:16:34 -07005619 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005620 return 1;
5621 }
5622 if (tmp == NULL) {
5623 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5624 return 1;
5625 }
5626 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005627 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005628 res = obj2ast_identifier(tmp, &name, arena);
5629 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005630 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005631 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005632 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005633 return 1;
5634 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005635 if (tmp == NULL) {
5636 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5637 return 1;
5638 }
5639 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005640 int res;
5641 Py_ssize_t len;
5642 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005643 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005644 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 +02005645 goto failed;
5646 }
5647 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005648 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005649 if (bases == NULL) goto failed;
5650 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005651 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005652 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5653 Py_INCREF(tmp2);
5654 res = obj2ast_expr(tmp2, &val, arena);
5655 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005656 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005657 if (len != PyList_GET_SIZE(tmp)) {
5658 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5659 goto failed;
5660 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005661 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005662 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005663 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005664 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005665 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5666 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005667 return 1;
5668 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005669 if (tmp == NULL) {
5670 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5671 return 1;
5672 }
5673 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005674 int res;
5675 Py_ssize_t len;
5676 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005677 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005678 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 +02005679 goto failed;
5680 }
5681 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005682 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005683 if (keywords == NULL) goto failed;
5684 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005685 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005686 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5687 Py_INCREF(tmp2);
5688 res = obj2ast_keyword(tmp2, &val, arena);
5689 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005690 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005691 if (len != PyList_GET_SIZE(tmp)) {
5692 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5693 goto failed;
5694 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005695 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005696 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005697 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005698 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005699 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005700 return 1;
5701 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005702 if (tmp == NULL) {
5703 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5704 return 1;
5705 }
5706 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005707 int res;
5708 Py_ssize_t len;
5709 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005710 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005711 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 +02005712 goto failed;
5713 }
5714 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005715 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005716 if (body == NULL) goto failed;
5717 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005718 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005719 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5720 Py_INCREF(tmp2);
5721 res = obj2ast_stmt(tmp2, &val, arena);
5722 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005723 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005724 if (len != PyList_GET_SIZE(tmp)) {
5725 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5726 goto failed;
5727 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005728 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005729 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005730 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005731 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005732 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5733 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005734 return 1;
5735 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005736 if (tmp == NULL) {
5737 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5738 return 1;
5739 }
5740 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005741 int res;
5742 Py_ssize_t len;
5743 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005744 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005745 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 +02005746 goto failed;
5747 }
5748 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005749 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005750 if (decorator_list == NULL) goto failed;
5751 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005752 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005753 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5754 Py_INCREF(tmp2);
5755 res = obj2ast_expr(tmp2, &val, arena);
5756 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005757 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005758 if (len != PyList_GET_SIZE(tmp)) {
5759 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5760 goto failed;
5761 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005762 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005763 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005764 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005765 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005766 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005767 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005768 if (*out == NULL) goto failed;
5769 return 0;
5770 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005771 tp = astmodulestate_global->Return_type;
5772 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005773 if (isinstance == -1) {
5774 return 1;
5775 }
5776 if (isinstance) {
5777 expr_ty value;
5778
Dino Viehlandac46eb42019-09-11 10:16:34 -07005779 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005780 return 1;
5781 }
5782 if (tmp == NULL || tmp == Py_None) {
5783 Py_CLEAR(tmp);
5784 value = NULL;
5785 }
5786 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005787 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005788 res = obj2ast_expr(tmp, &value, arena);
5789 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005790 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005791 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005792 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5793 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005794 if (*out == NULL) goto failed;
5795 return 0;
5796 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005797 tp = astmodulestate_global->Delete_type;
5798 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005799 if (isinstance == -1) {
5800 return 1;
5801 }
5802 if (isinstance) {
5803 asdl_seq* targets;
5804
Dino Viehlandac46eb42019-09-11 10:16:34 -07005805 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5806 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005807 return 1;
5808 }
5809 if (tmp == NULL) {
5810 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5811 return 1;
5812 }
5813 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005814 int res;
5815 Py_ssize_t len;
5816 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005817 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005818 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 +02005819 goto failed;
5820 }
5821 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005822 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005823 if (targets == NULL) goto failed;
5824 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005825 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005826 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5827 Py_INCREF(tmp2);
5828 res = obj2ast_expr(tmp2, &val, arena);
5829 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005830 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005831 if (len != PyList_GET_SIZE(tmp)) {
5832 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5833 goto failed;
5834 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005835 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005836 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005837 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005838 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005839 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5840 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005841 if (*out == NULL) goto failed;
5842 return 0;
5843 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005844 tp = astmodulestate_global->Assign_type;
5845 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005846 if (isinstance == -1) {
5847 return 1;
5848 }
5849 if (isinstance) {
5850 asdl_seq* targets;
5851 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005852 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005853
Dino Viehlandac46eb42019-09-11 10:16:34 -07005854 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5855 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005856 return 1;
5857 }
5858 if (tmp == NULL) {
5859 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5860 return 1;
5861 }
5862 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005863 int res;
5864 Py_ssize_t len;
5865 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005866 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005867 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 +02005868 goto failed;
5869 }
5870 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005871 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005872 if (targets == NULL) goto failed;
5873 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005874 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005875 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5876 Py_INCREF(tmp2);
5877 res = obj2ast_expr(tmp2, &val, arena);
5878 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005879 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005880 if (len != PyList_GET_SIZE(tmp)) {
5881 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5882 goto failed;
5883 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005884 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005885 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005886 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005887 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005888 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005889 return 1;
5890 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005891 if (tmp == NULL) {
5892 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5893 return 1;
5894 }
5895 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005896 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005897 res = obj2ast_expr(tmp, &value, arena);
5898 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005899 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005900 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005901 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5902 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005903 return 1;
5904 }
5905 if (tmp == NULL || tmp == Py_None) {
5906 Py_CLEAR(tmp);
5907 type_comment = NULL;
5908 }
5909 else {
5910 int res;
5911 res = obj2ast_string(tmp, &type_comment, arena);
5912 if (res != 0) goto failed;
5913 Py_CLEAR(tmp);
5914 }
5915 *out = Assign(targets, value, type_comment, lineno, col_offset,
5916 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005917 if (*out == NULL) goto failed;
5918 return 0;
5919 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005920 tp = astmodulestate_global->AugAssign_type;
5921 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005922 if (isinstance == -1) {
5923 return 1;
5924 }
5925 if (isinstance) {
5926 expr_ty target;
5927 operator_ty op;
5928 expr_ty value;
5929
Dino Viehlandac46eb42019-09-11 10:16:34 -07005930 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5931 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005932 return 1;
5933 }
5934 if (tmp == NULL) {
5935 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5936 return 1;
5937 }
5938 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005939 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005940 res = obj2ast_expr(tmp, &target, arena);
5941 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005942 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005944 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005945 return 1;
5946 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005947 if (tmp == NULL) {
5948 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5949 return 1;
5950 }
5951 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005952 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005953 res = obj2ast_operator(tmp, &op, arena);
5954 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005955 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005956 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005957 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005958 return 1;
5959 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005960 if (tmp == NULL) {
5961 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5962 return 1;
5963 }
5964 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005965 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005966 res = obj2ast_expr(tmp, &value, arena);
5967 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005968 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005969 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005970 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5971 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005972 if (*out == NULL) goto failed;
5973 return 0;
5974 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005975 tp = astmodulestate_global->AnnAssign_type;
5976 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005977 if (isinstance == -1) {
5978 return 1;
5979 }
5980 if (isinstance) {
5981 expr_ty target;
5982 expr_ty annotation;
5983 expr_ty value;
5984 int simple;
5985
Dino Viehlandac46eb42019-09-11 10:16:34 -07005986 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5987 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005988 return 1;
5989 }
5990 if (tmp == NULL) {
5991 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5992 return 1;
5993 }
5994 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005995 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005996 res = obj2ast_expr(tmp, &target, arena);
5997 if (res != 0) goto failed;
5998 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005999 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006000 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6001 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006002 return 1;
6003 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006004 if (tmp == NULL) {
6005 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6006 return 1;
6007 }
6008 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006009 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006010 res = obj2ast_expr(tmp, &annotation, arena);
6011 if (res != 0) goto failed;
6012 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006013 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006014 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006015 return 1;
6016 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006017 if (tmp == NULL || tmp == Py_None) {
6018 Py_CLEAR(tmp);
6019 value = NULL;
6020 }
6021 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006022 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006023 res = obj2ast_expr(tmp, &value, arena);
6024 if (res != 0) goto failed;
6025 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006026 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006027 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6028 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006029 return 1;
6030 }
6031 if (tmp == NULL) {
6032 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6033 return 1;
6034 }
6035 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006036 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006037 res = obj2ast_int(tmp, &simple, arena);
6038 if (res != 0) goto failed;
6039 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006040 }
6041 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006042 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006043 if (*out == NULL) goto failed;
6044 return 0;
6045 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006046 tp = astmodulestate_global->For_type;
6047 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006048 if (isinstance == -1) {
6049 return 1;
6050 }
6051 if (isinstance) {
6052 expr_ty target;
6053 expr_ty iter;
6054 asdl_seq* body;
6055 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006056 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006057
Dino Viehlandac46eb42019-09-11 10:16:34 -07006058 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6059 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006060 return 1;
6061 }
6062 if (tmp == NULL) {
6063 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6064 return 1;
6065 }
6066 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006067 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006068 res = obj2ast_expr(tmp, &target, arena);
6069 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006070 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006071 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006072 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006073 return 1;
6074 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006075 if (tmp == NULL) {
6076 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6077 return 1;
6078 }
6079 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006080 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006081 res = obj2ast_expr(tmp, &iter, arena);
6082 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006083 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006084 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006085 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006086 return 1;
6087 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006088 if (tmp == NULL) {
6089 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6090 return 1;
6091 }
6092 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006093 int res;
6094 Py_ssize_t len;
6095 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006096 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006097 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 +02006098 goto failed;
6099 }
6100 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006101 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006102 if (body == NULL) goto failed;
6103 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006104 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006105 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6106 Py_INCREF(tmp2);
6107 res = obj2ast_stmt(tmp2, &val, arena);
6108 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006109 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006110 if (len != PyList_GET_SIZE(tmp)) {
6111 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6112 goto failed;
6113 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006114 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006115 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006116 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006117 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006118 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6119 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006120 return 1;
6121 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006122 if (tmp == NULL) {
6123 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6124 return 1;
6125 }
6126 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006127 int res;
6128 Py_ssize_t len;
6129 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006130 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006131 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 +02006132 goto failed;
6133 }
6134 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006135 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006136 if (orelse == NULL) goto failed;
6137 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006138 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006139 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6140 Py_INCREF(tmp2);
6141 res = obj2ast_stmt(tmp2, &val, arena);
6142 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006143 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006144 if (len != PyList_GET_SIZE(tmp)) {
6145 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6146 goto failed;
6147 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006148 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006149 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006150 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006152 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6153 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006154 return 1;
6155 }
6156 if (tmp == NULL || tmp == Py_None) {
6157 Py_CLEAR(tmp);
6158 type_comment = NULL;
6159 }
6160 else {
6161 int res;
6162 res = obj2ast_string(tmp, &type_comment, arena);
6163 if (res != 0) goto failed;
6164 Py_CLEAR(tmp);
6165 }
6166 *out = For(target, iter, body, orelse, type_comment, lineno,
6167 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006168 if (*out == NULL) goto failed;
6169 return 0;
6170 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006171 tp = astmodulestate_global->AsyncFor_type;
6172 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006173 if (isinstance == -1) {
6174 return 1;
6175 }
6176 if (isinstance) {
6177 expr_ty target;
6178 expr_ty iter;
6179 asdl_seq* body;
6180 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006181 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006182
Dino Viehlandac46eb42019-09-11 10:16:34 -07006183 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6184 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006185 return 1;
6186 }
6187 if (tmp == NULL) {
6188 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6189 return 1;
6190 }
6191 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006192 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006193 res = obj2ast_expr(tmp, &target, arena);
6194 if (res != 0) goto failed;
6195 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006196 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006197 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006198 return 1;
6199 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006200 if (tmp == NULL) {
6201 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6202 return 1;
6203 }
6204 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006205 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006206 res = obj2ast_expr(tmp, &iter, arena);
6207 if (res != 0) goto failed;
6208 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006209 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006210 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006211 return 1;
6212 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006213 if (tmp == NULL) {
6214 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6215 return 1;
6216 }
6217 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006218 int res;
6219 Py_ssize_t len;
6220 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006221 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006222 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 -04006223 goto failed;
6224 }
6225 len = PyList_GET_SIZE(tmp);
6226 body = _Py_asdl_seq_new(len, arena);
6227 if (body == NULL) goto failed;
6228 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006229 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006230 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6231 Py_INCREF(tmp2);
6232 res = obj2ast_stmt(tmp2, &val, arena);
6233 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006234 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006235 if (len != PyList_GET_SIZE(tmp)) {
6236 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6237 goto failed;
6238 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006239 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006240 }
6241 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006242 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006243 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6244 {
Yury Selivanov75445082015-05-11 22:57:16 -04006245 return 1;
6246 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006247 if (tmp == NULL) {
6248 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6249 return 1;
6250 }
6251 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006252 int res;
6253 Py_ssize_t len;
6254 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006255 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006256 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 -04006257 goto failed;
6258 }
6259 len = PyList_GET_SIZE(tmp);
6260 orelse = _Py_asdl_seq_new(len, arena);
6261 if (orelse == NULL) goto failed;
6262 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006263 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006264 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6265 Py_INCREF(tmp2);
6266 res = obj2ast_stmt(tmp2, &val, arena);
6267 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006268 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006269 if (len != PyList_GET_SIZE(tmp)) {
6270 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6271 goto failed;
6272 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006273 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006274 }
6275 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006277 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6278 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006279 return 1;
6280 }
6281 if (tmp == NULL || tmp == Py_None) {
6282 Py_CLEAR(tmp);
6283 type_comment = NULL;
6284 }
6285 else {
6286 int res;
6287 res = obj2ast_string(tmp, &type_comment, arena);
6288 if (res != 0) goto failed;
6289 Py_CLEAR(tmp);
6290 }
6291 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6292 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006293 if (*out == NULL) goto failed;
6294 return 0;
6295 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006296 tp = astmodulestate_global->While_type;
6297 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006298 if (isinstance == -1) {
6299 return 1;
6300 }
6301 if (isinstance) {
6302 expr_ty test;
6303 asdl_seq* body;
6304 asdl_seq* orelse;
6305
Dino Viehlandac46eb42019-09-11 10:16:34 -07006306 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006307 return 1;
6308 }
6309 if (tmp == NULL) {
6310 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6311 return 1;
6312 }
6313 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006314 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006315 res = obj2ast_expr(tmp, &test, arena);
6316 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006317 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006318 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006319 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006320 return 1;
6321 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006322 if (tmp == NULL) {
6323 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6324 return 1;
6325 }
6326 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006327 int res;
6328 Py_ssize_t len;
6329 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006330 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006331 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 +02006332 goto failed;
6333 }
6334 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006335 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006336 if (body == NULL) goto failed;
6337 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006338 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006339 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6340 Py_INCREF(tmp2);
6341 res = obj2ast_stmt(tmp2, &val, arena);
6342 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006343 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006344 if (len != PyList_GET_SIZE(tmp)) {
6345 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6346 goto failed;
6347 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006348 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006349 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006350 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006351 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006352 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6353 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006354 return 1;
6355 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006356 if (tmp == NULL) {
6357 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6358 return 1;
6359 }
6360 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006361 int res;
6362 Py_ssize_t len;
6363 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006364 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006365 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 +02006366 goto failed;
6367 }
6368 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006369 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006370 if (orelse == NULL) goto failed;
6371 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006372 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006373 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6374 Py_INCREF(tmp2);
6375 res = obj2ast_stmt(tmp2, &val, arena);
6376 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006377 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006378 if (len != PyList_GET_SIZE(tmp)) {
6379 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6380 goto failed;
6381 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006382 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006383 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006384 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006385 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006386 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6387 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006388 if (*out == NULL) goto failed;
6389 return 0;
6390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006391 tp = astmodulestate_global->If_type;
6392 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006393 if (isinstance == -1) {
6394 return 1;
6395 }
6396 if (isinstance) {
6397 expr_ty test;
6398 asdl_seq* body;
6399 asdl_seq* orelse;
6400
Dino Viehlandac46eb42019-09-11 10:16:34 -07006401 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006402 return 1;
6403 }
6404 if (tmp == NULL) {
6405 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6406 return 1;
6407 }
6408 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006409 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006410 res = obj2ast_expr(tmp, &test, arena);
6411 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006412 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006413 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006414 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006415 return 1;
6416 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006417 if (tmp == NULL) {
6418 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6419 return 1;
6420 }
6421 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006422 int res;
6423 Py_ssize_t len;
6424 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006425 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006426 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 +02006427 goto failed;
6428 }
6429 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006430 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006431 if (body == NULL) goto failed;
6432 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006433 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006434 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6435 Py_INCREF(tmp2);
6436 res = obj2ast_stmt(tmp2, &val, arena);
6437 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006438 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006439 if (len != PyList_GET_SIZE(tmp)) {
6440 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6441 goto failed;
6442 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006443 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006444 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006445 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006446 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006447 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6448 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006449 return 1;
6450 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006451 if (tmp == NULL) {
6452 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6453 return 1;
6454 }
6455 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006456 int res;
6457 Py_ssize_t len;
6458 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006459 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006460 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 +02006461 goto failed;
6462 }
6463 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006464 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006465 if (orelse == NULL) goto failed;
6466 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006467 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006468 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6469 Py_INCREF(tmp2);
6470 res = obj2ast_stmt(tmp2, &val, arena);
6471 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006472 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006473 if (len != PyList_GET_SIZE(tmp)) {
6474 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6475 goto failed;
6476 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006477 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006478 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006479 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006480 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006481 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6482 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006483 if (*out == NULL) goto failed;
6484 return 0;
6485 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006486 tp = astmodulestate_global->With_type;
6487 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006488 if (isinstance == -1) {
6489 return 1;
6490 }
6491 if (isinstance) {
6492 asdl_seq* items;
6493 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006494 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006495
Dino Viehlandac46eb42019-09-11 10:16:34 -07006496 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006497 return 1;
6498 }
6499 if (tmp == NULL) {
6500 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6501 return 1;
6502 }
6503 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006504 int res;
6505 Py_ssize_t len;
6506 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006507 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006508 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 +02006509 goto failed;
6510 }
6511 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006512 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006513 if (items == NULL) goto failed;
6514 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006515 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006516 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6517 Py_INCREF(tmp2);
6518 res = obj2ast_withitem(tmp2, &val, arena);
6519 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006520 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006521 if (len != PyList_GET_SIZE(tmp)) {
6522 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6523 goto failed;
6524 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006525 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006526 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006527 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006528 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006529 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006530 return 1;
6531 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006532 if (tmp == NULL) {
6533 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6534 return 1;
6535 }
6536 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006537 int res;
6538 Py_ssize_t len;
6539 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006540 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006541 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 +02006542 goto failed;
6543 }
6544 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006545 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006546 if (body == NULL) goto failed;
6547 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006548 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006549 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6550 Py_INCREF(tmp2);
6551 res = obj2ast_stmt(tmp2, &val, arena);
6552 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006553 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006554 if (len != PyList_GET_SIZE(tmp)) {
6555 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6556 goto failed;
6557 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006558 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006559 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006560 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006561 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006562 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6563 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006564 return 1;
6565 }
6566 if (tmp == NULL || tmp == Py_None) {
6567 Py_CLEAR(tmp);
6568 type_comment = NULL;
6569 }
6570 else {
6571 int res;
6572 res = obj2ast_string(tmp, &type_comment, arena);
6573 if (res != 0) goto failed;
6574 Py_CLEAR(tmp);
6575 }
6576 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006577 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006578 if (*out == NULL) goto failed;
6579 return 0;
6580 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006581 tp = astmodulestate_global->AsyncWith_type;
6582 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006583 if (isinstance == -1) {
6584 return 1;
6585 }
6586 if (isinstance) {
6587 asdl_seq* items;
6588 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006589 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006590
Dino Viehlandac46eb42019-09-11 10:16:34 -07006591 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006592 return 1;
6593 }
6594 if (tmp == NULL) {
6595 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6596 return 1;
6597 }
6598 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006599 int res;
6600 Py_ssize_t len;
6601 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006602 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006603 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 -04006604 goto failed;
6605 }
6606 len = PyList_GET_SIZE(tmp);
6607 items = _Py_asdl_seq_new(len, arena);
6608 if (items == NULL) goto failed;
6609 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006610 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006611 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6612 Py_INCREF(tmp2);
6613 res = obj2ast_withitem(tmp2, &val, arena);
6614 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006615 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006616 if (len != PyList_GET_SIZE(tmp)) {
6617 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6618 goto failed;
6619 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006620 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006621 }
6622 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006623 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006624 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006625 return 1;
6626 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006627 if (tmp == NULL) {
6628 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6629 return 1;
6630 }
6631 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006632 int res;
6633 Py_ssize_t len;
6634 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006635 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006636 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 -04006637 goto failed;
6638 }
6639 len = PyList_GET_SIZE(tmp);
6640 body = _Py_asdl_seq_new(len, arena);
6641 if (body == NULL) goto failed;
6642 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006643 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006644 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6645 Py_INCREF(tmp2);
6646 res = obj2ast_stmt(tmp2, &val, arena);
6647 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006648 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006649 if (len != PyList_GET_SIZE(tmp)) {
6650 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6651 goto failed;
6652 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006653 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006654 }
6655 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006656 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006657 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6658 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006659 return 1;
6660 }
6661 if (tmp == NULL || tmp == Py_None) {
6662 Py_CLEAR(tmp);
6663 type_comment = NULL;
6664 }
6665 else {
6666 int res;
6667 res = obj2ast_string(tmp, &type_comment, arena);
6668 if (res != 0) goto failed;
6669 Py_CLEAR(tmp);
6670 }
6671 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6672 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006673 if (*out == NULL) goto failed;
6674 return 0;
6675 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006676 tp = astmodulestate_global->Raise_type;
6677 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006678 if (isinstance == -1) {
6679 return 1;
6680 }
6681 if (isinstance) {
6682 expr_ty exc;
6683 expr_ty cause;
6684
Dino Viehlandac46eb42019-09-11 10:16:34 -07006685 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006686 return 1;
6687 }
6688 if (tmp == NULL || tmp == Py_None) {
6689 Py_CLEAR(tmp);
6690 exc = NULL;
6691 }
6692 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006693 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006694 res = obj2ast_expr(tmp, &exc, arena);
6695 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006696 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006697 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006698 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006699 return 1;
6700 }
6701 if (tmp == NULL || tmp == Py_None) {
6702 Py_CLEAR(tmp);
6703 cause = NULL;
6704 }
6705 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006706 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006707 res = obj2ast_expr(tmp, &cause, arena);
6708 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006709 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006710 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006711 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6712 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006713 if (*out == NULL) goto failed;
6714 return 0;
6715 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006716 tp = astmodulestate_global->Try_type;
6717 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006718 if (isinstance == -1) {
6719 return 1;
6720 }
6721 if (isinstance) {
6722 asdl_seq* body;
6723 asdl_seq* handlers;
6724 asdl_seq* orelse;
6725 asdl_seq* finalbody;
6726
Dino Viehlandac46eb42019-09-11 10:16:34 -07006727 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006728 return 1;
6729 }
6730 if (tmp == NULL) {
6731 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6732 return 1;
6733 }
6734 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006735 int res;
6736 Py_ssize_t len;
6737 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006738 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006739 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 +02006740 goto failed;
6741 }
6742 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006743 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006744 if (body == NULL) goto failed;
6745 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006746 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006747 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6748 Py_INCREF(tmp2);
6749 res = obj2ast_stmt(tmp2, &val, arena);
6750 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006751 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006752 if (len != PyList_GET_SIZE(tmp)) {
6753 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6754 goto failed;
6755 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006756 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006757 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006758 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006759 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006760 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6761 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006762 return 1;
6763 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006764 if (tmp == NULL) {
6765 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6766 return 1;
6767 }
6768 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006769 int res;
6770 Py_ssize_t len;
6771 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006772 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006773 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 +02006774 goto failed;
6775 }
6776 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006777 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006778 if (handlers == NULL) goto failed;
6779 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006780 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006781 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6782 Py_INCREF(tmp2);
6783 res = obj2ast_excepthandler(tmp2, &val, arena);
6784 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006785 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006786 if (len != PyList_GET_SIZE(tmp)) {
6787 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6788 goto failed;
6789 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006790 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006792 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006793 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006794 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6795 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006796 return 1;
6797 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006798 if (tmp == NULL) {
6799 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6800 return 1;
6801 }
6802 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006803 int res;
6804 Py_ssize_t len;
6805 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006806 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006807 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 +02006808 goto failed;
6809 }
6810 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006811 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006812 if (orelse == NULL) goto failed;
6813 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006814 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006815 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6816 Py_INCREF(tmp2);
6817 res = obj2ast_stmt(tmp2, &val, arena);
6818 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006819 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006820 if (len != PyList_GET_SIZE(tmp)) {
6821 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6822 goto failed;
6823 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006824 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006825 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006826 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006827 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006828 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6829 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006830 return 1;
6831 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006832 if (tmp == NULL) {
6833 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6834 return 1;
6835 }
6836 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006837 int res;
6838 Py_ssize_t len;
6839 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006840 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006841 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 +02006842 goto failed;
6843 }
6844 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006845 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006846 if (finalbody == NULL) goto failed;
6847 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006848 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006849 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6850 Py_INCREF(tmp2);
6851 res = obj2ast_stmt(tmp2, &val, arena);
6852 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006853 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006854 if (len != PyList_GET_SIZE(tmp)) {
6855 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6856 goto failed;
6857 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006858 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006859 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006860 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006861 }
6862 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006863 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006864 if (*out == NULL) goto failed;
6865 return 0;
6866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006867 tp = astmodulestate_global->Assert_type;
6868 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006869 if (isinstance == -1) {
6870 return 1;
6871 }
6872 if (isinstance) {
6873 expr_ty test;
6874 expr_ty msg;
6875
Dino Viehlandac46eb42019-09-11 10:16:34 -07006876 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006877 return 1;
6878 }
6879 if (tmp == NULL) {
6880 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6881 return 1;
6882 }
6883 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006884 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006885 res = obj2ast_expr(tmp, &test, arena);
6886 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006887 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006888 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006889 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006890 return 1;
6891 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006892 if (tmp == NULL || tmp == Py_None) {
6893 Py_CLEAR(tmp);
6894 msg = NULL;
6895 }
6896 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006897 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006898 res = obj2ast_expr(tmp, &msg, arena);
6899 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006900 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006901 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006902 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6903 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006904 if (*out == NULL) goto failed;
6905 return 0;
6906 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006907 tp = astmodulestate_global->Import_type;
6908 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006909 if (isinstance == -1) {
6910 return 1;
6911 }
6912 if (isinstance) {
6913 asdl_seq* names;
6914
Dino Viehlandac46eb42019-09-11 10:16:34 -07006915 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006916 return 1;
6917 }
6918 if (tmp == NULL) {
6919 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6920 return 1;
6921 }
6922 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006923 int res;
6924 Py_ssize_t len;
6925 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006926 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006927 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 +02006928 goto failed;
6929 }
6930 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006931 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006932 if (names == NULL) goto failed;
6933 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006934 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006935 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6936 Py_INCREF(tmp2);
6937 res = obj2ast_alias(tmp2, &val, arena);
6938 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006939 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006940 if (len != PyList_GET_SIZE(tmp)) {
6941 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6942 goto failed;
6943 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006944 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006945 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006946 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006947 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006948 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6949 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006950 if (*out == NULL) goto failed;
6951 return 0;
6952 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006953 tp = astmodulestate_global->ImportFrom_type;
6954 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006955 if (isinstance == -1) {
6956 return 1;
6957 }
6958 if (isinstance) {
6959 identifier module;
6960 asdl_seq* names;
6961 int level;
6962
Dino Viehlandac46eb42019-09-11 10:16:34 -07006963 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6964 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006965 return 1;
6966 }
6967 if (tmp == NULL || tmp == Py_None) {
6968 Py_CLEAR(tmp);
6969 module = NULL;
6970 }
6971 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006972 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006973 res = obj2ast_identifier(tmp, &module, arena);
6974 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006975 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006976 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006977 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006978 return 1;
6979 }
6980 if (tmp == NULL) {
6981 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6982 return 1;
6983 }
6984 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006985 int res;
6986 Py_ssize_t len;
6987 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006988 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006989 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 +02006990 goto failed;
6991 }
6992 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006993 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006994 if (names == NULL) goto failed;
6995 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006996 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006997 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6998 Py_INCREF(tmp2);
6999 res = obj2ast_alias(tmp2, &val, arena);
7000 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007001 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007002 if (len != PyList_GET_SIZE(tmp)) {
7003 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7004 goto failed;
7005 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007006 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007007 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007008 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007010 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007011 return 1;
7012 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007013 if (tmp == NULL || tmp == Py_None) {
7014 Py_CLEAR(tmp);
7015 level = 0;
7016 }
7017 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007018 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007019 res = obj2ast_int(tmp, &level, arena);
7020 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007021 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007022 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007023 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7024 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007025 if (*out == NULL) goto failed;
7026 return 0;
7027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007028 tp = astmodulestate_global->Global_type;
7029 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007030 if (isinstance == -1) {
7031 return 1;
7032 }
7033 if (isinstance) {
7034 asdl_seq* names;
7035
Dino Viehlandac46eb42019-09-11 10:16:34 -07007036 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007037 return 1;
7038 }
7039 if (tmp == NULL) {
7040 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7041 return 1;
7042 }
7043 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007044 int res;
7045 Py_ssize_t len;
7046 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007047 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007048 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 +02007049 goto failed;
7050 }
7051 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007052 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007053 if (names == NULL) goto failed;
7054 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007055 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007056 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7057 Py_INCREF(tmp2);
7058 res = obj2ast_identifier(tmp2, &val, arena);
7059 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007060 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007061 if (len != PyList_GET_SIZE(tmp)) {
7062 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7063 goto failed;
7064 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007065 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007066 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007067 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007068 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007069 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7070 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007071 if (*out == NULL) goto failed;
7072 return 0;
7073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007074 tp = astmodulestate_global->Nonlocal_type;
7075 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007076 if (isinstance == -1) {
7077 return 1;
7078 }
7079 if (isinstance) {
7080 asdl_seq* names;
7081
Dino Viehlandac46eb42019-09-11 10:16:34 -07007082 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007083 return 1;
7084 }
7085 if (tmp == NULL) {
7086 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7087 return 1;
7088 }
7089 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007090 int res;
7091 Py_ssize_t len;
7092 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007093 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007094 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 +02007095 goto failed;
7096 }
7097 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007098 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007099 if (names == NULL) goto failed;
7100 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007101 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007102 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7103 Py_INCREF(tmp2);
7104 res = obj2ast_identifier(tmp2, &val, arena);
7105 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007106 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007107 if (len != PyList_GET_SIZE(tmp)) {
7108 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7109 goto failed;
7110 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007111 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007112 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007113 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007114 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007115 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7116 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007117 if (*out == NULL) goto failed;
7118 return 0;
7119 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007120 tp = astmodulestate_global->Expr_type;
7121 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007122 if (isinstance == -1) {
7123 return 1;
7124 }
7125 if (isinstance) {
7126 expr_ty value;
7127
Dino Viehlandac46eb42019-09-11 10:16:34 -07007128 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007129 return 1;
7130 }
7131 if (tmp == NULL) {
7132 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7133 return 1;
7134 }
7135 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007136 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007137 res = obj2ast_expr(tmp, &value, arena);
7138 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007139 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007140 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007141 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7142 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007143 if (*out == NULL) goto failed;
7144 return 0;
7145 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007146 tp = astmodulestate_global->Pass_type;
7147 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007148 if (isinstance == -1) {
7149 return 1;
7150 }
7151 if (isinstance) {
7152
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007153 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007154 if (*out == NULL) goto failed;
7155 return 0;
7156 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007157 tp = astmodulestate_global->Break_type;
7158 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007159 if (isinstance == -1) {
7160 return 1;
7161 }
7162 if (isinstance) {
7163
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007164 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007165 if (*out == NULL) goto failed;
7166 return 0;
7167 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007168 tp = astmodulestate_global->Continue_type;
7169 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007170 if (isinstance == -1) {
7171 return 1;
7172 }
7173 if (isinstance) {
7174
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007175 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007176 if (*out == NULL) goto failed;
7177 return 0;
7178 }
7179
7180 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7181 failed:
7182 Py_XDECREF(tmp);
7183 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007184}
7185
7186int
7187obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7188{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007189 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007190
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007191 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007192 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007193 int lineno;
7194 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007195 int end_lineno;
7196 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007197
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007198 if (obj == Py_None) {
7199 *out = NULL;
7200 return 0;
7201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007202 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007203 return 1;
7204 }
7205 if (tmp == NULL) {
7206 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7207 return 1;
7208 }
7209 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007210 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007211 res = obj2ast_int(tmp, &lineno, arena);
7212 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007213 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007214 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007215 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7216 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007217 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007218 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007219 if (tmp == NULL) {
7220 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7221 return 1;
7222 }
7223 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007224 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007225 res = obj2ast_int(tmp, &col_offset, arena);
7226 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007227 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007229 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7230 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007231 return 1;
7232 }
7233 if (tmp == NULL || tmp == Py_None) {
7234 Py_CLEAR(tmp);
7235 end_lineno = 0;
7236 }
7237 else {
7238 int res;
7239 res = obj2ast_int(tmp, &end_lineno, arena);
7240 if (res != 0) goto failed;
7241 Py_CLEAR(tmp);
7242 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007243 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7244 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007245 return 1;
7246 }
7247 if (tmp == NULL || tmp == Py_None) {
7248 Py_CLEAR(tmp);
7249 end_col_offset = 0;
7250 }
7251 else {
7252 int res;
7253 res = obj2ast_int(tmp, &end_col_offset, arena);
7254 if (res != 0) goto failed;
7255 Py_CLEAR(tmp);
7256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007257 tp = astmodulestate_global->BoolOp_type;
7258 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007259 if (isinstance == -1) {
7260 return 1;
7261 }
7262 if (isinstance) {
7263 boolop_ty op;
7264 asdl_seq* values;
7265
Dino Viehlandac46eb42019-09-11 10:16:34 -07007266 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007267 return 1;
7268 }
7269 if (tmp == NULL) {
7270 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7271 return 1;
7272 }
7273 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007274 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007275 res = obj2ast_boolop(tmp, &op, arena);
7276 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007277 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007279 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7280 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007281 return 1;
7282 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007283 if (tmp == NULL) {
7284 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7285 return 1;
7286 }
7287 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007288 int res;
7289 Py_ssize_t len;
7290 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007291 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007292 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 +02007293 goto failed;
7294 }
7295 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007296 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007297 if (values == NULL) goto failed;
7298 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007299 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007300 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7301 Py_INCREF(tmp2);
7302 res = obj2ast_expr(tmp2, &val, arena);
7303 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007304 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007305 if (len != PyList_GET_SIZE(tmp)) {
7306 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7307 goto failed;
7308 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007309 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007310 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007311 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007312 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007313 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7314 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007315 if (*out == NULL) goto failed;
7316 return 0;
7317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007318 tp = astmodulestate_global->NamedExpr_type;
7319 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007320 if (isinstance == -1) {
7321 return 1;
7322 }
7323 if (isinstance) {
7324 expr_ty target;
7325 expr_ty value;
7326
Dino Viehlandac46eb42019-09-11 10:16:34 -07007327 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7328 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007329 return 1;
7330 }
7331 if (tmp == NULL) {
7332 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7333 return 1;
7334 }
7335 else {
7336 int res;
7337 res = obj2ast_expr(tmp, &target, arena);
7338 if (res != 0) goto failed;
7339 Py_CLEAR(tmp);
7340 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007341 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007342 return 1;
7343 }
7344 if (tmp == NULL) {
7345 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7346 return 1;
7347 }
7348 else {
7349 int res;
7350 res = obj2ast_expr(tmp, &value, arena);
7351 if (res != 0) goto failed;
7352 Py_CLEAR(tmp);
7353 }
7354 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7355 end_col_offset, arena);
7356 if (*out == NULL) goto failed;
7357 return 0;
7358 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007359 tp = astmodulestate_global->BinOp_type;
7360 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007361 if (isinstance == -1) {
7362 return 1;
7363 }
7364 if (isinstance) {
7365 expr_ty left;
7366 operator_ty op;
7367 expr_ty right;
7368
Dino Viehlandac46eb42019-09-11 10:16:34 -07007369 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007370 return 1;
7371 }
7372 if (tmp == NULL) {
7373 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7374 return 1;
7375 }
7376 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007377 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007378 res = obj2ast_expr(tmp, &left, arena);
7379 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007380 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007381 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007382 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007383 return 1;
7384 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007385 if (tmp == NULL) {
7386 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7387 return 1;
7388 }
7389 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007390 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007391 res = obj2ast_operator(tmp, &op, arena);
7392 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007393 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007394 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007395 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007396 return 1;
7397 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007398 if (tmp == NULL) {
7399 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7400 return 1;
7401 }
7402 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007403 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007404 res = obj2ast_expr(tmp, &right, arena);
7405 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007406 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007407 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007408 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7409 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007410 if (*out == NULL) goto failed;
7411 return 0;
7412 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007413 tp = astmodulestate_global->UnaryOp_type;
7414 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007415 if (isinstance == -1) {
7416 return 1;
7417 }
7418 if (isinstance) {
7419 unaryop_ty op;
7420 expr_ty operand;
7421
Dino Viehlandac46eb42019-09-11 10:16:34 -07007422 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007423 return 1;
7424 }
7425 if (tmp == NULL) {
7426 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7427 return 1;
7428 }
7429 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007430 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007431 res = obj2ast_unaryop(tmp, &op, arena);
7432 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007433 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007434 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007435 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7436 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007437 return 1;
7438 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007439 if (tmp == NULL) {
7440 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7441 return 1;
7442 }
7443 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007444 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007445 res = obj2ast_expr(tmp, &operand, arena);
7446 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007447 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007448 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007449 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7450 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007451 if (*out == NULL) goto failed;
7452 return 0;
7453 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007454 tp = astmodulestate_global->Lambda_type;
7455 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007456 if (isinstance == -1) {
7457 return 1;
7458 }
7459 if (isinstance) {
7460 arguments_ty args;
7461 expr_ty body;
7462
Dino Viehlandac46eb42019-09-11 10:16:34 -07007463 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007464 return 1;
7465 }
7466 if (tmp == NULL) {
7467 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7468 return 1;
7469 }
7470 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007471 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007472 res = obj2ast_arguments(tmp, &args, arena);
7473 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007474 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007475 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007476 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007477 return 1;
7478 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007479 if (tmp == NULL) {
7480 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7481 return 1;
7482 }
7483 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007484 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007485 res = obj2ast_expr(tmp, &body, arena);
7486 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007487 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007488 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007489 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7490 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007491 if (*out == NULL) goto failed;
7492 return 0;
7493 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007494 tp = astmodulestate_global->IfExp_type;
7495 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007496 if (isinstance == -1) {
7497 return 1;
7498 }
7499 if (isinstance) {
7500 expr_ty test;
7501 expr_ty body;
7502 expr_ty orelse;
7503
Dino Viehlandac46eb42019-09-11 10:16:34 -07007504 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007505 return 1;
7506 }
7507 if (tmp == NULL) {
7508 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7509 return 1;
7510 }
7511 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007512 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007513 res = obj2ast_expr(tmp, &test, arena);
7514 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007515 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007516 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007517 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007518 return 1;
7519 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007520 if (tmp == NULL) {
7521 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7522 return 1;
7523 }
7524 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007525 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007526 res = obj2ast_expr(tmp, &body, arena);
7527 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007528 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007529 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007530 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7531 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007532 return 1;
7533 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007534 if (tmp == NULL) {
7535 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7536 return 1;
7537 }
7538 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007539 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007540 res = obj2ast_expr(tmp, &orelse, arena);
7541 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007542 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007543 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007544 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7545 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007546 if (*out == NULL) goto failed;
7547 return 0;
7548 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007549 tp = astmodulestate_global->Dict_type;
7550 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007551 if (isinstance == -1) {
7552 return 1;
7553 }
7554 if (isinstance) {
7555 asdl_seq* keys;
7556 asdl_seq* values;
7557
Dino Viehlandac46eb42019-09-11 10:16:34 -07007558 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007559 return 1;
7560 }
7561 if (tmp == NULL) {
7562 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7563 return 1;
7564 }
7565 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007566 int res;
7567 Py_ssize_t len;
7568 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007569 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007570 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 +02007571 goto failed;
7572 }
7573 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007574 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007575 if (keys == NULL) goto failed;
7576 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007577 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007578 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7579 Py_INCREF(tmp2);
7580 res = obj2ast_expr(tmp2, &val, arena);
7581 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007582 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007583 if (len != PyList_GET_SIZE(tmp)) {
7584 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7585 goto failed;
7586 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007587 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007588 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007589 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007590 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007591 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7592 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007593 return 1;
7594 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007595 if (tmp == NULL) {
7596 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7597 return 1;
7598 }
7599 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007600 int res;
7601 Py_ssize_t len;
7602 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007603 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007604 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 +02007605 goto failed;
7606 }
7607 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007608 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007609 if (values == NULL) goto failed;
7610 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007611 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007612 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7613 Py_INCREF(tmp2);
7614 res = obj2ast_expr(tmp2, &val, arena);
7615 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007616 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007617 if (len != PyList_GET_SIZE(tmp)) {
7618 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7619 goto failed;
7620 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007621 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007622 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007623 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007624 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007625 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7626 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007627 if (*out == NULL) goto failed;
7628 return 0;
7629 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007630 tp = astmodulestate_global->Set_type;
7631 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007632 if (isinstance == -1) {
7633 return 1;
7634 }
7635 if (isinstance) {
7636 asdl_seq* elts;
7637
Dino Viehlandac46eb42019-09-11 10:16:34 -07007638 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007639 return 1;
7640 }
7641 if (tmp == NULL) {
7642 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7643 return 1;
7644 }
7645 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007646 int res;
7647 Py_ssize_t len;
7648 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007649 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007650 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 +02007651 goto failed;
7652 }
7653 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007654 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007655 if (elts == NULL) goto failed;
7656 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007657 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007658 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7659 Py_INCREF(tmp2);
7660 res = obj2ast_expr(tmp2, &val, arena);
7661 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007662 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007663 if (len != PyList_GET_SIZE(tmp)) {
7664 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7665 goto failed;
7666 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007667 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007668 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007669 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007670 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007671 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007672 if (*out == NULL) goto failed;
7673 return 0;
7674 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007675 tp = astmodulestate_global->ListComp_type;
7676 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007677 if (isinstance == -1) {
7678 return 1;
7679 }
7680 if (isinstance) {
7681 expr_ty elt;
7682 asdl_seq* generators;
7683
Dino Viehlandac46eb42019-09-11 10:16:34 -07007684 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007685 return 1;
7686 }
7687 if (tmp == NULL) {
7688 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7689 return 1;
7690 }
7691 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007692 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007693 res = obj2ast_expr(tmp, &elt, arena);
7694 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007695 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007696 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007697 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7698 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007699 return 1;
7700 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007701 if (tmp == NULL) {
7702 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7703 return 1;
7704 }
7705 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007706 int res;
7707 Py_ssize_t len;
7708 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007709 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007710 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 +02007711 goto failed;
7712 }
7713 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007714 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007715 if (generators == NULL) goto failed;
7716 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007717 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007718 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7719 Py_INCREF(tmp2);
7720 res = obj2ast_comprehension(tmp2, &val, arena);
7721 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007722 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007723 if (len != PyList_GET_SIZE(tmp)) {
7724 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7725 goto failed;
7726 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007727 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007728 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007729 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007730 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007731 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7732 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007733 if (*out == NULL) goto failed;
7734 return 0;
7735 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007736 tp = astmodulestate_global->SetComp_type;
7737 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007738 if (isinstance == -1) {
7739 return 1;
7740 }
7741 if (isinstance) {
7742 expr_ty elt;
7743 asdl_seq* generators;
7744
Dino Viehlandac46eb42019-09-11 10:16:34 -07007745 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007746 return 1;
7747 }
7748 if (tmp == NULL) {
7749 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7750 return 1;
7751 }
7752 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007753 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007754 res = obj2ast_expr(tmp, &elt, arena);
7755 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007756 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007757 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007758 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7759 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007760 return 1;
7761 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007762 if (tmp == NULL) {
7763 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7764 return 1;
7765 }
7766 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007767 int res;
7768 Py_ssize_t len;
7769 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007770 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007771 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 +02007772 goto failed;
7773 }
7774 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007775 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007776 if (generators == NULL) goto failed;
7777 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007778 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007779 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7780 Py_INCREF(tmp2);
7781 res = obj2ast_comprehension(tmp2, &val, arena);
7782 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007783 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007784 if (len != PyList_GET_SIZE(tmp)) {
7785 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7786 goto failed;
7787 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007788 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007789 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007790 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007791 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007792 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7793 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007794 if (*out == NULL) goto failed;
7795 return 0;
7796 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007797 tp = astmodulestate_global->DictComp_type;
7798 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007799 if (isinstance == -1) {
7800 return 1;
7801 }
7802 if (isinstance) {
7803 expr_ty key;
7804 expr_ty value;
7805 asdl_seq* generators;
7806
Dino Viehlandac46eb42019-09-11 10:16:34 -07007807 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007808 return 1;
7809 }
7810 if (tmp == NULL) {
7811 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7812 return 1;
7813 }
7814 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007815 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007816 res = obj2ast_expr(tmp, &key, arena);
7817 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007818 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007819 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007820 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007821 return 1;
7822 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007823 if (tmp == NULL) {
7824 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7825 return 1;
7826 }
7827 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007828 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007829 res = obj2ast_expr(tmp, &value, arena);
7830 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007831 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007832 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007833 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7834 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007835 return 1;
7836 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007837 if (tmp == NULL) {
7838 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7839 return 1;
7840 }
7841 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007842 int res;
7843 Py_ssize_t len;
7844 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007845 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007846 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 +02007847 goto failed;
7848 }
7849 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007850 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007851 if (generators == NULL) goto failed;
7852 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007853 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007854 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7855 Py_INCREF(tmp2);
7856 res = obj2ast_comprehension(tmp2, &val, arena);
7857 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007858 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007859 if (len != PyList_GET_SIZE(tmp)) {
7860 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7861 goto failed;
7862 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007863 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007864 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007865 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007866 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007867 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7868 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007869 if (*out == NULL) goto failed;
7870 return 0;
7871 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007872 tp = astmodulestate_global->GeneratorExp_type;
7873 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007874 if (isinstance == -1) {
7875 return 1;
7876 }
7877 if (isinstance) {
7878 expr_ty elt;
7879 asdl_seq* generators;
7880
Dino Viehlandac46eb42019-09-11 10:16:34 -07007881 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007882 return 1;
7883 }
7884 if (tmp == NULL) {
7885 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7886 return 1;
7887 }
7888 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007889 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007890 res = obj2ast_expr(tmp, &elt, arena);
7891 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007892 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007893 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007894 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7895 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007896 return 1;
7897 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007898 if (tmp == NULL) {
7899 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7900 return 1;
7901 }
7902 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007903 int res;
7904 Py_ssize_t len;
7905 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007906 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007907 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 +02007908 goto failed;
7909 }
7910 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007911 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007912 if (generators == NULL) goto failed;
7913 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007914 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007915 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7916 Py_INCREF(tmp2);
7917 res = obj2ast_comprehension(tmp2, &val, arena);
7918 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007919 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007920 if (len != PyList_GET_SIZE(tmp)) {
7921 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7922 goto failed;
7923 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007924 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007925 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007926 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007927 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007928 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7929 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007930 if (*out == NULL) goto failed;
7931 return 0;
7932 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007933 tp = astmodulestate_global->Await_type;
7934 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007935 if (isinstance == -1) {
7936 return 1;
7937 }
7938 if (isinstance) {
7939 expr_ty value;
7940
Dino Viehlandac46eb42019-09-11 10:16:34 -07007941 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007942 return 1;
7943 }
7944 if (tmp == NULL) {
7945 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7946 return 1;
7947 }
7948 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007949 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007950 res = obj2ast_expr(tmp, &value, arena);
7951 if (res != 0) goto failed;
7952 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007953 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007954 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7955 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007956 if (*out == NULL) goto failed;
7957 return 0;
7958 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007959 tp = astmodulestate_global->Yield_type;
7960 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007961 if (isinstance == -1) {
7962 return 1;
7963 }
7964 if (isinstance) {
7965 expr_ty value;
7966
Dino Viehlandac46eb42019-09-11 10:16:34 -07007967 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007968 return 1;
7969 }
7970 if (tmp == NULL || tmp == Py_None) {
7971 Py_CLEAR(tmp);
7972 value = NULL;
7973 }
7974 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007975 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007976 res = obj2ast_expr(tmp, &value, arena);
7977 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007978 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007979 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007980 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
7981 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007982 if (*out == NULL) goto failed;
7983 return 0;
7984 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007985 tp = astmodulestate_global->YieldFrom_type;
7986 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007987 if (isinstance == -1) {
7988 return 1;
7989 }
7990 if (isinstance) {
7991 expr_ty value;
7992
Dino Viehlandac46eb42019-09-11 10:16:34 -07007993 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007994 return 1;
7995 }
7996 if (tmp == NULL) {
7997 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
7998 return 1;
7999 }
8000 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008001 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008002 res = obj2ast_expr(tmp, &value, arena);
8003 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008004 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008005 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008006 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8007 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008008 if (*out == NULL) goto failed;
8009 return 0;
8010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008011 tp = astmodulestate_global->Compare_type;
8012 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008013 if (isinstance == -1) {
8014 return 1;
8015 }
8016 if (isinstance) {
8017 expr_ty left;
8018 asdl_int_seq* ops;
8019 asdl_seq* comparators;
8020
Dino Viehlandac46eb42019-09-11 10:16:34 -07008021 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008022 return 1;
8023 }
8024 if (tmp == NULL) {
8025 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8026 return 1;
8027 }
8028 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008029 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008030 res = obj2ast_expr(tmp, &left, arena);
8031 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008032 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008033 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008034 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008035 return 1;
8036 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008037 if (tmp == NULL) {
8038 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8039 return 1;
8040 }
8041 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008042 int res;
8043 Py_ssize_t len;
8044 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008045 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008046 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 +02008047 goto failed;
8048 }
8049 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008050 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008051 if (ops == NULL) goto failed;
8052 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008053 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008054 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8055 Py_INCREF(tmp2);
8056 res = obj2ast_cmpop(tmp2, &val, arena);
8057 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008058 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008059 if (len != PyList_GET_SIZE(tmp)) {
8060 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8061 goto failed;
8062 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008063 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008064 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008065 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008066 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008067 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8068 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008069 return 1;
8070 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008071 if (tmp == NULL) {
8072 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8073 return 1;
8074 }
8075 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008076 int res;
8077 Py_ssize_t len;
8078 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008079 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008080 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 +02008081 goto failed;
8082 }
8083 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008084 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008085 if (comparators == NULL) goto failed;
8086 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008087 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008088 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8089 Py_INCREF(tmp2);
8090 res = obj2ast_expr(tmp2, &val, arena);
8091 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008092 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008093 if (len != PyList_GET_SIZE(tmp)) {
8094 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8095 goto failed;
8096 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008097 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008098 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008099 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008100 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008101 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8102 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008103 if (*out == NULL) goto failed;
8104 return 0;
8105 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008106 tp = astmodulestate_global->Call_type;
8107 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008108 if (isinstance == -1) {
8109 return 1;
8110 }
8111 if (isinstance) {
8112 expr_ty func;
8113 asdl_seq* args;
8114 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008115
Dino Viehlandac46eb42019-09-11 10:16:34 -07008116 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008117 return 1;
8118 }
8119 if (tmp == NULL) {
8120 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8121 return 1;
8122 }
8123 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008124 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008125 res = obj2ast_expr(tmp, &func, arena);
8126 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008127 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008128 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008129 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008130 return 1;
8131 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008132 if (tmp == NULL) {
8133 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8134 return 1;
8135 }
8136 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008137 int res;
8138 Py_ssize_t len;
8139 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008140 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008141 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 +02008142 goto failed;
8143 }
8144 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008145 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008146 if (args == NULL) goto failed;
8147 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008148 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008149 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8150 Py_INCREF(tmp2);
8151 res = obj2ast_expr(tmp2, &val, arena);
8152 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008153 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008154 if (len != PyList_GET_SIZE(tmp)) {
8155 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8156 goto failed;
8157 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008158 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008159 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008160 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008162 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8163 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008164 return 1;
8165 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008166 if (tmp == NULL) {
8167 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8168 return 1;
8169 }
8170 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008171 int res;
8172 Py_ssize_t len;
8173 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008174 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008175 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 +02008176 goto failed;
8177 }
8178 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008179 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008180 if (keywords == NULL) goto failed;
8181 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008182 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008183 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8184 Py_INCREF(tmp2);
8185 res = obj2ast_keyword(tmp2, &val, arena);
8186 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008187 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008188 if (len != PyList_GET_SIZE(tmp)) {
8189 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8190 goto failed;
8191 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008192 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008193 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008194 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008195 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008196 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8197 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008198 if (*out == NULL) goto failed;
8199 return 0;
8200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008201 tp = astmodulestate_global->FormattedValue_type;
8202 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008203 if (isinstance == -1) {
8204 return 1;
8205 }
8206 if (isinstance) {
8207 expr_ty value;
8208 int conversion;
8209 expr_ty format_spec;
8210
Dino Viehlandac46eb42019-09-11 10:16:34 -07008211 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008212 return 1;
8213 }
8214 if (tmp == NULL) {
8215 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8216 return 1;
8217 }
8218 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008219 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008220 res = obj2ast_expr(tmp, &value, arena);
8221 if (res != 0) goto failed;
8222 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008224 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8225 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008226 return 1;
8227 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008228 if (tmp == NULL || tmp == Py_None) {
8229 Py_CLEAR(tmp);
8230 conversion = 0;
8231 }
8232 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008233 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008234 res = obj2ast_int(tmp, &conversion, arena);
8235 if (res != 0) goto failed;
8236 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008238 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8239 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008240 return 1;
8241 }
8242 if (tmp == NULL || tmp == Py_None) {
8243 Py_CLEAR(tmp);
8244 format_spec = NULL;
8245 }
8246 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008247 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008248 res = obj2ast_expr(tmp, &format_spec, arena);
8249 if (res != 0) goto failed;
8250 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008251 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008252 *out = FormattedValue(value, conversion, format_spec, lineno,
8253 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008254 if (*out == NULL) goto failed;
8255 return 0;
8256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008257 tp = astmodulestate_global->JoinedStr_type;
8258 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008259 if (isinstance == -1) {
8260 return 1;
8261 }
8262 if (isinstance) {
8263 asdl_seq* values;
8264
Dino Viehlandac46eb42019-09-11 10:16:34 -07008265 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8266 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008267 return 1;
8268 }
8269 if (tmp == NULL) {
8270 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8271 return 1;
8272 }
8273 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008274 int res;
8275 Py_ssize_t len;
8276 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008277 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008278 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 -04008279 goto failed;
8280 }
8281 len = PyList_GET_SIZE(tmp);
8282 values = _Py_asdl_seq_new(len, arena);
8283 if (values == NULL) goto failed;
8284 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008285 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008286 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8287 Py_INCREF(tmp2);
8288 res = obj2ast_expr(tmp2, &val, arena);
8289 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008290 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008291 if (len != PyList_GET_SIZE(tmp)) {
8292 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8293 goto failed;
8294 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008295 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008296 }
8297 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008298 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008299 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8300 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008301 if (*out == NULL) goto failed;
8302 return 0;
8303 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008304 tp = astmodulestate_global->Constant_type;
8305 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008306 if (isinstance == -1) {
8307 return 1;
8308 }
8309 if (isinstance) {
8310 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008311 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008312
Dino Viehlandac46eb42019-09-11 10:16:34 -07008313 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008314 return 1;
8315 }
8316 if (tmp == NULL) {
8317 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8318 return 1;
8319 }
8320 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008321 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008322 res = obj2ast_constant(tmp, &value, arena);
8323 if (res != 0) goto failed;
8324 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008325 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008326 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008327 return 1;
8328 }
8329 if (tmp == NULL || tmp == Py_None) {
8330 Py_CLEAR(tmp);
8331 kind = NULL;
8332 }
8333 else {
8334 int res;
8335 res = obj2ast_string(tmp, &kind, arena);
8336 if (res != 0) goto failed;
8337 Py_CLEAR(tmp);
8338 }
8339 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8340 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008341 if (*out == NULL) goto failed;
8342 return 0;
8343 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008344 tp = astmodulestate_global->Attribute_type;
8345 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008346 if (isinstance == -1) {
8347 return 1;
8348 }
8349 if (isinstance) {
8350 expr_ty value;
8351 identifier attr;
8352 expr_context_ty ctx;
8353
Dino Viehlandac46eb42019-09-11 10:16:34 -07008354 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008355 return 1;
8356 }
8357 if (tmp == NULL) {
8358 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8359 return 1;
8360 }
8361 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008362 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008363 res = obj2ast_expr(tmp, &value, arena);
8364 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008365 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008366 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008367 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008368 return 1;
8369 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008370 if (tmp == NULL) {
8371 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8372 return 1;
8373 }
8374 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008375 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008376 res = obj2ast_identifier(tmp, &attr, arena);
8377 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008378 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008379 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008380 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008381 return 1;
8382 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008383 if (tmp == NULL) {
8384 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8385 return 1;
8386 }
8387 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008388 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008389 res = obj2ast_expr_context(tmp, &ctx, arena);
8390 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008391 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008392 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008393 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8394 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008395 if (*out == NULL) goto failed;
8396 return 0;
8397 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008398 tp = astmodulestate_global->Subscript_type;
8399 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008400 if (isinstance == -1) {
8401 return 1;
8402 }
8403 if (isinstance) {
8404 expr_ty value;
8405 slice_ty slice;
8406 expr_context_ty ctx;
8407
Dino Viehlandac46eb42019-09-11 10:16:34 -07008408 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008409 return 1;
8410 }
8411 if (tmp == NULL) {
8412 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8413 return 1;
8414 }
8415 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008416 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008417 res = obj2ast_expr(tmp, &value, arena);
8418 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008419 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008420 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008421 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008422 return 1;
8423 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008424 if (tmp == NULL) {
8425 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8426 return 1;
8427 }
8428 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008429 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008430 res = obj2ast_slice(tmp, &slice, arena);
8431 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008432 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008433 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008434 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008435 return 1;
8436 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008437 if (tmp == NULL) {
8438 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8439 return 1;
8440 }
8441 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008442 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008443 res = obj2ast_expr_context(tmp, &ctx, arena);
8444 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008445 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008446 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008447 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8448 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008449 if (*out == NULL) goto failed;
8450 return 0;
8451 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008452 tp = astmodulestate_global->Starred_type;
8453 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008454 if (isinstance == -1) {
8455 return 1;
8456 }
8457 if (isinstance) {
8458 expr_ty value;
8459 expr_context_ty ctx;
8460
Dino Viehlandac46eb42019-09-11 10:16:34 -07008461 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008462 return 1;
8463 }
8464 if (tmp == NULL) {
8465 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8466 return 1;
8467 }
8468 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008469 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008470 res = obj2ast_expr(tmp, &value, arena);
8471 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008472 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008473 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008474 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008475 return 1;
8476 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008477 if (tmp == NULL) {
8478 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8479 return 1;
8480 }
8481 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008482 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008483 res = obj2ast_expr_context(tmp, &ctx, arena);
8484 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008485 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008486 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008487 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8488 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008489 if (*out == NULL) goto failed;
8490 return 0;
8491 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008492 tp = astmodulestate_global->Name_type;
8493 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008494 if (isinstance == -1) {
8495 return 1;
8496 }
8497 if (isinstance) {
8498 identifier id;
8499 expr_context_ty ctx;
8500
Dino Viehlandac46eb42019-09-11 10:16:34 -07008501 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008502 return 1;
8503 }
8504 if (tmp == NULL) {
8505 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8506 return 1;
8507 }
8508 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008509 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008510 res = obj2ast_identifier(tmp, &id, arena);
8511 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008512 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008513 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008514 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008515 return 1;
8516 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008517 if (tmp == NULL) {
8518 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8519 return 1;
8520 }
8521 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008522 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008523 res = obj2ast_expr_context(tmp, &ctx, arena);
8524 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008525 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008526 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008527 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8528 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008529 if (*out == NULL) goto failed;
8530 return 0;
8531 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008532 tp = astmodulestate_global->List_type;
8533 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008534 if (isinstance == -1) {
8535 return 1;
8536 }
8537 if (isinstance) {
8538 asdl_seq* elts;
8539 expr_context_ty ctx;
8540
Dino Viehlandac46eb42019-09-11 10:16:34 -07008541 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008542 return 1;
8543 }
8544 if (tmp == NULL) {
8545 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8546 return 1;
8547 }
8548 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008549 int res;
8550 Py_ssize_t len;
8551 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008552 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008553 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 +02008554 goto failed;
8555 }
8556 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008557 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008558 if (elts == NULL) goto failed;
8559 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008560 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008561 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8562 Py_INCREF(tmp2);
8563 res = obj2ast_expr(tmp2, &val, arena);
8564 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008565 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008566 if (len != PyList_GET_SIZE(tmp)) {
8567 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8568 goto failed;
8569 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008570 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008571 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008572 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008573 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008574 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008575 return 1;
8576 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008577 if (tmp == NULL) {
8578 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8579 return 1;
8580 }
8581 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008582 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008583 res = obj2ast_expr_context(tmp, &ctx, arena);
8584 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008585 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008586 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008587 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8588 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008589 if (*out == NULL) goto failed;
8590 return 0;
8591 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008592 tp = astmodulestate_global->Tuple_type;
8593 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008594 if (isinstance == -1) {
8595 return 1;
8596 }
8597 if (isinstance) {
8598 asdl_seq* elts;
8599 expr_context_ty ctx;
8600
Dino Viehlandac46eb42019-09-11 10:16:34 -07008601 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008602 return 1;
8603 }
8604 if (tmp == NULL) {
8605 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8606 return 1;
8607 }
8608 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008609 int res;
8610 Py_ssize_t len;
8611 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008612 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008613 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 +02008614 goto failed;
8615 }
8616 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008617 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008618 if (elts == NULL) goto failed;
8619 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008620 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008621 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8622 Py_INCREF(tmp2);
8623 res = obj2ast_expr(tmp2, &val, arena);
8624 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008625 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008626 if (len != PyList_GET_SIZE(tmp)) {
8627 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8628 goto failed;
8629 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008630 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008631 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008632 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008633 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008634 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008635 return 1;
8636 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008637 if (tmp == NULL) {
8638 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8639 return 1;
8640 }
8641 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008642 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008643 res = obj2ast_expr_context(tmp, &ctx, arena);
8644 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008645 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008646 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008647 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8648 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008649 if (*out == NULL) goto failed;
8650 return 0;
8651 }
8652
8653 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8654 failed:
8655 Py_XDECREF(tmp);
8656 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008657}
8658
8659int
8660obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8661{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008662 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008663
Dino Viehlandac46eb42019-09-11 10:16:34 -07008664 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008665 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008666 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008667 }
8668 if (isinstance) {
8669 *out = Load;
8670 return 0;
8671 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008672 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008673 if (isinstance == -1) {
8674 return 1;
8675 }
8676 if (isinstance) {
8677 *out = Store;
8678 return 0;
8679 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008680 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008681 if (isinstance == -1) {
8682 return 1;
8683 }
8684 if (isinstance) {
8685 *out = Del;
8686 return 0;
8687 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008688 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008689 if (isinstance == -1) {
8690 return 1;
8691 }
8692 if (isinstance) {
8693 *out = AugLoad;
8694 return 0;
8695 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008696 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008697 if (isinstance == -1) {
8698 return 1;
8699 }
8700 if (isinstance) {
8701 *out = AugStore;
8702 return 0;
8703 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008704 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008705 if (isinstance == -1) {
8706 return 1;
8707 }
8708 if (isinstance) {
8709 *out = Param;
8710 return 0;
8711 }
8712
8713 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8714 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008715}
8716
8717int
8718obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
8719{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008720 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008721
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008722 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008723 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008724
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008725 if (obj == Py_None) {
8726 *out = NULL;
8727 return 0;
8728 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008729 tp = astmodulestate_global->Slice_type;
8730 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008731 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008732 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008733 }
8734 if (isinstance) {
8735 expr_ty lower;
8736 expr_ty upper;
8737 expr_ty step;
8738
Dino Viehlandac46eb42019-09-11 10:16:34 -07008739 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008740 return 1;
8741 }
8742 if (tmp == NULL || tmp == Py_None) {
8743 Py_CLEAR(tmp);
8744 lower = NULL;
8745 }
8746 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008747 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008748 res = obj2ast_expr(tmp, &lower, arena);
8749 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008750 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008751 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008752 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008753 return 1;
8754 }
8755 if (tmp == NULL || tmp == Py_None) {
8756 Py_CLEAR(tmp);
8757 upper = NULL;
8758 }
8759 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008760 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008761 res = obj2ast_expr(tmp, &upper, arena);
8762 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008763 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008764 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008765 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008766 return 1;
8767 }
8768 if (tmp == NULL || tmp == Py_None) {
8769 Py_CLEAR(tmp);
8770 step = NULL;
8771 }
8772 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008773 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008774 res = obj2ast_expr(tmp, &step, arena);
8775 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008776 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008777 }
8778 *out = Slice(lower, upper, step, arena);
8779 if (*out == NULL) goto failed;
8780 return 0;
8781 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008782 tp = astmodulestate_global->ExtSlice_type;
8783 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008784 if (isinstance == -1) {
8785 return 1;
8786 }
8787 if (isinstance) {
8788 asdl_seq* dims;
8789
Dino Viehlandac46eb42019-09-11 10:16:34 -07008790 if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008791 return 1;
8792 }
8793 if (tmp == NULL) {
8794 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
8795 return 1;
8796 }
8797 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008798 int res;
8799 Py_ssize_t len;
8800 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008801 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008802 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 +02008803 goto failed;
8804 }
8805 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008806 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008807 if (dims == NULL) goto failed;
8808 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008809 slice_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008810 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8811 Py_INCREF(tmp2);
8812 res = obj2ast_slice(tmp2, &val, arena);
8813 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008814 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008815 if (len != PyList_GET_SIZE(tmp)) {
8816 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
8817 goto failed;
8818 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008819 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008820 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008821 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008822 }
8823 *out = ExtSlice(dims, arena);
8824 if (*out == NULL) goto failed;
8825 return 0;
8826 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008827 tp = astmodulestate_global->Index_type;
8828 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008829 if (isinstance == -1) {
8830 return 1;
8831 }
8832 if (isinstance) {
8833 expr_ty value;
8834
Dino Viehlandac46eb42019-09-11 10:16:34 -07008835 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008836 return 1;
8837 }
8838 if (tmp == NULL) {
8839 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
8840 return 1;
8841 }
8842 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008843 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008844 res = obj2ast_expr(tmp, &value, arena);
8845 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008846 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008847 }
8848 *out = Index(value, arena);
8849 if (*out == NULL) goto failed;
8850 return 0;
8851 }
8852
8853 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
8854 failed:
8855 Py_XDECREF(tmp);
8856 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008857}
8858
8859int
8860obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8861{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008862 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008863
Dino Viehlandac46eb42019-09-11 10:16:34 -07008864 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008865 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008866 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008867 }
8868 if (isinstance) {
8869 *out = And;
8870 return 0;
8871 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008872 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008873 if (isinstance == -1) {
8874 return 1;
8875 }
8876 if (isinstance) {
8877 *out = Or;
8878 return 0;
8879 }
8880
8881 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8882 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008883}
8884
8885int
8886obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8887{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008888 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008889
Dino Viehlandac46eb42019-09-11 10:16:34 -07008890 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008891 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008892 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008893 }
8894 if (isinstance) {
8895 *out = Add;
8896 return 0;
8897 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008898 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008899 if (isinstance == -1) {
8900 return 1;
8901 }
8902 if (isinstance) {
8903 *out = Sub;
8904 return 0;
8905 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008906 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008907 if (isinstance == -1) {
8908 return 1;
8909 }
8910 if (isinstance) {
8911 *out = Mult;
8912 return 0;
8913 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008914 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008915 if (isinstance == -1) {
8916 return 1;
8917 }
8918 if (isinstance) {
8919 *out = MatMult;
8920 return 0;
8921 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008922 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008923 if (isinstance == -1) {
8924 return 1;
8925 }
8926 if (isinstance) {
8927 *out = Div;
8928 return 0;
8929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008930 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008931 if (isinstance == -1) {
8932 return 1;
8933 }
8934 if (isinstance) {
8935 *out = Mod;
8936 return 0;
8937 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008938 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008939 if (isinstance == -1) {
8940 return 1;
8941 }
8942 if (isinstance) {
8943 *out = Pow;
8944 return 0;
8945 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008946 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008947 if (isinstance == -1) {
8948 return 1;
8949 }
8950 if (isinstance) {
8951 *out = LShift;
8952 return 0;
8953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008954 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008955 if (isinstance == -1) {
8956 return 1;
8957 }
8958 if (isinstance) {
8959 *out = RShift;
8960 return 0;
8961 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008962 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008963 if (isinstance == -1) {
8964 return 1;
8965 }
8966 if (isinstance) {
8967 *out = BitOr;
8968 return 0;
8969 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008970 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008971 if (isinstance == -1) {
8972 return 1;
8973 }
8974 if (isinstance) {
8975 *out = BitXor;
8976 return 0;
8977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008978 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008979 if (isinstance == -1) {
8980 return 1;
8981 }
8982 if (isinstance) {
8983 *out = BitAnd;
8984 return 0;
8985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008986 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008987 if (isinstance == -1) {
8988 return 1;
8989 }
8990 if (isinstance) {
8991 *out = FloorDiv;
8992 return 0;
8993 }
8994
8995 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8996 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008997}
8998
8999int
9000obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
9001{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009002 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009003
Dino Viehlandac46eb42019-09-11 10:16:34 -07009004 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009005 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009006 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009007 }
9008 if (isinstance) {
9009 *out = Invert;
9010 return 0;
9011 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009012 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009013 if (isinstance == -1) {
9014 return 1;
9015 }
9016 if (isinstance) {
9017 *out = Not;
9018 return 0;
9019 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009020 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009021 if (isinstance == -1) {
9022 return 1;
9023 }
9024 if (isinstance) {
9025 *out = UAdd;
9026 return 0;
9027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009028 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009029 if (isinstance == -1) {
9030 return 1;
9031 }
9032 if (isinstance) {
9033 *out = USub;
9034 return 0;
9035 }
9036
9037 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9038 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009039}
9040
9041int
9042obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9043{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009044 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009045
Dino Viehlandac46eb42019-09-11 10:16:34 -07009046 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009047 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009048 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009049 }
9050 if (isinstance) {
9051 *out = Eq;
9052 return 0;
9053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009054 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009055 if (isinstance == -1) {
9056 return 1;
9057 }
9058 if (isinstance) {
9059 *out = NotEq;
9060 return 0;
9061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009062 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009063 if (isinstance == -1) {
9064 return 1;
9065 }
9066 if (isinstance) {
9067 *out = Lt;
9068 return 0;
9069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009070 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009071 if (isinstance == -1) {
9072 return 1;
9073 }
9074 if (isinstance) {
9075 *out = LtE;
9076 return 0;
9077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009078 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009079 if (isinstance == -1) {
9080 return 1;
9081 }
9082 if (isinstance) {
9083 *out = Gt;
9084 return 0;
9085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009086 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009087 if (isinstance == -1) {
9088 return 1;
9089 }
9090 if (isinstance) {
9091 *out = GtE;
9092 return 0;
9093 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009094 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009095 if (isinstance == -1) {
9096 return 1;
9097 }
9098 if (isinstance) {
9099 *out = Is;
9100 return 0;
9101 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009102 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009103 if (isinstance == -1) {
9104 return 1;
9105 }
9106 if (isinstance) {
9107 *out = IsNot;
9108 return 0;
9109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009110 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009111 if (isinstance == -1) {
9112 return 1;
9113 }
9114 if (isinstance) {
9115 *out = In;
9116 return 0;
9117 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009118 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009119 if (isinstance == -1) {
9120 return 1;
9121 }
9122 if (isinstance) {
9123 *out = NotIn;
9124 return 0;
9125 }
9126
9127 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9128 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009129}
9130
9131int
9132obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9133{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009134 PyObject* tmp = NULL;
9135 expr_ty target;
9136 expr_ty iter;
9137 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009138 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009139
Dino Viehlandac46eb42019-09-11 10:16:34 -07009140 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009141 return 1;
9142 }
9143 if (tmp == NULL) {
9144 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9145 return 1;
9146 }
9147 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009148 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009149 res = obj2ast_expr(tmp, &target, arena);
9150 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009151 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009152 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009153 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009154 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009155 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009156 if (tmp == NULL) {
9157 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9158 return 1;
9159 }
9160 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009161 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009162 res = obj2ast_expr(tmp, &iter, arena);
9163 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009164 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009165 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009166 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009167 return 1;
9168 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009169 if (tmp == NULL) {
9170 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9171 return 1;
9172 }
9173 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009174 int res;
9175 Py_ssize_t len;
9176 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009177 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009178 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 +02009179 goto failed;
9180 }
9181 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009182 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009183 if (ifs == NULL) goto failed;
9184 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009185 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009186 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9187 Py_INCREF(tmp2);
9188 res = obj2ast_expr(tmp2, &val, arena);
9189 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009190 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009191 if (len != PyList_GET_SIZE(tmp)) {
9192 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9193 goto failed;
9194 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009195 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009196 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009197 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009198 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009199 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009200 return 1;
9201 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009202 if (tmp == NULL) {
9203 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9204 return 1;
9205 }
9206 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009207 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009208 res = obj2ast_int(tmp, &is_async, arena);
9209 if (res != 0) goto failed;
9210 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009211 }
9212 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009213 return 0;
9214failed:
9215 Py_XDECREF(tmp);
9216 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009217}
9218
9219int
9220obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9221{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009222 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009223
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009224 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009225 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009226 int lineno;
9227 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009228 int end_lineno;
9229 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009230
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009231 if (obj == Py_None) {
9232 *out = NULL;
9233 return 0;
9234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009235 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009236 return 1;
9237 }
9238 if (tmp == NULL) {
9239 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9240 return 1;
9241 }
9242 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009243 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009244 res = obj2ast_int(tmp, &lineno, arena);
9245 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009246 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009247 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009248 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9249 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009250 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009251 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009252 if (tmp == NULL) {
9253 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9254 return 1;
9255 }
9256 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009257 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009258 res = obj2ast_int(tmp, &col_offset, arena);
9259 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009260 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009261 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009262 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9263 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009264 return 1;
9265 }
9266 if (tmp == NULL || tmp == Py_None) {
9267 Py_CLEAR(tmp);
9268 end_lineno = 0;
9269 }
9270 else {
9271 int res;
9272 res = obj2ast_int(tmp, &end_lineno, arena);
9273 if (res != 0) goto failed;
9274 Py_CLEAR(tmp);
9275 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009276 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9277 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009278 return 1;
9279 }
9280 if (tmp == NULL || tmp == Py_None) {
9281 Py_CLEAR(tmp);
9282 end_col_offset = 0;
9283 }
9284 else {
9285 int res;
9286 res = obj2ast_int(tmp, &end_col_offset, arena);
9287 if (res != 0) goto failed;
9288 Py_CLEAR(tmp);
9289 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009290 tp = astmodulestate_global->ExceptHandler_type;
9291 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009292 if (isinstance == -1) {
9293 return 1;
9294 }
9295 if (isinstance) {
9296 expr_ty type;
9297 identifier name;
9298 asdl_seq* body;
9299
Dino Viehlandac46eb42019-09-11 10:16:34 -07009300 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009301 return 1;
9302 }
9303 if (tmp == NULL || tmp == Py_None) {
9304 Py_CLEAR(tmp);
9305 type = NULL;
9306 }
9307 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009308 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009309 res = obj2ast_expr(tmp, &type, arena);
9310 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009311 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009313 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009314 return 1;
9315 }
9316 if (tmp == NULL || tmp == Py_None) {
9317 Py_CLEAR(tmp);
9318 name = NULL;
9319 }
9320 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009321 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009322 res = obj2ast_identifier(tmp, &name, arena);
9323 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009324 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009325 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009326 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009327 return 1;
9328 }
9329 if (tmp == NULL) {
9330 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9331 return 1;
9332 }
9333 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009334 int res;
9335 Py_ssize_t len;
9336 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009337 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009338 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 +02009339 goto failed;
9340 }
9341 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009342 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009343 if (body == NULL) goto failed;
9344 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009345 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009346 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9347 Py_INCREF(tmp2);
9348 res = obj2ast_stmt(tmp2, &val, arena);
9349 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009350 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009351 if (len != PyList_GET_SIZE(tmp)) {
9352 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9353 goto failed;
9354 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009355 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009356 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009357 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009358 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009359 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9360 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009361 if (*out == NULL) goto failed;
9362 return 0;
9363 }
9364
9365 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9366 failed:
9367 Py_XDECREF(tmp);
9368 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009369}
9370
9371int
9372obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9373{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009374 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009375 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009376 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009377 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009378 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009379 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009380 arg_ty kwarg;
9381 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009382
Dino Viehlandac46eb42019-09-11 10:16:34 -07009383 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9384 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009385 return 1;
9386 }
9387 if (tmp == NULL) {
9388 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9389 return 1;
9390 }
9391 else {
9392 int res;
9393 Py_ssize_t len;
9394 Py_ssize_t i;
9395 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009396 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 +01009397 goto failed;
9398 }
9399 len = PyList_GET_SIZE(tmp);
9400 posonlyargs = _Py_asdl_seq_new(len, arena);
9401 if (posonlyargs == NULL) goto failed;
9402 for (i = 0; i < len; i++) {
9403 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009404 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9405 Py_INCREF(tmp2);
9406 res = obj2ast_arg(tmp2, &val, arena);
9407 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009408 if (res != 0) goto failed;
9409 if (len != PyList_GET_SIZE(tmp)) {
9410 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9411 goto failed;
9412 }
9413 asdl_seq_SET(posonlyargs, i, val);
9414 }
9415 Py_CLEAR(tmp);
9416 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009417 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009418 return 1;
9419 }
9420 if (tmp == NULL) {
9421 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9422 return 1;
9423 }
9424 else {
9425 int res;
9426 Py_ssize_t len;
9427 Py_ssize_t i;
9428 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009429 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 +02009430 goto failed;
9431 }
9432 len = PyList_GET_SIZE(tmp);
9433 args = _Py_asdl_seq_new(len, arena);
9434 if (args == NULL) goto failed;
9435 for (i = 0; i < len; i++) {
9436 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009437 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9438 Py_INCREF(tmp2);
9439 res = obj2ast_arg(tmp2, &val, arena);
9440 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009441 if (res != 0) goto failed;
9442 if (len != PyList_GET_SIZE(tmp)) {
9443 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9444 goto failed;
9445 }
9446 asdl_seq_SET(args, i, val);
9447 }
9448 Py_CLEAR(tmp);
9449 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009450 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009451 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009452 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009453 if (tmp == NULL || tmp == Py_None) {
9454 Py_CLEAR(tmp);
9455 vararg = NULL;
9456 }
9457 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009458 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009459 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009460 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009461 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009462 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009463 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9464 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009465 return 1;
9466 }
9467 if (tmp == NULL) {
9468 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9469 return 1;
9470 }
9471 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009472 int res;
9473 Py_ssize_t len;
9474 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009475 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009476 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 +02009477 goto failed;
9478 }
9479 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009480 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009481 if (kwonlyargs == NULL) goto failed;
9482 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009483 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009484 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9485 Py_INCREF(tmp2);
9486 res = obj2ast_arg(tmp2, &val, arena);
9487 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009488 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009489 if (len != PyList_GET_SIZE(tmp)) {
9490 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9491 goto failed;
9492 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009493 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009494 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009495 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009496 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009497 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9498 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009499 return 1;
9500 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009501 if (tmp == NULL) {
9502 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9503 return 1;
9504 }
9505 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009506 int res;
9507 Py_ssize_t len;
9508 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009509 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009510 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 +02009511 goto failed;
9512 }
9513 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009514 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009515 if (kw_defaults == NULL) goto failed;
9516 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009517 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009518 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9519 Py_INCREF(tmp2);
9520 res = obj2ast_expr(tmp2, &val, arena);
9521 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009522 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009523 if (len != PyList_GET_SIZE(tmp)) {
9524 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9525 goto failed;
9526 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009527 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009528 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009529 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009530 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009531 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009532 return 1;
9533 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009534 if (tmp == NULL || tmp == Py_None) {
9535 Py_CLEAR(tmp);
9536 kwarg = NULL;
9537 }
9538 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009539 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009540 res = obj2ast_arg(tmp, &kwarg, arena);
9541 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009542 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009543 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009544 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009545 return 1;
9546 }
9547 if (tmp == NULL) {
9548 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9549 return 1;
9550 }
9551 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009552 int res;
9553 Py_ssize_t len;
9554 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009555 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009556 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 +02009557 goto failed;
9558 }
9559 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009560 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009561 if (defaults == NULL) goto failed;
9562 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009563 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009564 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9565 Py_INCREF(tmp2);
9566 res = obj2ast_expr(tmp2, &val, arena);
9567 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009568 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009569 if (len != PyList_GET_SIZE(tmp)) {
9570 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9571 goto failed;
9572 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009573 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009574 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009575 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009576 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009577 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009578 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009579 return 0;
9580failed:
9581 Py_XDECREF(tmp);
9582 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009583}
9584
9585int
9586obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9587{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009588 PyObject* tmp = NULL;
9589 identifier arg;
9590 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009591 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009592 int lineno;
9593 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009594 int end_lineno;
9595 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009596
Dino Viehlandac46eb42019-09-11 10:16:34 -07009597 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009598 return 1;
9599 }
9600 if (tmp == NULL) {
9601 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9602 return 1;
9603 }
9604 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009605 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009606 res = obj2ast_identifier(tmp, &arg, arena);
9607 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009608 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009609 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009610 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9611 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009612 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009613 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009614 if (tmp == NULL || tmp == Py_None) {
9615 Py_CLEAR(tmp);
9616 annotation = NULL;
9617 }
9618 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009619 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009620 res = obj2ast_expr(tmp, &annotation, arena);
9621 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009622 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009623 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009624 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9625 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009626 return 1;
9627 }
9628 if (tmp == NULL || tmp == Py_None) {
9629 Py_CLEAR(tmp);
9630 type_comment = NULL;
9631 }
9632 else {
9633 int res;
9634 res = obj2ast_string(tmp, &type_comment, arena);
9635 if (res != 0) goto failed;
9636 Py_CLEAR(tmp);
9637 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009638 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009639 return 1;
9640 }
9641 if (tmp == NULL) {
9642 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9643 return 1;
9644 }
9645 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009646 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009647 res = obj2ast_int(tmp, &lineno, arena);
9648 if (res != 0) goto failed;
9649 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009650 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009651 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9652 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009653 return 1;
9654 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009655 if (tmp == NULL) {
9656 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9657 return 1;
9658 }
9659 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009660 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009661 res = obj2ast_int(tmp, &col_offset, arena);
9662 if (res != 0) goto failed;
9663 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009664 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009665 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9666 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009667 return 1;
9668 }
9669 if (tmp == NULL || tmp == Py_None) {
9670 Py_CLEAR(tmp);
9671 end_lineno = 0;
9672 }
9673 else {
9674 int res;
9675 res = obj2ast_int(tmp, &end_lineno, arena);
9676 if (res != 0) goto failed;
9677 Py_CLEAR(tmp);
9678 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009679 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9680 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009681 return 1;
9682 }
9683 if (tmp == NULL || tmp == Py_None) {
9684 Py_CLEAR(tmp);
9685 end_col_offset = 0;
9686 }
9687 else {
9688 int res;
9689 res = obj2ast_int(tmp, &end_col_offset, arena);
9690 if (res != 0) goto failed;
9691 Py_CLEAR(tmp);
9692 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009693 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9694 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009695 return 0;
9696failed:
9697 Py_XDECREF(tmp);
9698 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009699}
9700
9701int
9702obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9703{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009704 PyObject* tmp = NULL;
9705 identifier arg;
9706 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009707
Dino Viehlandac46eb42019-09-11 10:16:34 -07009708 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009709 return 1;
9710 }
9711 if (tmp == NULL || tmp == Py_None) {
9712 Py_CLEAR(tmp);
9713 arg = NULL;
9714 }
9715 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009716 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009717 res = obj2ast_identifier(tmp, &arg, arena);
9718 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009719 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009720 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009721 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009722 return 1;
9723 }
9724 if (tmp == NULL) {
9725 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9726 return 1;
9727 }
9728 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009729 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009730 res = obj2ast_expr(tmp, &value, arena);
9731 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009732 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009733 }
9734 *out = keyword(arg, value, arena);
9735 return 0;
9736failed:
9737 Py_XDECREF(tmp);
9738 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009739}
9740
9741int
9742obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9743{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009744 PyObject* tmp = NULL;
9745 identifier name;
9746 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009747
Dino Viehlandac46eb42019-09-11 10:16:34 -07009748 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009749 return 1;
9750 }
9751 if (tmp == NULL) {
9752 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9753 return 1;
9754 }
9755 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009756 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009757 res = obj2ast_identifier(tmp, &name, arena);
9758 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009759 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009760 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009761 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009762 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009763 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009764 if (tmp == NULL || tmp == Py_None) {
9765 Py_CLEAR(tmp);
9766 asname = NULL;
9767 }
9768 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009769 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009770 res = obj2ast_identifier(tmp, &asname, arena);
9771 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009772 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009773 }
9774 *out = alias(name, asname, arena);
9775 return 0;
9776failed:
9777 Py_XDECREF(tmp);
9778 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009779}
9780
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009781int
9782obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9783{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009784 PyObject* tmp = NULL;
9785 expr_ty context_expr;
9786 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009787
Dino Viehlandac46eb42019-09-11 10:16:34 -07009788 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9789 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009790 return 1;
9791 }
9792 if (tmp == NULL) {
9793 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9794 return 1;
9795 }
9796 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009797 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009798 res = obj2ast_expr(tmp, &context_expr, arena);
9799 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009800 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009801 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009802 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9803 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009804 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009805 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009806 if (tmp == NULL || tmp == Py_None) {
9807 Py_CLEAR(tmp);
9808 optional_vars = NULL;
9809 }
9810 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009811 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009812 res = obj2ast_expr(tmp, &optional_vars, arena);
9813 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009814 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009815 }
9816 *out = withitem(context_expr, optional_vars, arena);
9817 return 0;
9818failed:
9819 Py_XDECREF(tmp);
9820 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009821}
9822
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009823int
9824obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9825{
9826 int isinstance;
9827
9828 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009829 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009830
9831 if (obj == Py_None) {
9832 *out = NULL;
9833 return 0;
9834 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009835 tp = astmodulestate_global->TypeIgnore_type;
9836 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009837 if (isinstance == -1) {
9838 return 1;
9839 }
9840 if (isinstance) {
9841 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009842 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009843
Dino Viehlandac46eb42019-09-11 10:16:34 -07009844 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9845 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009846 return 1;
9847 }
9848 if (tmp == NULL) {
9849 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9850 return 1;
9851 }
9852 else {
9853 int res;
9854 res = obj2ast_int(tmp, &lineno, arena);
9855 if (res != 0) goto failed;
9856 Py_CLEAR(tmp);
9857 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009858 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009859 return 1;
9860 }
9861 if (tmp == NULL) {
9862 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9863 return 1;
9864 }
9865 else {
9866 int res;
9867 res = obj2ast_string(tmp, &tag, arena);
9868 if (res != 0) goto failed;
9869 Py_CLEAR(tmp);
9870 }
9871 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009872 if (*out == NULL) goto failed;
9873 return 0;
9874 }
9875
9876 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9877 failed:
9878 Py_XDECREF(tmp);
9879 return 1;
9880}
9881
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009882
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009883PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009884PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009885{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009886 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009887 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009888 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009889 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009890 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9891 goto error;
9892 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009893 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009894 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9895 goto error;
9896 }
9897 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9898 goto error;
9899 }
9900 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9901 goto error;
9902 }
9903 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9904 goto error;
9905 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009906 Py_INCREF(astmodulestate(m)->mod_type);
9907 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009908 0) {
9909 goto error;
9910 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009911 Py_INCREF(astmodulestate(m)->Module_type);
9912 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009913 astmodulestate_global->Interactive_type) < 0) {
9914 goto error;
9915 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009916 Py_INCREF(astmodulestate(m)->Interactive_type);
9917 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009918 astmodulestate_global->Expression_type) < 0) {
9919 goto error;
9920 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009921 Py_INCREF(astmodulestate(m)->Expression_type);
9922 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009923 astmodulestate_global->FunctionType_type) < 0) {
9924 goto error;
9925 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009926 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009927 if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0) {
9928 goto error;
9929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009930 Py_INCREF(astmodulestate(m)->Suite_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009931 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9932 goto error;
9933 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009934 Py_INCREF(astmodulestate(m)->stmt_type);
9935 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009936 astmodulestate_global->FunctionDef_type) < 0) {
9937 goto error;
9938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009939 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9940 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009941 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9942 goto error;
9943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009944 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9945 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009946 < 0) {
9947 goto error;
9948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009949 Py_INCREF(astmodulestate(m)->ClassDef_type);
9950 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009951 0) {
9952 goto error;
9953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009954 Py_INCREF(astmodulestate(m)->Return_type);
9955 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009956 0) {
9957 goto error;
9958 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009959 Py_INCREF(astmodulestate(m)->Delete_type);
9960 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009961 0) {
9962 goto error;
9963 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009964 Py_INCREF(astmodulestate(m)->Assign_type);
9965 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009966 astmodulestate_global->AugAssign_type) < 0) {
9967 goto error;
9968 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009969 Py_INCREF(astmodulestate(m)->AugAssign_type);
9970 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009971 astmodulestate_global->AnnAssign_type) < 0) {
9972 goto error;
9973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009974 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009975 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9976 goto error;
9977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009978 Py_INCREF(astmodulestate(m)->For_type);
9979 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009980 < 0) {
9981 goto error;
9982 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009983 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009984 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
9985 goto error;
9986 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009987 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009988 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
9989 goto error;
9990 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009991 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009992 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
9993 goto error;
9994 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009995 Py_INCREF(astmodulestate(m)->With_type);
9996 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009997 astmodulestate_global->AsyncWith_type) < 0) {
9998 goto error;
9999 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010000 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010001 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
10002 goto error;
10003 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010004 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010005 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
10006 goto error;
10007 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010008 Py_INCREF(astmodulestate(m)->Try_type);
10009 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010010 0) {
10011 goto error;
10012 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010013 Py_INCREF(astmodulestate(m)->Assert_type);
10014 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010015 0) {
10016 goto error;
10017 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010018 Py_INCREF(astmodulestate(m)->Import_type);
10019 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010020 astmodulestate_global->ImportFrom_type) < 0) {
10021 goto error;
10022 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010023 Py_INCREF(astmodulestate(m)->ImportFrom_type);
10024 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010025 0) {
10026 goto error;
10027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010028 Py_INCREF(astmodulestate(m)->Global_type);
10029 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010030 < 0) {
10031 goto error;
10032 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010033 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010034 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10035 goto error;
10036 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010037 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010038 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10039 goto error;
10040 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010041 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010042 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10043 goto error;
10044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010045 Py_INCREF(astmodulestate(m)->Break_type);
10046 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010047 < 0) {
10048 goto error;
10049 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010050 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010051 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10052 goto error;
10053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010054 Py_INCREF(astmodulestate(m)->expr_type);
10055 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010056 0) {
10057 goto error;
10058 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010059 Py_INCREF(astmodulestate(m)->BoolOp_type);
10060 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010061 astmodulestate_global->NamedExpr_type) < 0) {
10062 goto error;
10063 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010064 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010065 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10066 goto error;
10067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010068 Py_INCREF(astmodulestate(m)->BinOp_type);
10069 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010070 0) {
10071 goto error;
10072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010073 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10074 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010075 0) {
10076 goto error;
10077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010078 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010079 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10080 goto error;
10081 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010082 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010083 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10084 goto error;
10085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010086 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010087 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10088 goto error;
10089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010090 Py_INCREF(astmodulestate(m)->Set_type);
10091 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010092 < 0) {
10093 goto error;
10094 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010095 Py_INCREF(astmodulestate(m)->ListComp_type);
10096 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010097 0) {
10098 goto error;
10099 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010100 Py_INCREF(astmodulestate(m)->SetComp_type);
10101 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010102 < 0) {
10103 goto error;
10104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010105 Py_INCREF(astmodulestate(m)->DictComp_type);
10106 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010107 astmodulestate_global->GeneratorExp_type) < 0) {
10108 goto error;
10109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010110 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010111 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10112 goto error;
10113 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010114 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010115 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10116 goto error;
10117 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010118 Py_INCREF(astmodulestate(m)->Yield_type);
10119 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010120 astmodulestate_global->YieldFrom_type) < 0) {
10121 goto error;
10122 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010123 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10124 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010125 0) {
10126 goto error;
10127 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010128 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010129 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10130 goto error;
10131 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010132 Py_INCREF(astmodulestate(m)->Call_type);
10133 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010134 astmodulestate_global->FormattedValue_type) < 0) {
10135 goto error;
10136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010137 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10138 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010139 astmodulestate_global->JoinedStr_type) < 0) {
10140 goto error;
10141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010142 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10143 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010144 < 0) {
10145 goto error;
10146 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010147 Py_INCREF(astmodulestate(m)->Constant_type);
10148 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010149 astmodulestate_global->Attribute_type) < 0) {
10150 goto error;
10151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010152 Py_INCREF(astmodulestate(m)->Attribute_type);
10153 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010154 astmodulestate_global->Subscript_type) < 0) {
10155 goto error;
10156 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010157 Py_INCREF(astmodulestate(m)->Subscript_type);
10158 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010159 0) {
10160 goto error;
10161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010162 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010163 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10164 goto error;
10165 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010166 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010167 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10168 goto error;
10169 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010170 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010171 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10172 goto error;
10173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010174 Py_INCREF(astmodulestate(m)->Tuple_type);
10175 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010176 astmodulestate_global->expr_context_type) < 0) {
10177 goto error;
10178 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010179 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010180 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10181 goto error;
10182 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010183 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010184 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10185 goto error;
10186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010187 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010188 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10189 goto error;
10190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010191 Py_INCREF(astmodulestate(m)->Del_type);
10192 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010193 0) {
10194 goto error;
10195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010196 Py_INCREF(astmodulestate(m)->AugLoad_type);
10197 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010198 < 0) {
10199 goto error;
10200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010201 Py_INCREF(astmodulestate(m)->AugStore_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010202 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) {
10203 goto error;
10204 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010205 Py_INCREF(astmodulestate(m)->Param_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010206 if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) {
10207 goto error;
10208 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010209 Py_INCREF(astmodulestate(m)->slice_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010210 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10211 goto error;
10212 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010213 Py_INCREF(astmodulestate(m)->Slice_type);
10214 if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010215 < 0) {
10216 goto error;
10217 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010218 Py_INCREF(astmodulestate(m)->ExtSlice_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010219 if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) {
10220 goto error;
10221 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010222 Py_INCREF(astmodulestate(m)->Index_type);
10223 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010224 0) {
10225 goto error;
10226 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010227 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010228 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10229 goto error;
10230 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010231 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010232 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10233 goto error;
10234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010235 Py_INCREF(astmodulestate(m)->Or_type);
10236 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010237 < 0) {
10238 goto error;
10239 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010240 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010241 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10242 goto error;
10243 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010244 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010245 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10246 goto error;
10247 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010248 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010249 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10250 goto error;
10251 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010252 Py_INCREF(astmodulestate(m)->Mult_type);
10253 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010254 0) {
10255 goto error;
10256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010257 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010258 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10259 goto error;
10260 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010261 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010262 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10263 goto error;
10264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010265 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010266 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10267 goto error;
10268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010269 Py_INCREF(astmodulestate(m)->Pow_type);
10270 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010271 0) {
10272 goto error;
10273 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010274 Py_INCREF(astmodulestate(m)->LShift_type);
10275 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010276 0) {
10277 goto error;
10278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010279 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010280 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10281 goto error;
10282 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010283 Py_INCREF(astmodulestate(m)->BitOr_type);
10284 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010285 0) {
10286 goto error;
10287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010288 Py_INCREF(astmodulestate(m)->BitXor_type);
10289 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010290 0) {
10291 goto error;
10292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010293 Py_INCREF(astmodulestate(m)->BitAnd_type);
10294 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010295 < 0) {
10296 goto error;
10297 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010298 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10299 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010300 0) {
10301 goto error;
10302 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010303 Py_INCREF(astmodulestate(m)->unaryop_type);
10304 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010305 0) {
10306 goto error;
10307 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010308 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010309 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10310 goto error;
10311 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010312 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010313 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10314 goto error;
10315 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010316 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010317 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10318 goto error;
10319 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010320 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010321 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10322 goto error;
10323 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010324 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010325 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10326 goto error;
10327 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010328 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010329 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10330 goto error;
10331 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010332 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010333 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10334 goto error;
10335 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010336 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010337 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10338 goto error;
10339 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010340 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010341 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10342 goto error;
10343 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010344 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010345 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10346 goto error;
10347 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010348 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010349 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10350 goto error;
10351 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010352 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010353 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10354 goto error;
10355 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010356 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010357 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10358 goto error;
10359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010360 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010361 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10362 goto error;
10363 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010364 Py_INCREF(astmodulestate(m)->NotIn_type);
10365 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010366 astmodulestate_global->comprehension_type) < 0) {
10367 goto error;
10368 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010369 Py_INCREF(astmodulestate(m)->comprehension_type);
10370 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010371 astmodulestate_global->excepthandler_type) < 0) {
10372 goto error;
10373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010374 Py_INCREF(astmodulestate(m)->excepthandler_type);
10375 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010376 astmodulestate_global->ExceptHandler_type) < 0) {
10377 goto error;
10378 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010379 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10380 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010381 astmodulestate_global->arguments_type) < 0) {
10382 goto error;
10383 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010384 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010385 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10386 goto error;
10387 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010388 Py_INCREF(astmodulestate(m)->arg_type);
10389 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010390 0) {
10391 goto error;
10392 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010393 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010394 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10395 goto error;
10396 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010397 Py_INCREF(astmodulestate(m)->alias_type);
10398 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010399 < 0) {
10400 goto error;
10401 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010402 Py_INCREF(astmodulestate(m)->withitem_type);
10403 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010404 astmodulestate_global->type_ignore_type) < 0) {
10405 goto error;
10406 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010407 Py_INCREF(astmodulestate(m)->type_ignore_type);
10408 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010409 astmodulestate_global->TypeIgnore_type) < 0) {
10410 goto error;
10411 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010412 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010413 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010414error:
10415 Py_DECREF(m);
10416 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010417}
10418
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010419
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010420PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010421{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010422 if (!init_types())
10423 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010424 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010425}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010426
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010427/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10428mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010429{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010430 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010431 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010432 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010433
Steve Dowerb82e17e2019-05-23 08:45:22 -070010434 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10435 return NULL;
10436 }
10437
Dino Viehlandac46eb42019-09-11 10:16:34 -070010438 req_type[0] = astmodulestate_global->Module_type;
10439 req_type[1] = astmodulestate_global->Expression_type;
10440 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010441
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010442 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010443
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010444 if (!init_types())
10445 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010446
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010447 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10448 if (isinstance == -1)
10449 return NULL;
10450 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010451 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010452 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010453 return NULL;
10454 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010455
10456 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010457 if (obj2ast_mod(ast, &res, arena) != 0)
10458 return NULL;
10459 else
10460 return res;
10461}
10462
10463int PyAST_Check(PyObject* obj)
10464{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010465 if (!init_types())
10466 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010467 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010468}
10469
Martin v. Löwis5b222132007-06-10 09:51:05 +000010470