blob: e2c703d815552ee1a3f2dc09fb2d3d0a2a7284a4 [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},
1247 {Py_tp_free, PyType_GenericNew},
1248 {Py_tp_free, PyObject_GC_Del},
1249 {0, 0},
1250};
1251
1252static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001253 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001254 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001255 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001256 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1257 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001258};
1259
Dino Viehlandac46eb42019-09-11 10:16:34 -07001260static PyObject *
1261make_type(const char *type, PyObject* base, const char* const* fields, int num_fields)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001262{
1263 PyObject *fnames, *result;
1264 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001265 fnames = PyTuple_New(num_fields);
1266 if (!fnames) return NULL;
1267 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001268 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001269 if (!field) {
1270 Py_DECREF(fnames);
1271 return NULL;
1272 }
1273 PyTuple_SET_ITEM(fnames, i, field);
1274 }
INADA Naokifc489082017-01-25 22:33:43 +09001275 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
1276 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001277 astmodulestate_global->_fields, fnames,
1278 astmodulestate_global->__module__,
1279 astmodulestate_global->_ast);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001280 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001281 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001282}
1283
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001284static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001285add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001286{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001287 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001288 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001289 if (!l)
1290 return 0;
1291 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001292 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001293 if (!s) {
1294 Py_DECREF(l);
1295 return 0;
1296 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001297 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001298 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001299 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001300 Py_DECREF(l);
1301 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001302}
1303
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001304/* Conversion AST -> Python */
1305
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001306static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1307{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001308 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001309 PyObject *result = PyList_New(n);
1310 PyObject *value;
1311 if (!result)
1312 return NULL;
1313 for (i = 0; i < n; i++) {
1314 value = func(asdl_seq_GET(seq, i));
1315 if (!value) {
1316 Py_DECREF(result);
1317 return NULL;
1318 }
1319 PyList_SET_ITEM(result, i, value);
1320 }
1321 return result;
1322}
1323
1324static PyObject* ast2obj_object(void *o)
1325{
1326 if (!o)
1327 o = Py_None;
1328 Py_INCREF((PyObject*)o);
1329 return (PyObject*)o;
1330}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001331#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001332#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001333#define ast2obj_identifier ast2obj_object
1334#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001335#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001336
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001337static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001338{
Christian Heimes217cfd12007-12-02 14:31:20 +00001339 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001340}
1341
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001342/* Conversion Python -> AST */
1343
1344static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1345{
1346 if (obj == Py_None)
1347 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001348 if (obj) {
1349 if (PyArena_AddPyObject(arena, obj) < 0) {
1350 *out = NULL;
1351 return -1;
1352 }
1353 Py_INCREF(obj);
1354 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001355 *out = obj;
1356 return 0;
1357}
1358
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001359static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1360{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001361 if (PyArena_AddPyObject(arena, obj) < 0) {
1362 *out = NULL;
1363 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001364 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001365 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001366 *out = obj;
1367 return 0;
1368}
1369
Benjamin Peterson180e6352011-07-22 11:09:07 -05001370static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001371{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001372 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1373 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001374 return 1;
1375 }
1376 return obj2ast_object(obj, out, arena);
1377}
1378
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001379static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1380{
1381 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1382 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1383 return 1;
1384 }
1385 return obj2ast_object(obj, out, arena);
1386}
1387
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001388static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1389{
1390 int i;
1391 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001392 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001393 return 1;
1394 }
1395
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001396 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001397 if (i == -1 && PyErr_Occurred())
1398 return 1;
1399 *out = i;
1400 return 0;
1401}
1402
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001403static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001404{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001405 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001406 empty_tuple = PyTuple_New(0);
1407 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001408 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1409 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001410 Py_XDECREF(empty_tuple);
1411 return -1;
1412 }
1413 Py_DECREF(empty_tuple);
1414 return 0;
1415}
1416
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001417
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001418static int init_types(void)
1419{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001420 PyObject *m;
1421 if (PyState_FindModule(&_astmodule) == NULL) {
1422 m = PyModule_Create(&_astmodule);
1423 if (!m) return 0;
1424 PyState_AddModule(m, &_astmodule);
1425 }
1426 astmodulestate *state = astmodulestate_global;
1427 if (state->initialized) return 1;
1428 if (init_identifiers() < 0) return 0;
1429 state->AST_type = PyType_FromSpec(&AST_type_spec);
1430 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001431 if (add_ast_fields() < 0) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001432 state->mod_type = make_type("mod", state->AST_type, NULL, 0);
1433 if (!state->mod_type) return 0;
1434 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
1435 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2);
1436 if (!state->Module_type) return 0;
1437 state->Interactive_type = make_type("Interactive", state->mod_type,
1438 Interactive_fields, 1);
1439 if (!state->Interactive_type) return 0;
1440 state->Expression_type = make_type("Expression", state->mod_type,
1441 Expression_fields, 1);
1442 if (!state->Expression_type) return 0;
1443 state->FunctionType_type = make_type("FunctionType", state->mod_type,
1444 FunctionType_fields, 2);
1445 if (!state->FunctionType_type) return 0;
1446 state->Suite_type = make_type("Suite", state->mod_type, Suite_fields, 1);
1447 if (!state->Suite_type) return 0;
1448 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
1449 if (!state->stmt_type) return 0;
1450 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
1451 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1452 FunctionDef_fields, 6);
1453 if (!state->FunctionDef_type) return 0;
1454 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1455 state->stmt_type,
1456 AsyncFunctionDef_fields, 6);
1457 if (!state->AsyncFunctionDef_type) return 0;
1458 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1459 ClassDef_fields, 5);
1460 if (!state->ClassDef_type) return 0;
1461 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1462 1);
1463 if (!state->Return_type) return 0;
1464 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1465 1);
1466 if (!state->Delete_type) return 0;
1467 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1468 3);
1469 if (!state->Assign_type) return 0;
1470 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1471 AugAssign_fields, 3);
1472 if (!state->AugAssign_type) return 0;
1473 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1474 AnnAssign_fields, 4);
1475 if (!state->AnnAssign_type) return 0;
1476 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1477 if (!state->For_type) return 0;
1478 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1479 AsyncFor_fields, 5);
1480 if (!state->AsyncFor_type) return 0;
1481 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1482 if (!state->While_type) return 0;
1483 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1484 if (!state->If_type) return 0;
1485 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1486 if (!state->With_type) return 0;
1487 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1488 AsyncWith_fields, 3);
1489 if (!state->AsyncWith_type) return 0;
1490 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1491 if (!state->Raise_type) return 0;
1492 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1493 if (!state->Try_type) return 0;
1494 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1495 2);
1496 if (!state->Assert_type) return 0;
1497 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1498 1);
1499 if (!state->Import_type) return 0;
1500 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1501 ImportFrom_fields, 3);
1502 if (!state->ImportFrom_type) return 0;
1503 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1504 1);
1505 if (!state->Global_type) return 0;
1506 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1507 Nonlocal_fields, 1);
1508 if (!state->Nonlocal_type) return 0;
1509 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1510 if (!state->Expr_type) return 0;
1511 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1512 if (!state->Pass_type) return 0;
1513 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1514 if (!state->Break_type) return 0;
1515 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1516 if (!state->Continue_type) return 0;
1517 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1518 if (!state->expr_type) return 0;
1519 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
1520 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1521 2);
1522 if (!state->BoolOp_type) return 0;
1523 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1524 NamedExpr_fields, 2);
1525 if (!state->NamedExpr_type) return 0;
1526 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1527 if (!state->BinOp_type) return 0;
1528 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1529 UnaryOp_fields, 2);
1530 if (!state->UnaryOp_type) return 0;
1531 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1532 2);
1533 if (!state->Lambda_type) return 0;
1534 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1535 if (!state->IfExp_type) return 0;
1536 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1537 if (!state->Dict_type) return 0;
1538 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1539 if (!state->Set_type) return 0;
1540 state->ListComp_type = make_type("ListComp", state->expr_type,
1541 ListComp_fields, 2);
1542 if (!state->ListComp_type) return 0;
1543 state->SetComp_type = make_type("SetComp", state->expr_type,
1544 SetComp_fields, 2);
1545 if (!state->SetComp_type) return 0;
1546 state->DictComp_type = make_type("DictComp", state->expr_type,
1547 DictComp_fields, 3);
1548 if (!state->DictComp_type) return 0;
1549 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1550 GeneratorExp_fields, 2);
1551 if (!state->GeneratorExp_type) return 0;
1552 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1553 if (!state->Await_type) return 0;
1554 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1555 if (!state->Yield_type) return 0;
1556 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1557 YieldFrom_fields, 1);
1558 if (!state->YieldFrom_type) return 0;
1559 state->Compare_type = make_type("Compare", state->expr_type,
1560 Compare_fields, 3);
1561 if (!state->Compare_type) return 0;
1562 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1563 if (!state->Call_type) return 0;
1564 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1565 FormattedValue_fields, 3);
1566 if (!state->FormattedValue_type) return 0;
1567 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1568 JoinedStr_fields, 1);
1569 if (!state->JoinedStr_type) return 0;
1570 state->Constant_type = make_type("Constant", state->expr_type,
1571 Constant_fields, 2);
1572 if (!state->Constant_type) return 0;
1573 state->Attribute_type = make_type("Attribute", state->expr_type,
1574 Attribute_fields, 3);
1575 if (!state->Attribute_type) return 0;
1576 state->Subscript_type = make_type("Subscript", state->expr_type,
1577 Subscript_fields, 3);
1578 if (!state->Subscript_type) return 0;
1579 state->Starred_type = make_type("Starred", state->expr_type,
1580 Starred_fields, 2);
1581 if (!state->Starred_type) return 0;
1582 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1583 if (!state->Name_type) return 0;
1584 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1585 if (!state->List_type) return 0;
1586 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1587 if (!state->Tuple_type) return 0;
1588 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1589 0);
1590 if (!state->expr_context_type) return 0;
1591 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1592 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1593 if (!state->Load_type) return 0;
1594 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1595 NULL, NULL);
1596 if (!state->Load_singleton) return 0;
1597 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1598 if (!state->Store_type) return 0;
1599 state->Store_singleton = PyType_GenericNew((PyTypeObject
1600 *)state->Store_type, NULL, NULL);
1601 if (!state->Store_singleton) return 0;
1602 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1603 if (!state->Del_type) return 0;
1604 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1605 NULL, NULL);
1606 if (!state->Del_singleton) return 0;
1607 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1608 0);
1609 if (!state->AugLoad_type) return 0;
1610 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1611 *)state->AugLoad_type, NULL,
1612 NULL);
1613 if (!state->AugLoad_singleton) return 0;
1614 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1615 NULL, 0);
1616 if (!state->AugStore_type) return 0;
1617 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1618 *)state->AugStore_type, NULL,
1619 NULL);
1620 if (!state->AugStore_singleton) return 0;
1621 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1622 if (!state->Param_type) return 0;
1623 state->Param_singleton = PyType_GenericNew((PyTypeObject
1624 *)state->Param_type, NULL, NULL);
1625 if (!state->Param_singleton) return 0;
1626 state->slice_type = make_type("slice", state->AST_type, NULL, 0);
1627 if (!state->slice_type) return 0;
1628 if (!add_attributes(state->slice_type, NULL, 0)) return 0;
1629 state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3);
1630 if (!state->Slice_type) return 0;
1631 state->ExtSlice_type = make_type("ExtSlice", state->slice_type,
1632 ExtSlice_fields, 1);
1633 if (!state->ExtSlice_type) return 0;
1634 state->Index_type = make_type("Index", state->slice_type, Index_fields, 1);
1635 if (!state->Index_type) return 0;
1636 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1637 if (!state->boolop_type) return 0;
1638 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1639 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1640 if (!state->And_type) return 0;
1641 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1642 NULL, NULL);
1643 if (!state->And_singleton) return 0;
1644 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1645 if (!state->Or_type) return 0;
1646 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1647 NULL, NULL);
1648 if (!state->Or_singleton) return 0;
1649 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1650 if (!state->operator_type) return 0;
1651 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1652 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1653 if (!state->Add_type) return 0;
1654 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1655 NULL, NULL);
1656 if (!state->Add_singleton) return 0;
1657 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1658 if (!state->Sub_type) return 0;
1659 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1660 NULL, NULL);
1661 if (!state->Sub_singleton) return 0;
1662 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1663 if (!state->Mult_type) return 0;
1664 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1665 NULL, NULL);
1666 if (!state->Mult_singleton) return 0;
1667 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1668 if (!state->MatMult_type) return 0;
1669 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1670 *)state->MatMult_type, NULL,
1671 NULL);
1672 if (!state->MatMult_singleton) return 0;
1673 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1674 if (!state->Div_type) return 0;
1675 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1676 NULL, NULL);
1677 if (!state->Div_singleton) return 0;
1678 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1679 if (!state->Mod_type) return 0;
1680 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1681 NULL, NULL);
1682 if (!state->Mod_singleton) return 0;
1683 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1684 if (!state->Pow_type) return 0;
1685 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1686 NULL, NULL);
1687 if (!state->Pow_singleton) return 0;
1688 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1689 if (!state->LShift_type) return 0;
1690 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1691 *)state->LShift_type, NULL,
1692 NULL);
1693 if (!state->LShift_singleton) return 0;
1694 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1695 if (!state->RShift_type) return 0;
1696 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1697 *)state->RShift_type, NULL,
1698 NULL);
1699 if (!state->RShift_singleton) return 0;
1700 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1701 if (!state->BitOr_type) return 0;
1702 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1703 *)state->BitOr_type, NULL, NULL);
1704 if (!state->BitOr_singleton) return 0;
1705 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1706 if (!state->BitXor_type) return 0;
1707 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1708 *)state->BitXor_type, NULL,
1709 NULL);
1710 if (!state->BitXor_singleton) return 0;
1711 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1712 if (!state->BitAnd_type) return 0;
1713 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1714 *)state->BitAnd_type, NULL,
1715 NULL);
1716 if (!state->BitAnd_singleton) return 0;
1717 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1718 if (!state->FloorDiv_type) return 0;
1719 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1720 *)state->FloorDiv_type, NULL,
1721 NULL);
1722 if (!state->FloorDiv_singleton) return 0;
1723 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1724 if (!state->unaryop_type) return 0;
1725 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1726 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1727 if (!state->Invert_type) return 0;
1728 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1729 *)state->Invert_type, NULL,
1730 NULL);
1731 if (!state->Invert_singleton) return 0;
1732 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1733 if (!state->Not_type) return 0;
1734 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1735 NULL, NULL);
1736 if (!state->Not_singleton) return 0;
1737 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1738 if (!state->UAdd_type) return 0;
1739 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1740 NULL, NULL);
1741 if (!state->UAdd_singleton) return 0;
1742 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1743 if (!state->USub_type) return 0;
1744 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1745 NULL, NULL);
1746 if (!state->USub_singleton) return 0;
1747 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1748 if (!state->cmpop_type) return 0;
1749 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1750 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1751 if (!state->Eq_type) return 0;
1752 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1753 NULL, NULL);
1754 if (!state->Eq_singleton) return 0;
1755 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1756 if (!state->NotEq_type) return 0;
1757 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1758 *)state->NotEq_type, NULL, NULL);
1759 if (!state->NotEq_singleton) return 0;
1760 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1761 if (!state->Lt_type) return 0;
1762 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1763 NULL, NULL);
1764 if (!state->Lt_singleton) return 0;
1765 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1766 if (!state->LtE_type) return 0;
1767 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1768 NULL, NULL);
1769 if (!state->LtE_singleton) return 0;
1770 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1771 if (!state->Gt_type) return 0;
1772 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1773 NULL, NULL);
1774 if (!state->Gt_singleton) return 0;
1775 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1776 if (!state->GtE_type) return 0;
1777 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1778 NULL, NULL);
1779 if (!state->GtE_singleton) return 0;
1780 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1781 if (!state->Is_type) return 0;
1782 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1783 NULL, NULL);
1784 if (!state->Is_singleton) return 0;
1785 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1786 if (!state->IsNot_type) return 0;
1787 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1788 *)state->IsNot_type, NULL, NULL);
1789 if (!state->IsNot_singleton) return 0;
1790 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1791 if (!state->In_type) return 0;
1792 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1793 NULL, NULL);
1794 if (!state->In_singleton) return 0;
1795 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1796 if (!state->NotIn_type) return 0;
1797 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1798 *)state->NotIn_type, NULL, NULL);
1799 if (!state->NotIn_singleton) return 0;
1800 state->comprehension_type = make_type("comprehension", state->AST_type,
1801 comprehension_fields, 4);
1802 if (!state->comprehension_type) return 0;
1803 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1804 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1805 NULL, 0);
1806 if (!state->excepthandler_type) return 0;
1807 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1808 4)) return 0;
1809 state->ExceptHandler_type = make_type("ExceptHandler",
1810 state->excepthandler_type,
1811 ExceptHandler_fields, 3);
1812 if (!state->ExceptHandler_type) return 0;
1813 state->arguments_type = make_type("arguments", state->AST_type,
1814 arguments_fields, 7);
1815 if (!state->arguments_type) return 0;
1816 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
1817 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1818 if (!state->arg_type) return 0;
1819 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
1820 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1821 2);
1822 if (!state->keyword_type) return 0;
1823 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
1824 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1825 if (!state->alias_type) return 0;
1826 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
1827 state->withitem_type = make_type("withitem", state->AST_type,
1828 withitem_fields, 2);
1829 if (!state->withitem_type) return 0;
1830 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
1831 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1832 0);
1833 if (!state->type_ignore_type) return 0;
1834 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1835 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1836 TypeIgnore_fields, 2);
1837 if (!state->TypeIgnore_type) return 0;
1838 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001839 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001840}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001841
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001842static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1843static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1844static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1845static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1846 arena);
1847static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1848static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1849static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1850static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1851static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1852static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1853 arena);
1854static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1855 arena);
1856static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1857static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1858static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1859static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001860static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001861static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1862 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001863
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001864mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001865Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001867 mod_ty p;
1868 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1869 if (!p)
1870 return NULL;
1871 p->kind = Module_kind;
1872 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001873 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001874 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001875}
1876
1877mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001878Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001879{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001880 mod_ty p;
1881 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1882 if (!p)
1883 return NULL;
1884 p->kind = Interactive_kind;
1885 p->v.Interactive.body = body;
1886 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001887}
1888
1889mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001890Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001891{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001892 mod_ty p;
1893 if (!body) {
1894 PyErr_SetString(PyExc_ValueError,
1895 "field body is required for Expression");
1896 return NULL;
1897 }
1898 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1899 if (!p)
1900 return NULL;
1901 p->kind = Expression_kind;
1902 p->v.Expression.body = body;
1903 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001904}
1905
1906mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001907FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1908{
1909 mod_ty p;
1910 if (!returns) {
1911 PyErr_SetString(PyExc_ValueError,
1912 "field returns is required for FunctionType");
1913 return NULL;
1914 }
1915 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1916 if (!p)
1917 return NULL;
1918 p->kind = FunctionType_kind;
1919 p->v.FunctionType.argtypes = argtypes;
1920 p->v.FunctionType.returns = returns;
1921 return p;
1922}
1923
1924mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001925Suite(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001926{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001927 mod_ty p;
1928 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1929 if (!p)
1930 return NULL;
1931 p->kind = Suite_kind;
1932 p->v.Suite.body = body;
1933 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001934}
1935
1936stmt_ty
1937FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001938 decorator_list, expr_ty returns, string type_comment, int lineno,
1939 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001940{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001941 stmt_ty p;
1942 if (!name) {
1943 PyErr_SetString(PyExc_ValueError,
1944 "field name is required for FunctionDef");
1945 return NULL;
1946 }
1947 if (!args) {
1948 PyErr_SetString(PyExc_ValueError,
1949 "field args is required for FunctionDef");
1950 return NULL;
1951 }
1952 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1953 if (!p)
1954 return NULL;
1955 p->kind = FunctionDef_kind;
1956 p->v.FunctionDef.name = name;
1957 p->v.FunctionDef.args = args;
1958 p->v.FunctionDef.body = body;
1959 p->v.FunctionDef.decorator_list = decorator_list;
1960 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001961 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001962 p->lineno = lineno;
1963 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001964 p->end_lineno = end_lineno;
1965 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001966 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001967}
1968
1969stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001970AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001971 * decorator_list, expr_ty returns, string type_comment, int
1972 lineno, int col_offset, int end_lineno, int end_col_offset,
1973 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001974{
1975 stmt_ty p;
1976 if (!name) {
1977 PyErr_SetString(PyExc_ValueError,
1978 "field name is required for AsyncFunctionDef");
1979 return NULL;
1980 }
1981 if (!args) {
1982 PyErr_SetString(PyExc_ValueError,
1983 "field args is required for AsyncFunctionDef");
1984 return NULL;
1985 }
1986 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1987 if (!p)
1988 return NULL;
1989 p->kind = AsyncFunctionDef_kind;
1990 p->v.AsyncFunctionDef.name = name;
1991 p->v.AsyncFunctionDef.args = args;
1992 p->v.AsyncFunctionDef.body = body;
1993 p->v.AsyncFunctionDef.decorator_list = decorator_list;
1994 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001995 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04001996 p->lineno = lineno;
1997 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001998 p->end_lineno = end_lineno;
1999 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002000 return p;
2001}
2002
2003stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002004ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002005 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2006 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002007{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002008 stmt_ty p;
2009 if (!name) {
2010 PyErr_SetString(PyExc_ValueError,
2011 "field name is required for ClassDef");
2012 return NULL;
2013 }
2014 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2015 if (!p)
2016 return NULL;
2017 p->kind = ClassDef_kind;
2018 p->v.ClassDef.name = name;
2019 p->v.ClassDef.bases = bases;
2020 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002021 p->v.ClassDef.body = body;
2022 p->v.ClassDef.decorator_list = decorator_list;
2023 p->lineno = lineno;
2024 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002025 p->end_lineno = end_lineno;
2026 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002027 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002028}
2029
2030stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002031Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2032 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002033{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002034 stmt_ty p;
2035 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2036 if (!p)
2037 return NULL;
2038 p->kind = Return_kind;
2039 p->v.Return.value = value;
2040 p->lineno = lineno;
2041 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002042 p->end_lineno = end_lineno;
2043 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002044 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002045}
2046
2047stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002048Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2049 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002050{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002051 stmt_ty p;
2052 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2053 if (!p)
2054 return NULL;
2055 p->kind = Delete_kind;
2056 p->v.Delete.targets = targets;
2057 p->lineno = lineno;
2058 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002059 p->end_lineno = end_lineno;
2060 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002061 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002062}
2063
2064stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002065Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2066 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002067{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002068 stmt_ty p;
2069 if (!value) {
2070 PyErr_SetString(PyExc_ValueError,
2071 "field value is required for Assign");
2072 return NULL;
2073 }
2074 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2075 if (!p)
2076 return NULL;
2077 p->kind = Assign_kind;
2078 p->v.Assign.targets = targets;
2079 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002080 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002081 p->lineno = lineno;
2082 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002083 p->end_lineno = end_lineno;
2084 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002085 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002086}
2087
2088stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002089AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002090 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002091{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002092 stmt_ty p;
2093 if (!target) {
2094 PyErr_SetString(PyExc_ValueError,
2095 "field target is required for AugAssign");
2096 return NULL;
2097 }
2098 if (!op) {
2099 PyErr_SetString(PyExc_ValueError,
2100 "field op is required for AugAssign");
2101 return NULL;
2102 }
2103 if (!value) {
2104 PyErr_SetString(PyExc_ValueError,
2105 "field value is required for AugAssign");
2106 return NULL;
2107 }
2108 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2109 if (!p)
2110 return NULL;
2111 p->kind = AugAssign_kind;
2112 p->v.AugAssign.target = target;
2113 p->v.AugAssign.op = op;
2114 p->v.AugAssign.value = value;
2115 p->lineno = lineno;
2116 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002117 p->end_lineno = end_lineno;
2118 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002119 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002120}
2121
2122stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002123AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002124 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2125 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002126{
2127 stmt_ty p;
2128 if (!target) {
2129 PyErr_SetString(PyExc_ValueError,
2130 "field target is required for AnnAssign");
2131 return NULL;
2132 }
2133 if (!annotation) {
2134 PyErr_SetString(PyExc_ValueError,
2135 "field annotation is required for AnnAssign");
2136 return NULL;
2137 }
2138 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2139 if (!p)
2140 return NULL;
2141 p->kind = AnnAssign_kind;
2142 p->v.AnnAssign.target = target;
2143 p->v.AnnAssign.annotation = annotation;
2144 p->v.AnnAssign.value = value;
2145 p->v.AnnAssign.simple = simple;
2146 p->lineno = lineno;
2147 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002148 p->end_lineno = end_lineno;
2149 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002150 return p;
2151}
2152
2153stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002154For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2155 type_comment, int lineno, int col_offset, int end_lineno, int
2156 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002157{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002158 stmt_ty p;
2159 if (!target) {
2160 PyErr_SetString(PyExc_ValueError,
2161 "field target is required for For");
2162 return NULL;
2163 }
2164 if (!iter) {
2165 PyErr_SetString(PyExc_ValueError,
2166 "field iter is required for For");
2167 return NULL;
2168 }
2169 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2170 if (!p)
2171 return NULL;
2172 p->kind = For_kind;
2173 p->v.For.target = target;
2174 p->v.For.iter = iter;
2175 p->v.For.body = body;
2176 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002177 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002178 p->lineno = lineno;
2179 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002180 p->end_lineno = end_lineno;
2181 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002182 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002183}
2184
2185stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002186AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2187 string type_comment, int lineno, int col_offset, int end_lineno, int
2188 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002189{
2190 stmt_ty p;
2191 if (!target) {
2192 PyErr_SetString(PyExc_ValueError,
2193 "field target is required for AsyncFor");
2194 return NULL;
2195 }
2196 if (!iter) {
2197 PyErr_SetString(PyExc_ValueError,
2198 "field iter is required for AsyncFor");
2199 return NULL;
2200 }
2201 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2202 if (!p)
2203 return NULL;
2204 p->kind = AsyncFor_kind;
2205 p->v.AsyncFor.target = target;
2206 p->v.AsyncFor.iter = iter;
2207 p->v.AsyncFor.body = body;
2208 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002209 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002210 p->lineno = lineno;
2211 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002212 p->end_lineno = end_lineno;
2213 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002214 return p;
2215}
2216
2217stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002218While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002219 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002220{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002221 stmt_ty p;
2222 if (!test) {
2223 PyErr_SetString(PyExc_ValueError,
2224 "field test is required for While");
2225 return NULL;
2226 }
2227 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2228 if (!p)
2229 return NULL;
2230 p->kind = While_kind;
2231 p->v.While.test = test;
2232 p->v.While.body = body;
2233 p->v.While.orelse = orelse;
2234 p->lineno = lineno;
2235 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002236 p->end_lineno = end_lineno;
2237 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002238 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002239}
2240
2241stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002242If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002243 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002244{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002245 stmt_ty p;
2246 if (!test) {
2247 PyErr_SetString(PyExc_ValueError,
2248 "field test is required for If");
2249 return NULL;
2250 }
2251 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2252 if (!p)
2253 return NULL;
2254 p->kind = If_kind;
2255 p->v.If.test = test;
2256 p->v.If.body = body;
2257 p->v.If.orelse = orelse;
2258 p->lineno = lineno;
2259 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002260 p->end_lineno = end_lineno;
2261 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002262 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002263}
2264
2265stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002266With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2267 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002268{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002269 stmt_ty p;
2270 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2271 if (!p)
2272 return NULL;
2273 p->kind = With_kind;
2274 p->v.With.items = items;
2275 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002276 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002277 p->lineno = lineno;
2278 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002279 p->end_lineno = end_lineno;
2280 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002281 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002282}
2283
2284stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002285AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2286 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002287{
2288 stmt_ty p;
2289 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2290 if (!p)
2291 return NULL;
2292 p->kind = AsyncWith_kind;
2293 p->v.AsyncWith.items = items;
2294 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002295 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002296 p->lineno = lineno;
2297 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002298 p->end_lineno = end_lineno;
2299 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002300 return p;
2301}
2302
2303stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002304Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2305 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002306{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002307 stmt_ty p;
2308 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2309 if (!p)
2310 return NULL;
2311 p->kind = Raise_kind;
2312 p->v.Raise.exc = exc;
2313 p->v.Raise.cause = cause;
2314 p->lineno = lineno;
2315 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002316 p->end_lineno = end_lineno;
2317 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002318 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002319}
2320
2321stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002322Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002323 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2324 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002325{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002326 stmt_ty p;
2327 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2328 if (!p)
2329 return NULL;
2330 p->kind = Try_kind;
2331 p->v.Try.body = body;
2332 p->v.Try.handlers = handlers;
2333 p->v.Try.orelse = orelse;
2334 p->v.Try.finalbody = finalbody;
2335 p->lineno = lineno;
2336 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002337 p->end_lineno = end_lineno;
2338 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002339 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002340}
2341
2342stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002343Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2344 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002345{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002346 stmt_ty p;
2347 if (!test) {
2348 PyErr_SetString(PyExc_ValueError,
2349 "field test is required for Assert");
2350 return NULL;
2351 }
2352 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2353 if (!p)
2354 return NULL;
2355 p->kind = Assert_kind;
2356 p->v.Assert.test = test;
2357 p->v.Assert.msg = msg;
2358 p->lineno = lineno;
2359 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002360 p->end_lineno = end_lineno;
2361 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002362 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002363}
2364
2365stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002366Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2367 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002368{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002369 stmt_ty p;
2370 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2371 if (!p)
2372 return NULL;
2373 p->kind = Import_kind;
2374 p->v.Import.names = names;
2375 p->lineno = lineno;
2376 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002377 p->end_lineno = end_lineno;
2378 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002379 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002380}
2381
2382stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002383ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002384 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002385{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002386 stmt_ty p;
2387 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2388 if (!p)
2389 return NULL;
2390 p->kind = ImportFrom_kind;
2391 p->v.ImportFrom.module = module;
2392 p->v.ImportFrom.names = names;
2393 p->v.ImportFrom.level = level;
2394 p->lineno = lineno;
2395 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002396 p->end_lineno = end_lineno;
2397 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002398 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002399}
2400
2401stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002402Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2403 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002404{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002405 stmt_ty p;
2406 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2407 if (!p)
2408 return NULL;
2409 p->kind = Global_kind;
2410 p->v.Global.names = names;
2411 p->lineno = lineno;
2412 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002413 p->end_lineno = end_lineno;
2414 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002415 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002416}
2417
2418stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002419Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2420 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002421{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002422 stmt_ty p;
2423 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2424 if (!p)
2425 return NULL;
2426 p->kind = Nonlocal_kind;
2427 p->v.Nonlocal.names = names;
2428 p->lineno = lineno;
2429 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002430 p->end_lineno = end_lineno;
2431 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002432 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002433}
2434
2435stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002436Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2437 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002438{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002439 stmt_ty p;
2440 if (!value) {
2441 PyErr_SetString(PyExc_ValueError,
2442 "field value is required for Expr");
2443 return NULL;
2444 }
2445 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2446 if (!p)
2447 return NULL;
2448 p->kind = Expr_kind;
2449 p->v.Expr.value = value;
2450 p->lineno = lineno;
2451 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002452 p->end_lineno = end_lineno;
2453 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002454 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002455}
2456
2457stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002458Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2459 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002460{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002461 stmt_ty p;
2462 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2463 if (!p)
2464 return NULL;
2465 p->kind = Pass_kind;
2466 p->lineno = lineno;
2467 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002468 p->end_lineno = end_lineno;
2469 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002470 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471}
2472
2473stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002474Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2475 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002476{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002477 stmt_ty p;
2478 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2479 if (!p)
2480 return NULL;
2481 p->kind = Break_kind;
2482 p->lineno = lineno;
2483 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002484 p->end_lineno = end_lineno;
2485 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002486 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487}
2488
2489stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002490Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2491 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002492{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002493 stmt_ty p;
2494 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2495 if (!p)
2496 return NULL;
2497 p->kind = Continue_kind;
2498 p->lineno = lineno;
2499 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002500 p->end_lineno = end_lineno;
2501 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002502 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002503}
2504
2505expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002506BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2507 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002508{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002509 expr_ty p;
2510 if (!op) {
2511 PyErr_SetString(PyExc_ValueError,
2512 "field op is required for BoolOp");
2513 return NULL;
2514 }
2515 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2516 if (!p)
2517 return NULL;
2518 p->kind = BoolOp_kind;
2519 p->v.BoolOp.op = op;
2520 p->v.BoolOp.values = values;
2521 p->lineno = lineno;
2522 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002523 p->end_lineno = end_lineno;
2524 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002525 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002526}
2527
2528expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002529NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2530 end_lineno, int end_col_offset, PyArena *arena)
2531{
2532 expr_ty p;
2533 if (!target) {
2534 PyErr_SetString(PyExc_ValueError,
2535 "field target is required for NamedExpr");
2536 return NULL;
2537 }
2538 if (!value) {
2539 PyErr_SetString(PyExc_ValueError,
2540 "field value is required for NamedExpr");
2541 return NULL;
2542 }
2543 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2544 if (!p)
2545 return NULL;
2546 p->kind = NamedExpr_kind;
2547 p->v.NamedExpr.target = target;
2548 p->v.NamedExpr.value = value;
2549 p->lineno = lineno;
2550 p->col_offset = col_offset;
2551 p->end_lineno = end_lineno;
2552 p->end_col_offset = end_col_offset;
2553 return p;
2554}
2555
2556expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002557BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002558 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002559{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002560 expr_ty p;
2561 if (!left) {
2562 PyErr_SetString(PyExc_ValueError,
2563 "field left is required for BinOp");
2564 return NULL;
2565 }
2566 if (!op) {
2567 PyErr_SetString(PyExc_ValueError,
2568 "field op is required for BinOp");
2569 return NULL;
2570 }
2571 if (!right) {
2572 PyErr_SetString(PyExc_ValueError,
2573 "field right is required for BinOp");
2574 return NULL;
2575 }
2576 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2577 if (!p)
2578 return NULL;
2579 p->kind = BinOp_kind;
2580 p->v.BinOp.left = left;
2581 p->v.BinOp.op = op;
2582 p->v.BinOp.right = right;
2583 p->lineno = lineno;
2584 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002585 p->end_lineno = end_lineno;
2586 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002587 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002588}
2589
2590expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002591UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2592 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002593{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002594 expr_ty p;
2595 if (!op) {
2596 PyErr_SetString(PyExc_ValueError,
2597 "field op is required for UnaryOp");
2598 return NULL;
2599 }
2600 if (!operand) {
2601 PyErr_SetString(PyExc_ValueError,
2602 "field operand is required for UnaryOp");
2603 return NULL;
2604 }
2605 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2606 if (!p)
2607 return NULL;
2608 p->kind = UnaryOp_kind;
2609 p->v.UnaryOp.op = op;
2610 p->v.UnaryOp.operand = operand;
2611 p->lineno = lineno;
2612 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002613 p->end_lineno = end_lineno;
2614 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002615 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002616}
2617
2618expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002619Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2620 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002621{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002622 expr_ty p;
2623 if (!args) {
2624 PyErr_SetString(PyExc_ValueError,
2625 "field args is required for Lambda");
2626 return NULL;
2627 }
2628 if (!body) {
2629 PyErr_SetString(PyExc_ValueError,
2630 "field body is required for Lambda");
2631 return NULL;
2632 }
2633 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2634 if (!p)
2635 return NULL;
2636 p->kind = Lambda_kind;
2637 p->v.Lambda.args = args;
2638 p->v.Lambda.body = body;
2639 p->lineno = lineno;
2640 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002641 p->end_lineno = end_lineno;
2642 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002643 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002644}
2645
2646expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002647IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002648 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002649{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002650 expr_ty p;
2651 if (!test) {
2652 PyErr_SetString(PyExc_ValueError,
2653 "field test is required for IfExp");
2654 return NULL;
2655 }
2656 if (!body) {
2657 PyErr_SetString(PyExc_ValueError,
2658 "field body is required for IfExp");
2659 return NULL;
2660 }
2661 if (!orelse) {
2662 PyErr_SetString(PyExc_ValueError,
2663 "field orelse is required for IfExp");
2664 return NULL;
2665 }
2666 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2667 if (!p)
2668 return NULL;
2669 p->kind = IfExp_kind;
2670 p->v.IfExp.test = test;
2671 p->v.IfExp.body = body;
2672 p->v.IfExp.orelse = orelse;
2673 p->lineno = lineno;
2674 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002675 p->end_lineno = end_lineno;
2676 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002677 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002678}
2679
2680expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002681Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2682 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002683{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002684 expr_ty p;
2685 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2686 if (!p)
2687 return NULL;
2688 p->kind = Dict_kind;
2689 p->v.Dict.keys = keys;
2690 p->v.Dict.values = values;
2691 p->lineno = lineno;
2692 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002693 p->end_lineno = end_lineno;
2694 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002695 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002696}
2697
2698expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002699Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2700 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002701{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002702 expr_ty p;
2703 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2704 if (!p)
2705 return NULL;
2706 p->kind = Set_kind;
2707 p->v.Set.elts = elts;
2708 p->lineno = lineno;
2709 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002710 p->end_lineno = end_lineno;
2711 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002712 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002713}
2714
2715expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002716ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2717 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002718{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002719 expr_ty p;
2720 if (!elt) {
2721 PyErr_SetString(PyExc_ValueError,
2722 "field elt is required for ListComp");
2723 return NULL;
2724 }
2725 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2726 if (!p)
2727 return NULL;
2728 p->kind = ListComp_kind;
2729 p->v.ListComp.elt = elt;
2730 p->v.ListComp.generators = generators;
2731 p->lineno = lineno;
2732 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002733 p->end_lineno = end_lineno;
2734 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002735 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002736}
2737
2738expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002739SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2740 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002741{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002742 expr_ty p;
2743 if (!elt) {
2744 PyErr_SetString(PyExc_ValueError,
2745 "field elt is required for SetComp");
2746 return NULL;
2747 }
2748 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2749 if (!p)
2750 return NULL;
2751 p->kind = SetComp_kind;
2752 p->v.SetComp.elt = elt;
2753 p->v.SetComp.generators = generators;
2754 p->lineno = lineno;
2755 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002756 p->end_lineno = end_lineno;
2757 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002758 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002759}
2760
2761expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002762DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002763 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002764{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002765 expr_ty p;
2766 if (!key) {
2767 PyErr_SetString(PyExc_ValueError,
2768 "field key is required for DictComp");
2769 return NULL;
2770 }
2771 if (!value) {
2772 PyErr_SetString(PyExc_ValueError,
2773 "field value is required for DictComp");
2774 return NULL;
2775 }
2776 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2777 if (!p)
2778 return NULL;
2779 p->kind = DictComp_kind;
2780 p->v.DictComp.key = key;
2781 p->v.DictComp.value = value;
2782 p->v.DictComp.generators = generators;
2783 p->lineno = lineno;
2784 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002785 p->end_lineno = end_lineno;
2786 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002787 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002788}
2789
2790expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002791GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002792 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002793{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002794 expr_ty p;
2795 if (!elt) {
2796 PyErr_SetString(PyExc_ValueError,
2797 "field elt is required for GeneratorExp");
2798 return NULL;
2799 }
2800 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2801 if (!p)
2802 return NULL;
2803 p->kind = GeneratorExp_kind;
2804 p->v.GeneratorExp.elt = elt;
2805 p->v.GeneratorExp.generators = generators;
2806 p->lineno = lineno;
2807 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002808 p->end_lineno = end_lineno;
2809 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002810 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002811}
2812
2813expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002814Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2815 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002816{
2817 expr_ty p;
2818 if (!value) {
2819 PyErr_SetString(PyExc_ValueError,
2820 "field value is required for Await");
2821 return NULL;
2822 }
2823 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2824 if (!p)
2825 return NULL;
2826 p->kind = Await_kind;
2827 p->v.Await.value = value;
2828 p->lineno = lineno;
2829 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002830 p->end_lineno = end_lineno;
2831 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002832 return p;
2833}
2834
2835expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002836Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2837 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002838{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002839 expr_ty p;
2840 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2841 if (!p)
2842 return NULL;
2843 p->kind = Yield_kind;
2844 p->v.Yield.value = value;
2845 p->lineno = lineno;
2846 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002847 p->end_lineno = end_lineno;
2848 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002849 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002850}
2851
2852expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002853YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2854 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002855{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002856 expr_ty p;
2857 if (!value) {
2858 PyErr_SetString(PyExc_ValueError,
2859 "field value is required for YieldFrom");
2860 return NULL;
2861 }
2862 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2863 if (!p)
2864 return NULL;
2865 p->kind = YieldFrom_kind;
2866 p->v.YieldFrom.value = value;
2867 p->lineno = lineno;
2868 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002869 p->end_lineno = end_lineno;
2870 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002871 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002872}
2873
2874expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002875Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002876 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002877{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002878 expr_ty p;
2879 if (!left) {
2880 PyErr_SetString(PyExc_ValueError,
2881 "field left is required for Compare");
2882 return NULL;
2883 }
2884 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2885 if (!p)
2886 return NULL;
2887 p->kind = Compare_kind;
2888 p->v.Compare.left = left;
2889 p->v.Compare.ops = ops;
2890 p->v.Compare.comparators = comparators;
2891 p->lineno = lineno;
2892 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002893 p->end_lineno = end_lineno;
2894 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002895 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002896}
2897
2898expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002899Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002900 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002901{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002902 expr_ty p;
2903 if (!func) {
2904 PyErr_SetString(PyExc_ValueError,
2905 "field func is required for Call");
2906 return NULL;
2907 }
2908 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2909 if (!p)
2910 return NULL;
2911 p->kind = Call_kind;
2912 p->v.Call.func = func;
2913 p->v.Call.args = args;
2914 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002915 p->lineno = lineno;
2916 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002917 p->end_lineno = end_lineno;
2918 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002919 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002920}
2921
2922expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002923FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2924 int col_offset, int end_lineno, int end_col_offset, PyArena
2925 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002926{
2927 expr_ty p;
2928 if (!value) {
2929 PyErr_SetString(PyExc_ValueError,
2930 "field value is required for FormattedValue");
2931 return NULL;
2932 }
2933 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2934 if (!p)
2935 return NULL;
2936 p->kind = FormattedValue_kind;
2937 p->v.FormattedValue.value = value;
2938 p->v.FormattedValue.conversion = conversion;
2939 p->v.FormattedValue.format_spec = format_spec;
2940 p->lineno = lineno;
2941 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002942 p->end_lineno = end_lineno;
2943 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002944 return p;
2945}
2946
2947expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002948JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2949 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002950{
2951 expr_ty p;
2952 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2953 if (!p)
2954 return NULL;
2955 p->kind = JoinedStr_kind;
2956 p->v.JoinedStr.values = values;
2957 p->lineno = lineno;
2958 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002959 p->end_lineno = end_lineno;
2960 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002961 return p;
2962}
2963
2964expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002965Constant(constant value, string kind, int lineno, int col_offset, int
2966 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002967{
2968 expr_ty p;
2969 if (!value) {
2970 PyErr_SetString(PyExc_ValueError,
2971 "field value is required for Constant");
2972 return NULL;
2973 }
2974 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2975 if (!p)
2976 return NULL;
2977 p->kind = Constant_kind;
2978 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002979 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002980 p->lineno = lineno;
2981 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002982 p->end_lineno = end_lineno;
2983 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002984 return p;
2985}
2986
2987expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002988Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002989 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002990{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002991 expr_ty p;
2992 if (!value) {
2993 PyErr_SetString(PyExc_ValueError,
2994 "field value is required for Attribute");
2995 return NULL;
2996 }
2997 if (!attr) {
2998 PyErr_SetString(PyExc_ValueError,
2999 "field attr is required for Attribute");
3000 return NULL;
3001 }
3002 if (!ctx) {
3003 PyErr_SetString(PyExc_ValueError,
3004 "field ctx is required for Attribute");
3005 return NULL;
3006 }
3007 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3008 if (!p)
3009 return NULL;
3010 p->kind = Attribute_kind;
3011 p->v.Attribute.value = value;
3012 p->v.Attribute.attr = attr;
3013 p->v.Attribute.ctx = ctx;
3014 p->lineno = lineno;
3015 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003016 p->end_lineno = end_lineno;
3017 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003018 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003019}
3020
3021expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003022Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003023 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003024{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003025 expr_ty p;
3026 if (!value) {
3027 PyErr_SetString(PyExc_ValueError,
3028 "field value is required for Subscript");
3029 return NULL;
3030 }
3031 if (!slice) {
3032 PyErr_SetString(PyExc_ValueError,
3033 "field slice is required for Subscript");
3034 return NULL;
3035 }
3036 if (!ctx) {
3037 PyErr_SetString(PyExc_ValueError,
3038 "field ctx is required for Subscript");
3039 return NULL;
3040 }
3041 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3042 if (!p)
3043 return NULL;
3044 p->kind = Subscript_kind;
3045 p->v.Subscript.value = value;
3046 p->v.Subscript.slice = slice;
3047 p->v.Subscript.ctx = ctx;
3048 p->lineno = lineno;
3049 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003050 p->end_lineno = end_lineno;
3051 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003052 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003053}
3054
3055expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003056Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3057 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003058{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003059 expr_ty p;
3060 if (!value) {
3061 PyErr_SetString(PyExc_ValueError,
3062 "field value is required for Starred");
3063 return NULL;
3064 }
3065 if (!ctx) {
3066 PyErr_SetString(PyExc_ValueError,
3067 "field ctx is required for Starred");
3068 return NULL;
3069 }
3070 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3071 if (!p)
3072 return NULL;
3073 p->kind = Starred_kind;
3074 p->v.Starred.value = value;
3075 p->v.Starred.ctx = ctx;
3076 p->lineno = lineno;
3077 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003078 p->end_lineno = end_lineno;
3079 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003080 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003081}
3082
3083expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003084Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3085 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003086{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003087 expr_ty p;
3088 if (!id) {
3089 PyErr_SetString(PyExc_ValueError,
3090 "field id is required for Name");
3091 return NULL;
3092 }
3093 if (!ctx) {
3094 PyErr_SetString(PyExc_ValueError,
3095 "field ctx is required for Name");
3096 return NULL;
3097 }
3098 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3099 if (!p)
3100 return NULL;
3101 p->kind = Name_kind;
3102 p->v.Name.id = id;
3103 p->v.Name.ctx = ctx;
3104 p->lineno = lineno;
3105 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003106 p->end_lineno = end_lineno;
3107 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003108 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003109}
3110
3111expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003112List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3113 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003114{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003115 expr_ty p;
3116 if (!ctx) {
3117 PyErr_SetString(PyExc_ValueError,
3118 "field ctx is required for List");
3119 return NULL;
3120 }
3121 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3122 if (!p)
3123 return NULL;
3124 p->kind = List_kind;
3125 p->v.List.elts = elts;
3126 p->v.List.ctx = ctx;
3127 p->lineno = lineno;
3128 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003129 p->end_lineno = end_lineno;
3130 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003131 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003132}
3133
3134expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003135Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3136 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003137{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003138 expr_ty p;
3139 if (!ctx) {
3140 PyErr_SetString(PyExc_ValueError,
3141 "field ctx is required for Tuple");
3142 return NULL;
3143 }
3144 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3145 if (!p)
3146 return NULL;
3147 p->kind = Tuple_kind;
3148 p->v.Tuple.elts = elts;
3149 p->v.Tuple.ctx = ctx;
3150 p->lineno = lineno;
3151 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003152 p->end_lineno = end_lineno;
3153 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003154 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003155}
3156
3157slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003158Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003159{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003160 slice_ty p;
3161 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3162 if (!p)
3163 return NULL;
3164 p->kind = Slice_kind;
3165 p->v.Slice.lower = lower;
3166 p->v.Slice.upper = upper;
3167 p->v.Slice.step = step;
3168 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003169}
3170
3171slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003172ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003173{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003174 slice_ty p;
3175 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3176 if (!p)
3177 return NULL;
3178 p->kind = ExtSlice_kind;
3179 p->v.ExtSlice.dims = dims;
3180 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003181}
3182
3183slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003184Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003185{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003186 slice_ty p;
3187 if (!value) {
3188 PyErr_SetString(PyExc_ValueError,
3189 "field value is required for Index");
3190 return NULL;
3191 }
3192 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3193 if (!p)
3194 return NULL;
3195 p->kind = Index_kind;
3196 p->v.Index.value = value;
3197 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003198}
3199
3200comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003201comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3202 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003203{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003204 comprehension_ty p;
3205 if (!target) {
3206 PyErr_SetString(PyExc_ValueError,
3207 "field target is required for comprehension");
3208 return NULL;
3209 }
3210 if (!iter) {
3211 PyErr_SetString(PyExc_ValueError,
3212 "field iter is required for comprehension");
3213 return NULL;
3214 }
3215 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3216 if (!p)
3217 return NULL;
3218 p->target = target;
3219 p->iter = iter;
3220 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003221 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003222 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003223}
3224
3225excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003226ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003227 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003228{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003229 excepthandler_ty p;
3230 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3231 if (!p)
3232 return NULL;
3233 p->kind = ExceptHandler_kind;
3234 p->v.ExceptHandler.type = type;
3235 p->v.ExceptHandler.name = name;
3236 p->v.ExceptHandler.body = body;
3237 p->lineno = lineno;
3238 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003239 p->end_lineno = end_lineno;
3240 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003241 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003242}
3243
3244arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003245arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003246 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3247 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003248{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003249 arguments_ty p;
3250 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3251 if (!p)
3252 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003253 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003254 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003255 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003256 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003257 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003258 p->kwarg = kwarg;
3259 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003260 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003261}
3262
Neal Norwitzc1505362006-12-28 06:47:50 +00003263arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003264arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3265 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003266{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003267 arg_ty p;
3268 if (!arg) {
3269 PyErr_SetString(PyExc_ValueError,
3270 "field arg is required for arg");
3271 return NULL;
3272 }
3273 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3274 if (!p)
3275 return NULL;
3276 p->arg = arg;
3277 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003278 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003279 p->lineno = lineno;
3280 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003281 p->end_lineno = end_lineno;
3282 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003283 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003284}
3285
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003286keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003287keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003288{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003289 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003290 if (!value) {
3291 PyErr_SetString(PyExc_ValueError,
3292 "field value is required for keyword");
3293 return NULL;
3294 }
3295 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3296 if (!p)
3297 return NULL;
3298 p->arg = arg;
3299 p->value = value;
3300 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003301}
3302
3303alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003304alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003305{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003306 alias_ty p;
3307 if (!name) {
3308 PyErr_SetString(PyExc_ValueError,
3309 "field name is required for alias");
3310 return NULL;
3311 }
3312 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3313 if (!p)
3314 return NULL;
3315 p->name = name;
3316 p->asname = asname;
3317 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003318}
3319
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003320withitem_ty
3321withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3322{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003323 withitem_ty p;
3324 if (!context_expr) {
3325 PyErr_SetString(PyExc_ValueError,
3326 "field context_expr is required for withitem");
3327 return NULL;
3328 }
3329 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3330 if (!p)
3331 return NULL;
3332 p->context_expr = context_expr;
3333 p->optional_vars = optional_vars;
3334 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003335}
3336
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003337type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003338TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003339{
3340 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003341 if (!tag) {
3342 PyErr_SetString(PyExc_ValueError,
3343 "field tag is required for TypeIgnore");
3344 return NULL;
3345 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003346 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3347 if (!p)
3348 return NULL;
3349 p->kind = TypeIgnore_kind;
3350 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003351 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003352 return p;
3353}
3354
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003355
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003356PyObject*
3357ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003358{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003359 mod_ty o = (mod_ty)_o;
3360 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003361 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003362 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003363 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003364 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003365
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003366 switch (o->kind) {
3367 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003368 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3369 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003370 if (!result) goto failed;
3371 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3372 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003373 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003374 goto failed;
3375 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003376 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3377 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003378 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3379 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003380 goto failed;
3381 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003382 break;
3383 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003384 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3385 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003386 if (!result) goto failed;
3387 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3388 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003389 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003390 goto failed;
3391 Py_DECREF(value);
3392 break;
3393 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003394 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3395 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003396 if (!result) goto failed;
3397 value = ast2obj_expr(o->v.Expression.body);
3398 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003399 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003400 goto failed;
3401 Py_DECREF(value);
3402 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003403 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003404 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3405 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003406 if (!result) goto failed;
3407 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3408 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003409 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3410 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003411 goto failed;
3412 Py_DECREF(value);
3413 value = ast2obj_expr(o->v.FunctionType.returns);
3414 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003415 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3416 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003417 goto failed;
3418 Py_DECREF(value);
3419 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003420 case Suite_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003421 tp = (PyTypeObject *)astmodulestate_global->Suite_type;
3422 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003423 if (!result) goto failed;
3424 value = ast2obj_list(o->v.Suite.body, ast2obj_stmt);
3425 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003426 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003427 goto failed;
3428 Py_DECREF(value);
3429 break;
3430 }
3431 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003432failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003433 Py_XDECREF(value);
3434 Py_XDECREF(result);
3435 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003436}
3437
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003438PyObject*
3439ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003440{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003441 stmt_ty o = (stmt_ty)_o;
3442 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003443 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003444 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003445 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003446 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003447
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003448 switch (o->kind) {
3449 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003450 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3451 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003452 if (!result) goto failed;
3453 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003454 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003455 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003456 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003457 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003458 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003459 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003460 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003461 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003462 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003463 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3464 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003465 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003466 goto failed;
3467 Py_DECREF(value);
3468 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3469 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003470 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3471 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003472 goto failed;
3473 Py_DECREF(value);
3474 value = ast2obj_expr(o->v.FunctionDef.returns);
3475 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003476 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3477 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003478 goto failed;
3479 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003480 value = ast2obj_string(o->v.FunctionDef.type_comment);
3481 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003482 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3483 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003484 goto failed;
3485 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003486 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003487 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003488 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3489 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003490 if (!result) goto failed;
3491 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3492 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003493 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003494 goto failed;
3495 Py_DECREF(value);
3496 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3497 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003498 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003499 goto failed;
3500 Py_DECREF(value);
3501 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3502 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003503 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003504 goto failed;
3505 Py_DECREF(value);
3506 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3507 ast2obj_expr);
3508 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003509 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3510 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003511 goto failed;
3512 Py_DECREF(value);
3513 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3514 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003515 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3516 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003517 goto failed;
3518 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003519 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3520 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003521 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3522 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003523 goto failed;
3524 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003525 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003526 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003527 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3528 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003529 if (!result) goto failed;
3530 value = ast2obj_identifier(o->v.ClassDef.name);
3531 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003532 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003533 goto failed;
3534 Py_DECREF(value);
3535 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3536 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003537 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003538 goto failed;
3539 Py_DECREF(value);
3540 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3541 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003542 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3543 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003544 goto failed;
3545 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003546 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3547 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003548 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003549 goto failed;
3550 Py_DECREF(value);
3551 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3552 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003553 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3554 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003555 goto failed;
3556 Py_DECREF(value);
3557 break;
3558 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003559 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3560 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003561 if (!result) goto failed;
3562 value = ast2obj_expr(o->v.Return.value);
3563 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003564 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003565 goto failed;
3566 Py_DECREF(value);
3567 break;
3568 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003569 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3570 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003571 if (!result) goto failed;
3572 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3573 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003574 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3575 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003576 goto failed;
3577 Py_DECREF(value);
3578 break;
3579 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003580 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3581 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003582 if (!result) goto failed;
3583 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3584 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003585 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3586 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003587 goto failed;
3588 Py_DECREF(value);
3589 value = ast2obj_expr(o->v.Assign.value);
3590 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003591 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003592 goto failed;
3593 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003594 value = ast2obj_string(o->v.Assign.type_comment);
3595 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003596 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3597 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003598 goto failed;
3599 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003600 break;
3601 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003602 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3603 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003604 if (!result) goto failed;
3605 value = ast2obj_expr(o->v.AugAssign.target);
3606 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003607 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3608 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003609 goto failed;
3610 Py_DECREF(value);
3611 value = ast2obj_operator(o->v.AugAssign.op);
3612 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003613 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 goto failed;
3615 Py_DECREF(value);
3616 value = ast2obj_expr(o->v.AugAssign.value);
3617 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003618 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003619 goto failed;
3620 Py_DECREF(value);
3621 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003622 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003623 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3624 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003625 if (!result) goto failed;
3626 value = ast2obj_expr(o->v.AnnAssign.target);
3627 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003628 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3629 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003630 goto failed;
3631 Py_DECREF(value);
3632 value = ast2obj_expr(o->v.AnnAssign.annotation);
3633 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003634 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3635 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003636 goto failed;
3637 Py_DECREF(value);
3638 value = ast2obj_expr(o->v.AnnAssign.value);
3639 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003640 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003641 goto failed;
3642 Py_DECREF(value);
3643 value = ast2obj_int(o->v.AnnAssign.simple);
3644 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003645 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3646 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003647 goto failed;
3648 Py_DECREF(value);
3649 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003650 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003651 tp = (PyTypeObject *)astmodulestate_global->For_type;
3652 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003653 if (!result) goto failed;
3654 value = ast2obj_expr(o->v.For.target);
3655 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003656 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3657 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003658 goto failed;
3659 Py_DECREF(value);
3660 value = ast2obj_expr(o->v.For.iter);
3661 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003662 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003663 goto failed;
3664 Py_DECREF(value);
3665 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3666 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003667 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003668 goto failed;
3669 Py_DECREF(value);
3670 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3671 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003672 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3673 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003674 goto failed;
3675 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003676 value = ast2obj_string(o->v.For.type_comment);
3677 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003678 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3679 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003680 goto failed;
3681 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003682 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003683 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003684 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3685 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003686 if (!result) goto failed;
3687 value = ast2obj_expr(o->v.AsyncFor.target);
3688 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003689 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3690 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003691 goto failed;
3692 Py_DECREF(value);
3693 value = ast2obj_expr(o->v.AsyncFor.iter);
3694 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003695 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003696 goto failed;
3697 Py_DECREF(value);
3698 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3699 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003700 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003701 goto failed;
3702 Py_DECREF(value);
3703 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3704 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003705 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3706 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003707 goto failed;
3708 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003709 value = ast2obj_string(o->v.AsyncFor.type_comment);
3710 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003711 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3712 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003713 goto failed;
3714 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003715 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003716 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003717 tp = (PyTypeObject *)astmodulestate_global->While_type;
3718 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003719 if (!result) goto failed;
3720 value = ast2obj_expr(o->v.While.test);
3721 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003722 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003723 goto failed;
3724 Py_DECREF(value);
3725 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3726 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003727 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003728 goto failed;
3729 Py_DECREF(value);
3730 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3731 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003732 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3733 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003734 goto failed;
3735 Py_DECREF(value);
3736 break;
3737 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003738 tp = (PyTypeObject *)astmodulestate_global->If_type;
3739 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003740 if (!result) goto failed;
3741 value = ast2obj_expr(o->v.If.test);
3742 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003743 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003744 goto failed;
3745 Py_DECREF(value);
3746 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3747 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003748 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003749 goto failed;
3750 Py_DECREF(value);
3751 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3752 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003753 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3754 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003755 goto failed;
3756 Py_DECREF(value);
3757 break;
3758 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003759 tp = (PyTypeObject *)astmodulestate_global->With_type;
3760 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003761 if (!result) goto failed;
3762 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003764 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003765 goto failed;
3766 Py_DECREF(value);
3767 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3768 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003769 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003770 goto failed;
3771 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003772 value = ast2obj_string(o->v.With.type_comment);
3773 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003774 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3775 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003776 goto failed;
3777 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003778 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003779 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003780 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3781 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003782 if (!result) goto failed;
3783 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003785 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003786 goto failed;
3787 Py_DECREF(value);
3788 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3789 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003790 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003791 goto failed;
3792 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003793 value = ast2obj_string(o->v.AsyncWith.type_comment);
3794 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003795 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3796 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003797 goto failed;
3798 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003799 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003800 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003801 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3802 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003803 if (!result) goto failed;
3804 value = ast2obj_expr(o->v.Raise.exc);
3805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003806 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003807 goto failed;
3808 Py_DECREF(value);
3809 value = ast2obj_expr(o->v.Raise.cause);
3810 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003811 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003812 goto failed;
3813 Py_DECREF(value);
3814 break;
3815 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003816 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3817 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003818 if (!result) goto failed;
3819 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3820 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003821 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003822 goto failed;
3823 Py_DECREF(value);
3824 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3825 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003826 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3827 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003828 goto failed;
3829 Py_DECREF(value);
3830 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3831 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003832 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3833 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003834 goto failed;
3835 Py_DECREF(value);
3836 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3837 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003838 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3839 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003840 goto failed;
3841 Py_DECREF(value);
3842 break;
3843 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003844 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3845 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003846 if (!result) goto failed;
3847 value = ast2obj_expr(o->v.Assert.test);
3848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003849 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003850 goto failed;
3851 Py_DECREF(value);
3852 value = ast2obj_expr(o->v.Assert.msg);
3853 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003854 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003855 goto failed;
3856 Py_DECREF(value);
3857 break;
3858 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003859 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3860 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003861 if (!result) goto failed;
3862 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3863 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003864 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003865 goto failed;
3866 Py_DECREF(value);
3867 break;
3868 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3870 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003871 if (!result) goto failed;
3872 value = ast2obj_identifier(o->v.ImportFrom.module);
3873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003874 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3875 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003876 goto failed;
3877 Py_DECREF(value);
3878 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3879 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003880 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003881 goto failed;
3882 Py_DECREF(value);
3883 value = ast2obj_int(o->v.ImportFrom.level);
3884 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003885 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003886 goto failed;
3887 Py_DECREF(value);
3888 break;
3889 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003890 tp = (PyTypeObject *)astmodulestate_global->Global_type;
3891 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003892 if (!result) goto failed;
3893 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003895 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003896 goto failed;
3897 Py_DECREF(value);
3898 break;
3899 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003900 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3901 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003902 if (!result) goto failed;
3903 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3904 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003905 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003906 goto failed;
3907 Py_DECREF(value);
3908 break;
3909 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003910 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3911 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003912 if (!result) goto failed;
3913 value = ast2obj_expr(o->v.Expr.value);
3914 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003915 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003916 goto failed;
3917 Py_DECREF(value);
3918 break;
3919 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003920 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3921 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003922 if (!result) goto failed;
3923 break;
3924 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003925 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3926 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003927 if (!result) goto failed;
3928 break;
3929 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003930 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3931 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003932 if (!result) goto failed;
3933 break;
3934 }
3935 value = ast2obj_int(o->lineno);
3936 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003937 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003938 goto failed;
3939 Py_DECREF(value);
3940 value = ast2obj_int(o->col_offset);
3941 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003942 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003943 goto failed;
3944 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003945 value = ast2obj_int(o->end_lineno);
3946 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003947 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003948 goto failed;
3949 Py_DECREF(value);
3950 value = ast2obj_int(o->end_col_offset);
3951 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003952 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
3953 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003954 goto failed;
3955 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003956 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003957failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003958 Py_XDECREF(value);
3959 Py_XDECREF(result);
3960 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003961}
3962
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003963PyObject*
3964ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003965{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003966 expr_ty o = (expr_ty)_o;
3967 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003968 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003969 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003970 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003971 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003972
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003973 switch (o->kind) {
3974 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003975 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
3976 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003977 if (!result) goto failed;
3978 value = ast2obj_boolop(o->v.BoolOp.op);
3979 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003980 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003981 goto failed;
3982 Py_DECREF(value);
3983 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3984 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003985 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
3986 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003987 goto failed;
3988 Py_DECREF(value);
3989 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003990 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003991 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
3992 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003993 if (!result) goto failed;
3994 value = ast2obj_expr(o->v.NamedExpr.target);
3995 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003996 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3997 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003998 goto failed;
3999 Py_DECREF(value);
4000 value = ast2obj_expr(o->v.NamedExpr.value);
4001 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004002 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004003 goto failed;
4004 Py_DECREF(value);
4005 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004006 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004007 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4008 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004009 if (!result) goto failed;
4010 value = ast2obj_expr(o->v.BinOp.left);
4011 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004012 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004013 goto failed;
4014 Py_DECREF(value);
4015 value = ast2obj_operator(o->v.BinOp.op);
4016 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004017 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004018 goto failed;
4019 Py_DECREF(value);
4020 value = ast2obj_expr(o->v.BinOp.right);
4021 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004022 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004023 goto failed;
4024 Py_DECREF(value);
4025 break;
4026 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4028 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004029 if (!result) goto failed;
4030 value = ast2obj_unaryop(o->v.UnaryOp.op);
4031 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004032 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004033 goto failed;
4034 Py_DECREF(value);
4035 value = ast2obj_expr(o->v.UnaryOp.operand);
4036 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004037 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4038 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004039 goto failed;
4040 Py_DECREF(value);
4041 break;
4042 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004043 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4044 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004045 if (!result) goto failed;
4046 value = ast2obj_arguments(o->v.Lambda.args);
4047 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004048 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004049 goto failed;
4050 Py_DECREF(value);
4051 value = ast2obj_expr(o->v.Lambda.body);
4052 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004053 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004054 goto failed;
4055 Py_DECREF(value);
4056 break;
4057 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004058 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4059 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004060 if (!result) goto failed;
4061 value = ast2obj_expr(o->v.IfExp.test);
4062 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004063 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004064 goto failed;
4065 Py_DECREF(value);
4066 value = ast2obj_expr(o->v.IfExp.body);
4067 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004068 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004069 goto failed;
4070 Py_DECREF(value);
4071 value = ast2obj_expr(o->v.IfExp.orelse);
4072 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004073 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4074 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004075 goto failed;
4076 Py_DECREF(value);
4077 break;
4078 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004079 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4080 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004081 if (!result) goto failed;
4082 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4083 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004084 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004085 goto failed;
4086 Py_DECREF(value);
4087 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4088 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004089 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4090 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004091 goto failed;
4092 Py_DECREF(value);
4093 break;
4094 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004095 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4096 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004097 if (!result) goto failed;
4098 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4099 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004100 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004101 goto failed;
4102 Py_DECREF(value);
4103 break;
4104 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004105 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4106 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004107 if (!result) goto failed;
4108 value = ast2obj_expr(o->v.ListComp.elt);
4109 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004110 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004111 goto failed;
4112 Py_DECREF(value);
4113 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4114 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004115 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4116 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004117 goto failed;
4118 Py_DECREF(value);
4119 break;
4120 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004121 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4122 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004123 if (!result) goto failed;
4124 value = ast2obj_expr(o->v.SetComp.elt);
4125 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004126 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004127 goto failed;
4128 Py_DECREF(value);
4129 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4130 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004131 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4132 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004133 goto failed;
4134 Py_DECREF(value);
4135 break;
4136 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004137 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4138 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004139 if (!result) goto failed;
4140 value = ast2obj_expr(o->v.DictComp.key);
4141 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004142 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004143 goto failed;
4144 Py_DECREF(value);
4145 value = ast2obj_expr(o->v.DictComp.value);
4146 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004147 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004148 goto failed;
4149 Py_DECREF(value);
4150 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4151 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004152 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4153 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004154 goto failed;
4155 Py_DECREF(value);
4156 break;
4157 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004158 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4159 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004160 if (!result) goto failed;
4161 value = ast2obj_expr(o->v.GeneratorExp.elt);
4162 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004163 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004164 goto failed;
4165 Py_DECREF(value);
4166 value = ast2obj_list(o->v.GeneratorExp.generators,
4167 ast2obj_comprehension);
4168 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004169 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4170 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004171 goto failed;
4172 Py_DECREF(value);
4173 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004174 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004175 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4176 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004177 if (!result) goto failed;
4178 value = ast2obj_expr(o->v.Await.value);
4179 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004180 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004181 goto failed;
4182 Py_DECREF(value);
4183 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004184 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004185 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4186 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004187 if (!result) goto failed;
4188 value = ast2obj_expr(o->v.Yield.value);
4189 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004190 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004191 goto failed;
4192 Py_DECREF(value);
4193 break;
4194 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004195 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4196 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004197 if (!result) goto failed;
4198 value = ast2obj_expr(o->v.YieldFrom.value);
4199 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004200 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004201 goto failed;
4202 Py_DECREF(value);
4203 break;
4204 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004205 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4206 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004207 if (!result) goto failed;
4208 value = ast2obj_expr(o->v.Compare.left);
4209 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004210 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004211 goto failed;
4212 Py_DECREF(value);
4213 {
4214 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4215 value = PyList_New(n);
4216 if (!value) goto failed;
4217 for(i = 0; i < n; i++)
4218 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004219 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004220 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004221 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004222 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004223 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004224 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004225 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004226 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4227 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004228 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004229 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004230 break;
4231 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004232 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4233 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004234 if (!result) goto failed;
4235 value = ast2obj_expr(o->v.Call.func);
4236 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004237 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004238 goto failed;
4239 Py_DECREF(value);
4240 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4241 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004242 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004243 goto failed;
4244 Py_DECREF(value);
4245 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4246 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004247 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4248 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004249 goto failed;
4250 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004251 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004252 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004253 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4254 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004255 if (!result) goto failed;
4256 value = ast2obj_expr(o->v.FormattedValue.value);
4257 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004258 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004259 goto failed;
4260 Py_DECREF(value);
4261 value = ast2obj_int(o->v.FormattedValue.conversion);
4262 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004263 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4264 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004265 goto failed;
4266 Py_DECREF(value);
4267 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4268 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004269 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4270 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004271 goto failed;
4272 Py_DECREF(value);
4273 break;
4274 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004275 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4276 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004277 if (!result) goto failed;
4278 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4279 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004280 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4281 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004282 goto failed;
4283 Py_DECREF(value);
4284 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004285 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004286 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4287 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004288 if (!result) goto failed;
4289 value = ast2obj_constant(o->v.Constant.value);
4290 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004291 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004292 goto failed;
4293 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004294 value = ast2obj_string(o->v.Constant.kind);
4295 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004296 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004297 goto failed;
4298 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004299 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004300 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004301 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4302 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004303 if (!result) goto failed;
4304 value = ast2obj_expr(o->v.Attribute.value);
4305 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004306 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004307 goto failed;
4308 Py_DECREF(value);
4309 value = ast2obj_identifier(o->v.Attribute.attr);
4310 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004311 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 goto failed;
4313 Py_DECREF(value);
4314 value = ast2obj_expr_context(o->v.Attribute.ctx);
4315 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004316 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004317 goto failed;
4318 Py_DECREF(value);
4319 break;
4320 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004321 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4322 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004323 if (!result) goto failed;
4324 value = ast2obj_expr(o->v.Subscript.value);
4325 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004326 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004327 goto failed;
4328 Py_DECREF(value);
4329 value = ast2obj_slice(o->v.Subscript.slice);
4330 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004331 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004332 goto failed;
4333 Py_DECREF(value);
4334 value = ast2obj_expr_context(o->v.Subscript.ctx);
4335 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004336 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004337 goto failed;
4338 Py_DECREF(value);
4339 break;
4340 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004341 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4342 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004343 if (!result) goto failed;
4344 value = ast2obj_expr(o->v.Starred.value);
4345 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004346 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004347 goto failed;
4348 Py_DECREF(value);
4349 value = ast2obj_expr_context(o->v.Starred.ctx);
4350 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004351 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004352 goto failed;
4353 Py_DECREF(value);
4354 break;
4355 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004356 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4357 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004358 if (!result) goto failed;
4359 value = ast2obj_identifier(o->v.Name.id);
4360 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004361 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004362 goto failed;
4363 Py_DECREF(value);
4364 value = ast2obj_expr_context(o->v.Name.ctx);
4365 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004366 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004367 goto failed;
4368 Py_DECREF(value);
4369 break;
4370 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004371 tp = (PyTypeObject *)astmodulestate_global->List_type;
4372 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004373 if (!result) goto failed;
4374 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4375 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004376 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004377 goto failed;
4378 Py_DECREF(value);
4379 value = ast2obj_expr_context(o->v.List.ctx);
4380 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004381 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004382 goto failed;
4383 Py_DECREF(value);
4384 break;
4385 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004386 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4387 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004388 if (!result) goto failed;
4389 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4390 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004391 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004392 goto failed;
4393 Py_DECREF(value);
4394 value = ast2obj_expr_context(o->v.Tuple.ctx);
4395 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004396 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004397 goto failed;
4398 Py_DECREF(value);
4399 break;
4400 }
4401 value = ast2obj_int(o->lineno);
4402 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004403 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004404 goto failed;
4405 Py_DECREF(value);
4406 value = ast2obj_int(o->col_offset);
4407 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004408 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004409 goto failed;
4410 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004411 value = ast2obj_int(o->end_lineno);
4412 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004413 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004414 goto failed;
4415 Py_DECREF(value);
4416 value = ast2obj_int(o->end_col_offset);
4417 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004418 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4419 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004420 goto failed;
4421 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004422 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004423failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004424 Py_XDECREF(value);
4425 Py_XDECREF(result);
4426 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004427}
4428
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004429PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004430{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004431 switch(o) {
4432 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004433 Py_INCREF(astmodulestate_global->Load_singleton);
4434 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004435 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004436 Py_INCREF(astmodulestate_global->Store_singleton);
4437 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004438 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004439 Py_INCREF(astmodulestate_global->Del_singleton);
4440 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004441 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004442 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4443 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004444 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004445 Py_INCREF(astmodulestate_global->AugStore_singleton);
4446 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004447 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004448 Py_INCREF(astmodulestate_global->Param_singleton);
4449 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004450 default:
4451 /* should never happen, but just in case ... */
4452 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4453 return NULL;
4454 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004455}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004456PyObject*
4457ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004458{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004459 slice_ty o = (slice_ty)_o;
4460 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004461 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004462 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004463 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004464 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004465
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004466 switch (o->kind) {
4467 case Slice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004468 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4469 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004470 if (!result) goto failed;
4471 value = ast2obj_expr(o->v.Slice.lower);
4472 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004473 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004474 goto failed;
4475 Py_DECREF(value);
4476 value = ast2obj_expr(o->v.Slice.upper);
4477 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004478 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004479 goto failed;
4480 Py_DECREF(value);
4481 value = ast2obj_expr(o->v.Slice.step);
4482 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004483 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004484 goto failed;
4485 Py_DECREF(value);
4486 break;
4487 case ExtSlice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004488 tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type;
4489 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004490 if (!result) goto failed;
4491 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
4492 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004493 if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004494 goto failed;
4495 Py_DECREF(value);
4496 break;
4497 case Index_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004498 tp = (PyTypeObject *)astmodulestate_global->Index_type;
4499 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004500 if (!result) goto failed;
4501 value = ast2obj_expr(o->v.Index.value);
4502 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004503 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004504 goto failed;
4505 Py_DECREF(value);
4506 break;
4507 }
4508 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004509failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 Py_XDECREF(value);
4511 Py_XDECREF(result);
4512 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004513}
4514
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004515PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004516{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004517 switch(o) {
4518 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004519 Py_INCREF(astmodulestate_global->And_singleton);
4520 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004521 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004522 Py_INCREF(astmodulestate_global->Or_singleton);
4523 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004524 default:
4525 /* should never happen, but just in case ... */
4526 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4527 return NULL;
4528 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004529}
4530PyObject* ast2obj_operator(operator_ty o)
4531{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004532 switch(o) {
4533 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004534 Py_INCREF(astmodulestate_global->Add_singleton);
4535 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004536 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004537 Py_INCREF(astmodulestate_global->Sub_singleton);
4538 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004539 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004540 Py_INCREF(astmodulestate_global->Mult_singleton);
4541 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004542 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004543 Py_INCREF(astmodulestate_global->MatMult_singleton);
4544 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004545 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004546 Py_INCREF(astmodulestate_global->Div_singleton);
4547 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004548 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004549 Py_INCREF(astmodulestate_global->Mod_singleton);
4550 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004551 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004552 Py_INCREF(astmodulestate_global->Pow_singleton);
4553 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004554 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004555 Py_INCREF(astmodulestate_global->LShift_singleton);
4556 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004557 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004558 Py_INCREF(astmodulestate_global->RShift_singleton);
4559 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004560 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004561 Py_INCREF(astmodulestate_global->BitOr_singleton);
4562 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004563 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004564 Py_INCREF(astmodulestate_global->BitXor_singleton);
4565 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004566 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004567 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4568 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004569 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004570 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4571 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004572 default:
4573 /* should never happen, but just in case ... */
4574 PyErr_Format(PyExc_SystemError, "unknown operator found");
4575 return NULL;
4576 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004577}
4578PyObject* ast2obj_unaryop(unaryop_ty o)
4579{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004580 switch(o) {
4581 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004582 Py_INCREF(astmodulestate_global->Invert_singleton);
4583 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004584 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004585 Py_INCREF(astmodulestate_global->Not_singleton);
4586 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004587 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004588 Py_INCREF(astmodulestate_global->UAdd_singleton);
4589 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004590 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004591 Py_INCREF(astmodulestate_global->USub_singleton);
4592 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004593 default:
4594 /* should never happen, but just in case ... */
4595 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4596 return NULL;
4597 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004598}
4599PyObject* ast2obj_cmpop(cmpop_ty o)
4600{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004601 switch(o) {
4602 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004603 Py_INCREF(astmodulestate_global->Eq_singleton);
4604 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004605 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004606 Py_INCREF(astmodulestate_global->NotEq_singleton);
4607 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004608 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004609 Py_INCREF(astmodulestate_global->Lt_singleton);
4610 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004611 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004612 Py_INCREF(astmodulestate_global->LtE_singleton);
4613 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004614 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004615 Py_INCREF(astmodulestate_global->Gt_singleton);
4616 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004617 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004618 Py_INCREF(astmodulestate_global->GtE_singleton);
4619 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004621 Py_INCREF(astmodulestate_global->Is_singleton);
4622 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004623 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004624 Py_INCREF(astmodulestate_global->IsNot_singleton);
4625 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004626 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004627 Py_INCREF(astmodulestate_global->In_singleton);
4628 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004629 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004630 Py_INCREF(astmodulestate_global->NotIn_singleton);
4631 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004632 default:
4633 /* should never happen, but just in case ... */
4634 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4635 return NULL;
4636 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004637}
4638PyObject*
4639ast2obj_comprehension(void* _o)
4640{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004641 comprehension_ty o = (comprehension_ty)_o;
4642 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004643 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004644 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004645 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004646 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004647
Dino Viehlandac46eb42019-09-11 10:16:34 -07004648 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4649 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 if (!result) return NULL;
4651 value = ast2obj_expr(o->target);
4652 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004653 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004654 goto failed;
4655 Py_DECREF(value);
4656 value = ast2obj_expr(o->iter);
4657 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004658 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004659 goto failed;
4660 Py_DECREF(value);
4661 value = ast2obj_list(o->ifs, ast2obj_expr);
4662 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004663 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004664 goto failed;
4665 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004666 value = ast2obj_int(o->is_async);
4667 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004668 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004669 goto failed;
4670 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004671 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004672failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004673 Py_XDECREF(value);
4674 Py_XDECREF(result);
4675 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004676}
4677
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004678PyObject*
4679ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004680{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004681 excepthandler_ty o = (excepthandler_ty)_o;
4682 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004683 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004684 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004685 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004686 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004687
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004688 switch (o->kind) {
4689 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004690 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4691 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004692 if (!result) goto failed;
4693 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004694 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004695 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004696 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004697 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004698 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004699 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004700 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004701 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004702 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004703 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4704 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004705 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004706 goto failed;
4707 Py_DECREF(value);
4708 break;
4709 }
4710 value = ast2obj_int(o->lineno);
4711 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004712 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004713 goto failed;
4714 Py_DECREF(value);
4715 value = ast2obj_int(o->col_offset);
4716 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004717 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004718 goto failed;
4719 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004720 value = ast2obj_int(o->end_lineno);
4721 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004722 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004723 goto failed;
4724 Py_DECREF(value);
4725 value = ast2obj_int(o->end_col_offset);
4726 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004727 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4728 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004729 goto failed;
4730 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004731 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004732failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004733 Py_XDECREF(value);
4734 Py_XDECREF(result);
4735 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004736}
4737
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004738PyObject*
4739ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004740{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004741 arguments_ty o = (arguments_ty)_o;
4742 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004743 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004744 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004745 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004746 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004747
Dino Viehlandac46eb42019-09-11 10:16:34 -07004748 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4749 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004750 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004751 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4752 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004753 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4754 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004755 goto failed;
4756 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004757 value = ast2obj_list(o->args, ast2obj_arg);
4758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004759 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004760 goto failed;
4761 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004762 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004764 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 goto failed;
4766 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004767 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4768 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004769 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4770 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 goto failed;
4772 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004773 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004774 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004775 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4776 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 goto failed;
4778 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004779 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004780 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004781 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 goto failed;
4783 Py_DECREF(value);
4784 value = ast2obj_list(o->defaults, ast2obj_expr);
4785 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004786 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004787 goto failed;
4788 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004789 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004790failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004791 Py_XDECREF(value);
4792 Py_XDECREF(result);
4793 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004794}
4795
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004796PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004797ast2obj_arg(void* _o)
4798{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004799 arg_ty o = (arg_ty)_o;
4800 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004801 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004802 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004803 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004804 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004805
Dino Viehlandac46eb42019-09-11 10:16:34 -07004806 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4807 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004808 if (!result) return NULL;
4809 value = ast2obj_identifier(o->arg);
4810 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004811 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004812 goto failed;
4813 Py_DECREF(value);
4814 value = ast2obj_expr(o->annotation);
4815 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004816 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4817 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004818 goto failed;
4819 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004820 value = ast2obj_string(o->type_comment);
4821 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004822 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4823 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004824 goto failed;
4825 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004826 value = ast2obj_int(o->lineno);
4827 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004828 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004829 goto failed;
4830 Py_DECREF(value);
4831 value = ast2obj_int(o->col_offset);
4832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004833 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004834 goto failed;
4835 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004836 value = ast2obj_int(o->end_lineno);
4837 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004838 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004839 goto failed;
4840 Py_DECREF(value);
4841 value = ast2obj_int(o->end_col_offset);
4842 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004843 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4844 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004845 goto failed;
4846 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004847 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004848failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004849 Py_XDECREF(value);
4850 Py_XDECREF(result);
4851 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004852}
4853
4854PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004855ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004856{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004857 keyword_ty o = (keyword_ty)_o;
4858 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004859 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004860 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004861 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004862 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004863
Dino Viehlandac46eb42019-09-11 10:16:34 -07004864 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4865 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004866 if (!result) return NULL;
4867 value = ast2obj_identifier(o->arg);
4868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004869 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004870 goto failed;
4871 Py_DECREF(value);
4872 value = ast2obj_expr(o->value);
4873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004874 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004875 goto failed;
4876 Py_DECREF(value);
4877 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004878failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004879 Py_XDECREF(value);
4880 Py_XDECREF(result);
4881 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004882}
4883
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004884PyObject*
4885ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004886{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004887 alias_ty o = (alias_ty)_o;
4888 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004889 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004890 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004891 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004892 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004893
Dino Viehlandac46eb42019-09-11 10:16:34 -07004894 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4895 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004896 if (!result) return NULL;
4897 value = ast2obj_identifier(o->name);
4898 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004899 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 goto failed;
4901 Py_DECREF(value);
4902 value = ast2obj_identifier(o->asname);
4903 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004904 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004905 goto failed;
4906 Py_DECREF(value);
4907 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004908failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004909 Py_XDECREF(value);
4910 Py_XDECREF(result);
4911 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004912}
4913
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004914PyObject*
4915ast2obj_withitem(void* _o)
4916{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004917 withitem_ty o = (withitem_ty)_o;
4918 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004919 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004920 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004921 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004922 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004923
Dino Viehlandac46eb42019-09-11 10:16:34 -07004924 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4925 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004926 if (!result) return NULL;
4927 value = ast2obj_expr(o->context_expr);
4928 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004929 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4930 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004931 goto failed;
4932 Py_DECREF(value);
4933 value = ast2obj_expr(o->optional_vars);
4934 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004935 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4936 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004937 goto failed;
4938 Py_DECREF(value);
4939 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004940failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004941 Py_XDECREF(value);
4942 Py_XDECREF(result);
4943 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004944}
4945
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004946PyObject*
4947ast2obj_type_ignore(void* _o)
4948{
4949 type_ignore_ty o = (type_ignore_ty)_o;
4950 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004951 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004952 if (!o) {
4953 Py_RETURN_NONE;
4954 }
4955
4956 switch (o->kind) {
4957 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004958 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
4959 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004960 if (!result) goto failed;
4961 value = ast2obj_int(o->v.TypeIgnore.lineno);
4962 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004963 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
4964 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004965 goto failed;
4966 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004967 value = ast2obj_string(o->v.TypeIgnore.tag);
4968 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004969 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004970 goto failed;
4971 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004972 break;
4973 }
4974 return result;
4975failed:
4976 Py_XDECREF(value);
4977 Py_XDECREF(result);
4978 return NULL;
4979}
4980
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004981
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004982int
4983obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4984{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004985 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004986
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004987 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004988 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004989
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004990 if (obj == Py_None) {
4991 *out = NULL;
4992 return 0;
4993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07004994 tp = astmodulestate_global->Module_type;
4995 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004996 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004997 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004998 }
4999 if (isinstance) {
5000 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005001 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005002
Dino Viehlandac46eb42019-09-11 10:16:34 -07005003 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005004 return 1;
5005 }
5006 if (tmp == NULL) {
5007 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5008 return 1;
5009 }
5010 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005011 int res;
5012 Py_ssize_t len;
5013 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005014 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005015 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 +02005016 goto failed;
5017 }
5018 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005019 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005020 if (body == NULL) goto failed;
5021 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005022 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005023 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5024 Py_INCREF(tmp2);
5025 res = obj2ast_stmt(tmp2, &val, arena);
5026 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005027 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005028 if (len != PyList_GET_SIZE(tmp)) {
5029 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5030 goto failed;
5031 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005032 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005033 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005034 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005035 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005036 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5037 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005038 return 1;
5039 }
5040 if (tmp == NULL) {
5041 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5042 return 1;
5043 }
5044 else {
5045 int res;
5046 Py_ssize_t len;
5047 Py_ssize_t i;
5048 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005049 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 -08005050 goto failed;
5051 }
5052 len = PyList_GET_SIZE(tmp);
5053 type_ignores = _Py_asdl_seq_new(len, arena);
5054 if (type_ignores == NULL) goto failed;
5055 for (i = 0; i < len; i++) {
5056 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005057 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5058 Py_INCREF(tmp2);
5059 res = obj2ast_type_ignore(tmp2, &val, arena);
5060 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005061 if (res != 0) goto failed;
5062 if (len != PyList_GET_SIZE(tmp)) {
5063 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5064 goto failed;
5065 }
5066 asdl_seq_SET(type_ignores, i, val);
5067 }
5068 Py_CLEAR(tmp);
5069 }
5070 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005071 if (*out == NULL) goto failed;
5072 return 0;
5073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005074 tp = astmodulestate_global->Interactive_type;
5075 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005076 if (isinstance == -1) {
5077 return 1;
5078 }
5079 if (isinstance) {
5080 asdl_seq* body;
5081
Dino Viehlandac46eb42019-09-11 10:16:34 -07005082 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005083 return 1;
5084 }
5085 if (tmp == NULL) {
5086 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5087 return 1;
5088 }
5089 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005090 int res;
5091 Py_ssize_t len;
5092 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005093 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005094 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 +02005095 goto failed;
5096 }
5097 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005098 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005099 if (body == NULL) goto failed;
5100 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005101 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005102 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5103 Py_INCREF(tmp2);
5104 res = obj2ast_stmt(tmp2, &val, arena);
5105 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005106 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005107 if (len != PyList_GET_SIZE(tmp)) {
5108 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5109 goto failed;
5110 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005111 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005112 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005113 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005114 }
5115 *out = Interactive(body, arena);
5116 if (*out == NULL) goto failed;
5117 return 0;
5118 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005119 tp = astmodulestate_global->Expression_type;
5120 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005121 if (isinstance == -1) {
5122 return 1;
5123 }
5124 if (isinstance) {
5125 expr_ty body;
5126
Dino Viehlandac46eb42019-09-11 10:16:34 -07005127 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005128 return 1;
5129 }
5130 if (tmp == NULL) {
5131 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5132 return 1;
5133 }
5134 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005135 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005136 res = obj2ast_expr(tmp, &body, arena);
5137 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005138 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005139 }
5140 *out = Expression(body, arena);
5141 if (*out == NULL) goto failed;
5142 return 0;
5143 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005144 tp = astmodulestate_global->FunctionType_type;
5145 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005146 if (isinstance == -1) {
5147 return 1;
5148 }
5149 if (isinstance) {
5150 asdl_seq* argtypes;
5151 expr_ty returns;
5152
Dino Viehlandac46eb42019-09-11 10:16:34 -07005153 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5154 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005155 return 1;
5156 }
5157 if (tmp == NULL) {
5158 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5159 return 1;
5160 }
5161 else {
5162 int res;
5163 Py_ssize_t len;
5164 Py_ssize_t i;
5165 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005166 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 -08005167 goto failed;
5168 }
5169 len = PyList_GET_SIZE(tmp);
5170 argtypes = _Py_asdl_seq_new(len, arena);
5171 if (argtypes == NULL) goto failed;
5172 for (i = 0; i < len; i++) {
5173 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005174 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5175 Py_INCREF(tmp2);
5176 res = obj2ast_expr(tmp2, &val, arena);
5177 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005178 if (res != 0) goto failed;
5179 if (len != PyList_GET_SIZE(tmp)) {
5180 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5181 goto failed;
5182 }
5183 asdl_seq_SET(argtypes, i, val);
5184 }
5185 Py_CLEAR(tmp);
5186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005187 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5188 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005189 return 1;
5190 }
5191 if (tmp == NULL) {
5192 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5193 return 1;
5194 }
5195 else {
5196 int res;
5197 res = obj2ast_expr(tmp, &returns, arena);
5198 if (res != 0) goto failed;
5199 Py_CLEAR(tmp);
5200 }
5201 *out = FunctionType(argtypes, returns, arena);
5202 if (*out == NULL) goto failed;
5203 return 0;
5204 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005205 tp = astmodulestate_global->Suite_type;
5206 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005207 if (isinstance == -1) {
5208 return 1;
5209 }
5210 if (isinstance) {
5211 asdl_seq* body;
5212
Dino Viehlandac46eb42019-09-11 10:16:34 -07005213 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005214 return 1;
5215 }
5216 if (tmp == NULL) {
5217 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Suite");
5218 return 1;
5219 }
5220 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005221 int res;
5222 Py_ssize_t len;
5223 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005224 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005225 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 +02005226 goto failed;
5227 }
5228 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005229 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005230 if (body == NULL) goto failed;
5231 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005232 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005233 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5234 Py_INCREF(tmp2);
5235 res = obj2ast_stmt(tmp2, &val, arena);
5236 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005237 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005238 if (len != PyList_GET_SIZE(tmp)) {
5239 PyErr_SetString(PyExc_RuntimeError, "Suite field \"body\" changed size during iteration");
5240 goto failed;
5241 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005242 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005243 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005244 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005245 }
5246 *out = Suite(body, arena);
5247 if (*out == NULL) goto failed;
5248 return 0;
5249 }
5250
5251 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5252 failed:
5253 Py_XDECREF(tmp);
5254 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005255}
5256
5257int
5258obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5259{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005260 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005261
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005262 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005263 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005264 int lineno;
5265 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005266 int end_lineno;
5267 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005268
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005269 if (obj == Py_None) {
5270 *out = NULL;
5271 return 0;
5272 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005273 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005274 return 1;
5275 }
5276 if (tmp == NULL) {
5277 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5278 return 1;
5279 }
5280 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005281 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005282 res = obj2ast_int(tmp, &lineno, arena);
5283 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005284 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005285 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005286 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5287 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005288 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005289 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005290 if (tmp == NULL) {
5291 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5292 return 1;
5293 }
5294 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005295 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005296 res = obj2ast_int(tmp, &col_offset, arena);
5297 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005298 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005299 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005300 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5301 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005302 return 1;
5303 }
5304 if (tmp == NULL || tmp == Py_None) {
5305 Py_CLEAR(tmp);
5306 end_lineno = 0;
5307 }
5308 else {
5309 int res;
5310 res = obj2ast_int(tmp, &end_lineno, arena);
5311 if (res != 0) goto failed;
5312 Py_CLEAR(tmp);
5313 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005314 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5315 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005316 return 1;
5317 }
5318 if (tmp == NULL || tmp == Py_None) {
5319 Py_CLEAR(tmp);
5320 end_col_offset = 0;
5321 }
5322 else {
5323 int res;
5324 res = obj2ast_int(tmp, &end_col_offset, arena);
5325 if (res != 0) goto failed;
5326 Py_CLEAR(tmp);
5327 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005328 tp = astmodulestate_global->FunctionDef_type;
5329 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005330 if (isinstance == -1) {
5331 return 1;
5332 }
5333 if (isinstance) {
5334 identifier name;
5335 arguments_ty args;
5336 asdl_seq* body;
5337 asdl_seq* decorator_list;
5338 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005339 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005340
Dino Viehlandac46eb42019-09-11 10:16:34 -07005341 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005342 return 1;
5343 }
5344 if (tmp == NULL) {
5345 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5346 return 1;
5347 }
5348 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005349 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005350 res = obj2ast_identifier(tmp, &name, arena);
5351 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005352 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005353 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005354 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005355 return 1;
5356 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005357 if (tmp == NULL) {
5358 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5359 return 1;
5360 }
5361 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005362 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005363 res = obj2ast_arguments(tmp, &args, arena);
5364 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005365 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005366 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005367 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005368 return 1;
5369 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005370 if (tmp == NULL) {
5371 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5372 return 1;
5373 }
5374 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005375 int res;
5376 Py_ssize_t len;
5377 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005378 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005379 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 +02005380 goto failed;
5381 }
5382 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005383 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005384 if (body == NULL) goto failed;
5385 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005386 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005387 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5388 Py_INCREF(tmp2);
5389 res = obj2ast_stmt(tmp2, &val, arena);
5390 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005391 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005392 if (len != PyList_GET_SIZE(tmp)) {
5393 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5394 goto failed;
5395 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005396 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005397 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005398 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005399 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005400 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5401 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005402 return 1;
5403 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005404 if (tmp == NULL) {
5405 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5406 return 1;
5407 }
5408 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005409 int res;
5410 Py_ssize_t len;
5411 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005412 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005413 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 +02005414 goto failed;
5415 }
5416 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005417 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005418 if (decorator_list == NULL) goto failed;
5419 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005420 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005421 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5422 Py_INCREF(tmp2);
5423 res = obj2ast_expr(tmp2, &val, arena);
5424 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005425 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005426 if (len != PyList_GET_SIZE(tmp)) {
5427 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5428 goto failed;
5429 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005430 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005431 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005432 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005433 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005434 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5435 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005436 return 1;
5437 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005438 if (tmp == NULL || tmp == Py_None) {
5439 Py_CLEAR(tmp);
5440 returns = NULL;
5441 }
5442 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005443 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005444 res = obj2ast_expr(tmp, &returns, arena);
5445 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005446 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005447 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005448 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5449 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005450 return 1;
5451 }
5452 if (tmp == NULL || tmp == Py_None) {
5453 Py_CLEAR(tmp);
5454 type_comment = NULL;
5455 }
5456 else {
5457 int res;
5458 res = obj2ast_string(tmp, &type_comment, arena);
5459 if (res != 0) goto failed;
5460 Py_CLEAR(tmp);
5461 }
5462 *out = FunctionDef(name, args, body, decorator_list, returns,
5463 type_comment, lineno, col_offset, end_lineno,
5464 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005465 if (*out == NULL) goto failed;
5466 return 0;
5467 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005468 tp = astmodulestate_global->AsyncFunctionDef_type;
5469 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005470 if (isinstance == -1) {
5471 return 1;
5472 }
5473 if (isinstance) {
5474 identifier name;
5475 arguments_ty args;
5476 asdl_seq* body;
5477 asdl_seq* decorator_list;
5478 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005479 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005480
Dino Viehlandac46eb42019-09-11 10:16:34 -07005481 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005482 return 1;
5483 }
5484 if (tmp == NULL) {
5485 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5486 return 1;
5487 }
5488 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005489 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005490 res = obj2ast_identifier(tmp, &name, arena);
5491 if (res != 0) goto failed;
5492 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005493 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005494 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005495 return 1;
5496 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005497 if (tmp == NULL) {
5498 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5499 return 1;
5500 }
5501 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005502 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005503 res = obj2ast_arguments(tmp, &args, arena);
5504 if (res != 0) goto failed;
5505 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005506 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005507 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005508 return 1;
5509 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005510 if (tmp == NULL) {
5511 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5512 return 1;
5513 }
5514 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005515 int res;
5516 Py_ssize_t len;
5517 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005518 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005519 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 -04005520 goto failed;
5521 }
5522 len = PyList_GET_SIZE(tmp);
5523 body = _Py_asdl_seq_new(len, arena);
5524 if (body == NULL) goto failed;
5525 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005526 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005527 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5528 Py_INCREF(tmp2);
5529 res = obj2ast_stmt(tmp2, &val, arena);
5530 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005531 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005532 if (len != PyList_GET_SIZE(tmp)) {
5533 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5534 goto failed;
5535 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005536 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005537 }
5538 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005539 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005540 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5541 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005542 return 1;
5543 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005544 if (tmp == NULL) {
5545 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5546 return 1;
5547 }
5548 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005549 int res;
5550 Py_ssize_t len;
5551 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005552 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005553 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 -04005554 goto failed;
5555 }
5556 len = PyList_GET_SIZE(tmp);
5557 decorator_list = _Py_asdl_seq_new(len, arena);
5558 if (decorator_list == NULL) goto failed;
5559 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005560 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005561 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5562 Py_INCREF(tmp2);
5563 res = obj2ast_expr(tmp2, &val, arena);
5564 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005565 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005566 if (len != PyList_GET_SIZE(tmp)) {
5567 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5568 goto failed;
5569 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005570 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005571 }
5572 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005573 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005574 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5575 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005576 return 1;
5577 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005578 if (tmp == NULL || tmp == Py_None) {
5579 Py_CLEAR(tmp);
5580 returns = NULL;
5581 }
5582 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005583 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005584 res = obj2ast_expr(tmp, &returns, arena);
5585 if (res != 0) goto failed;
5586 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005587 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005588 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5589 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005590 return 1;
5591 }
5592 if (tmp == NULL || tmp == Py_None) {
5593 Py_CLEAR(tmp);
5594 type_comment = NULL;
5595 }
5596 else {
5597 int res;
5598 res = obj2ast_string(tmp, &type_comment, arena);
5599 if (res != 0) goto failed;
5600 Py_CLEAR(tmp);
5601 }
Yury Selivanov75445082015-05-11 22:57:16 -04005602 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005603 type_comment, lineno, col_offset, end_lineno,
5604 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005605 if (*out == NULL) goto failed;
5606 return 0;
5607 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005608 tp = astmodulestate_global->ClassDef_type;
5609 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005610 if (isinstance == -1) {
5611 return 1;
5612 }
5613 if (isinstance) {
5614 identifier name;
5615 asdl_seq* bases;
5616 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005617 asdl_seq* body;
5618 asdl_seq* decorator_list;
5619
Dino Viehlandac46eb42019-09-11 10:16:34 -07005620 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005621 return 1;
5622 }
5623 if (tmp == NULL) {
5624 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5625 return 1;
5626 }
5627 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005628 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005629 res = obj2ast_identifier(tmp, &name, arena);
5630 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005631 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005632 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005633 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005634 return 1;
5635 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005636 if (tmp == NULL) {
5637 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5638 return 1;
5639 }
5640 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005641 int res;
5642 Py_ssize_t len;
5643 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005644 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005645 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 +02005646 goto failed;
5647 }
5648 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005649 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005650 if (bases == NULL) goto failed;
5651 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005652 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005653 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5654 Py_INCREF(tmp2);
5655 res = obj2ast_expr(tmp2, &val, arena);
5656 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005657 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005658 if (len != PyList_GET_SIZE(tmp)) {
5659 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5660 goto failed;
5661 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005662 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005663 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005664 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005665 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005666 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5667 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005668 return 1;
5669 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005670 if (tmp == NULL) {
5671 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5672 return 1;
5673 }
5674 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005675 int res;
5676 Py_ssize_t len;
5677 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005678 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005679 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 +02005680 goto failed;
5681 }
5682 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005683 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005684 if (keywords == NULL) goto failed;
5685 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005686 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005687 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5688 Py_INCREF(tmp2);
5689 res = obj2ast_keyword(tmp2, &val, arena);
5690 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005691 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005692 if (len != PyList_GET_SIZE(tmp)) {
5693 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5694 goto failed;
5695 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005696 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005697 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005698 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005699 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005700 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005701 return 1;
5702 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005703 if (tmp == NULL) {
5704 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5705 return 1;
5706 }
5707 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005708 int res;
5709 Py_ssize_t len;
5710 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005711 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005712 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 +02005713 goto failed;
5714 }
5715 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005716 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005717 if (body == NULL) goto failed;
5718 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005719 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005720 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5721 Py_INCREF(tmp2);
5722 res = obj2ast_stmt(tmp2, &val, arena);
5723 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005724 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005725 if (len != PyList_GET_SIZE(tmp)) {
5726 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5727 goto failed;
5728 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005729 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005730 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005731 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005732 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005733 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5734 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005735 return 1;
5736 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005737 if (tmp == NULL) {
5738 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5739 return 1;
5740 }
5741 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005742 int res;
5743 Py_ssize_t len;
5744 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005745 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005746 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 +02005747 goto failed;
5748 }
5749 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005750 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005751 if (decorator_list == NULL) goto failed;
5752 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005753 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005754 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5755 Py_INCREF(tmp2);
5756 res = obj2ast_expr(tmp2, &val, arena);
5757 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005758 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005759 if (len != PyList_GET_SIZE(tmp)) {
5760 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5761 goto failed;
5762 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005763 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005764 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005765 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005766 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005767 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005768 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005769 if (*out == NULL) goto failed;
5770 return 0;
5771 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005772 tp = astmodulestate_global->Return_type;
5773 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005774 if (isinstance == -1) {
5775 return 1;
5776 }
5777 if (isinstance) {
5778 expr_ty value;
5779
Dino Viehlandac46eb42019-09-11 10:16:34 -07005780 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005781 return 1;
5782 }
5783 if (tmp == NULL || tmp == Py_None) {
5784 Py_CLEAR(tmp);
5785 value = NULL;
5786 }
5787 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005788 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005789 res = obj2ast_expr(tmp, &value, arena);
5790 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005791 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005792 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005793 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5794 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005795 if (*out == NULL) goto failed;
5796 return 0;
5797 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005798 tp = astmodulestate_global->Delete_type;
5799 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005800 if (isinstance == -1) {
5801 return 1;
5802 }
5803 if (isinstance) {
5804 asdl_seq* targets;
5805
Dino Viehlandac46eb42019-09-11 10:16:34 -07005806 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5807 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005808 return 1;
5809 }
5810 if (tmp == NULL) {
5811 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5812 return 1;
5813 }
5814 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005815 int res;
5816 Py_ssize_t len;
5817 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005818 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005819 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 +02005820 goto failed;
5821 }
5822 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005823 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005824 if (targets == NULL) goto failed;
5825 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005826 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005827 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5828 Py_INCREF(tmp2);
5829 res = obj2ast_expr(tmp2, &val, arena);
5830 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005831 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005832 if (len != PyList_GET_SIZE(tmp)) {
5833 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5834 goto failed;
5835 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005836 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005837 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005838 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005839 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005840 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5841 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005842 if (*out == NULL) goto failed;
5843 return 0;
5844 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005845 tp = astmodulestate_global->Assign_type;
5846 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005847 if (isinstance == -1) {
5848 return 1;
5849 }
5850 if (isinstance) {
5851 asdl_seq* targets;
5852 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005853 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005854
Dino Viehlandac46eb42019-09-11 10:16:34 -07005855 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5856 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005857 return 1;
5858 }
5859 if (tmp == NULL) {
5860 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5861 return 1;
5862 }
5863 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005864 int res;
5865 Py_ssize_t len;
5866 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005867 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005868 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 +02005869 goto failed;
5870 }
5871 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005872 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005873 if (targets == NULL) goto failed;
5874 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005875 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005876 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5877 Py_INCREF(tmp2);
5878 res = obj2ast_expr(tmp2, &val, arena);
5879 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005880 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005881 if (len != PyList_GET_SIZE(tmp)) {
5882 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5883 goto failed;
5884 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005885 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005886 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005887 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005888 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005889 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005890 return 1;
5891 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005892 if (tmp == NULL) {
5893 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5894 return 1;
5895 }
5896 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005897 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005898 res = obj2ast_expr(tmp, &value, arena);
5899 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005900 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005901 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005902 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5903 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005904 return 1;
5905 }
5906 if (tmp == NULL || tmp == Py_None) {
5907 Py_CLEAR(tmp);
5908 type_comment = NULL;
5909 }
5910 else {
5911 int res;
5912 res = obj2ast_string(tmp, &type_comment, arena);
5913 if (res != 0) goto failed;
5914 Py_CLEAR(tmp);
5915 }
5916 *out = Assign(targets, value, type_comment, lineno, col_offset,
5917 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005918 if (*out == NULL) goto failed;
5919 return 0;
5920 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005921 tp = astmodulestate_global->AugAssign_type;
5922 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005923 if (isinstance == -1) {
5924 return 1;
5925 }
5926 if (isinstance) {
5927 expr_ty target;
5928 operator_ty op;
5929 expr_ty value;
5930
Dino Viehlandac46eb42019-09-11 10:16:34 -07005931 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5932 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005933 return 1;
5934 }
5935 if (tmp == NULL) {
5936 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5937 return 1;
5938 }
5939 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005940 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005941 res = obj2ast_expr(tmp, &target, arena);
5942 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005943 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005945 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005946 return 1;
5947 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005948 if (tmp == NULL) {
5949 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5950 return 1;
5951 }
5952 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005953 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005954 res = obj2ast_operator(tmp, &op, arena);
5955 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005956 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005957 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005958 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005959 return 1;
5960 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005961 if (tmp == NULL) {
5962 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5963 return 1;
5964 }
5965 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005966 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005967 res = obj2ast_expr(tmp, &value, arena);
5968 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005969 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005970 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005971 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5972 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005973 if (*out == NULL) goto failed;
5974 return 0;
5975 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005976 tp = astmodulestate_global->AnnAssign_type;
5977 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005978 if (isinstance == -1) {
5979 return 1;
5980 }
5981 if (isinstance) {
5982 expr_ty target;
5983 expr_ty annotation;
5984 expr_ty value;
5985 int simple;
5986
Dino Viehlandac46eb42019-09-11 10:16:34 -07005987 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5988 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005989 return 1;
5990 }
5991 if (tmp == NULL) {
5992 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5993 return 1;
5994 }
5995 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005996 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005997 res = obj2ast_expr(tmp, &target, arena);
5998 if (res != 0) goto failed;
5999 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006000 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006001 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6002 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006003 return 1;
6004 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006005 if (tmp == NULL) {
6006 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6007 return 1;
6008 }
6009 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006010 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006011 res = obj2ast_expr(tmp, &annotation, arena);
6012 if (res != 0) goto failed;
6013 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006014 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006015 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006016 return 1;
6017 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006018 if (tmp == NULL || tmp == Py_None) {
6019 Py_CLEAR(tmp);
6020 value = NULL;
6021 }
6022 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006023 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006024 res = obj2ast_expr(tmp, &value, arena);
6025 if (res != 0) goto failed;
6026 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006028 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6029 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006030 return 1;
6031 }
6032 if (tmp == NULL) {
6033 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6034 return 1;
6035 }
6036 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006037 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006038 res = obj2ast_int(tmp, &simple, arena);
6039 if (res != 0) goto failed;
6040 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006041 }
6042 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006043 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006044 if (*out == NULL) goto failed;
6045 return 0;
6046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006047 tp = astmodulestate_global->For_type;
6048 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006049 if (isinstance == -1) {
6050 return 1;
6051 }
6052 if (isinstance) {
6053 expr_ty target;
6054 expr_ty iter;
6055 asdl_seq* body;
6056 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006057 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006058
Dino Viehlandac46eb42019-09-11 10:16:34 -07006059 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6060 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006061 return 1;
6062 }
6063 if (tmp == NULL) {
6064 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6065 return 1;
6066 }
6067 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006068 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006069 res = obj2ast_expr(tmp, &target, arena);
6070 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006071 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006073 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006074 return 1;
6075 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006076 if (tmp == NULL) {
6077 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6078 return 1;
6079 }
6080 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006081 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006082 res = obj2ast_expr(tmp, &iter, arena);
6083 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006084 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006086 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006087 return 1;
6088 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006089 if (tmp == NULL) {
6090 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6091 return 1;
6092 }
6093 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006094 int res;
6095 Py_ssize_t len;
6096 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006097 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006098 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 +02006099 goto failed;
6100 }
6101 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006102 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006103 if (body == NULL) goto failed;
6104 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006105 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006106 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6107 Py_INCREF(tmp2);
6108 res = obj2ast_stmt(tmp2, &val, arena);
6109 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006110 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006111 if (len != PyList_GET_SIZE(tmp)) {
6112 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6113 goto failed;
6114 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006115 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006116 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006117 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006118 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006119 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6120 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006121 return 1;
6122 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006123 if (tmp == NULL) {
6124 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6125 return 1;
6126 }
6127 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006128 int res;
6129 Py_ssize_t len;
6130 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006131 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006132 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 +02006133 goto failed;
6134 }
6135 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006136 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006137 if (orelse == NULL) goto failed;
6138 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006139 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006140 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6141 Py_INCREF(tmp2);
6142 res = obj2ast_stmt(tmp2, &val, arena);
6143 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006144 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006145 if (len != PyList_GET_SIZE(tmp)) {
6146 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6147 goto failed;
6148 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006149 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006150 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006151 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006152 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006153 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6154 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006155 return 1;
6156 }
6157 if (tmp == NULL || tmp == Py_None) {
6158 Py_CLEAR(tmp);
6159 type_comment = NULL;
6160 }
6161 else {
6162 int res;
6163 res = obj2ast_string(tmp, &type_comment, arena);
6164 if (res != 0) goto failed;
6165 Py_CLEAR(tmp);
6166 }
6167 *out = For(target, iter, body, orelse, type_comment, lineno,
6168 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006169 if (*out == NULL) goto failed;
6170 return 0;
6171 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006172 tp = astmodulestate_global->AsyncFor_type;
6173 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006174 if (isinstance == -1) {
6175 return 1;
6176 }
6177 if (isinstance) {
6178 expr_ty target;
6179 expr_ty iter;
6180 asdl_seq* body;
6181 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006182 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006183
Dino Viehlandac46eb42019-09-11 10:16:34 -07006184 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6185 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006186 return 1;
6187 }
6188 if (tmp == NULL) {
6189 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6190 return 1;
6191 }
6192 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006193 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006194 res = obj2ast_expr(tmp, &target, arena);
6195 if (res != 0) goto failed;
6196 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006197 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006198 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006199 return 1;
6200 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006201 if (tmp == NULL) {
6202 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6203 return 1;
6204 }
6205 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006206 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006207 res = obj2ast_expr(tmp, &iter, arena);
6208 if (res != 0) goto failed;
6209 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006210 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006211 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006212 return 1;
6213 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006214 if (tmp == NULL) {
6215 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6216 return 1;
6217 }
6218 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006219 int res;
6220 Py_ssize_t len;
6221 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006222 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006223 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 -04006224 goto failed;
6225 }
6226 len = PyList_GET_SIZE(tmp);
6227 body = _Py_asdl_seq_new(len, arena);
6228 if (body == NULL) goto failed;
6229 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006230 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006231 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6232 Py_INCREF(tmp2);
6233 res = obj2ast_stmt(tmp2, &val, arena);
6234 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006235 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006236 if (len != PyList_GET_SIZE(tmp)) {
6237 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6238 goto failed;
6239 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006240 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006241 }
6242 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006243 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006244 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6245 {
Yury Selivanov75445082015-05-11 22:57:16 -04006246 return 1;
6247 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006248 if (tmp == NULL) {
6249 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6250 return 1;
6251 }
6252 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006253 int res;
6254 Py_ssize_t len;
6255 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006256 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006257 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 -04006258 goto failed;
6259 }
6260 len = PyList_GET_SIZE(tmp);
6261 orelse = _Py_asdl_seq_new(len, arena);
6262 if (orelse == NULL) goto failed;
6263 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006264 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006265 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6266 Py_INCREF(tmp2);
6267 res = obj2ast_stmt(tmp2, &val, arena);
6268 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006269 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006270 if (len != PyList_GET_SIZE(tmp)) {
6271 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6272 goto failed;
6273 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006274 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006275 }
6276 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006277 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006278 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6279 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006280 return 1;
6281 }
6282 if (tmp == NULL || tmp == Py_None) {
6283 Py_CLEAR(tmp);
6284 type_comment = NULL;
6285 }
6286 else {
6287 int res;
6288 res = obj2ast_string(tmp, &type_comment, arena);
6289 if (res != 0) goto failed;
6290 Py_CLEAR(tmp);
6291 }
6292 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6293 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006294 if (*out == NULL) goto failed;
6295 return 0;
6296 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006297 tp = astmodulestate_global->While_type;
6298 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006299 if (isinstance == -1) {
6300 return 1;
6301 }
6302 if (isinstance) {
6303 expr_ty test;
6304 asdl_seq* body;
6305 asdl_seq* orelse;
6306
Dino Viehlandac46eb42019-09-11 10:16:34 -07006307 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006308 return 1;
6309 }
6310 if (tmp == NULL) {
6311 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6312 return 1;
6313 }
6314 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006315 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006316 res = obj2ast_expr(tmp, &test, arena);
6317 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006318 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006319 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006320 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006321 return 1;
6322 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006323 if (tmp == NULL) {
6324 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6325 return 1;
6326 }
6327 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006328 int res;
6329 Py_ssize_t len;
6330 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006331 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006332 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 +02006333 goto failed;
6334 }
6335 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006336 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006337 if (body == NULL) goto failed;
6338 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006339 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006340 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6341 Py_INCREF(tmp2);
6342 res = obj2ast_stmt(tmp2, &val, arena);
6343 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006344 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006345 if (len != PyList_GET_SIZE(tmp)) {
6346 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6347 goto failed;
6348 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006349 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006350 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006351 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006352 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006353 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6354 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006355 return 1;
6356 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006357 if (tmp == NULL) {
6358 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6359 return 1;
6360 }
6361 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006362 int res;
6363 Py_ssize_t len;
6364 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006365 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006366 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 +02006367 goto failed;
6368 }
6369 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006370 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006371 if (orelse == NULL) goto failed;
6372 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006373 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006374 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6375 Py_INCREF(tmp2);
6376 res = obj2ast_stmt(tmp2, &val, arena);
6377 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006378 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006379 if (len != PyList_GET_SIZE(tmp)) {
6380 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6381 goto failed;
6382 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006383 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006384 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006385 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006386 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006387 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6388 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006389 if (*out == NULL) goto failed;
6390 return 0;
6391 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006392 tp = astmodulestate_global->If_type;
6393 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006394 if (isinstance == -1) {
6395 return 1;
6396 }
6397 if (isinstance) {
6398 expr_ty test;
6399 asdl_seq* body;
6400 asdl_seq* orelse;
6401
Dino Viehlandac46eb42019-09-11 10:16:34 -07006402 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006403 return 1;
6404 }
6405 if (tmp == NULL) {
6406 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6407 return 1;
6408 }
6409 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006410 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006411 res = obj2ast_expr(tmp, &test, arena);
6412 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006413 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006414 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006415 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006416 return 1;
6417 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006418 if (tmp == NULL) {
6419 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6420 return 1;
6421 }
6422 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006423 int res;
6424 Py_ssize_t len;
6425 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006426 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006427 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 +02006428 goto failed;
6429 }
6430 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006431 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006432 if (body == NULL) goto failed;
6433 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006434 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006435 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6436 Py_INCREF(tmp2);
6437 res = obj2ast_stmt(tmp2, &val, arena);
6438 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006439 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006440 if (len != PyList_GET_SIZE(tmp)) {
6441 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6442 goto failed;
6443 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006444 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006445 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006446 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006447 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006448 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6449 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006450 return 1;
6451 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006452 if (tmp == NULL) {
6453 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6454 return 1;
6455 }
6456 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006457 int res;
6458 Py_ssize_t len;
6459 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006460 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006461 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 +02006462 goto failed;
6463 }
6464 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006465 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006466 if (orelse == NULL) goto failed;
6467 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006468 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006469 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6470 Py_INCREF(tmp2);
6471 res = obj2ast_stmt(tmp2, &val, arena);
6472 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006473 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006474 if (len != PyList_GET_SIZE(tmp)) {
6475 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6476 goto failed;
6477 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006478 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006479 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006480 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006481 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006482 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6483 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006484 if (*out == NULL) goto failed;
6485 return 0;
6486 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006487 tp = astmodulestate_global->With_type;
6488 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006489 if (isinstance == -1) {
6490 return 1;
6491 }
6492 if (isinstance) {
6493 asdl_seq* items;
6494 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006495 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006496
Dino Viehlandac46eb42019-09-11 10:16:34 -07006497 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006498 return 1;
6499 }
6500 if (tmp == NULL) {
6501 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6502 return 1;
6503 }
6504 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006505 int res;
6506 Py_ssize_t len;
6507 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006508 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006509 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 +02006510 goto failed;
6511 }
6512 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006513 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006514 if (items == NULL) goto failed;
6515 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006516 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006517 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6518 Py_INCREF(tmp2);
6519 res = obj2ast_withitem(tmp2, &val, arena);
6520 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006521 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006522 if (len != PyList_GET_SIZE(tmp)) {
6523 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6524 goto failed;
6525 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006526 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006527 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006528 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006529 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006530 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006531 return 1;
6532 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006533 if (tmp == NULL) {
6534 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6535 return 1;
6536 }
6537 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006538 int res;
6539 Py_ssize_t len;
6540 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006541 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006542 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 +02006543 goto failed;
6544 }
6545 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006546 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006547 if (body == NULL) goto failed;
6548 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006549 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006550 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6551 Py_INCREF(tmp2);
6552 res = obj2ast_stmt(tmp2, &val, arena);
6553 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006554 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006555 if (len != PyList_GET_SIZE(tmp)) {
6556 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6557 goto failed;
6558 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006559 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006560 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006561 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006562 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006563 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6564 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006565 return 1;
6566 }
6567 if (tmp == NULL || tmp == Py_None) {
6568 Py_CLEAR(tmp);
6569 type_comment = NULL;
6570 }
6571 else {
6572 int res;
6573 res = obj2ast_string(tmp, &type_comment, arena);
6574 if (res != 0) goto failed;
6575 Py_CLEAR(tmp);
6576 }
6577 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006578 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006579 if (*out == NULL) goto failed;
6580 return 0;
6581 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006582 tp = astmodulestate_global->AsyncWith_type;
6583 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006584 if (isinstance == -1) {
6585 return 1;
6586 }
6587 if (isinstance) {
6588 asdl_seq* items;
6589 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006590 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006591
Dino Viehlandac46eb42019-09-11 10:16:34 -07006592 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006593 return 1;
6594 }
6595 if (tmp == NULL) {
6596 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6597 return 1;
6598 }
6599 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006600 int res;
6601 Py_ssize_t len;
6602 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006603 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006604 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 -04006605 goto failed;
6606 }
6607 len = PyList_GET_SIZE(tmp);
6608 items = _Py_asdl_seq_new(len, arena);
6609 if (items == NULL) goto failed;
6610 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006611 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006612 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6613 Py_INCREF(tmp2);
6614 res = obj2ast_withitem(tmp2, &val, arena);
6615 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006616 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006617 if (len != PyList_GET_SIZE(tmp)) {
6618 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6619 goto failed;
6620 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006621 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006622 }
6623 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006624 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006625 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006626 return 1;
6627 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006628 if (tmp == NULL) {
6629 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6630 return 1;
6631 }
6632 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006633 int res;
6634 Py_ssize_t len;
6635 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006636 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006637 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 -04006638 goto failed;
6639 }
6640 len = PyList_GET_SIZE(tmp);
6641 body = _Py_asdl_seq_new(len, arena);
6642 if (body == NULL) goto failed;
6643 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006644 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006645 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6646 Py_INCREF(tmp2);
6647 res = obj2ast_stmt(tmp2, &val, arena);
6648 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006649 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006650 if (len != PyList_GET_SIZE(tmp)) {
6651 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6652 goto failed;
6653 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006654 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006655 }
6656 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006657 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006658 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6659 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006660 return 1;
6661 }
6662 if (tmp == NULL || tmp == Py_None) {
6663 Py_CLEAR(tmp);
6664 type_comment = NULL;
6665 }
6666 else {
6667 int res;
6668 res = obj2ast_string(tmp, &type_comment, arena);
6669 if (res != 0) goto failed;
6670 Py_CLEAR(tmp);
6671 }
6672 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6673 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006674 if (*out == NULL) goto failed;
6675 return 0;
6676 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006677 tp = astmodulestate_global->Raise_type;
6678 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006679 if (isinstance == -1) {
6680 return 1;
6681 }
6682 if (isinstance) {
6683 expr_ty exc;
6684 expr_ty cause;
6685
Dino Viehlandac46eb42019-09-11 10:16:34 -07006686 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006687 return 1;
6688 }
6689 if (tmp == NULL || tmp == Py_None) {
6690 Py_CLEAR(tmp);
6691 exc = NULL;
6692 }
6693 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006694 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006695 res = obj2ast_expr(tmp, &exc, arena);
6696 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006697 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006698 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006699 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006700 return 1;
6701 }
6702 if (tmp == NULL || tmp == Py_None) {
6703 Py_CLEAR(tmp);
6704 cause = NULL;
6705 }
6706 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006707 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006708 res = obj2ast_expr(tmp, &cause, arena);
6709 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006710 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006711 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006712 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6713 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006714 if (*out == NULL) goto failed;
6715 return 0;
6716 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006717 tp = astmodulestate_global->Try_type;
6718 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006719 if (isinstance == -1) {
6720 return 1;
6721 }
6722 if (isinstance) {
6723 asdl_seq* body;
6724 asdl_seq* handlers;
6725 asdl_seq* orelse;
6726 asdl_seq* finalbody;
6727
Dino Viehlandac46eb42019-09-11 10:16:34 -07006728 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006729 return 1;
6730 }
6731 if (tmp == NULL) {
6732 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6733 return 1;
6734 }
6735 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006736 int res;
6737 Py_ssize_t len;
6738 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006739 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006740 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 +02006741 goto failed;
6742 }
6743 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006744 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006745 if (body == NULL) goto failed;
6746 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006747 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006748 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6749 Py_INCREF(tmp2);
6750 res = obj2ast_stmt(tmp2, &val, arena);
6751 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006752 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006753 if (len != PyList_GET_SIZE(tmp)) {
6754 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6755 goto failed;
6756 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006757 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006758 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006759 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006760 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006761 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6762 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006763 return 1;
6764 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006765 if (tmp == NULL) {
6766 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6767 return 1;
6768 }
6769 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006770 int res;
6771 Py_ssize_t len;
6772 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006773 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006774 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 +02006775 goto failed;
6776 }
6777 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006778 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006779 if (handlers == NULL) goto failed;
6780 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006781 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006782 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6783 Py_INCREF(tmp2);
6784 res = obj2ast_excepthandler(tmp2, &val, arena);
6785 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006786 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006787 if (len != PyList_GET_SIZE(tmp)) {
6788 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6789 goto failed;
6790 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006791 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006792 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006793 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006794 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006795 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6796 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006797 return 1;
6798 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006799 if (tmp == NULL) {
6800 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6801 return 1;
6802 }
6803 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006804 int res;
6805 Py_ssize_t len;
6806 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006807 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006808 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 +02006809 goto failed;
6810 }
6811 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006812 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006813 if (orelse == NULL) goto failed;
6814 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006815 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006816 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6817 Py_INCREF(tmp2);
6818 res = obj2ast_stmt(tmp2, &val, arena);
6819 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006820 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006821 if (len != PyList_GET_SIZE(tmp)) {
6822 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6823 goto failed;
6824 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006825 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006826 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006827 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006828 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006829 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6830 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006831 return 1;
6832 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006833 if (tmp == NULL) {
6834 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6835 return 1;
6836 }
6837 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006838 int res;
6839 Py_ssize_t len;
6840 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006841 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006842 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 +02006843 goto failed;
6844 }
6845 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006846 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006847 if (finalbody == NULL) goto failed;
6848 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006849 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006850 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6851 Py_INCREF(tmp2);
6852 res = obj2ast_stmt(tmp2, &val, arena);
6853 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006854 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006855 if (len != PyList_GET_SIZE(tmp)) {
6856 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6857 goto failed;
6858 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006859 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006860 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006861 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006862 }
6863 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006864 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006865 if (*out == NULL) goto failed;
6866 return 0;
6867 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006868 tp = astmodulestate_global->Assert_type;
6869 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006870 if (isinstance == -1) {
6871 return 1;
6872 }
6873 if (isinstance) {
6874 expr_ty test;
6875 expr_ty msg;
6876
Dino Viehlandac46eb42019-09-11 10:16:34 -07006877 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006878 return 1;
6879 }
6880 if (tmp == NULL) {
6881 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6882 return 1;
6883 }
6884 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006885 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006886 res = obj2ast_expr(tmp, &test, arena);
6887 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006888 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006890 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006891 return 1;
6892 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006893 if (tmp == NULL || tmp == Py_None) {
6894 Py_CLEAR(tmp);
6895 msg = NULL;
6896 }
6897 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006898 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006899 res = obj2ast_expr(tmp, &msg, arena);
6900 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006901 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006902 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006903 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6904 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006905 if (*out == NULL) goto failed;
6906 return 0;
6907 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006908 tp = astmodulestate_global->Import_type;
6909 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006910 if (isinstance == -1) {
6911 return 1;
6912 }
6913 if (isinstance) {
6914 asdl_seq* names;
6915
Dino Viehlandac46eb42019-09-11 10:16:34 -07006916 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006917 return 1;
6918 }
6919 if (tmp == NULL) {
6920 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6921 return 1;
6922 }
6923 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006924 int res;
6925 Py_ssize_t len;
6926 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006927 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006928 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 +02006929 goto failed;
6930 }
6931 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006932 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006933 if (names == NULL) goto failed;
6934 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006935 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006936 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6937 Py_INCREF(tmp2);
6938 res = obj2ast_alias(tmp2, &val, arena);
6939 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006940 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006941 if (len != PyList_GET_SIZE(tmp)) {
6942 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6943 goto failed;
6944 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006945 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006946 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006947 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006948 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006949 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6950 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006951 if (*out == NULL) goto failed;
6952 return 0;
6953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006954 tp = astmodulestate_global->ImportFrom_type;
6955 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006956 if (isinstance == -1) {
6957 return 1;
6958 }
6959 if (isinstance) {
6960 identifier module;
6961 asdl_seq* names;
6962 int level;
6963
Dino Viehlandac46eb42019-09-11 10:16:34 -07006964 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6965 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006966 return 1;
6967 }
6968 if (tmp == NULL || tmp == Py_None) {
6969 Py_CLEAR(tmp);
6970 module = NULL;
6971 }
6972 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006973 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 res = obj2ast_identifier(tmp, &module, arena);
6975 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006976 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006978 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006979 return 1;
6980 }
6981 if (tmp == NULL) {
6982 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6983 return 1;
6984 }
6985 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006986 int res;
6987 Py_ssize_t len;
6988 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006989 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006990 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 +02006991 goto failed;
6992 }
6993 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006994 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006995 if (names == NULL) goto failed;
6996 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006997 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006998 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6999 Py_INCREF(tmp2);
7000 res = obj2ast_alias(tmp2, &val, arena);
7001 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007002 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007003 if (len != PyList_GET_SIZE(tmp)) {
7004 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7005 goto failed;
7006 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007007 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007008 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007009 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007011 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007012 return 1;
7013 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007014 if (tmp == NULL || tmp == Py_None) {
7015 Py_CLEAR(tmp);
7016 level = 0;
7017 }
7018 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007019 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007020 res = obj2ast_int(tmp, &level, arena);
7021 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007022 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007023 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007024 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7025 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007026 if (*out == NULL) goto failed;
7027 return 0;
7028 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007029 tp = astmodulestate_global->Global_type;
7030 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007031 if (isinstance == -1) {
7032 return 1;
7033 }
7034 if (isinstance) {
7035 asdl_seq* names;
7036
Dino Viehlandac46eb42019-09-11 10:16:34 -07007037 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007038 return 1;
7039 }
7040 if (tmp == NULL) {
7041 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7042 return 1;
7043 }
7044 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007045 int res;
7046 Py_ssize_t len;
7047 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007048 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007049 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 +02007050 goto failed;
7051 }
7052 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007053 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007054 if (names == NULL) goto failed;
7055 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007056 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007057 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7058 Py_INCREF(tmp2);
7059 res = obj2ast_identifier(tmp2, &val, arena);
7060 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007061 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007062 if (len != PyList_GET_SIZE(tmp)) {
7063 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7064 goto failed;
7065 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007066 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007067 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007068 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007069 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007070 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7071 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007072 if (*out == NULL) goto failed;
7073 return 0;
7074 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007075 tp = astmodulestate_global->Nonlocal_type;
7076 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007077 if (isinstance == -1) {
7078 return 1;
7079 }
7080 if (isinstance) {
7081 asdl_seq* names;
7082
Dino Viehlandac46eb42019-09-11 10:16:34 -07007083 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007084 return 1;
7085 }
7086 if (tmp == NULL) {
7087 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7088 return 1;
7089 }
7090 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007091 int res;
7092 Py_ssize_t len;
7093 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007094 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007095 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 +02007096 goto failed;
7097 }
7098 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007099 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007100 if (names == NULL) goto failed;
7101 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007102 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007103 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7104 Py_INCREF(tmp2);
7105 res = obj2ast_identifier(tmp2, &val, arena);
7106 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007107 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007108 if (len != PyList_GET_SIZE(tmp)) {
7109 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7110 goto failed;
7111 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007112 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007113 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007114 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007115 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007116 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7117 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007118 if (*out == NULL) goto failed;
7119 return 0;
7120 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007121 tp = astmodulestate_global->Expr_type;
7122 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007123 if (isinstance == -1) {
7124 return 1;
7125 }
7126 if (isinstance) {
7127 expr_ty value;
7128
Dino Viehlandac46eb42019-09-11 10:16:34 -07007129 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007130 return 1;
7131 }
7132 if (tmp == NULL) {
7133 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7134 return 1;
7135 }
7136 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007137 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007138 res = obj2ast_expr(tmp, &value, arena);
7139 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007140 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007141 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007142 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7143 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007144 if (*out == NULL) goto failed;
7145 return 0;
7146 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007147 tp = astmodulestate_global->Pass_type;
7148 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007149 if (isinstance == -1) {
7150 return 1;
7151 }
7152 if (isinstance) {
7153
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007154 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007155 if (*out == NULL) goto failed;
7156 return 0;
7157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007158 tp = astmodulestate_global->Break_type;
7159 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007160 if (isinstance == -1) {
7161 return 1;
7162 }
7163 if (isinstance) {
7164
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007165 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007166 if (*out == NULL) goto failed;
7167 return 0;
7168 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007169 tp = astmodulestate_global->Continue_type;
7170 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007171 if (isinstance == -1) {
7172 return 1;
7173 }
7174 if (isinstance) {
7175
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007176 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007177 if (*out == NULL) goto failed;
7178 return 0;
7179 }
7180
7181 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7182 failed:
7183 Py_XDECREF(tmp);
7184 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007185}
7186
7187int
7188obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7189{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007190 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007191
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007192 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007193 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007194 int lineno;
7195 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007196 int end_lineno;
7197 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007198
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007199 if (obj == Py_None) {
7200 *out = NULL;
7201 return 0;
7202 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007203 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007204 return 1;
7205 }
7206 if (tmp == NULL) {
7207 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7208 return 1;
7209 }
7210 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007211 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007212 res = obj2ast_int(tmp, &lineno, arena);
7213 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007214 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007215 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007216 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7217 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007218 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007219 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007220 if (tmp == NULL) {
7221 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7222 return 1;
7223 }
7224 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007225 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007226 res = obj2ast_int(tmp, &col_offset, arena);
7227 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007228 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007230 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7231 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007232 return 1;
7233 }
7234 if (tmp == NULL || tmp == Py_None) {
7235 Py_CLEAR(tmp);
7236 end_lineno = 0;
7237 }
7238 else {
7239 int res;
7240 res = obj2ast_int(tmp, &end_lineno, arena);
7241 if (res != 0) goto failed;
7242 Py_CLEAR(tmp);
7243 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007244 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7245 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007246 return 1;
7247 }
7248 if (tmp == NULL || tmp == Py_None) {
7249 Py_CLEAR(tmp);
7250 end_col_offset = 0;
7251 }
7252 else {
7253 int res;
7254 res = obj2ast_int(tmp, &end_col_offset, arena);
7255 if (res != 0) goto failed;
7256 Py_CLEAR(tmp);
7257 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007258 tp = astmodulestate_global->BoolOp_type;
7259 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007260 if (isinstance == -1) {
7261 return 1;
7262 }
7263 if (isinstance) {
7264 boolop_ty op;
7265 asdl_seq* values;
7266
Dino Viehlandac46eb42019-09-11 10:16:34 -07007267 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007268 return 1;
7269 }
7270 if (tmp == NULL) {
7271 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7272 return 1;
7273 }
7274 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007275 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007276 res = obj2ast_boolop(tmp, &op, arena);
7277 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007278 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007279 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007280 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7281 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007282 return 1;
7283 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007284 if (tmp == NULL) {
7285 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7286 return 1;
7287 }
7288 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007289 int res;
7290 Py_ssize_t len;
7291 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007292 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007293 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 +02007294 goto failed;
7295 }
7296 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007297 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007298 if (values == NULL) goto failed;
7299 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007300 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007301 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7302 Py_INCREF(tmp2);
7303 res = obj2ast_expr(tmp2, &val, arena);
7304 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007305 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007306 if (len != PyList_GET_SIZE(tmp)) {
7307 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7308 goto failed;
7309 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007310 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007311 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007312 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007313 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007314 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7315 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007316 if (*out == NULL) goto failed;
7317 return 0;
7318 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007319 tp = astmodulestate_global->NamedExpr_type;
7320 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007321 if (isinstance == -1) {
7322 return 1;
7323 }
7324 if (isinstance) {
7325 expr_ty target;
7326 expr_ty value;
7327
Dino Viehlandac46eb42019-09-11 10:16:34 -07007328 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7329 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007330 return 1;
7331 }
7332 if (tmp == NULL) {
7333 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7334 return 1;
7335 }
7336 else {
7337 int res;
7338 res = obj2ast_expr(tmp, &target, arena);
7339 if (res != 0) goto failed;
7340 Py_CLEAR(tmp);
7341 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007342 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007343 return 1;
7344 }
7345 if (tmp == NULL) {
7346 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7347 return 1;
7348 }
7349 else {
7350 int res;
7351 res = obj2ast_expr(tmp, &value, arena);
7352 if (res != 0) goto failed;
7353 Py_CLEAR(tmp);
7354 }
7355 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7356 end_col_offset, arena);
7357 if (*out == NULL) goto failed;
7358 return 0;
7359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007360 tp = astmodulestate_global->BinOp_type;
7361 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007362 if (isinstance == -1) {
7363 return 1;
7364 }
7365 if (isinstance) {
7366 expr_ty left;
7367 operator_ty op;
7368 expr_ty right;
7369
Dino Viehlandac46eb42019-09-11 10:16:34 -07007370 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007371 return 1;
7372 }
7373 if (tmp == NULL) {
7374 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7375 return 1;
7376 }
7377 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007378 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007379 res = obj2ast_expr(tmp, &left, arena);
7380 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007381 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007383 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007384 return 1;
7385 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007386 if (tmp == NULL) {
7387 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7388 return 1;
7389 }
7390 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007391 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007392 res = obj2ast_operator(tmp, &op, arena);
7393 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007394 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007395 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007396 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007397 return 1;
7398 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007399 if (tmp == NULL) {
7400 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7401 return 1;
7402 }
7403 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007404 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007405 res = obj2ast_expr(tmp, &right, arena);
7406 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007407 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007408 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007409 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7410 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007411 if (*out == NULL) goto failed;
7412 return 0;
7413 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007414 tp = astmodulestate_global->UnaryOp_type;
7415 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007416 if (isinstance == -1) {
7417 return 1;
7418 }
7419 if (isinstance) {
7420 unaryop_ty op;
7421 expr_ty operand;
7422
Dino Viehlandac46eb42019-09-11 10:16:34 -07007423 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007424 return 1;
7425 }
7426 if (tmp == NULL) {
7427 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7428 return 1;
7429 }
7430 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007431 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007432 res = obj2ast_unaryop(tmp, &op, arena);
7433 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007434 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007435 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007436 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7437 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007438 return 1;
7439 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007440 if (tmp == NULL) {
7441 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7442 return 1;
7443 }
7444 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007445 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007446 res = obj2ast_expr(tmp, &operand, arena);
7447 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007448 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007449 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007450 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7451 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007452 if (*out == NULL) goto failed;
7453 return 0;
7454 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007455 tp = astmodulestate_global->Lambda_type;
7456 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007457 if (isinstance == -1) {
7458 return 1;
7459 }
7460 if (isinstance) {
7461 arguments_ty args;
7462 expr_ty body;
7463
Dino Viehlandac46eb42019-09-11 10:16:34 -07007464 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007465 return 1;
7466 }
7467 if (tmp == NULL) {
7468 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7469 return 1;
7470 }
7471 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007472 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007473 res = obj2ast_arguments(tmp, &args, arena);
7474 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007475 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007476 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007477 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007478 return 1;
7479 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007480 if (tmp == NULL) {
7481 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7482 return 1;
7483 }
7484 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007485 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007486 res = obj2ast_expr(tmp, &body, arena);
7487 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007488 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007489 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007490 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7491 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007492 if (*out == NULL) goto failed;
7493 return 0;
7494 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007495 tp = astmodulestate_global->IfExp_type;
7496 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007497 if (isinstance == -1) {
7498 return 1;
7499 }
7500 if (isinstance) {
7501 expr_ty test;
7502 expr_ty body;
7503 expr_ty orelse;
7504
Dino Viehlandac46eb42019-09-11 10:16:34 -07007505 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007506 return 1;
7507 }
7508 if (tmp == NULL) {
7509 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7510 return 1;
7511 }
7512 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007513 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007514 res = obj2ast_expr(tmp, &test, arena);
7515 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007516 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007517 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007518 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007519 return 1;
7520 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007521 if (tmp == NULL) {
7522 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7523 return 1;
7524 }
7525 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007526 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007527 res = obj2ast_expr(tmp, &body, arena);
7528 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007529 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007530 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007531 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7532 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007533 return 1;
7534 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007535 if (tmp == NULL) {
7536 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7537 return 1;
7538 }
7539 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007540 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007541 res = obj2ast_expr(tmp, &orelse, arena);
7542 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007543 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007544 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007545 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7546 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007547 if (*out == NULL) goto failed;
7548 return 0;
7549 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007550 tp = astmodulestate_global->Dict_type;
7551 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007552 if (isinstance == -1) {
7553 return 1;
7554 }
7555 if (isinstance) {
7556 asdl_seq* keys;
7557 asdl_seq* values;
7558
Dino Viehlandac46eb42019-09-11 10:16:34 -07007559 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007560 return 1;
7561 }
7562 if (tmp == NULL) {
7563 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7564 return 1;
7565 }
7566 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007567 int res;
7568 Py_ssize_t len;
7569 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007570 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007571 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 +02007572 goto failed;
7573 }
7574 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007575 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007576 if (keys == NULL) goto failed;
7577 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007578 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007579 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7580 Py_INCREF(tmp2);
7581 res = obj2ast_expr(tmp2, &val, arena);
7582 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007583 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007584 if (len != PyList_GET_SIZE(tmp)) {
7585 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7586 goto failed;
7587 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007588 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007589 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007590 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007591 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007592 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7593 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007594 return 1;
7595 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007596 if (tmp == NULL) {
7597 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7598 return 1;
7599 }
7600 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007601 int res;
7602 Py_ssize_t len;
7603 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007604 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007605 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 +02007606 goto failed;
7607 }
7608 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007609 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007610 if (values == NULL) goto failed;
7611 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007612 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007613 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7614 Py_INCREF(tmp2);
7615 res = obj2ast_expr(tmp2, &val, arena);
7616 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007617 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007618 if (len != PyList_GET_SIZE(tmp)) {
7619 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7620 goto failed;
7621 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007622 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007623 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007624 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007625 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007626 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7627 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007628 if (*out == NULL) goto failed;
7629 return 0;
7630 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007631 tp = astmodulestate_global->Set_type;
7632 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007633 if (isinstance == -1) {
7634 return 1;
7635 }
7636 if (isinstance) {
7637 asdl_seq* elts;
7638
Dino Viehlandac46eb42019-09-11 10:16:34 -07007639 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007640 return 1;
7641 }
7642 if (tmp == NULL) {
7643 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7644 return 1;
7645 }
7646 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007647 int res;
7648 Py_ssize_t len;
7649 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007650 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007651 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 +02007652 goto failed;
7653 }
7654 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007655 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007656 if (elts == NULL) goto failed;
7657 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007658 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007659 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7660 Py_INCREF(tmp2);
7661 res = obj2ast_expr(tmp2, &val, arena);
7662 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007663 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007664 if (len != PyList_GET_SIZE(tmp)) {
7665 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7666 goto failed;
7667 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007668 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007669 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007670 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007671 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007672 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007673 if (*out == NULL) goto failed;
7674 return 0;
7675 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007676 tp = astmodulestate_global->ListComp_type;
7677 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007678 if (isinstance == -1) {
7679 return 1;
7680 }
7681 if (isinstance) {
7682 expr_ty elt;
7683 asdl_seq* generators;
7684
Dino Viehlandac46eb42019-09-11 10:16:34 -07007685 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007686 return 1;
7687 }
7688 if (tmp == NULL) {
7689 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7690 return 1;
7691 }
7692 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007693 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007694 res = obj2ast_expr(tmp, &elt, arena);
7695 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007696 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007697 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007698 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7699 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007700 return 1;
7701 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007702 if (tmp == NULL) {
7703 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7704 return 1;
7705 }
7706 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007707 int res;
7708 Py_ssize_t len;
7709 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007710 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007711 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 +02007712 goto failed;
7713 }
7714 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007715 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007716 if (generators == NULL) goto failed;
7717 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007718 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007719 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7720 Py_INCREF(tmp2);
7721 res = obj2ast_comprehension(tmp2, &val, arena);
7722 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007723 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007724 if (len != PyList_GET_SIZE(tmp)) {
7725 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7726 goto failed;
7727 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007728 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007729 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007730 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007731 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007732 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7733 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007734 if (*out == NULL) goto failed;
7735 return 0;
7736 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007737 tp = astmodulestate_global->SetComp_type;
7738 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007739 if (isinstance == -1) {
7740 return 1;
7741 }
7742 if (isinstance) {
7743 expr_ty elt;
7744 asdl_seq* generators;
7745
Dino Viehlandac46eb42019-09-11 10:16:34 -07007746 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007747 return 1;
7748 }
7749 if (tmp == NULL) {
7750 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7751 return 1;
7752 }
7753 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007754 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007755 res = obj2ast_expr(tmp, &elt, arena);
7756 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007757 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007758 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007759 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7760 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007761 return 1;
7762 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007763 if (tmp == NULL) {
7764 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7765 return 1;
7766 }
7767 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007768 int res;
7769 Py_ssize_t len;
7770 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007771 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007772 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 +02007773 goto failed;
7774 }
7775 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007776 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007777 if (generators == NULL) goto failed;
7778 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007779 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007780 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7781 Py_INCREF(tmp2);
7782 res = obj2ast_comprehension(tmp2, &val, arena);
7783 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007784 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007785 if (len != PyList_GET_SIZE(tmp)) {
7786 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7787 goto failed;
7788 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007789 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007790 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007791 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007792 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007793 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7794 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007795 if (*out == NULL) goto failed;
7796 return 0;
7797 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007798 tp = astmodulestate_global->DictComp_type;
7799 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007800 if (isinstance == -1) {
7801 return 1;
7802 }
7803 if (isinstance) {
7804 expr_ty key;
7805 expr_ty value;
7806 asdl_seq* generators;
7807
Dino Viehlandac46eb42019-09-11 10:16:34 -07007808 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007809 return 1;
7810 }
7811 if (tmp == NULL) {
7812 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7813 return 1;
7814 }
7815 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007816 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007817 res = obj2ast_expr(tmp, &key, arena);
7818 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007819 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007820 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007821 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007822 return 1;
7823 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007824 if (tmp == NULL) {
7825 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7826 return 1;
7827 }
7828 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007829 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007830 res = obj2ast_expr(tmp, &value, arena);
7831 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007832 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007833 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007834 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7835 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007836 return 1;
7837 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007838 if (tmp == NULL) {
7839 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7840 return 1;
7841 }
7842 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007843 int res;
7844 Py_ssize_t len;
7845 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007846 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007847 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 +02007848 goto failed;
7849 }
7850 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007851 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007852 if (generators == NULL) goto failed;
7853 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007854 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007855 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7856 Py_INCREF(tmp2);
7857 res = obj2ast_comprehension(tmp2, &val, arena);
7858 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007859 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007860 if (len != PyList_GET_SIZE(tmp)) {
7861 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7862 goto failed;
7863 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007864 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007865 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007866 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007867 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007868 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7869 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007870 if (*out == NULL) goto failed;
7871 return 0;
7872 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007873 tp = astmodulestate_global->GeneratorExp_type;
7874 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007875 if (isinstance == -1) {
7876 return 1;
7877 }
7878 if (isinstance) {
7879 expr_ty elt;
7880 asdl_seq* generators;
7881
Dino Viehlandac46eb42019-09-11 10:16:34 -07007882 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007883 return 1;
7884 }
7885 if (tmp == NULL) {
7886 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7887 return 1;
7888 }
7889 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007890 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007891 res = obj2ast_expr(tmp, &elt, arena);
7892 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007893 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007894 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007895 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7896 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007897 return 1;
7898 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007899 if (tmp == NULL) {
7900 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7901 return 1;
7902 }
7903 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007904 int res;
7905 Py_ssize_t len;
7906 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007907 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007908 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 +02007909 goto failed;
7910 }
7911 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007912 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007913 if (generators == NULL) goto failed;
7914 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007915 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007916 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7917 Py_INCREF(tmp2);
7918 res = obj2ast_comprehension(tmp2, &val, arena);
7919 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007920 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007921 if (len != PyList_GET_SIZE(tmp)) {
7922 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7923 goto failed;
7924 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007925 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007926 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007927 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007928 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007929 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7930 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007931 if (*out == NULL) goto failed;
7932 return 0;
7933 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007934 tp = astmodulestate_global->Await_type;
7935 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007936 if (isinstance == -1) {
7937 return 1;
7938 }
7939 if (isinstance) {
7940 expr_ty value;
7941
Dino Viehlandac46eb42019-09-11 10:16:34 -07007942 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007943 return 1;
7944 }
7945 if (tmp == NULL) {
7946 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7947 return 1;
7948 }
7949 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007950 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007951 res = obj2ast_expr(tmp, &value, arena);
7952 if (res != 0) goto failed;
7953 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007954 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007955 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7956 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007957 if (*out == NULL) goto failed;
7958 return 0;
7959 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007960 tp = astmodulestate_global->Yield_type;
7961 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007962 if (isinstance == -1) {
7963 return 1;
7964 }
7965 if (isinstance) {
7966 expr_ty value;
7967
Dino Viehlandac46eb42019-09-11 10:16:34 -07007968 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007969 return 1;
7970 }
7971 if (tmp == NULL || tmp == Py_None) {
7972 Py_CLEAR(tmp);
7973 value = NULL;
7974 }
7975 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007976 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007977 res = obj2ast_expr(tmp, &value, arena);
7978 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007979 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007980 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007981 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
7982 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007983 if (*out == NULL) goto failed;
7984 return 0;
7985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007986 tp = astmodulestate_global->YieldFrom_type;
7987 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007988 if (isinstance == -1) {
7989 return 1;
7990 }
7991 if (isinstance) {
7992 expr_ty value;
7993
Dino Viehlandac46eb42019-09-11 10:16:34 -07007994 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007995 return 1;
7996 }
7997 if (tmp == NULL) {
7998 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
7999 return 1;
8000 }
8001 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008002 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008003 res = obj2ast_expr(tmp, &value, arena);
8004 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008005 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008006 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008007 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8008 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008009 if (*out == NULL) goto failed;
8010 return 0;
8011 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008012 tp = astmodulestate_global->Compare_type;
8013 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008014 if (isinstance == -1) {
8015 return 1;
8016 }
8017 if (isinstance) {
8018 expr_ty left;
8019 asdl_int_seq* ops;
8020 asdl_seq* comparators;
8021
Dino Viehlandac46eb42019-09-11 10:16:34 -07008022 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008023 return 1;
8024 }
8025 if (tmp == NULL) {
8026 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8027 return 1;
8028 }
8029 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008030 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008031 res = obj2ast_expr(tmp, &left, arena);
8032 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008033 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008035 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008036 return 1;
8037 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008038 if (tmp == NULL) {
8039 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8040 return 1;
8041 }
8042 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008043 int res;
8044 Py_ssize_t len;
8045 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008046 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008047 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 +02008048 goto failed;
8049 }
8050 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008051 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008052 if (ops == NULL) goto failed;
8053 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008054 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008055 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8056 Py_INCREF(tmp2);
8057 res = obj2ast_cmpop(tmp2, &val, arena);
8058 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008059 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008060 if (len != PyList_GET_SIZE(tmp)) {
8061 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8062 goto failed;
8063 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008064 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008065 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008066 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008068 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8069 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008070 return 1;
8071 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008072 if (tmp == NULL) {
8073 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8074 return 1;
8075 }
8076 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008077 int res;
8078 Py_ssize_t len;
8079 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008080 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008081 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 +02008082 goto failed;
8083 }
8084 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008085 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008086 if (comparators == NULL) goto failed;
8087 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008088 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008089 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8090 Py_INCREF(tmp2);
8091 res = obj2ast_expr(tmp2, &val, arena);
8092 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008093 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008094 if (len != PyList_GET_SIZE(tmp)) {
8095 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8096 goto failed;
8097 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008098 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008099 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008100 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008101 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008102 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8103 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008104 if (*out == NULL) goto failed;
8105 return 0;
8106 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008107 tp = astmodulestate_global->Call_type;
8108 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008109 if (isinstance == -1) {
8110 return 1;
8111 }
8112 if (isinstance) {
8113 expr_ty func;
8114 asdl_seq* args;
8115 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008116
Dino Viehlandac46eb42019-09-11 10:16:34 -07008117 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008118 return 1;
8119 }
8120 if (tmp == NULL) {
8121 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8122 return 1;
8123 }
8124 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008125 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008126 res = obj2ast_expr(tmp, &func, arena);
8127 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008128 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008129 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008130 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008131 return 1;
8132 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008133 if (tmp == NULL) {
8134 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8135 return 1;
8136 }
8137 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008138 int res;
8139 Py_ssize_t len;
8140 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008141 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008142 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 +02008143 goto failed;
8144 }
8145 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008146 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008147 if (args == NULL) goto failed;
8148 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008149 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008150 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8151 Py_INCREF(tmp2);
8152 res = obj2ast_expr(tmp2, &val, arena);
8153 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008154 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008155 if (len != PyList_GET_SIZE(tmp)) {
8156 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8157 goto failed;
8158 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008159 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008160 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008161 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008162 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008163 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8164 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008165 return 1;
8166 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008167 if (tmp == NULL) {
8168 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8169 return 1;
8170 }
8171 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008172 int res;
8173 Py_ssize_t len;
8174 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008175 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008176 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 +02008177 goto failed;
8178 }
8179 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008180 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008181 if (keywords == NULL) goto failed;
8182 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008183 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008184 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8185 Py_INCREF(tmp2);
8186 res = obj2ast_keyword(tmp2, &val, arena);
8187 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008188 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008189 if (len != PyList_GET_SIZE(tmp)) {
8190 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8191 goto failed;
8192 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008193 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008194 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008195 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008196 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008197 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8198 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008199 if (*out == NULL) goto failed;
8200 return 0;
8201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008202 tp = astmodulestate_global->FormattedValue_type;
8203 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008204 if (isinstance == -1) {
8205 return 1;
8206 }
8207 if (isinstance) {
8208 expr_ty value;
8209 int conversion;
8210 expr_ty format_spec;
8211
Dino Viehlandac46eb42019-09-11 10:16:34 -07008212 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008213 return 1;
8214 }
8215 if (tmp == NULL) {
8216 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8217 return 1;
8218 }
8219 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008220 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008221 res = obj2ast_expr(tmp, &value, arena);
8222 if (res != 0) goto failed;
8223 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008225 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8226 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008227 return 1;
8228 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008229 if (tmp == NULL || tmp == Py_None) {
8230 Py_CLEAR(tmp);
8231 conversion = 0;
8232 }
8233 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008234 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008235 res = obj2ast_int(tmp, &conversion, arena);
8236 if (res != 0) goto failed;
8237 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008238 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008239 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8240 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008241 return 1;
8242 }
8243 if (tmp == NULL || tmp == Py_None) {
8244 Py_CLEAR(tmp);
8245 format_spec = NULL;
8246 }
8247 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008248 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008249 res = obj2ast_expr(tmp, &format_spec, arena);
8250 if (res != 0) goto failed;
8251 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008252 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008253 *out = FormattedValue(value, conversion, format_spec, lineno,
8254 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008255 if (*out == NULL) goto failed;
8256 return 0;
8257 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008258 tp = astmodulestate_global->JoinedStr_type;
8259 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008260 if (isinstance == -1) {
8261 return 1;
8262 }
8263 if (isinstance) {
8264 asdl_seq* values;
8265
Dino Viehlandac46eb42019-09-11 10:16:34 -07008266 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8267 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008268 return 1;
8269 }
8270 if (tmp == NULL) {
8271 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8272 return 1;
8273 }
8274 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008275 int res;
8276 Py_ssize_t len;
8277 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008278 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008279 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 -04008280 goto failed;
8281 }
8282 len = PyList_GET_SIZE(tmp);
8283 values = _Py_asdl_seq_new(len, arena);
8284 if (values == NULL) goto failed;
8285 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008286 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008287 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8288 Py_INCREF(tmp2);
8289 res = obj2ast_expr(tmp2, &val, arena);
8290 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008291 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008292 if (len != PyList_GET_SIZE(tmp)) {
8293 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8294 goto failed;
8295 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008296 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008297 }
8298 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008299 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008300 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8301 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008302 if (*out == NULL) goto failed;
8303 return 0;
8304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008305 tp = astmodulestate_global->Constant_type;
8306 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008307 if (isinstance == -1) {
8308 return 1;
8309 }
8310 if (isinstance) {
8311 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008312 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008313
Dino Viehlandac46eb42019-09-11 10:16:34 -07008314 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008315 return 1;
8316 }
8317 if (tmp == NULL) {
8318 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8319 return 1;
8320 }
8321 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008322 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008323 res = obj2ast_constant(tmp, &value, arena);
8324 if (res != 0) goto failed;
8325 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008327 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008328 return 1;
8329 }
8330 if (tmp == NULL || tmp == Py_None) {
8331 Py_CLEAR(tmp);
8332 kind = NULL;
8333 }
8334 else {
8335 int res;
8336 res = obj2ast_string(tmp, &kind, arena);
8337 if (res != 0) goto failed;
8338 Py_CLEAR(tmp);
8339 }
8340 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8341 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008342 if (*out == NULL) goto failed;
8343 return 0;
8344 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008345 tp = astmodulestate_global->Attribute_type;
8346 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008347 if (isinstance == -1) {
8348 return 1;
8349 }
8350 if (isinstance) {
8351 expr_ty value;
8352 identifier attr;
8353 expr_context_ty ctx;
8354
Dino Viehlandac46eb42019-09-11 10:16:34 -07008355 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008356 return 1;
8357 }
8358 if (tmp == NULL) {
8359 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8360 return 1;
8361 }
8362 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008363 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008364 res = obj2ast_expr(tmp, &value, arena);
8365 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008366 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008367 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008368 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008369 return 1;
8370 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008371 if (tmp == NULL) {
8372 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8373 return 1;
8374 }
8375 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008376 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008377 res = obj2ast_identifier(tmp, &attr, arena);
8378 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008379 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008380 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008381 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008382 return 1;
8383 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008384 if (tmp == NULL) {
8385 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8386 return 1;
8387 }
8388 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008389 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008390 res = obj2ast_expr_context(tmp, &ctx, arena);
8391 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008392 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008393 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008394 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8395 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008396 if (*out == NULL) goto failed;
8397 return 0;
8398 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008399 tp = astmodulestate_global->Subscript_type;
8400 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008401 if (isinstance == -1) {
8402 return 1;
8403 }
8404 if (isinstance) {
8405 expr_ty value;
8406 slice_ty slice;
8407 expr_context_ty ctx;
8408
Dino Viehlandac46eb42019-09-11 10:16:34 -07008409 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008410 return 1;
8411 }
8412 if (tmp == NULL) {
8413 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8414 return 1;
8415 }
8416 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008417 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008418 res = obj2ast_expr(tmp, &value, arena);
8419 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008420 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008421 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008422 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008423 return 1;
8424 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008425 if (tmp == NULL) {
8426 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8427 return 1;
8428 }
8429 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008430 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008431 res = obj2ast_slice(tmp, &slice, arena);
8432 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008433 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008434 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008435 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008436 return 1;
8437 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008438 if (tmp == NULL) {
8439 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8440 return 1;
8441 }
8442 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008443 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008444 res = obj2ast_expr_context(tmp, &ctx, arena);
8445 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008446 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008447 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008448 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8449 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008450 if (*out == NULL) goto failed;
8451 return 0;
8452 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008453 tp = astmodulestate_global->Starred_type;
8454 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008455 if (isinstance == -1) {
8456 return 1;
8457 }
8458 if (isinstance) {
8459 expr_ty value;
8460 expr_context_ty ctx;
8461
Dino Viehlandac46eb42019-09-11 10:16:34 -07008462 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008463 return 1;
8464 }
8465 if (tmp == NULL) {
8466 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8467 return 1;
8468 }
8469 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008470 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008471 res = obj2ast_expr(tmp, &value, arena);
8472 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008473 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008474 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008475 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008476 return 1;
8477 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008478 if (tmp == NULL) {
8479 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8480 return 1;
8481 }
8482 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008483 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008484 res = obj2ast_expr_context(tmp, &ctx, arena);
8485 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008486 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008487 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008488 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8489 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008490 if (*out == NULL) goto failed;
8491 return 0;
8492 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008493 tp = astmodulestate_global->Name_type;
8494 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008495 if (isinstance == -1) {
8496 return 1;
8497 }
8498 if (isinstance) {
8499 identifier id;
8500 expr_context_ty ctx;
8501
Dino Viehlandac46eb42019-09-11 10:16:34 -07008502 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008503 return 1;
8504 }
8505 if (tmp == NULL) {
8506 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8507 return 1;
8508 }
8509 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008510 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008511 res = obj2ast_identifier(tmp, &id, arena);
8512 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008513 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008514 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008515 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008516 return 1;
8517 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008518 if (tmp == NULL) {
8519 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8520 return 1;
8521 }
8522 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008523 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008524 res = obj2ast_expr_context(tmp, &ctx, arena);
8525 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008526 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008527 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008528 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8529 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008530 if (*out == NULL) goto failed;
8531 return 0;
8532 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008533 tp = astmodulestate_global->List_type;
8534 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008535 if (isinstance == -1) {
8536 return 1;
8537 }
8538 if (isinstance) {
8539 asdl_seq* elts;
8540 expr_context_ty ctx;
8541
Dino Viehlandac46eb42019-09-11 10:16:34 -07008542 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008543 return 1;
8544 }
8545 if (tmp == NULL) {
8546 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8547 return 1;
8548 }
8549 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008550 int res;
8551 Py_ssize_t len;
8552 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008553 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008554 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 +02008555 goto failed;
8556 }
8557 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008558 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008559 if (elts == NULL) goto failed;
8560 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008561 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008562 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8563 Py_INCREF(tmp2);
8564 res = obj2ast_expr(tmp2, &val, arena);
8565 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008566 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008567 if (len != PyList_GET_SIZE(tmp)) {
8568 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8569 goto failed;
8570 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008571 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008572 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008573 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008574 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008575 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008576 return 1;
8577 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008578 if (tmp == NULL) {
8579 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8580 return 1;
8581 }
8582 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008583 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008584 res = obj2ast_expr_context(tmp, &ctx, arena);
8585 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008586 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008587 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008588 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8589 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008590 if (*out == NULL) goto failed;
8591 return 0;
8592 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008593 tp = astmodulestate_global->Tuple_type;
8594 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008595 if (isinstance == -1) {
8596 return 1;
8597 }
8598 if (isinstance) {
8599 asdl_seq* elts;
8600 expr_context_ty ctx;
8601
Dino Viehlandac46eb42019-09-11 10:16:34 -07008602 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008603 return 1;
8604 }
8605 if (tmp == NULL) {
8606 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8607 return 1;
8608 }
8609 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008610 int res;
8611 Py_ssize_t len;
8612 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008613 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008614 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 +02008615 goto failed;
8616 }
8617 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008618 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008619 if (elts == NULL) goto failed;
8620 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008621 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008622 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8623 Py_INCREF(tmp2);
8624 res = obj2ast_expr(tmp2, &val, arena);
8625 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008626 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008627 if (len != PyList_GET_SIZE(tmp)) {
8628 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8629 goto failed;
8630 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008631 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008632 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008633 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008634 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008635 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008636 return 1;
8637 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008638 if (tmp == NULL) {
8639 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8640 return 1;
8641 }
8642 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008643 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008644 res = obj2ast_expr_context(tmp, &ctx, arena);
8645 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008646 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008647 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008648 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8649 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008650 if (*out == NULL) goto failed;
8651 return 0;
8652 }
8653
8654 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8655 failed:
8656 Py_XDECREF(tmp);
8657 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008658}
8659
8660int
8661obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8662{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008663 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008664
Dino Viehlandac46eb42019-09-11 10:16:34 -07008665 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008666 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008667 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008668 }
8669 if (isinstance) {
8670 *out = Load;
8671 return 0;
8672 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008673 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008674 if (isinstance == -1) {
8675 return 1;
8676 }
8677 if (isinstance) {
8678 *out = Store;
8679 return 0;
8680 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008681 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008682 if (isinstance == -1) {
8683 return 1;
8684 }
8685 if (isinstance) {
8686 *out = Del;
8687 return 0;
8688 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008689 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008690 if (isinstance == -1) {
8691 return 1;
8692 }
8693 if (isinstance) {
8694 *out = AugLoad;
8695 return 0;
8696 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008697 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008698 if (isinstance == -1) {
8699 return 1;
8700 }
8701 if (isinstance) {
8702 *out = AugStore;
8703 return 0;
8704 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008705 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008706 if (isinstance == -1) {
8707 return 1;
8708 }
8709 if (isinstance) {
8710 *out = Param;
8711 return 0;
8712 }
8713
8714 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8715 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008716}
8717
8718int
8719obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
8720{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008721 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008722
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008723 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008724 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008725
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008726 if (obj == Py_None) {
8727 *out = NULL;
8728 return 0;
8729 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008730 tp = astmodulestate_global->Slice_type;
8731 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008732 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008733 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008734 }
8735 if (isinstance) {
8736 expr_ty lower;
8737 expr_ty upper;
8738 expr_ty step;
8739
Dino Viehlandac46eb42019-09-11 10:16:34 -07008740 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008741 return 1;
8742 }
8743 if (tmp == NULL || tmp == Py_None) {
8744 Py_CLEAR(tmp);
8745 lower = NULL;
8746 }
8747 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008748 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008749 res = obj2ast_expr(tmp, &lower, arena);
8750 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008751 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008753 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008754 return 1;
8755 }
8756 if (tmp == NULL || tmp == Py_None) {
8757 Py_CLEAR(tmp);
8758 upper = NULL;
8759 }
8760 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008761 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008762 res = obj2ast_expr(tmp, &upper, arena);
8763 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008764 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008765 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008766 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008767 return 1;
8768 }
8769 if (tmp == NULL || tmp == Py_None) {
8770 Py_CLEAR(tmp);
8771 step = NULL;
8772 }
8773 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008774 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008775 res = obj2ast_expr(tmp, &step, arena);
8776 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008777 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008778 }
8779 *out = Slice(lower, upper, step, arena);
8780 if (*out == NULL) goto failed;
8781 return 0;
8782 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008783 tp = astmodulestate_global->ExtSlice_type;
8784 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008785 if (isinstance == -1) {
8786 return 1;
8787 }
8788 if (isinstance) {
8789 asdl_seq* dims;
8790
Dino Viehlandac46eb42019-09-11 10:16:34 -07008791 if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008792 return 1;
8793 }
8794 if (tmp == NULL) {
8795 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
8796 return 1;
8797 }
8798 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008799 int res;
8800 Py_ssize_t len;
8801 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008802 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008803 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 +02008804 goto failed;
8805 }
8806 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008807 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008808 if (dims == NULL) goto failed;
8809 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008810 slice_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008811 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8812 Py_INCREF(tmp2);
8813 res = obj2ast_slice(tmp2, &val, arena);
8814 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008815 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008816 if (len != PyList_GET_SIZE(tmp)) {
8817 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
8818 goto failed;
8819 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008820 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008821 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008822 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008823 }
8824 *out = ExtSlice(dims, arena);
8825 if (*out == NULL) goto failed;
8826 return 0;
8827 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008828 tp = astmodulestate_global->Index_type;
8829 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008830 if (isinstance == -1) {
8831 return 1;
8832 }
8833 if (isinstance) {
8834 expr_ty value;
8835
Dino Viehlandac46eb42019-09-11 10:16:34 -07008836 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008837 return 1;
8838 }
8839 if (tmp == NULL) {
8840 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
8841 return 1;
8842 }
8843 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008844 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008845 res = obj2ast_expr(tmp, &value, arena);
8846 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008847 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008848 }
8849 *out = Index(value, arena);
8850 if (*out == NULL) goto failed;
8851 return 0;
8852 }
8853
8854 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
8855 failed:
8856 Py_XDECREF(tmp);
8857 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008858}
8859
8860int
8861obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8862{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008863 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008864
Dino Viehlandac46eb42019-09-11 10:16:34 -07008865 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008866 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008867 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008868 }
8869 if (isinstance) {
8870 *out = And;
8871 return 0;
8872 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008873 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008874 if (isinstance == -1) {
8875 return 1;
8876 }
8877 if (isinstance) {
8878 *out = Or;
8879 return 0;
8880 }
8881
8882 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8883 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008884}
8885
8886int
8887obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8888{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008889 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008890
Dino Viehlandac46eb42019-09-11 10:16:34 -07008891 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008892 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008893 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008894 }
8895 if (isinstance) {
8896 *out = Add;
8897 return 0;
8898 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008899 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008900 if (isinstance == -1) {
8901 return 1;
8902 }
8903 if (isinstance) {
8904 *out = Sub;
8905 return 0;
8906 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008907 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008908 if (isinstance == -1) {
8909 return 1;
8910 }
8911 if (isinstance) {
8912 *out = Mult;
8913 return 0;
8914 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008915 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008916 if (isinstance == -1) {
8917 return 1;
8918 }
8919 if (isinstance) {
8920 *out = MatMult;
8921 return 0;
8922 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008923 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008924 if (isinstance == -1) {
8925 return 1;
8926 }
8927 if (isinstance) {
8928 *out = Div;
8929 return 0;
8930 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008931 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008932 if (isinstance == -1) {
8933 return 1;
8934 }
8935 if (isinstance) {
8936 *out = Mod;
8937 return 0;
8938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008939 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008940 if (isinstance == -1) {
8941 return 1;
8942 }
8943 if (isinstance) {
8944 *out = Pow;
8945 return 0;
8946 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008947 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008948 if (isinstance == -1) {
8949 return 1;
8950 }
8951 if (isinstance) {
8952 *out = LShift;
8953 return 0;
8954 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008955 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008956 if (isinstance == -1) {
8957 return 1;
8958 }
8959 if (isinstance) {
8960 *out = RShift;
8961 return 0;
8962 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008963 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008964 if (isinstance == -1) {
8965 return 1;
8966 }
8967 if (isinstance) {
8968 *out = BitOr;
8969 return 0;
8970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008971 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008972 if (isinstance == -1) {
8973 return 1;
8974 }
8975 if (isinstance) {
8976 *out = BitXor;
8977 return 0;
8978 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008979 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008980 if (isinstance == -1) {
8981 return 1;
8982 }
8983 if (isinstance) {
8984 *out = BitAnd;
8985 return 0;
8986 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008987 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008988 if (isinstance == -1) {
8989 return 1;
8990 }
8991 if (isinstance) {
8992 *out = FloorDiv;
8993 return 0;
8994 }
8995
8996 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8997 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008998}
8999
9000int
9001obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
9002{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009003 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009004
Dino Viehlandac46eb42019-09-11 10:16:34 -07009005 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009006 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009007 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009008 }
9009 if (isinstance) {
9010 *out = Invert;
9011 return 0;
9012 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009013 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009014 if (isinstance == -1) {
9015 return 1;
9016 }
9017 if (isinstance) {
9018 *out = Not;
9019 return 0;
9020 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009021 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009022 if (isinstance == -1) {
9023 return 1;
9024 }
9025 if (isinstance) {
9026 *out = UAdd;
9027 return 0;
9028 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009029 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009030 if (isinstance == -1) {
9031 return 1;
9032 }
9033 if (isinstance) {
9034 *out = USub;
9035 return 0;
9036 }
9037
9038 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9039 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009040}
9041
9042int
9043obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9044{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009045 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009046
Dino Viehlandac46eb42019-09-11 10:16:34 -07009047 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009048 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009049 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009050 }
9051 if (isinstance) {
9052 *out = Eq;
9053 return 0;
9054 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009055 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009056 if (isinstance == -1) {
9057 return 1;
9058 }
9059 if (isinstance) {
9060 *out = NotEq;
9061 return 0;
9062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009063 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009064 if (isinstance == -1) {
9065 return 1;
9066 }
9067 if (isinstance) {
9068 *out = Lt;
9069 return 0;
9070 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009071 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009072 if (isinstance == -1) {
9073 return 1;
9074 }
9075 if (isinstance) {
9076 *out = LtE;
9077 return 0;
9078 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009079 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009080 if (isinstance == -1) {
9081 return 1;
9082 }
9083 if (isinstance) {
9084 *out = Gt;
9085 return 0;
9086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009087 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009088 if (isinstance == -1) {
9089 return 1;
9090 }
9091 if (isinstance) {
9092 *out = GtE;
9093 return 0;
9094 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009095 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009096 if (isinstance == -1) {
9097 return 1;
9098 }
9099 if (isinstance) {
9100 *out = Is;
9101 return 0;
9102 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009103 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009104 if (isinstance == -1) {
9105 return 1;
9106 }
9107 if (isinstance) {
9108 *out = IsNot;
9109 return 0;
9110 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009111 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009112 if (isinstance == -1) {
9113 return 1;
9114 }
9115 if (isinstance) {
9116 *out = In;
9117 return 0;
9118 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009119 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009120 if (isinstance == -1) {
9121 return 1;
9122 }
9123 if (isinstance) {
9124 *out = NotIn;
9125 return 0;
9126 }
9127
9128 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9129 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009130}
9131
9132int
9133obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9134{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009135 PyObject* tmp = NULL;
9136 expr_ty target;
9137 expr_ty iter;
9138 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009139 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009140
Dino Viehlandac46eb42019-09-11 10:16:34 -07009141 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009142 return 1;
9143 }
9144 if (tmp == NULL) {
9145 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9146 return 1;
9147 }
9148 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009149 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009150 res = obj2ast_expr(tmp, &target, arena);
9151 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009152 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009154 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009155 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009156 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009157 if (tmp == NULL) {
9158 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9159 return 1;
9160 }
9161 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009162 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009163 res = obj2ast_expr(tmp, &iter, arena);
9164 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009165 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009166 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009167 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009168 return 1;
9169 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009170 if (tmp == NULL) {
9171 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9172 return 1;
9173 }
9174 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009175 int res;
9176 Py_ssize_t len;
9177 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009178 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009179 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 +02009180 goto failed;
9181 }
9182 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009183 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009184 if (ifs == NULL) goto failed;
9185 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009186 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009187 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9188 Py_INCREF(tmp2);
9189 res = obj2ast_expr(tmp2, &val, arena);
9190 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009191 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009192 if (len != PyList_GET_SIZE(tmp)) {
9193 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9194 goto failed;
9195 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009196 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009197 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009198 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009200 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009201 return 1;
9202 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009203 if (tmp == NULL) {
9204 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9205 return 1;
9206 }
9207 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009208 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009209 res = obj2ast_int(tmp, &is_async, arena);
9210 if (res != 0) goto failed;
9211 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009212 }
9213 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009214 return 0;
9215failed:
9216 Py_XDECREF(tmp);
9217 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009218}
9219
9220int
9221obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9222{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009223 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009224
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009225 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009226 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009227 int lineno;
9228 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009229 int end_lineno;
9230 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009231
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009232 if (obj == Py_None) {
9233 *out = NULL;
9234 return 0;
9235 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009236 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009237 return 1;
9238 }
9239 if (tmp == NULL) {
9240 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9241 return 1;
9242 }
9243 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009244 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009245 res = obj2ast_int(tmp, &lineno, arena);
9246 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009247 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009248 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009249 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9250 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009251 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009252 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009253 if (tmp == NULL) {
9254 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9255 return 1;
9256 }
9257 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009258 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009259 res = obj2ast_int(tmp, &col_offset, arena);
9260 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009261 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009262 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009263 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9264 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009265 return 1;
9266 }
9267 if (tmp == NULL || tmp == Py_None) {
9268 Py_CLEAR(tmp);
9269 end_lineno = 0;
9270 }
9271 else {
9272 int res;
9273 res = obj2ast_int(tmp, &end_lineno, arena);
9274 if (res != 0) goto failed;
9275 Py_CLEAR(tmp);
9276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009277 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9278 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009279 return 1;
9280 }
9281 if (tmp == NULL || tmp == Py_None) {
9282 Py_CLEAR(tmp);
9283 end_col_offset = 0;
9284 }
9285 else {
9286 int res;
9287 res = obj2ast_int(tmp, &end_col_offset, arena);
9288 if (res != 0) goto failed;
9289 Py_CLEAR(tmp);
9290 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009291 tp = astmodulestate_global->ExceptHandler_type;
9292 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009293 if (isinstance == -1) {
9294 return 1;
9295 }
9296 if (isinstance) {
9297 expr_ty type;
9298 identifier name;
9299 asdl_seq* body;
9300
Dino Viehlandac46eb42019-09-11 10:16:34 -07009301 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009302 return 1;
9303 }
9304 if (tmp == NULL || tmp == Py_None) {
9305 Py_CLEAR(tmp);
9306 type = NULL;
9307 }
9308 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009309 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009310 res = obj2ast_expr(tmp, &type, arena);
9311 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009312 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009313 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009314 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009315 return 1;
9316 }
9317 if (tmp == NULL || tmp == Py_None) {
9318 Py_CLEAR(tmp);
9319 name = NULL;
9320 }
9321 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009322 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009323 res = obj2ast_identifier(tmp, &name, arena);
9324 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009325 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009327 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009328 return 1;
9329 }
9330 if (tmp == NULL) {
9331 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9332 return 1;
9333 }
9334 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009335 int res;
9336 Py_ssize_t len;
9337 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009338 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009339 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 +02009340 goto failed;
9341 }
9342 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009343 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009344 if (body == NULL) goto failed;
9345 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009346 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009347 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9348 Py_INCREF(tmp2);
9349 res = obj2ast_stmt(tmp2, &val, arena);
9350 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009351 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009352 if (len != PyList_GET_SIZE(tmp)) {
9353 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9354 goto failed;
9355 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009356 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009357 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009358 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009359 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009360 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9361 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009362 if (*out == NULL) goto failed;
9363 return 0;
9364 }
9365
9366 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9367 failed:
9368 Py_XDECREF(tmp);
9369 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009370}
9371
9372int
9373obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9374{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009375 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009376 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009377 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009378 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009379 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009380 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009381 arg_ty kwarg;
9382 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009383
Dino Viehlandac46eb42019-09-11 10:16:34 -07009384 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9385 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009386 return 1;
9387 }
9388 if (tmp == NULL) {
9389 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9390 return 1;
9391 }
9392 else {
9393 int res;
9394 Py_ssize_t len;
9395 Py_ssize_t i;
9396 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009397 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 +01009398 goto failed;
9399 }
9400 len = PyList_GET_SIZE(tmp);
9401 posonlyargs = _Py_asdl_seq_new(len, arena);
9402 if (posonlyargs == NULL) goto failed;
9403 for (i = 0; i < len; i++) {
9404 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009405 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9406 Py_INCREF(tmp2);
9407 res = obj2ast_arg(tmp2, &val, arena);
9408 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009409 if (res != 0) goto failed;
9410 if (len != PyList_GET_SIZE(tmp)) {
9411 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9412 goto failed;
9413 }
9414 asdl_seq_SET(posonlyargs, i, val);
9415 }
9416 Py_CLEAR(tmp);
9417 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009418 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009419 return 1;
9420 }
9421 if (tmp == NULL) {
9422 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9423 return 1;
9424 }
9425 else {
9426 int res;
9427 Py_ssize_t len;
9428 Py_ssize_t i;
9429 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009430 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 +02009431 goto failed;
9432 }
9433 len = PyList_GET_SIZE(tmp);
9434 args = _Py_asdl_seq_new(len, arena);
9435 if (args == NULL) goto failed;
9436 for (i = 0; i < len; i++) {
9437 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009438 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9439 Py_INCREF(tmp2);
9440 res = obj2ast_arg(tmp2, &val, arena);
9441 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009442 if (res != 0) goto failed;
9443 if (len != PyList_GET_SIZE(tmp)) {
9444 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9445 goto failed;
9446 }
9447 asdl_seq_SET(args, i, val);
9448 }
9449 Py_CLEAR(tmp);
9450 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009451 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009452 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009453 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009454 if (tmp == NULL || tmp == Py_None) {
9455 Py_CLEAR(tmp);
9456 vararg = NULL;
9457 }
9458 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009459 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009460 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009461 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009462 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009463 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009464 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9465 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009466 return 1;
9467 }
9468 if (tmp == NULL) {
9469 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9470 return 1;
9471 }
9472 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009473 int res;
9474 Py_ssize_t len;
9475 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009476 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009477 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 +02009478 goto failed;
9479 }
9480 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009481 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009482 if (kwonlyargs == NULL) goto failed;
9483 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009484 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009485 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9486 Py_INCREF(tmp2);
9487 res = obj2ast_arg(tmp2, &val, arena);
9488 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009489 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009490 if (len != PyList_GET_SIZE(tmp)) {
9491 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9492 goto failed;
9493 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009494 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009495 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009496 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009497 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009498 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9499 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009500 return 1;
9501 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009502 if (tmp == NULL) {
9503 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9504 return 1;
9505 }
9506 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009507 int res;
9508 Py_ssize_t len;
9509 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009510 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009511 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 +02009512 goto failed;
9513 }
9514 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009515 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009516 if (kw_defaults == NULL) goto failed;
9517 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009518 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009519 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9520 Py_INCREF(tmp2);
9521 res = obj2ast_expr(tmp2, &val, arena);
9522 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009523 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009524 if (len != PyList_GET_SIZE(tmp)) {
9525 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9526 goto failed;
9527 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009528 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009529 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009530 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009531 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009532 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009533 return 1;
9534 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009535 if (tmp == NULL || tmp == Py_None) {
9536 Py_CLEAR(tmp);
9537 kwarg = NULL;
9538 }
9539 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009540 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009541 res = obj2ast_arg(tmp, &kwarg, arena);
9542 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009543 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009544 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009545 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009546 return 1;
9547 }
9548 if (tmp == NULL) {
9549 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9550 return 1;
9551 }
9552 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009553 int res;
9554 Py_ssize_t len;
9555 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009556 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009557 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 +02009558 goto failed;
9559 }
9560 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009561 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009562 if (defaults == NULL) goto failed;
9563 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009564 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009565 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9566 Py_INCREF(tmp2);
9567 res = obj2ast_expr(tmp2, &val, arena);
9568 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009569 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009570 if (len != PyList_GET_SIZE(tmp)) {
9571 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9572 goto failed;
9573 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009574 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009575 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009576 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009577 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009578 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009579 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009580 return 0;
9581failed:
9582 Py_XDECREF(tmp);
9583 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009584}
9585
9586int
9587obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9588{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009589 PyObject* tmp = NULL;
9590 identifier arg;
9591 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009592 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009593 int lineno;
9594 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009595 int end_lineno;
9596 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009597
Dino Viehlandac46eb42019-09-11 10:16:34 -07009598 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009599 return 1;
9600 }
9601 if (tmp == NULL) {
9602 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9603 return 1;
9604 }
9605 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009606 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009607 res = obj2ast_identifier(tmp, &arg, arena);
9608 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009609 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009610 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009611 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9612 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009613 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009614 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009615 if (tmp == NULL || tmp == Py_None) {
9616 Py_CLEAR(tmp);
9617 annotation = NULL;
9618 }
9619 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009620 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009621 res = obj2ast_expr(tmp, &annotation, arena);
9622 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009623 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009624 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009625 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9626 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009627 return 1;
9628 }
9629 if (tmp == NULL || tmp == Py_None) {
9630 Py_CLEAR(tmp);
9631 type_comment = NULL;
9632 }
9633 else {
9634 int res;
9635 res = obj2ast_string(tmp, &type_comment, arena);
9636 if (res != 0) goto failed;
9637 Py_CLEAR(tmp);
9638 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009639 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009640 return 1;
9641 }
9642 if (tmp == NULL) {
9643 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9644 return 1;
9645 }
9646 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009647 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009648 res = obj2ast_int(tmp, &lineno, arena);
9649 if (res != 0) goto failed;
9650 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009651 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009652 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9653 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009654 return 1;
9655 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009656 if (tmp == NULL) {
9657 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9658 return 1;
9659 }
9660 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009661 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009662 res = obj2ast_int(tmp, &col_offset, arena);
9663 if (res != 0) goto failed;
9664 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009665 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009666 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9667 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009668 return 1;
9669 }
9670 if (tmp == NULL || tmp == Py_None) {
9671 Py_CLEAR(tmp);
9672 end_lineno = 0;
9673 }
9674 else {
9675 int res;
9676 res = obj2ast_int(tmp, &end_lineno, arena);
9677 if (res != 0) goto failed;
9678 Py_CLEAR(tmp);
9679 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009680 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9681 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009682 return 1;
9683 }
9684 if (tmp == NULL || tmp == Py_None) {
9685 Py_CLEAR(tmp);
9686 end_col_offset = 0;
9687 }
9688 else {
9689 int res;
9690 res = obj2ast_int(tmp, &end_col_offset, arena);
9691 if (res != 0) goto failed;
9692 Py_CLEAR(tmp);
9693 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009694 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9695 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009696 return 0;
9697failed:
9698 Py_XDECREF(tmp);
9699 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009700}
9701
9702int
9703obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9704{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009705 PyObject* tmp = NULL;
9706 identifier arg;
9707 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009708
Dino Viehlandac46eb42019-09-11 10:16:34 -07009709 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009710 return 1;
9711 }
9712 if (tmp == NULL || tmp == Py_None) {
9713 Py_CLEAR(tmp);
9714 arg = NULL;
9715 }
9716 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009717 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009718 res = obj2ast_identifier(tmp, &arg, arena);
9719 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009720 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009721 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009722 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009723 return 1;
9724 }
9725 if (tmp == NULL) {
9726 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9727 return 1;
9728 }
9729 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009730 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009731 res = obj2ast_expr(tmp, &value, arena);
9732 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009733 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009734 }
9735 *out = keyword(arg, value, arena);
9736 return 0;
9737failed:
9738 Py_XDECREF(tmp);
9739 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009740}
9741
9742int
9743obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9744{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009745 PyObject* tmp = NULL;
9746 identifier name;
9747 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009748
Dino Viehlandac46eb42019-09-11 10:16:34 -07009749 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009750 return 1;
9751 }
9752 if (tmp == NULL) {
9753 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9754 return 1;
9755 }
9756 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009757 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009758 res = obj2ast_identifier(tmp, &name, arena);
9759 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009760 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009761 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009762 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009763 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009764 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009765 if (tmp == NULL || tmp == Py_None) {
9766 Py_CLEAR(tmp);
9767 asname = NULL;
9768 }
9769 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009770 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009771 res = obj2ast_identifier(tmp, &asname, arena);
9772 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009773 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009774 }
9775 *out = alias(name, asname, arena);
9776 return 0;
9777failed:
9778 Py_XDECREF(tmp);
9779 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009780}
9781
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009782int
9783obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9784{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009785 PyObject* tmp = NULL;
9786 expr_ty context_expr;
9787 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009788
Dino Viehlandac46eb42019-09-11 10:16:34 -07009789 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9790 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009791 return 1;
9792 }
9793 if (tmp == NULL) {
9794 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9795 return 1;
9796 }
9797 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009798 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009799 res = obj2ast_expr(tmp, &context_expr, arena);
9800 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009801 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009802 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009803 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9804 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009805 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009806 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009807 if (tmp == NULL || tmp == Py_None) {
9808 Py_CLEAR(tmp);
9809 optional_vars = NULL;
9810 }
9811 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009812 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009813 res = obj2ast_expr(tmp, &optional_vars, arena);
9814 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009815 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009816 }
9817 *out = withitem(context_expr, optional_vars, arena);
9818 return 0;
9819failed:
9820 Py_XDECREF(tmp);
9821 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009822}
9823
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009824int
9825obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9826{
9827 int isinstance;
9828
9829 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009830 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009831
9832 if (obj == Py_None) {
9833 *out = NULL;
9834 return 0;
9835 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009836 tp = astmodulestate_global->TypeIgnore_type;
9837 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009838 if (isinstance == -1) {
9839 return 1;
9840 }
9841 if (isinstance) {
9842 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009843 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009844
Dino Viehlandac46eb42019-09-11 10:16:34 -07009845 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9846 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009847 return 1;
9848 }
9849 if (tmp == NULL) {
9850 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9851 return 1;
9852 }
9853 else {
9854 int res;
9855 res = obj2ast_int(tmp, &lineno, arena);
9856 if (res != 0) goto failed;
9857 Py_CLEAR(tmp);
9858 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009859 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009860 return 1;
9861 }
9862 if (tmp == NULL) {
9863 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9864 return 1;
9865 }
9866 else {
9867 int res;
9868 res = obj2ast_string(tmp, &tag, arena);
9869 if (res != 0) goto failed;
9870 Py_CLEAR(tmp);
9871 }
9872 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009873 if (*out == NULL) goto failed;
9874 return 0;
9875 }
9876
9877 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9878 failed:
9879 Py_XDECREF(tmp);
9880 return 1;
9881}
9882
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009883
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009884PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009885PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009886{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009887 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009888 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009889 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009890 if (!m) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009891 Py_INCREF(astmodulestate(m)->AST_type);
9892 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0)
9893 return NULL;
Matthias Bussonnier565b4f12019-05-21 13:12:03 -07009894 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0)
9895 return NULL;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009896 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009897 return NULL;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009898 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0)
9899 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009900 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0)
9901 return NULL;
9902 Py_INCREF(astmodulestate(m)->mod_type);
9903 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009904 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009905 Py_INCREF(astmodulestate(m)->Module_type);
9906 if (PyModule_AddObject(m, "Interactive",
9907 astmodulestate_global->Interactive_type) < 0) return NULL;
9908 Py_INCREF(astmodulestate(m)->Interactive_type);
9909 if (PyModule_AddObject(m, "Expression",
9910 astmodulestate_global->Expression_type) < 0) return NULL;
9911 Py_INCREF(astmodulestate(m)->Expression_type);
9912 if (PyModule_AddObject(m, "FunctionType",
9913 astmodulestate_global->FunctionType_type) < 0) return NULL;
9914 Py_INCREF(astmodulestate(m)->FunctionType_type);
9915 if (PyModule_AddObject(m, "Suite", astmodulestate_global->Suite_type) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009916 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009917 Py_INCREF(astmodulestate(m)->Suite_type);
9918 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009919 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009920 Py_INCREF(astmodulestate(m)->stmt_type);
9921 if (PyModule_AddObject(m, "FunctionDef",
9922 astmodulestate_global->FunctionDef_type) < 0) return NULL;
9923 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9924 if (PyModule_AddObject(m, "AsyncFunctionDef",
9925 astmodulestate_global->AsyncFunctionDef_type) < 0) return NULL;
9926 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9927 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009928 < 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009929 Py_INCREF(astmodulestate(m)->ClassDef_type);
9930 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009931 0) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009932 Py_INCREF(astmodulestate(m)->Return_type);
9933 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
9934 0) return NULL;
9935 Py_INCREF(astmodulestate(m)->Delete_type);
9936 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
9937 0) return NULL;
9938 Py_INCREF(astmodulestate(m)->Assign_type);
9939 if (PyModule_AddObject(m, "AugAssign",
9940 astmodulestate_global->AugAssign_type) < 0) return NULL;
9941 Py_INCREF(astmodulestate(m)->AugAssign_type);
9942 if (PyModule_AddObject(m, "AnnAssign",
9943 astmodulestate_global->AnnAssign_type) < 0) return NULL;
9944 Py_INCREF(astmodulestate(m)->AnnAssign_type);
9945 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009946 return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009947 Py_INCREF(astmodulestate(m)->For_type);
9948 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
9949 < 0) return NULL;
9950 Py_INCREF(astmodulestate(m)->AsyncFor_type);
9951 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0)
9952 return NULL;
9953 Py_INCREF(astmodulestate(m)->While_type);
9954 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) return
9955 NULL;
9956 Py_INCREF(astmodulestate(m)->If_type);
9957 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0)
9958 return NULL;
9959 Py_INCREF(astmodulestate(m)->With_type);
9960 if (PyModule_AddObject(m, "AsyncWith",
9961 astmodulestate_global->AsyncWith_type) < 0) return NULL;
9962 Py_INCREF(astmodulestate(m)->AsyncWith_type);
9963 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0)
9964 return NULL;
9965 Py_INCREF(astmodulestate(m)->Raise_type);
9966 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0)
9967 return NULL;
9968 Py_INCREF(astmodulestate(m)->Try_type);
9969 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
9970 0) return NULL;
9971 Py_INCREF(astmodulestate(m)->Assert_type);
9972 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
9973 0) return NULL;
9974 Py_INCREF(astmodulestate(m)->Import_type);
9975 if (PyModule_AddObject(m, "ImportFrom",
9976 astmodulestate_global->ImportFrom_type) < 0) return NULL;
9977 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9978 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
9979 0) return NULL;
9980 Py_INCREF(astmodulestate(m)->Global_type);
9981 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
9982 < 0) return NULL;
9983 Py_INCREF(astmodulestate(m)->Nonlocal_type);
9984 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0)
9985 return NULL;
9986 Py_INCREF(astmodulestate(m)->Expr_type);
9987 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0)
9988 return NULL;
9989 Py_INCREF(astmodulestate(m)->Pass_type);
9990 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0)
9991 return NULL;
9992 Py_INCREF(astmodulestate(m)->Break_type);
9993 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
9994 < 0) return NULL;
9995 Py_INCREF(astmodulestate(m)->Continue_type);
9996 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0)
9997 return NULL;
9998 Py_INCREF(astmodulestate(m)->expr_type);
9999 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
10000 0) return NULL;
10001 Py_INCREF(astmodulestate(m)->BoolOp_type);
10002 if (PyModule_AddObject(m, "NamedExpr",
10003 astmodulestate_global->NamedExpr_type) < 0) return NULL;
10004 Py_INCREF(astmodulestate(m)->NamedExpr_type);
10005 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0)
10006 return NULL;
10007 Py_INCREF(astmodulestate(m)->BinOp_type);
10008 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
10009 0) return NULL;
10010 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10011 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
10012 0) return NULL;
10013 Py_INCREF(astmodulestate(m)->Lambda_type);
10014 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0)
10015 return NULL;
10016 Py_INCREF(astmodulestate(m)->IfExp_type);
10017 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0)
10018 return NULL;
10019 Py_INCREF(astmodulestate(m)->Dict_type);
10020 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0)
10021 return NULL;
10022 Py_INCREF(astmodulestate(m)->Set_type);
10023 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
10024 < 0) return NULL;
10025 Py_INCREF(astmodulestate(m)->ListComp_type);
10026 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
10027 0) return NULL;
10028 Py_INCREF(astmodulestate(m)->SetComp_type);
10029 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
10030 < 0) return NULL;
10031 Py_INCREF(astmodulestate(m)->DictComp_type);
10032 if (PyModule_AddObject(m, "GeneratorExp",
10033 astmodulestate_global->GeneratorExp_type) < 0) return NULL;
10034 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
10035 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0)
10036 return NULL;
10037 Py_INCREF(astmodulestate(m)->Await_type);
10038 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0)
10039 return NULL;
10040 Py_INCREF(astmodulestate(m)->Yield_type);
10041 if (PyModule_AddObject(m, "YieldFrom",
10042 astmodulestate_global->YieldFrom_type) < 0) return NULL;
10043 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10044 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
10045 0) return NULL;
10046 Py_INCREF(astmodulestate(m)->Compare_type);
10047 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0)
10048 return NULL;
10049 Py_INCREF(astmodulestate(m)->Call_type);
10050 if (PyModule_AddObject(m, "FormattedValue",
10051 astmodulestate_global->FormattedValue_type) < 0) return NULL;
10052 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10053 if (PyModule_AddObject(m, "JoinedStr",
10054 astmodulestate_global->JoinedStr_type) < 0) return NULL;
10055 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10056 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
10057 < 0) return NULL;
10058 Py_INCREF(astmodulestate(m)->Constant_type);
10059 if (PyModule_AddObject(m, "Attribute",
10060 astmodulestate_global->Attribute_type) < 0) return NULL;
10061 Py_INCREF(astmodulestate(m)->Attribute_type);
10062 if (PyModule_AddObject(m, "Subscript",
10063 astmodulestate_global->Subscript_type) < 0) return NULL;
10064 Py_INCREF(astmodulestate(m)->Subscript_type);
10065 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
10066 0) return NULL;
10067 Py_INCREF(astmodulestate(m)->Starred_type);
10068 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0)
10069 return NULL;
10070 Py_INCREF(astmodulestate(m)->Name_type);
10071 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0)
10072 return NULL;
10073 Py_INCREF(astmodulestate(m)->List_type);
10074 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0)
10075 return NULL;
10076 Py_INCREF(astmodulestate(m)->Tuple_type);
10077 if (PyModule_AddObject(m, "expr_context",
10078 astmodulestate_global->expr_context_type) < 0) return NULL;
10079 Py_INCREF(astmodulestate(m)->expr_context_type);
10080 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0)
10081 return NULL;
10082 Py_INCREF(astmodulestate(m)->Load_type);
10083 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0)
10084 return NULL;
10085 Py_INCREF(astmodulestate(m)->Store_type);
10086 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0)
10087 return NULL;
10088 Py_INCREF(astmodulestate(m)->Del_type);
10089 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
10090 0) return NULL;
10091 Py_INCREF(astmodulestate(m)->AugLoad_type);
10092 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
10093 < 0) return NULL;
10094 Py_INCREF(astmodulestate(m)->AugStore_type);
10095 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0)
10096 return NULL;
10097 Py_INCREF(astmodulestate(m)->Param_type);
10098 if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0)
10099 return NULL;
10100 Py_INCREF(astmodulestate(m)->slice_type);
10101 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0)
10102 return NULL;
10103 Py_INCREF(astmodulestate(m)->Slice_type);
10104 if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type)
10105 < 0) return NULL;
10106 Py_INCREF(astmodulestate(m)->ExtSlice_type);
10107 if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0)
10108 return NULL;
10109 Py_INCREF(astmodulestate(m)->Index_type);
10110 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
10111 0) return NULL;
10112 Py_INCREF(astmodulestate(m)->boolop_type);
10113 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0)
10114 return NULL;
10115 Py_INCREF(astmodulestate(m)->And_type);
10116 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) return
10117 NULL;
10118 Py_INCREF(astmodulestate(m)->Or_type);
10119 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
10120 < 0) return NULL;
10121 Py_INCREF(astmodulestate(m)->operator_type);
10122 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0)
10123 return NULL;
10124 Py_INCREF(astmodulestate(m)->Add_type);
10125 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0)
10126 return NULL;
10127 Py_INCREF(astmodulestate(m)->Sub_type);
10128 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0)
10129 return NULL;
10130 Py_INCREF(astmodulestate(m)->Mult_type);
10131 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
10132 0) return NULL;
10133 Py_INCREF(astmodulestate(m)->MatMult_type);
10134 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0)
10135 return NULL;
10136 Py_INCREF(astmodulestate(m)->Div_type);
10137 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0)
10138 return NULL;
10139 Py_INCREF(astmodulestate(m)->Mod_type);
10140 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0)
10141 return NULL;
10142 Py_INCREF(astmodulestate(m)->Pow_type);
10143 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
10144 0) return NULL;
10145 Py_INCREF(astmodulestate(m)->LShift_type);
10146 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
10147 0) return NULL;
10148 Py_INCREF(astmodulestate(m)->RShift_type);
10149 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0)
10150 return NULL;
10151 Py_INCREF(astmodulestate(m)->BitOr_type);
10152 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
10153 0) return NULL;
10154 Py_INCREF(astmodulestate(m)->BitXor_type);
10155 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
10156 0) return NULL;
10157 Py_INCREF(astmodulestate(m)->BitAnd_type);
10158 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
10159 < 0) return NULL;
10160 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10161 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
10162 0) return NULL;
10163 Py_INCREF(astmodulestate(m)->unaryop_type);
10164 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
10165 0) return NULL;
10166 Py_INCREF(astmodulestate(m)->Invert_type);
10167 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0)
10168 return NULL;
10169 Py_INCREF(astmodulestate(m)->Not_type);
10170 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0)
10171 return NULL;
10172 Py_INCREF(astmodulestate(m)->UAdd_type);
10173 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0)
10174 return NULL;
10175 Py_INCREF(astmodulestate(m)->USub_type);
10176 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0)
10177 return NULL;
10178 Py_INCREF(astmodulestate(m)->cmpop_type);
10179 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) return
10180 NULL;
10181 Py_INCREF(astmodulestate(m)->Eq_type);
10182 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0)
10183 return NULL;
10184 Py_INCREF(astmodulestate(m)->NotEq_type);
10185 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) return
10186 NULL;
10187 Py_INCREF(astmodulestate(m)->Lt_type);
10188 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0)
10189 return NULL;
10190 Py_INCREF(astmodulestate(m)->LtE_type);
10191 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) return
10192 NULL;
10193 Py_INCREF(astmodulestate(m)->Gt_type);
10194 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0)
10195 return NULL;
10196 Py_INCREF(astmodulestate(m)->GtE_type);
10197 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) return
10198 NULL;
10199 Py_INCREF(astmodulestate(m)->Is_type);
10200 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0)
10201 return NULL;
10202 Py_INCREF(astmodulestate(m)->IsNot_type);
10203 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) return
10204 NULL;
10205 Py_INCREF(astmodulestate(m)->In_type);
10206 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0)
10207 return NULL;
10208 Py_INCREF(astmodulestate(m)->NotIn_type);
10209 if (PyModule_AddObject(m, "comprehension",
10210 astmodulestate_global->comprehension_type) < 0) return NULL;
10211 Py_INCREF(astmodulestate(m)->comprehension_type);
10212 if (PyModule_AddObject(m, "excepthandler",
10213 astmodulestate_global->excepthandler_type) < 0) return NULL;
10214 Py_INCREF(astmodulestate(m)->excepthandler_type);
10215 if (PyModule_AddObject(m, "ExceptHandler",
10216 astmodulestate_global->ExceptHandler_type) < 0) return NULL;
10217 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10218 if (PyModule_AddObject(m, "arguments",
10219 astmodulestate_global->arguments_type) < 0) return NULL;
10220 Py_INCREF(astmodulestate(m)->arguments_type);
10221 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0)
10222 return NULL;
10223 Py_INCREF(astmodulestate(m)->arg_type);
10224 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
10225 0) return NULL;
10226 Py_INCREF(astmodulestate(m)->keyword_type);
10227 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0)
10228 return NULL;
10229 Py_INCREF(astmodulestate(m)->alias_type);
10230 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
10231 < 0) return NULL;
10232 Py_INCREF(astmodulestate(m)->withitem_type);
10233 if (PyModule_AddObject(m, "type_ignore",
10234 astmodulestate_global->type_ignore_type) < 0) return NULL;
10235 Py_INCREF(astmodulestate(m)->type_ignore_type);
10236 if (PyModule_AddObject(m, "TypeIgnore",
10237 astmodulestate_global->TypeIgnore_type) < 0) return NULL;
10238 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010239 return m;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010240}
10241
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010242
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010243PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010244{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010245 if (!init_types())
10246 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010247 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010248}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010249
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010250/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10251mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010252{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010253 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010254 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010255 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010256
Steve Dowerb82e17e2019-05-23 08:45:22 -070010257 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10258 return NULL;
10259 }
10260
Dino Viehlandac46eb42019-09-11 10:16:34 -070010261 req_type[0] = astmodulestate_global->Module_type;
10262 req_type[1] = astmodulestate_global->Expression_type;
10263 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010264
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010265 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010266
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010267 if (!init_types())
10268 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010269
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010270 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10271 if (isinstance == -1)
10272 return NULL;
10273 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010274 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010275 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010276 return NULL;
10277 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010278
10279 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010280 if (obj2ast_mod(ast, &res, arena) != 0)
10281 return NULL;
10282 else
10283 return res;
10284}
10285
10286int PyAST_Check(PyObject* obj)
10287{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010288 if (!init_types())
10289 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010290 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010291}
10292
Martin v. Löwis5b222132007-06-10 09:51:05 +000010293