blob: 2784c427d72dc807a76616aef383231dc2f7378b [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;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700130 PyObject *Try_type;
131 PyObject *Tuple_type;
132 PyObject *TypeIgnore_type;
133 PyObject *UAdd_singleton;
134 PyObject *UAdd_type;
135 PyObject *USub_singleton;
136 PyObject *USub_type;
137 PyObject *UnaryOp_type;
138 PyObject *While_type;
139 PyObject *With_type;
140 PyObject *YieldFrom_type;
141 PyObject *Yield_type;
142 PyObject *__dict__;
143 PyObject *__module__;
144 PyObject *_ast;
145 PyObject *_attributes;
146 PyObject *_fields;
147 PyObject *alias_type;
148 PyObject *annotation;
149 PyObject *arg;
150 PyObject *arg_type;
151 PyObject *args;
152 PyObject *argtypes;
153 PyObject *arguments_type;
154 PyObject *asname;
155 PyObject *attr;
156 PyObject *bases;
157 PyObject *body;
158 PyObject *boolop_type;
159 PyObject *cause;
160 PyObject *cmpop_type;
161 PyObject *col_offset;
162 PyObject *comparators;
163 PyObject *comprehension_type;
164 PyObject *context_expr;
165 PyObject *conversion;
166 PyObject *ctx;
167 PyObject *decorator_list;
168 PyObject *defaults;
169 PyObject *dims;
170 PyObject *elt;
171 PyObject *elts;
172 PyObject *end_col_offset;
173 PyObject *end_lineno;
174 PyObject *exc;
175 PyObject *excepthandler_type;
176 PyObject *expr_context_type;
177 PyObject *expr_type;
178 PyObject *finalbody;
179 PyObject *format_spec;
180 PyObject *func;
181 PyObject *generators;
182 PyObject *handlers;
183 PyObject *id;
184 PyObject *ifs;
185 PyObject *is_async;
186 PyObject *items;
187 PyObject *iter;
188 PyObject *key;
189 PyObject *keys;
190 PyObject *keyword_type;
191 PyObject *keywords;
192 PyObject *kind;
193 PyObject *kw_defaults;
194 PyObject *kwarg;
195 PyObject *kwonlyargs;
196 PyObject *left;
197 PyObject *level;
198 PyObject *lineno;
199 PyObject *lower;
200 PyObject *mod_type;
201 PyObject *module;
202 PyObject *msg;
203 PyObject *name;
204 PyObject *names;
205 PyObject *op;
206 PyObject *operand;
207 PyObject *operator_type;
208 PyObject *ops;
209 PyObject *optional_vars;
210 PyObject *orelse;
211 PyObject *posonlyargs;
212 PyObject *returns;
213 PyObject *right;
214 PyObject *simple;
215 PyObject *slice;
216 PyObject *slice_type;
217 PyObject *step;
218 PyObject *stmt_type;
219 PyObject *tag;
220 PyObject *target;
221 PyObject *targets;
222 PyObject *test;
223 PyObject *type;
224 PyObject *type_comment;
225 PyObject *type_ignore_type;
226 PyObject *type_ignores;
227 PyObject *unaryop_type;
228 PyObject *upper;
229 PyObject *value;
230 PyObject *values;
231 PyObject *vararg;
232 PyObject *withitem_type;
233} astmodulestate;
234
235
236#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
237
238static int astmodule_clear(PyObject *module)
239{
240 Py_CLEAR(astmodulestate(module)->AST_type);
241 Py_CLEAR(astmodulestate(module)->Add_singleton);
242 Py_CLEAR(astmodulestate(module)->Add_type);
243 Py_CLEAR(astmodulestate(module)->And_singleton);
244 Py_CLEAR(astmodulestate(module)->And_type);
245 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
246 Py_CLEAR(astmodulestate(module)->Assert_type);
247 Py_CLEAR(astmodulestate(module)->Assign_type);
248 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
249 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
250 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
251 Py_CLEAR(astmodulestate(module)->Attribute_type);
252 Py_CLEAR(astmodulestate(module)->AugAssign_type);
253 Py_CLEAR(astmodulestate(module)->AugLoad_singleton);
254 Py_CLEAR(astmodulestate(module)->AugLoad_type);
255 Py_CLEAR(astmodulestate(module)->AugStore_singleton);
256 Py_CLEAR(astmodulestate(module)->AugStore_type);
257 Py_CLEAR(astmodulestate(module)->Await_type);
258 Py_CLEAR(astmodulestate(module)->BinOp_type);
259 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
260 Py_CLEAR(astmodulestate(module)->BitAnd_type);
261 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
262 Py_CLEAR(astmodulestate(module)->BitOr_type);
263 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
264 Py_CLEAR(astmodulestate(module)->BitXor_type);
265 Py_CLEAR(astmodulestate(module)->BoolOp_type);
266 Py_CLEAR(astmodulestate(module)->Break_type);
267 Py_CLEAR(astmodulestate(module)->Call_type);
268 Py_CLEAR(astmodulestate(module)->ClassDef_type);
269 Py_CLEAR(astmodulestate(module)->Compare_type);
270 Py_CLEAR(astmodulestate(module)->Constant_type);
271 Py_CLEAR(astmodulestate(module)->Continue_type);
272 Py_CLEAR(astmodulestate(module)->Del_singleton);
273 Py_CLEAR(astmodulestate(module)->Del_type);
274 Py_CLEAR(astmodulestate(module)->Delete_type);
275 Py_CLEAR(astmodulestate(module)->DictComp_type);
276 Py_CLEAR(astmodulestate(module)->Dict_type);
277 Py_CLEAR(astmodulestate(module)->Div_singleton);
278 Py_CLEAR(astmodulestate(module)->Div_type);
279 Py_CLEAR(astmodulestate(module)->Eq_singleton);
280 Py_CLEAR(astmodulestate(module)->Eq_type);
281 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
282 Py_CLEAR(astmodulestate(module)->Expr_type);
283 Py_CLEAR(astmodulestate(module)->Expression_type);
284 Py_CLEAR(astmodulestate(module)->ExtSlice_type);
285 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
286 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
287 Py_CLEAR(astmodulestate(module)->For_type);
288 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
289 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
290 Py_CLEAR(astmodulestate(module)->FunctionType_type);
291 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
292 Py_CLEAR(astmodulestate(module)->Global_type);
293 Py_CLEAR(astmodulestate(module)->GtE_singleton);
294 Py_CLEAR(astmodulestate(module)->GtE_type);
295 Py_CLEAR(astmodulestate(module)->Gt_singleton);
296 Py_CLEAR(astmodulestate(module)->Gt_type);
297 Py_CLEAR(astmodulestate(module)->IfExp_type);
298 Py_CLEAR(astmodulestate(module)->If_type);
299 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
300 Py_CLEAR(astmodulestate(module)->Import_type);
301 Py_CLEAR(astmodulestate(module)->In_singleton);
302 Py_CLEAR(astmodulestate(module)->In_type);
303 Py_CLEAR(astmodulestate(module)->Index_type);
304 Py_CLEAR(astmodulestate(module)->Interactive_type);
305 Py_CLEAR(astmodulestate(module)->Invert_singleton);
306 Py_CLEAR(astmodulestate(module)->Invert_type);
307 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
308 Py_CLEAR(astmodulestate(module)->IsNot_type);
309 Py_CLEAR(astmodulestate(module)->Is_singleton);
310 Py_CLEAR(astmodulestate(module)->Is_type);
311 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
312 Py_CLEAR(astmodulestate(module)->LShift_singleton);
313 Py_CLEAR(astmodulestate(module)->LShift_type);
314 Py_CLEAR(astmodulestate(module)->Lambda_type);
315 Py_CLEAR(astmodulestate(module)->ListComp_type);
316 Py_CLEAR(astmodulestate(module)->List_type);
317 Py_CLEAR(astmodulestate(module)->Load_singleton);
318 Py_CLEAR(astmodulestate(module)->Load_type);
319 Py_CLEAR(astmodulestate(module)->LtE_singleton);
320 Py_CLEAR(astmodulestate(module)->LtE_type);
321 Py_CLEAR(astmodulestate(module)->Lt_singleton);
322 Py_CLEAR(astmodulestate(module)->Lt_type);
323 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
324 Py_CLEAR(astmodulestate(module)->MatMult_type);
325 Py_CLEAR(astmodulestate(module)->Mod_singleton);
326 Py_CLEAR(astmodulestate(module)->Mod_type);
327 Py_CLEAR(astmodulestate(module)->Module_type);
328 Py_CLEAR(astmodulestate(module)->Mult_singleton);
329 Py_CLEAR(astmodulestate(module)->Mult_type);
330 Py_CLEAR(astmodulestate(module)->Name_type);
331 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
332 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
333 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
334 Py_CLEAR(astmodulestate(module)->NotEq_type);
335 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
336 Py_CLEAR(astmodulestate(module)->NotIn_type);
337 Py_CLEAR(astmodulestate(module)->Not_singleton);
338 Py_CLEAR(astmodulestate(module)->Not_type);
339 Py_CLEAR(astmodulestate(module)->Or_singleton);
340 Py_CLEAR(astmodulestate(module)->Or_type);
341 Py_CLEAR(astmodulestate(module)->Param_singleton);
342 Py_CLEAR(astmodulestate(module)->Param_type);
343 Py_CLEAR(astmodulestate(module)->Pass_type);
344 Py_CLEAR(astmodulestate(module)->Pow_singleton);
345 Py_CLEAR(astmodulestate(module)->Pow_type);
346 Py_CLEAR(astmodulestate(module)->RShift_singleton);
347 Py_CLEAR(astmodulestate(module)->RShift_type);
348 Py_CLEAR(astmodulestate(module)->Raise_type);
349 Py_CLEAR(astmodulestate(module)->Return_type);
350 Py_CLEAR(astmodulestate(module)->SetComp_type);
351 Py_CLEAR(astmodulestate(module)->Set_type);
352 Py_CLEAR(astmodulestate(module)->Slice_type);
353 Py_CLEAR(astmodulestate(module)->Starred_type);
354 Py_CLEAR(astmodulestate(module)->Store_singleton);
355 Py_CLEAR(astmodulestate(module)->Store_type);
356 Py_CLEAR(astmodulestate(module)->Sub_singleton);
357 Py_CLEAR(astmodulestate(module)->Sub_type);
358 Py_CLEAR(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700359 Py_CLEAR(astmodulestate(module)->Try_type);
360 Py_CLEAR(astmodulestate(module)->Tuple_type);
361 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
362 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
363 Py_CLEAR(astmodulestate(module)->UAdd_type);
364 Py_CLEAR(astmodulestate(module)->USub_singleton);
365 Py_CLEAR(astmodulestate(module)->USub_type);
366 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
367 Py_CLEAR(astmodulestate(module)->While_type);
368 Py_CLEAR(astmodulestate(module)->With_type);
369 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
370 Py_CLEAR(astmodulestate(module)->Yield_type);
371 Py_CLEAR(astmodulestate(module)->__dict__);
372 Py_CLEAR(astmodulestate(module)->__module__);
373 Py_CLEAR(astmodulestate(module)->_ast);
374 Py_CLEAR(astmodulestate(module)->_attributes);
375 Py_CLEAR(astmodulestate(module)->_fields);
376 Py_CLEAR(astmodulestate(module)->alias_type);
377 Py_CLEAR(astmodulestate(module)->annotation);
378 Py_CLEAR(astmodulestate(module)->arg);
379 Py_CLEAR(astmodulestate(module)->arg_type);
380 Py_CLEAR(astmodulestate(module)->args);
381 Py_CLEAR(astmodulestate(module)->argtypes);
382 Py_CLEAR(astmodulestate(module)->arguments_type);
383 Py_CLEAR(astmodulestate(module)->asname);
384 Py_CLEAR(astmodulestate(module)->attr);
385 Py_CLEAR(astmodulestate(module)->bases);
386 Py_CLEAR(astmodulestate(module)->body);
387 Py_CLEAR(astmodulestate(module)->boolop_type);
388 Py_CLEAR(astmodulestate(module)->cause);
389 Py_CLEAR(astmodulestate(module)->cmpop_type);
390 Py_CLEAR(astmodulestate(module)->col_offset);
391 Py_CLEAR(astmodulestate(module)->comparators);
392 Py_CLEAR(astmodulestate(module)->comprehension_type);
393 Py_CLEAR(astmodulestate(module)->context_expr);
394 Py_CLEAR(astmodulestate(module)->conversion);
395 Py_CLEAR(astmodulestate(module)->ctx);
396 Py_CLEAR(astmodulestate(module)->decorator_list);
397 Py_CLEAR(astmodulestate(module)->defaults);
398 Py_CLEAR(astmodulestate(module)->dims);
399 Py_CLEAR(astmodulestate(module)->elt);
400 Py_CLEAR(astmodulestate(module)->elts);
401 Py_CLEAR(astmodulestate(module)->end_col_offset);
402 Py_CLEAR(astmodulestate(module)->end_lineno);
403 Py_CLEAR(astmodulestate(module)->exc);
404 Py_CLEAR(astmodulestate(module)->excepthandler_type);
405 Py_CLEAR(astmodulestate(module)->expr_context_type);
406 Py_CLEAR(astmodulestate(module)->expr_type);
407 Py_CLEAR(astmodulestate(module)->finalbody);
408 Py_CLEAR(astmodulestate(module)->format_spec);
409 Py_CLEAR(astmodulestate(module)->func);
410 Py_CLEAR(astmodulestate(module)->generators);
411 Py_CLEAR(astmodulestate(module)->handlers);
412 Py_CLEAR(astmodulestate(module)->id);
413 Py_CLEAR(astmodulestate(module)->ifs);
414 Py_CLEAR(astmodulestate(module)->is_async);
415 Py_CLEAR(astmodulestate(module)->items);
416 Py_CLEAR(astmodulestate(module)->iter);
417 Py_CLEAR(astmodulestate(module)->key);
418 Py_CLEAR(astmodulestate(module)->keys);
419 Py_CLEAR(astmodulestate(module)->keyword_type);
420 Py_CLEAR(astmodulestate(module)->keywords);
421 Py_CLEAR(astmodulestate(module)->kind);
422 Py_CLEAR(astmodulestate(module)->kw_defaults);
423 Py_CLEAR(astmodulestate(module)->kwarg);
424 Py_CLEAR(astmodulestate(module)->kwonlyargs);
425 Py_CLEAR(astmodulestate(module)->left);
426 Py_CLEAR(astmodulestate(module)->level);
427 Py_CLEAR(astmodulestate(module)->lineno);
428 Py_CLEAR(astmodulestate(module)->lower);
429 Py_CLEAR(astmodulestate(module)->mod_type);
430 Py_CLEAR(astmodulestate(module)->module);
431 Py_CLEAR(astmodulestate(module)->msg);
432 Py_CLEAR(astmodulestate(module)->name);
433 Py_CLEAR(astmodulestate(module)->names);
434 Py_CLEAR(astmodulestate(module)->op);
435 Py_CLEAR(astmodulestate(module)->operand);
436 Py_CLEAR(astmodulestate(module)->operator_type);
437 Py_CLEAR(astmodulestate(module)->ops);
438 Py_CLEAR(astmodulestate(module)->optional_vars);
439 Py_CLEAR(astmodulestate(module)->orelse);
440 Py_CLEAR(astmodulestate(module)->posonlyargs);
441 Py_CLEAR(astmodulestate(module)->returns);
442 Py_CLEAR(astmodulestate(module)->right);
443 Py_CLEAR(astmodulestate(module)->simple);
444 Py_CLEAR(astmodulestate(module)->slice);
445 Py_CLEAR(astmodulestate(module)->slice_type);
446 Py_CLEAR(astmodulestate(module)->step);
447 Py_CLEAR(astmodulestate(module)->stmt_type);
448 Py_CLEAR(astmodulestate(module)->tag);
449 Py_CLEAR(astmodulestate(module)->target);
450 Py_CLEAR(astmodulestate(module)->targets);
451 Py_CLEAR(astmodulestate(module)->test);
452 Py_CLEAR(astmodulestate(module)->type);
453 Py_CLEAR(astmodulestate(module)->type_comment);
454 Py_CLEAR(astmodulestate(module)->type_ignore_type);
455 Py_CLEAR(astmodulestate(module)->type_ignores);
456 Py_CLEAR(astmodulestate(module)->unaryop_type);
457 Py_CLEAR(astmodulestate(module)->upper);
458 Py_CLEAR(astmodulestate(module)->value);
459 Py_CLEAR(astmodulestate(module)->values);
460 Py_CLEAR(astmodulestate(module)->vararg);
461 Py_CLEAR(astmodulestate(module)->withitem_type);
462
463 return 0;
464}
465
466static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
467{
468 Py_VISIT(astmodulestate(module)->AST_type);
469 Py_VISIT(astmodulestate(module)->Add_singleton);
470 Py_VISIT(astmodulestate(module)->Add_type);
471 Py_VISIT(astmodulestate(module)->And_singleton);
472 Py_VISIT(astmodulestate(module)->And_type);
473 Py_VISIT(astmodulestate(module)->AnnAssign_type);
474 Py_VISIT(astmodulestate(module)->Assert_type);
475 Py_VISIT(astmodulestate(module)->Assign_type);
476 Py_VISIT(astmodulestate(module)->AsyncFor_type);
477 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
478 Py_VISIT(astmodulestate(module)->AsyncWith_type);
479 Py_VISIT(astmodulestate(module)->Attribute_type);
480 Py_VISIT(astmodulestate(module)->AugAssign_type);
481 Py_VISIT(astmodulestate(module)->AugLoad_singleton);
482 Py_VISIT(astmodulestate(module)->AugLoad_type);
483 Py_VISIT(astmodulestate(module)->AugStore_singleton);
484 Py_VISIT(astmodulestate(module)->AugStore_type);
485 Py_VISIT(astmodulestate(module)->Await_type);
486 Py_VISIT(astmodulestate(module)->BinOp_type);
487 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
488 Py_VISIT(astmodulestate(module)->BitAnd_type);
489 Py_VISIT(astmodulestate(module)->BitOr_singleton);
490 Py_VISIT(astmodulestate(module)->BitOr_type);
491 Py_VISIT(astmodulestate(module)->BitXor_singleton);
492 Py_VISIT(astmodulestate(module)->BitXor_type);
493 Py_VISIT(astmodulestate(module)->BoolOp_type);
494 Py_VISIT(astmodulestate(module)->Break_type);
495 Py_VISIT(astmodulestate(module)->Call_type);
496 Py_VISIT(astmodulestate(module)->ClassDef_type);
497 Py_VISIT(astmodulestate(module)->Compare_type);
498 Py_VISIT(astmodulestate(module)->Constant_type);
499 Py_VISIT(astmodulestate(module)->Continue_type);
500 Py_VISIT(astmodulestate(module)->Del_singleton);
501 Py_VISIT(astmodulestate(module)->Del_type);
502 Py_VISIT(astmodulestate(module)->Delete_type);
503 Py_VISIT(astmodulestate(module)->DictComp_type);
504 Py_VISIT(astmodulestate(module)->Dict_type);
505 Py_VISIT(astmodulestate(module)->Div_singleton);
506 Py_VISIT(astmodulestate(module)->Div_type);
507 Py_VISIT(astmodulestate(module)->Eq_singleton);
508 Py_VISIT(astmodulestate(module)->Eq_type);
509 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
510 Py_VISIT(astmodulestate(module)->Expr_type);
511 Py_VISIT(astmodulestate(module)->Expression_type);
512 Py_VISIT(astmodulestate(module)->ExtSlice_type);
513 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
514 Py_VISIT(astmodulestate(module)->FloorDiv_type);
515 Py_VISIT(astmodulestate(module)->For_type);
516 Py_VISIT(astmodulestate(module)->FormattedValue_type);
517 Py_VISIT(astmodulestate(module)->FunctionDef_type);
518 Py_VISIT(astmodulestate(module)->FunctionType_type);
519 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
520 Py_VISIT(astmodulestate(module)->Global_type);
521 Py_VISIT(astmodulestate(module)->GtE_singleton);
522 Py_VISIT(astmodulestate(module)->GtE_type);
523 Py_VISIT(astmodulestate(module)->Gt_singleton);
524 Py_VISIT(astmodulestate(module)->Gt_type);
525 Py_VISIT(astmodulestate(module)->IfExp_type);
526 Py_VISIT(astmodulestate(module)->If_type);
527 Py_VISIT(astmodulestate(module)->ImportFrom_type);
528 Py_VISIT(astmodulestate(module)->Import_type);
529 Py_VISIT(astmodulestate(module)->In_singleton);
530 Py_VISIT(astmodulestate(module)->In_type);
531 Py_VISIT(astmodulestate(module)->Index_type);
532 Py_VISIT(astmodulestate(module)->Interactive_type);
533 Py_VISIT(astmodulestate(module)->Invert_singleton);
534 Py_VISIT(astmodulestate(module)->Invert_type);
535 Py_VISIT(astmodulestate(module)->IsNot_singleton);
536 Py_VISIT(astmodulestate(module)->IsNot_type);
537 Py_VISIT(astmodulestate(module)->Is_singleton);
538 Py_VISIT(astmodulestate(module)->Is_type);
539 Py_VISIT(astmodulestate(module)->JoinedStr_type);
540 Py_VISIT(astmodulestate(module)->LShift_singleton);
541 Py_VISIT(astmodulestate(module)->LShift_type);
542 Py_VISIT(astmodulestate(module)->Lambda_type);
543 Py_VISIT(astmodulestate(module)->ListComp_type);
544 Py_VISIT(astmodulestate(module)->List_type);
545 Py_VISIT(astmodulestate(module)->Load_singleton);
546 Py_VISIT(astmodulestate(module)->Load_type);
547 Py_VISIT(astmodulestate(module)->LtE_singleton);
548 Py_VISIT(astmodulestate(module)->LtE_type);
549 Py_VISIT(astmodulestate(module)->Lt_singleton);
550 Py_VISIT(astmodulestate(module)->Lt_type);
551 Py_VISIT(astmodulestate(module)->MatMult_singleton);
552 Py_VISIT(astmodulestate(module)->MatMult_type);
553 Py_VISIT(astmodulestate(module)->Mod_singleton);
554 Py_VISIT(astmodulestate(module)->Mod_type);
555 Py_VISIT(astmodulestate(module)->Module_type);
556 Py_VISIT(astmodulestate(module)->Mult_singleton);
557 Py_VISIT(astmodulestate(module)->Mult_type);
558 Py_VISIT(astmodulestate(module)->Name_type);
559 Py_VISIT(astmodulestate(module)->NamedExpr_type);
560 Py_VISIT(astmodulestate(module)->Nonlocal_type);
561 Py_VISIT(astmodulestate(module)->NotEq_singleton);
562 Py_VISIT(astmodulestate(module)->NotEq_type);
563 Py_VISIT(astmodulestate(module)->NotIn_singleton);
564 Py_VISIT(astmodulestate(module)->NotIn_type);
565 Py_VISIT(astmodulestate(module)->Not_singleton);
566 Py_VISIT(astmodulestate(module)->Not_type);
567 Py_VISIT(astmodulestate(module)->Or_singleton);
568 Py_VISIT(astmodulestate(module)->Or_type);
569 Py_VISIT(astmodulestate(module)->Param_singleton);
570 Py_VISIT(astmodulestate(module)->Param_type);
571 Py_VISIT(astmodulestate(module)->Pass_type);
572 Py_VISIT(astmodulestate(module)->Pow_singleton);
573 Py_VISIT(astmodulestate(module)->Pow_type);
574 Py_VISIT(astmodulestate(module)->RShift_singleton);
575 Py_VISIT(astmodulestate(module)->RShift_type);
576 Py_VISIT(astmodulestate(module)->Raise_type);
577 Py_VISIT(astmodulestate(module)->Return_type);
578 Py_VISIT(astmodulestate(module)->SetComp_type);
579 Py_VISIT(astmodulestate(module)->Set_type);
580 Py_VISIT(astmodulestate(module)->Slice_type);
581 Py_VISIT(astmodulestate(module)->Starred_type);
582 Py_VISIT(astmodulestate(module)->Store_singleton);
583 Py_VISIT(astmodulestate(module)->Store_type);
584 Py_VISIT(astmodulestate(module)->Sub_singleton);
585 Py_VISIT(astmodulestate(module)->Sub_type);
586 Py_VISIT(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700587 Py_VISIT(astmodulestate(module)->Try_type);
588 Py_VISIT(astmodulestate(module)->Tuple_type);
589 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
590 Py_VISIT(astmodulestate(module)->UAdd_singleton);
591 Py_VISIT(astmodulestate(module)->UAdd_type);
592 Py_VISIT(astmodulestate(module)->USub_singleton);
593 Py_VISIT(astmodulestate(module)->USub_type);
594 Py_VISIT(astmodulestate(module)->UnaryOp_type);
595 Py_VISIT(astmodulestate(module)->While_type);
596 Py_VISIT(astmodulestate(module)->With_type);
597 Py_VISIT(astmodulestate(module)->YieldFrom_type);
598 Py_VISIT(astmodulestate(module)->Yield_type);
599 Py_VISIT(astmodulestate(module)->__dict__);
600 Py_VISIT(astmodulestate(module)->__module__);
601 Py_VISIT(astmodulestate(module)->_ast);
602 Py_VISIT(astmodulestate(module)->_attributes);
603 Py_VISIT(astmodulestate(module)->_fields);
604 Py_VISIT(astmodulestate(module)->alias_type);
605 Py_VISIT(astmodulestate(module)->annotation);
606 Py_VISIT(astmodulestate(module)->arg);
607 Py_VISIT(astmodulestate(module)->arg_type);
608 Py_VISIT(astmodulestate(module)->args);
609 Py_VISIT(astmodulestate(module)->argtypes);
610 Py_VISIT(astmodulestate(module)->arguments_type);
611 Py_VISIT(astmodulestate(module)->asname);
612 Py_VISIT(astmodulestate(module)->attr);
613 Py_VISIT(astmodulestate(module)->bases);
614 Py_VISIT(astmodulestate(module)->body);
615 Py_VISIT(astmodulestate(module)->boolop_type);
616 Py_VISIT(astmodulestate(module)->cause);
617 Py_VISIT(astmodulestate(module)->cmpop_type);
618 Py_VISIT(astmodulestate(module)->col_offset);
619 Py_VISIT(astmodulestate(module)->comparators);
620 Py_VISIT(astmodulestate(module)->comprehension_type);
621 Py_VISIT(astmodulestate(module)->context_expr);
622 Py_VISIT(astmodulestate(module)->conversion);
623 Py_VISIT(astmodulestate(module)->ctx);
624 Py_VISIT(astmodulestate(module)->decorator_list);
625 Py_VISIT(astmodulestate(module)->defaults);
626 Py_VISIT(astmodulestate(module)->dims);
627 Py_VISIT(astmodulestate(module)->elt);
628 Py_VISIT(astmodulestate(module)->elts);
629 Py_VISIT(astmodulestate(module)->end_col_offset);
630 Py_VISIT(astmodulestate(module)->end_lineno);
631 Py_VISIT(astmodulestate(module)->exc);
632 Py_VISIT(astmodulestate(module)->excepthandler_type);
633 Py_VISIT(astmodulestate(module)->expr_context_type);
634 Py_VISIT(astmodulestate(module)->expr_type);
635 Py_VISIT(astmodulestate(module)->finalbody);
636 Py_VISIT(astmodulestate(module)->format_spec);
637 Py_VISIT(astmodulestate(module)->func);
638 Py_VISIT(astmodulestate(module)->generators);
639 Py_VISIT(astmodulestate(module)->handlers);
640 Py_VISIT(astmodulestate(module)->id);
641 Py_VISIT(astmodulestate(module)->ifs);
642 Py_VISIT(astmodulestate(module)->is_async);
643 Py_VISIT(astmodulestate(module)->items);
644 Py_VISIT(astmodulestate(module)->iter);
645 Py_VISIT(astmodulestate(module)->key);
646 Py_VISIT(astmodulestate(module)->keys);
647 Py_VISIT(astmodulestate(module)->keyword_type);
648 Py_VISIT(astmodulestate(module)->keywords);
649 Py_VISIT(astmodulestate(module)->kind);
650 Py_VISIT(astmodulestate(module)->kw_defaults);
651 Py_VISIT(astmodulestate(module)->kwarg);
652 Py_VISIT(astmodulestate(module)->kwonlyargs);
653 Py_VISIT(astmodulestate(module)->left);
654 Py_VISIT(astmodulestate(module)->level);
655 Py_VISIT(astmodulestate(module)->lineno);
656 Py_VISIT(astmodulestate(module)->lower);
657 Py_VISIT(astmodulestate(module)->mod_type);
658 Py_VISIT(astmodulestate(module)->module);
659 Py_VISIT(astmodulestate(module)->msg);
660 Py_VISIT(astmodulestate(module)->name);
661 Py_VISIT(astmodulestate(module)->names);
662 Py_VISIT(astmodulestate(module)->op);
663 Py_VISIT(astmodulestate(module)->operand);
664 Py_VISIT(astmodulestate(module)->operator_type);
665 Py_VISIT(astmodulestate(module)->ops);
666 Py_VISIT(astmodulestate(module)->optional_vars);
667 Py_VISIT(astmodulestate(module)->orelse);
668 Py_VISIT(astmodulestate(module)->posonlyargs);
669 Py_VISIT(astmodulestate(module)->returns);
670 Py_VISIT(astmodulestate(module)->right);
671 Py_VISIT(astmodulestate(module)->simple);
672 Py_VISIT(astmodulestate(module)->slice);
673 Py_VISIT(astmodulestate(module)->slice_type);
674 Py_VISIT(astmodulestate(module)->step);
675 Py_VISIT(astmodulestate(module)->stmt_type);
676 Py_VISIT(astmodulestate(module)->tag);
677 Py_VISIT(astmodulestate(module)->target);
678 Py_VISIT(astmodulestate(module)->targets);
679 Py_VISIT(astmodulestate(module)->test);
680 Py_VISIT(astmodulestate(module)->type);
681 Py_VISIT(astmodulestate(module)->type_comment);
682 Py_VISIT(astmodulestate(module)->type_ignore_type);
683 Py_VISIT(astmodulestate(module)->type_ignores);
684 Py_VISIT(astmodulestate(module)->unaryop_type);
685 Py_VISIT(astmodulestate(module)->upper);
686 Py_VISIT(astmodulestate(module)->value);
687 Py_VISIT(astmodulestate(module)->values);
688 Py_VISIT(astmodulestate(module)->vararg);
689 Py_VISIT(astmodulestate(module)->withitem_type);
690
691 return 0;
692}
693
694static void astmodule_free(void* module) {
695 astmodule_clear((PyObject*)module);
696}
697
698static struct PyModuleDef _astmodule = {
699 PyModuleDef_HEAD_INIT,
700 "_ast",
701 NULL,
702 sizeof(astmodulestate),
703 NULL,
704 NULL,
705 astmodule_traverse,
706 astmodule_clear,
707 astmodule_free,
708};
709
710#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
711
712static int init_identifiers(void)
713{
714 astmodulestate *state = astmodulestate_global;
715 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
716 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
717 if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0;
718 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
719 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
720 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
721 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
722 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
723 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
724 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
725 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
726 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
727 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
728 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
729 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
730 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
731 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
732 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
733 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
734 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
735 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
736 if ((state->dims = PyUnicode_InternFromString("dims")) == NULL) return 0;
737 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
738 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
739 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
740 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
741 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
742 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
743 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
744 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
745 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
746 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
747 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
748 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
749 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
750 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
751 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
752 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
753 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
754 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
755 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
756 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
757 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
758 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
759 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
760 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
761 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
762 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
763 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
764 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
765 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
766 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
767 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
768 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
769 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
770 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
771 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
772 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
773 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
774 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
775 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
776 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
777 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
778 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
779 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
780 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
781 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
782 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
783 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
784 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
785 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
786 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
787 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
788 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
789 return 1;
790};
791
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000792static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300793static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200794 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800795 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000796};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300797static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200798 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000799};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300800static const char * const Expression_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 FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800804 "argtypes",
805 "returns",
806};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300807static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200808 "lineno",
809 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000810 "end_lineno",
811 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000812};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000813static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300814static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200815 "name",
816 "args",
817 "body",
818 "decorator_list",
819 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800820 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000821};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300822static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400823 "name",
824 "args",
825 "body",
826 "decorator_list",
827 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800828 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400829};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300830static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200831 "name",
832 "bases",
833 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200834 "body",
835 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000836};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300837static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200838 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000839};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300840static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200841 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000842};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300843static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200844 "targets",
845 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800846 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000847};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300848static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200849 "target",
850 "op",
851 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000852};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300853static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700854 "target",
855 "annotation",
856 "value",
857 "simple",
858};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300859static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200860 "target",
861 "iter",
862 "body",
863 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800864 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000865};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300866static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400867 "target",
868 "iter",
869 "body",
870 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800871 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400872};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300873static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200874 "test",
875 "body",
876 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000877};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300878static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200879 "test",
880 "body",
881 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000882};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300883static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200884 "items",
885 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800886 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000887};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300888static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400889 "items",
890 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800891 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400892};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300893static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200894 "exc",
895 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000896};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300897static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200898 "body",
899 "handlers",
900 "orelse",
901 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000902};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300903static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200904 "test",
905 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000906};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300907static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200908 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000909};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300910static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200911 "module",
912 "names",
913 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000914};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300915static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200916 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000917};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300918static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200919 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000920};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300921static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200922 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000923};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300924static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200925 "lineno",
926 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000927 "end_lineno",
928 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000929};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000930static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300931static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200932 "op",
933 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000934};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300935static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700936 "target",
937 "value",
938};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300939static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200940 "left",
941 "op",
942 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000943};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300944static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200945 "op",
946 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000947};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300948static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200949 "args",
950 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000951};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300952static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200953 "test",
954 "body",
955 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000956};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300957static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200958 "keys",
959 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000960};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300961static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200962 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000963};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300964static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200965 "elt",
966 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000967};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300968static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200969 "elt",
970 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000971};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300972static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200973 "key",
974 "value",
975 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000976};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300977static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200978 "elt",
979 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000980};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300981static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400982 "value",
983};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300984static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200985 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500986};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300987static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200988 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000989};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300990static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200991 "left",
992 "ops",
993 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000994};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300995static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200996 "func",
997 "args",
998 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000999};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001000static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -04001001 "value",
1002 "conversion",
1003 "format_spec",
1004};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001005static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -04001006 "values",
1007};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001008static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001009 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -07001010 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001011};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001012static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001013 "value",
1014 "attr",
1015 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001016};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001017static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001018 "value",
1019 "slice",
1020 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001021};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001022static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001023 "value",
1024 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +00001025};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001026static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001027 "id",
1028 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001029};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001030static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001031 "elts",
1032 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001033};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001034static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001035 "elts",
1036 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001037};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001038static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001039static PyObject* ast2obj_slice(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001040static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001041 "lower",
1042 "upper",
1043 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001044};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001045static const char * const ExtSlice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001046 "dims",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001047};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001048static const char * const Index_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001049 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001050};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001051static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001052static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001053static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001054static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001055static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001056static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001057 "target",
1058 "iter",
1059 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001060 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001061};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001062static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001063 "lineno",
1064 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001065 "end_lineno",
1066 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001067};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001068static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001069static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001070 "type",
1071 "name",
1072 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001073};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001074static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001075static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001076 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001077 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001078 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001079 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001080 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001081 "kwarg",
1082 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001083};
Neal Norwitzc1505362006-12-28 06:47:50 +00001084static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001085static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001086 "lineno",
1087 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001088 "end_lineno",
1089 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001090};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001091static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001092 "arg",
1093 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001094 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001095};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001096static PyObject* ast2obj_keyword(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001097static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001098 "arg",
1099 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001100};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001101static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001102static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001103 "name",
1104 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001105};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001106static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001107static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001108 "context_expr",
1109 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001110};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001111static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001112static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001113 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001114 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001115};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001116
1117
INADA Naokifc489082017-01-25 22:33:43 +09001118
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001119typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001120 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001121 PyObject *dict;
1122} AST_object;
1123
Benjamin Peterson1767e022012-03-14 21:50:29 -05001124static void
1125ast_dealloc(AST_object *self)
1126{
INADA Naokia6296d32017-08-24 14:55:17 +09001127 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001128 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001129 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001130 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001131 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1132 assert(free_func != NULL);
1133 free_func(self);
1134 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001135}
1136
Neal Norwitz207c9f32008-03-31 04:42:11 +00001137static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001138ast_traverse(AST_object *self, visitproc visit, void *arg)
1139{
1140 Py_VISIT(self->dict);
1141 return 0;
1142}
1143
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001144static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001145ast_clear(AST_object *self)
1146{
1147 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001148 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001149}
1150
1151static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001152ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1153{
1154 Py_ssize_t i, numfields = 0;
1155 int res = -1;
1156 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001157 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001158 goto cleanup;
1159 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001160 if (fields) {
1161 numfields = PySequence_Size(fields);
1162 if (numfields == -1)
1163 goto cleanup;
1164 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001165
Neal Norwitz207c9f32008-03-31 04:42:11 +00001166 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001167 if (numfields < PyTuple_GET_SIZE(args)) {
1168 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1169 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001170 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001171 numfields, numfields == 1 ? "" : "s");
1172 res = -1;
1173 goto cleanup;
1174 }
1175 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1176 /* cannot be reached when fields is NULL */
1177 PyObject *name = PySequence_GetItem(fields, i);
1178 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001179 res = -1;
1180 goto cleanup;
1181 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001182 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1183 Py_DECREF(name);
1184 if (res < 0)
1185 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001186 }
1187 if (kw) {
1188 i = 0; /* needed by PyDict_Next */
1189 while (PyDict_Next(kw, &i, &key, &value)) {
1190 res = PyObject_SetAttr(self, key, value);
1191 if (res < 0)
1192 goto cleanup;
1193 }
1194 }
1195 cleanup:
1196 Py_XDECREF(fields);
1197 return res;
1198}
1199
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001200/* Pickling support */
1201static PyObject *
1202ast_type_reduce(PyObject *self, PyObject *unused)
1203{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001204 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001205 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001206 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001207 }
1208 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001209 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001210 }
1211 return Py_BuildValue("O()", Py_TYPE(self));
1212}
1213
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001214static PyMemberDef ast_type_members[] = {
1215 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1216 {NULL} /* Sentinel */
1217};
1218
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001219static PyMethodDef ast_type_methods[] = {
1220 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1221 {NULL}
1222};
1223
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001224static PyGetSetDef ast_type_getsets[] = {
1225 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1226 {NULL}
1227};
1228
Dino Viehlandac46eb42019-09-11 10:16:34 -07001229static PyType_Slot AST_type_slots[] = {
1230 {Py_tp_dealloc, ast_dealloc},
1231 {Py_tp_getattro, PyObject_GenericGetAttr},
1232 {Py_tp_setattro, PyObject_GenericSetAttr},
1233 {Py_tp_traverse, ast_traverse},
1234 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001235 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001236 {Py_tp_methods, ast_type_methods},
1237 {Py_tp_getset, ast_type_getsets},
1238 {Py_tp_init, ast_type_init},
1239 {Py_tp_alloc, PyType_GenericAlloc},
1240 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001241 {Py_tp_free, PyObject_GC_Del},
1242 {0, 0},
1243};
1244
1245static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001246 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001247 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001248 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001249 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1250 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001251};
1252
Dino Viehlandac46eb42019-09-11 10:16:34 -07001253static PyObject *
1254make_type(const char *type, PyObject* base, const char* const* fields, int num_fields)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001255{
1256 PyObject *fnames, *result;
1257 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001258 fnames = PyTuple_New(num_fields);
1259 if (!fnames) return NULL;
1260 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001261 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001262 if (!field) {
1263 Py_DECREF(fnames);
1264 return NULL;
1265 }
1266 PyTuple_SET_ITEM(fnames, i, field);
1267 }
INADA Naokifc489082017-01-25 22:33:43 +09001268 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOO}",
1269 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001270 astmodulestate_global->_fields, fnames,
1271 astmodulestate_global->__module__,
1272 astmodulestate_global->_ast);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001273 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001274 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001275}
1276
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001277static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001278add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001279{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001280 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001281 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001282 if (!l)
1283 return 0;
1284 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001285 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001286 if (!s) {
1287 Py_DECREF(l);
1288 return 0;
1289 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001290 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001292 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001293 Py_DECREF(l);
1294 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001295}
1296
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001297/* Conversion AST -> Python */
1298
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001299static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1300{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001301 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001302 PyObject *result = PyList_New(n);
1303 PyObject *value;
1304 if (!result)
1305 return NULL;
1306 for (i = 0; i < n; i++) {
1307 value = func(asdl_seq_GET(seq, i));
1308 if (!value) {
1309 Py_DECREF(result);
1310 return NULL;
1311 }
1312 PyList_SET_ITEM(result, i, value);
1313 }
1314 return result;
1315}
1316
1317static PyObject* ast2obj_object(void *o)
1318{
1319 if (!o)
1320 o = Py_None;
1321 Py_INCREF((PyObject*)o);
1322 return (PyObject*)o;
1323}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001324#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001325#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001326#define ast2obj_identifier ast2obj_object
1327#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001328#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001329
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001330static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001331{
Christian Heimes217cfd12007-12-02 14:31:20 +00001332 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001333}
1334
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001335/* Conversion Python -> AST */
1336
1337static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1338{
1339 if (obj == Py_None)
1340 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001341 if (obj) {
1342 if (PyArena_AddPyObject(arena, obj) < 0) {
1343 *out = NULL;
1344 return -1;
1345 }
1346 Py_INCREF(obj);
1347 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001348 *out = obj;
1349 return 0;
1350}
1351
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001352static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1353{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001354 if (PyArena_AddPyObject(arena, obj) < 0) {
1355 *out = NULL;
1356 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001357 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001358 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001359 *out = obj;
1360 return 0;
1361}
1362
Benjamin Peterson180e6352011-07-22 11:09:07 -05001363static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001364{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001365 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1366 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001367 return 1;
1368 }
1369 return obj2ast_object(obj, out, arena);
1370}
1371
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001372static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1373{
1374 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1375 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1376 return 1;
1377 }
1378 return obj2ast_object(obj, out, arena);
1379}
1380
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001381static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1382{
1383 int i;
1384 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001385 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001386 return 1;
1387 }
1388
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001389 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001390 if (i == -1 && PyErr_Occurred())
1391 return 1;
1392 *out = i;
1393 return 0;
1394}
1395
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001396static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001397{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001398 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001399 empty_tuple = PyTuple_New(0);
1400 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001401 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1402 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001403 Py_XDECREF(empty_tuple);
1404 return -1;
1405 }
1406 Py_DECREF(empty_tuple);
1407 return 0;
1408}
1409
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001410
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001411static int init_types(void)
1412{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001413 PyObject *m;
1414 if (PyState_FindModule(&_astmodule) == NULL) {
1415 m = PyModule_Create(&_astmodule);
1416 if (!m) return 0;
1417 PyState_AddModule(m, &_astmodule);
1418 }
1419 astmodulestate *state = astmodulestate_global;
1420 if (state->initialized) return 1;
1421 if (init_identifiers() < 0) return 0;
1422 state->AST_type = PyType_FromSpec(&AST_type_spec);
1423 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001424 if (add_ast_fields() < 0) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001425 state->mod_type = make_type("mod", state->AST_type, NULL, 0);
1426 if (!state->mod_type) return 0;
1427 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
1428 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2);
1429 if (!state->Module_type) return 0;
1430 state->Interactive_type = make_type("Interactive", state->mod_type,
1431 Interactive_fields, 1);
1432 if (!state->Interactive_type) return 0;
1433 state->Expression_type = make_type("Expression", state->mod_type,
1434 Expression_fields, 1);
1435 if (!state->Expression_type) return 0;
1436 state->FunctionType_type = make_type("FunctionType", state->mod_type,
1437 FunctionType_fields, 2);
1438 if (!state->FunctionType_type) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001439 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0);
1440 if (!state->stmt_type) return 0;
1441 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
1442 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1443 FunctionDef_fields, 6);
1444 if (!state->FunctionDef_type) return 0;
1445 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1446 state->stmt_type,
1447 AsyncFunctionDef_fields, 6);
1448 if (!state->AsyncFunctionDef_type) return 0;
1449 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1450 ClassDef_fields, 5);
1451 if (!state->ClassDef_type) return 0;
1452 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1453 1);
1454 if (!state->Return_type) return 0;
1455 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1456 1);
1457 if (!state->Delete_type) return 0;
1458 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1459 3);
1460 if (!state->Assign_type) return 0;
1461 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1462 AugAssign_fields, 3);
1463 if (!state->AugAssign_type) return 0;
1464 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1465 AnnAssign_fields, 4);
1466 if (!state->AnnAssign_type) return 0;
1467 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1468 if (!state->For_type) return 0;
1469 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1470 AsyncFor_fields, 5);
1471 if (!state->AsyncFor_type) return 0;
1472 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1473 if (!state->While_type) return 0;
1474 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1475 if (!state->If_type) return 0;
1476 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1477 if (!state->With_type) return 0;
1478 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1479 AsyncWith_fields, 3);
1480 if (!state->AsyncWith_type) return 0;
1481 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1482 if (!state->Raise_type) return 0;
1483 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1484 if (!state->Try_type) return 0;
1485 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1486 2);
1487 if (!state->Assert_type) return 0;
1488 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1489 1);
1490 if (!state->Import_type) return 0;
1491 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1492 ImportFrom_fields, 3);
1493 if (!state->ImportFrom_type) return 0;
1494 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1495 1);
1496 if (!state->Global_type) return 0;
1497 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1498 Nonlocal_fields, 1);
1499 if (!state->Nonlocal_type) return 0;
1500 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1501 if (!state->Expr_type) return 0;
1502 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1503 if (!state->Pass_type) return 0;
1504 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1505 if (!state->Break_type) return 0;
1506 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1507 if (!state->Continue_type) return 0;
1508 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1509 if (!state->expr_type) return 0;
1510 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
1511 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1512 2);
1513 if (!state->BoolOp_type) return 0;
1514 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1515 NamedExpr_fields, 2);
1516 if (!state->NamedExpr_type) return 0;
1517 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1518 if (!state->BinOp_type) return 0;
1519 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1520 UnaryOp_fields, 2);
1521 if (!state->UnaryOp_type) return 0;
1522 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1523 2);
1524 if (!state->Lambda_type) return 0;
1525 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1526 if (!state->IfExp_type) return 0;
1527 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1528 if (!state->Dict_type) return 0;
1529 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1530 if (!state->Set_type) return 0;
1531 state->ListComp_type = make_type("ListComp", state->expr_type,
1532 ListComp_fields, 2);
1533 if (!state->ListComp_type) return 0;
1534 state->SetComp_type = make_type("SetComp", state->expr_type,
1535 SetComp_fields, 2);
1536 if (!state->SetComp_type) return 0;
1537 state->DictComp_type = make_type("DictComp", state->expr_type,
1538 DictComp_fields, 3);
1539 if (!state->DictComp_type) return 0;
1540 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1541 GeneratorExp_fields, 2);
1542 if (!state->GeneratorExp_type) return 0;
1543 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1544 if (!state->Await_type) return 0;
1545 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1546 if (!state->Yield_type) return 0;
1547 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1548 YieldFrom_fields, 1);
1549 if (!state->YieldFrom_type) return 0;
1550 state->Compare_type = make_type("Compare", state->expr_type,
1551 Compare_fields, 3);
1552 if (!state->Compare_type) return 0;
1553 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1554 if (!state->Call_type) return 0;
1555 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1556 FormattedValue_fields, 3);
1557 if (!state->FormattedValue_type) return 0;
1558 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1559 JoinedStr_fields, 1);
1560 if (!state->JoinedStr_type) return 0;
1561 state->Constant_type = make_type("Constant", state->expr_type,
1562 Constant_fields, 2);
1563 if (!state->Constant_type) return 0;
1564 state->Attribute_type = make_type("Attribute", state->expr_type,
1565 Attribute_fields, 3);
1566 if (!state->Attribute_type) return 0;
1567 state->Subscript_type = make_type("Subscript", state->expr_type,
1568 Subscript_fields, 3);
1569 if (!state->Subscript_type) return 0;
1570 state->Starred_type = make_type("Starred", state->expr_type,
1571 Starred_fields, 2);
1572 if (!state->Starred_type) return 0;
1573 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1574 if (!state->Name_type) return 0;
1575 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1576 if (!state->List_type) return 0;
1577 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1578 if (!state->Tuple_type) return 0;
1579 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1580 0);
1581 if (!state->expr_context_type) return 0;
1582 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1583 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1584 if (!state->Load_type) return 0;
1585 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1586 NULL, NULL);
1587 if (!state->Load_singleton) return 0;
1588 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1589 if (!state->Store_type) return 0;
1590 state->Store_singleton = PyType_GenericNew((PyTypeObject
1591 *)state->Store_type, NULL, NULL);
1592 if (!state->Store_singleton) return 0;
1593 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1594 if (!state->Del_type) return 0;
1595 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1596 NULL, NULL);
1597 if (!state->Del_singleton) return 0;
1598 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1599 0);
1600 if (!state->AugLoad_type) return 0;
1601 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1602 *)state->AugLoad_type, NULL,
1603 NULL);
1604 if (!state->AugLoad_singleton) return 0;
1605 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1606 NULL, 0);
1607 if (!state->AugStore_type) return 0;
1608 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1609 *)state->AugStore_type, NULL,
1610 NULL);
1611 if (!state->AugStore_singleton) return 0;
1612 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1613 if (!state->Param_type) return 0;
1614 state->Param_singleton = PyType_GenericNew((PyTypeObject
1615 *)state->Param_type, NULL, NULL);
1616 if (!state->Param_singleton) return 0;
1617 state->slice_type = make_type("slice", state->AST_type, NULL, 0);
1618 if (!state->slice_type) return 0;
1619 if (!add_attributes(state->slice_type, NULL, 0)) return 0;
1620 state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3);
1621 if (!state->Slice_type) return 0;
1622 state->ExtSlice_type = make_type("ExtSlice", state->slice_type,
1623 ExtSlice_fields, 1);
1624 if (!state->ExtSlice_type) return 0;
1625 state->Index_type = make_type("Index", state->slice_type, Index_fields, 1);
1626 if (!state->Index_type) return 0;
1627 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1628 if (!state->boolop_type) return 0;
1629 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1630 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1631 if (!state->And_type) return 0;
1632 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1633 NULL, NULL);
1634 if (!state->And_singleton) return 0;
1635 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1636 if (!state->Or_type) return 0;
1637 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1638 NULL, NULL);
1639 if (!state->Or_singleton) return 0;
1640 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1641 if (!state->operator_type) return 0;
1642 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1643 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1644 if (!state->Add_type) return 0;
1645 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1646 NULL, NULL);
1647 if (!state->Add_singleton) return 0;
1648 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1649 if (!state->Sub_type) return 0;
1650 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1651 NULL, NULL);
1652 if (!state->Sub_singleton) return 0;
1653 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1654 if (!state->Mult_type) return 0;
1655 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1656 NULL, NULL);
1657 if (!state->Mult_singleton) return 0;
1658 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1659 if (!state->MatMult_type) return 0;
1660 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1661 *)state->MatMult_type, NULL,
1662 NULL);
1663 if (!state->MatMult_singleton) return 0;
1664 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1665 if (!state->Div_type) return 0;
1666 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1667 NULL, NULL);
1668 if (!state->Div_singleton) return 0;
1669 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1670 if (!state->Mod_type) return 0;
1671 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1672 NULL, NULL);
1673 if (!state->Mod_singleton) return 0;
1674 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1675 if (!state->Pow_type) return 0;
1676 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1677 NULL, NULL);
1678 if (!state->Pow_singleton) return 0;
1679 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1680 if (!state->LShift_type) return 0;
1681 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1682 *)state->LShift_type, NULL,
1683 NULL);
1684 if (!state->LShift_singleton) return 0;
1685 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1686 if (!state->RShift_type) return 0;
1687 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1688 *)state->RShift_type, NULL,
1689 NULL);
1690 if (!state->RShift_singleton) return 0;
1691 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1692 if (!state->BitOr_type) return 0;
1693 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1694 *)state->BitOr_type, NULL, NULL);
1695 if (!state->BitOr_singleton) return 0;
1696 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1697 if (!state->BitXor_type) return 0;
1698 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1699 *)state->BitXor_type, NULL,
1700 NULL);
1701 if (!state->BitXor_singleton) return 0;
1702 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1703 if (!state->BitAnd_type) return 0;
1704 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1705 *)state->BitAnd_type, NULL,
1706 NULL);
1707 if (!state->BitAnd_singleton) return 0;
1708 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1709 if (!state->FloorDiv_type) return 0;
1710 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1711 *)state->FloorDiv_type, NULL,
1712 NULL);
1713 if (!state->FloorDiv_singleton) return 0;
1714 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1715 if (!state->unaryop_type) return 0;
1716 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1717 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1718 if (!state->Invert_type) return 0;
1719 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1720 *)state->Invert_type, NULL,
1721 NULL);
1722 if (!state->Invert_singleton) return 0;
1723 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1724 if (!state->Not_type) return 0;
1725 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1726 NULL, NULL);
1727 if (!state->Not_singleton) return 0;
1728 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1729 if (!state->UAdd_type) return 0;
1730 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1731 NULL, NULL);
1732 if (!state->UAdd_singleton) return 0;
1733 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1734 if (!state->USub_type) return 0;
1735 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1736 NULL, NULL);
1737 if (!state->USub_singleton) return 0;
1738 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1739 if (!state->cmpop_type) return 0;
1740 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1741 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1742 if (!state->Eq_type) return 0;
1743 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1744 NULL, NULL);
1745 if (!state->Eq_singleton) return 0;
1746 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1747 if (!state->NotEq_type) return 0;
1748 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1749 *)state->NotEq_type, NULL, NULL);
1750 if (!state->NotEq_singleton) return 0;
1751 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1752 if (!state->Lt_type) return 0;
1753 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1754 NULL, NULL);
1755 if (!state->Lt_singleton) return 0;
1756 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1757 if (!state->LtE_type) return 0;
1758 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1759 NULL, NULL);
1760 if (!state->LtE_singleton) return 0;
1761 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1762 if (!state->Gt_type) return 0;
1763 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1764 NULL, NULL);
1765 if (!state->Gt_singleton) return 0;
1766 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1767 if (!state->GtE_type) return 0;
1768 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1769 NULL, NULL);
1770 if (!state->GtE_singleton) return 0;
1771 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1772 if (!state->Is_type) return 0;
1773 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1774 NULL, NULL);
1775 if (!state->Is_singleton) return 0;
1776 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1777 if (!state->IsNot_type) return 0;
1778 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1779 *)state->IsNot_type, NULL, NULL);
1780 if (!state->IsNot_singleton) return 0;
1781 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1782 if (!state->In_type) return 0;
1783 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1784 NULL, NULL);
1785 if (!state->In_singleton) return 0;
1786 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1787 if (!state->NotIn_type) return 0;
1788 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1789 *)state->NotIn_type, NULL, NULL);
1790 if (!state->NotIn_singleton) return 0;
1791 state->comprehension_type = make_type("comprehension", state->AST_type,
1792 comprehension_fields, 4);
1793 if (!state->comprehension_type) return 0;
1794 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1795 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1796 NULL, 0);
1797 if (!state->excepthandler_type) return 0;
1798 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1799 4)) return 0;
1800 state->ExceptHandler_type = make_type("ExceptHandler",
1801 state->excepthandler_type,
1802 ExceptHandler_fields, 3);
1803 if (!state->ExceptHandler_type) return 0;
1804 state->arguments_type = make_type("arguments", state->AST_type,
1805 arguments_fields, 7);
1806 if (!state->arguments_type) return 0;
1807 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
1808 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1809 if (!state->arg_type) return 0;
1810 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
1811 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1812 2);
1813 if (!state->keyword_type) return 0;
1814 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
1815 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1816 if (!state->alias_type) return 0;
1817 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
1818 state->withitem_type = make_type("withitem", state->AST_type,
1819 withitem_fields, 2);
1820 if (!state->withitem_type) return 0;
1821 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
1822 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1823 0);
1824 if (!state->type_ignore_type) return 0;
1825 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1826 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1827 TypeIgnore_fields, 2);
1828 if (!state->TypeIgnore_type) return 0;
1829 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001830 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001831}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001832
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001833static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1834static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1835static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1836static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1837 arena);
1838static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1839static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1840static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1841static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1842static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1843static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1844 arena);
1845static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1846 arena);
1847static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1848static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1849static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1850static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001851static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001852static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1853 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001854
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001855mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001856Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001857{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001858 mod_ty p;
1859 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1860 if (!p)
1861 return NULL;
1862 p->kind = Module_kind;
1863 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001864 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001865 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001866}
1867
1868mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001869Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001870{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001871 mod_ty p;
1872 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1873 if (!p)
1874 return NULL;
1875 p->kind = Interactive_kind;
1876 p->v.Interactive.body = body;
1877 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001878}
1879
1880mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001881Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001882{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001883 mod_ty p;
1884 if (!body) {
1885 PyErr_SetString(PyExc_ValueError,
1886 "field body is required for Expression");
1887 return NULL;
1888 }
1889 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1890 if (!p)
1891 return NULL;
1892 p->kind = Expression_kind;
1893 p->v.Expression.body = body;
1894 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001895}
1896
1897mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001898FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1899{
1900 mod_ty p;
1901 if (!returns) {
1902 PyErr_SetString(PyExc_ValueError,
1903 "field returns is required for FunctionType");
1904 return NULL;
1905 }
1906 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1907 if (!p)
1908 return NULL;
1909 p->kind = FunctionType_kind;
1910 p->v.FunctionType.argtypes = argtypes;
1911 p->v.FunctionType.returns = returns;
1912 return p;
1913}
1914
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001915stmt_ty
1916FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001917 decorator_list, expr_ty returns, string type_comment, int lineno,
1918 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001919{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001920 stmt_ty p;
1921 if (!name) {
1922 PyErr_SetString(PyExc_ValueError,
1923 "field name is required for FunctionDef");
1924 return NULL;
1925 }
1926 if (!args) {
1927 PyErr_SetString(PyExc_ValueError,
1928 "field args is required for FunctionDef");
1929 return NULL;
1930 }
1931 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1932 if (!p)
1933 return NULL;
1934 p->kind = FunctionDef_kind;
1935 p->v.FunctionDef.name = name;
1936 p->v.FunctionDef.args = args;
1937 p->v.FunctionDef.body = body;
1938 p->v.FunctionDef.decorator_list = decorator_list;
1939 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001940 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001941 p->lineno = lineno;
1942 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001943 p->end_lineno = end_lineno;
1944 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001945 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001946}
1947
1948stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04001949AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001950 * decorator_list, expr_ty returns, string type_comment, int
1951 lineno, int col_offset, int end_lineno, int end_col_offset,
1952 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04001953{
1954 stmt_ty p;
1955 if (!name) {
1956 PyErr_SetString(PyExc_ValueError,
1957 "field name is required for AsyncFunctionDef");
1958 return NULL;
1959 }
1960 if (!args) {
1961 PyErr_SetString(PyExc_ValueError,
1962 "field args is required for AsyncFunctionDef");
1963 return NULL;
1964 }
1965 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1966 if (!p)
1967 return NULL;
1968 p->kind = AsyncFunctionDef_kind;
1969 p->v.AsyncFunctionDef.name = name;
1970 p->v.AsyncFunctionDef.args = args;
1971 p->v.AsyncFunctionDef.body = body;
1972 p->v.AsyncFunctionDef.decorator_list = decorator_list;
1973 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001974 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04001975 p->lineno = lineno;
1976 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001977 p->end_lineno = end_lineno;
1978 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04001979 return p;
1980}
1981
1982stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04001983ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001984 body, asdl_seq * decorator_list, int lineno, int col_offset, int
1985 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001986{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001987 stmt_ty p;
1988 if (!name) {
1989 PyErr_SetString(PyExc_ValueError,
1990 "field name is required for ClassDef");
1991 return NULL;
1992 }
1993 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
1994 if (!p)
1995 return NULL;
1996 p->kind = ClassDef_kind;
1997 p->v.ClassDef.name = name;
1998 p->v.ClassDef.bases = bases;
1999 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002000 p->v.ClassDef.body = body;
2001 p->v.ClassDef.decorator_list = decorator_list;
2002 p->lineno = lineno;
2003 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002004 p->end_lineno = end_lineno;
2005 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002006 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002007}
2008
2009stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002010Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2011 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002012{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002013 stmt_ty p;
2014 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2015 if (!p)
2016 return NULL;
2017 p->kind = Return_kind;
2018 p->v.Return.value = value;
2019 p->lineno = lineno;
2020 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002021 p->end_lineno = end_lineno;
2022 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002023 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002024}
2025
2026stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002027Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2028 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002029{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002030 stmt_ty p;
2031 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2032 if (!p)
2033 return NULL;
2034 p->kind = Delete_kind;
2035 p->v.Delete.targets = targets;
2036 p->lineno = lineno;
2037 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002038 p->end_lineno = end_lineno;
2039 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002040 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002041}
2042
2043stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002044Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2045 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002046{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002047 stmt_ty p;
2048 if (!value) {
2049 PyErr_SetString(PyExc_ValueError,
2050 "field value is required for Assign");
2051 return NULL;
2052 }
2053 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2054 if (!p)
2055 return NULL;
2056 p->kind = Assign_kind;
2057 p->v.Assign.targets = targets;
2058 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002059 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002060 p->lineno = lineno;
2061 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002062 p->end_lineno = end_lineno;
2063 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002064 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002065}
2066
2067stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002068AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002069 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002070{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002071 stmt_ty p;
2072 if (!target) {
2073 PyErr_SetString(PyExc_ValueError,
2074 "field target is required for AugAssign");
2075 return NULL;
2076 }
2077 if (!op) {
2078 PyErr_SetString(PyExc_ValueError,
2079 "field op is required for AugAssign");
2080 return NULL;
2081 }
2082 if (!value) {
2083 PyErr_SetString(PyExc_ValueError,
2084 "field value is required for AugAssign");
2085 return NULL;
2086 }
2087 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2088 if (!p)
2089 return NULL;
2090 p->kind = AugAssign_kind;
2091 p->v.AugAssign.target = target;
2092 p->v.AugAssign.op = op;
2093 p->v.AugAssign.value = value;
2094 p->lineno = lineno;
2095 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002096 p->end_lineno = end_lineno;
2097 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002098 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002099}
2100
2101stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002102AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002103 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2104 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002105{
2106 stmt_ty p;
2107 if (!target) {
2108 PyErr_SetString(PyExc_ValueError,
2109 "field target is required for AnnAssign");
2110 return NULL;
2111 }
2112 if (!annotation) {
2113 PyErr_SetString(PyExc_ValueError,
2114 "field annotation is required for AnnAssign");
2115 return NULL;
2116 }
2117 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2118 if (!p)
2119 return NULL;
2120 p->kind = AnnAssign_kind;
2121 p->v.AnnAssign.target = target;
2122 p->v.AnnAssign.annotation = annotation;
2123 p->v.AnnAssign.value = value;
2124 p->v.AnnAssign.simple = simple;
2125 p->lineno = lineno;
2126 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002127 p->end_lineno = end_lineno;
2128 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002129 return p;
2130}
2131
2132stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002133For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2134 type_comment, int lineno, int col_offset, int end_lineno, int
2135 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002136{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002137 stmt_ty p;
2138 if (!target) {
2139 PyErr_SetString(PyExc_ValueError,
2140 "field target is required for For");
2141 return NULL;
2142 }
2143 if (!iter) {
2144 PyErr_SetString(PyExc_ValueError,
2145 "field iter is required for For");
2146 return NULL;
2147 }
2148 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2149 if (!p)
2150 return NULL;
2151 p->kind = For_kind;
2152 p->v.For.target = target;
2153 p->v.For.iter = iter;
2154 p->v.For.body = body;
2155 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002156 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002157 p->lineno = lineno;
2158 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002159 p->end_lineno = end_lineno;
2160 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002161 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002162}
2163
2164stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002165AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2166 string type_comment, int lineno, int col_offset, int end_lineno, int
2167 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002168{
2169 stmt_ty p;
2170 if (!target) {
2171 PyErr_SetString(PyExc_ValueError,
2172 "field target is required for AsyncFor");
2173 return NULL;
2174 }
2175 if (!iter) {
2176 PyErr_SetString(PyExc_ValueError,
2177 "field iter is required for AsyncFor");
2178 return NULL;
2179 }
2180 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2181 if (!p)
2182 return NULL;
2183 p->kind = AsyncFor_kind;
2184 p->v.AsyncFor.target = target;
2185 p->v.AsyncFor.iter = iter;
2186 p->v.AsyncFor.body = body;
2187 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002188 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002189 p->lineno = lineno;
2190 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002191 p->end_lineno = end_lineno;
2192 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002193 return p;
2194}
2195
2196stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002197While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002198 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002199{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002200 stmt_ty p;
2201 if (!test) {
2202 PyErr_SetString(PyExc_ValueError,
2203 "field test is required for While");
2204 return NULL;
2205 }
2206 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2207 if (!p)
2208 return NULL;
2209 p->kind = While_kind;
2210 p->v.While.test = test;
2211 p->v.While.body = body;
2212 p->v.While.orelse = orelse;
2213 p->lineno = lineno;
2214 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002215 p->end_lineno = end_lineno;
2216 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002217 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218}
2219
2220stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002221If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002222 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002223{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002224 stmt_ty p;
2225 if (!test) {
2226 PyErr_SetString(PyExc_ValueError,
2227 "field test is required for If");
2228 return NULL;
2229 }
2230 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2231 if (!p)
2232 return NULL;
2233 p->kind = If_kind;
2234 p->v.If.test = test;
2235 p->v.If.body = body;
2236 p->v.If.orelse = orelse;
2237 p->lineno = lineno;
2238 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002239 p->end_lineno = end_lineno;
2240 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002241 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002242}
2243
2244stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002245With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2246 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002247{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002248 stmt_ty p;
2249 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2250 if (!p)
2251 return NULL;
2252 p->kind = With_kind;
2253 p->v.With.items = items;
2254 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002255 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002256 p->lineno = lineno;
2257 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002258 p->end_lineno = end_lineno;
2259 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002260 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002261}
2262
2263stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002264AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2265 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002266{
2267 stmt_ty p;
2268 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2269 if (!p)
2270 return NULL;
2271 p->kind = AsyncWith_kind;
2272 p->v.AsyncWith.items = items;
2273 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002274 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002275 p->lineno = lineno;
2276 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002277 p->end_lineno = end_lineno;
2278 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002279 return p;
2280}
2281
2282stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002283Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2284 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002285{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002286 stmt_ty p;
2287 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2288 if (!p)
2289 return NULL;
2290 p->kind = Raise_kind;
2291 p->v.Raise.exc = exc;
2292 p->v.Raise.cause = cause;
2293 p->lineno = lineno;
2294 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002295 p->end_lineno = end_lineno;
2296 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002297 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002298}
2299
2300stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002301Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002302 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2303 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002304{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002305 stmt_ty p;
2306 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2307 if (!p)
2308 return NULL;
2309 p->kind = Try_kind;
2310 p->v.Try.body = body;
2311 p->v.Try.handlers = handlers;
2312 p->v.Try.orelse = orelse;
2313 p->v.Try.finalbody = finalbody;
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
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002322Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2323 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002324{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002325 stmt_ty p;
2326 if (!test) {
2327 PyErr_SetString(PyExc_ValueError,
2328 "field test is required for Assert");
2329 return NULL;
2330 }
2331 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2332 if (!p)
2333 return NULL;
2334 p->kind = Assert_kind;
2335 p->v.Assert.test = test;
2336 p->v.Assert.msg = msg;
2337 p->lineno = lineno;
2338 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002339 p->end_lineno = end_lineno;
2340 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002341 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002342}
2343
2344stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002345Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2346 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002347{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002348 stmt_ty p;
2349 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2350 if (!p)
2351 return NULL;
2352 p->kind = Import_kind;
2353 p->v.Import.names = names;
2354 p->lineno = lineno;
2355 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002356 p->end_lineno = end_lineno;
2357 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002358 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002359}
2360
2361stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002362ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002363 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002364{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002365 stmt_ty p;
2366 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2367 if (!p)
2368 return NULL;
2369 p->kind = ImportFrom_kind;
2370 p->v.ImportFrom.module = module;
2371 p->v.ImportFrom.names = names;
2372 p->v.ImportFrom.level = level;
2373 p->lineno = lineno;
2374 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002375 p->end_lineno = end_lineno;
2376 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002377 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002378}
2379
2380stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002381Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2382 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002383{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002384 stmt_ty p;
2385 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2386 if (!p)
2387 return NULL;
2388 p->kind = Global_kind;
2389 p->v.Global.names = names;
2390 p->lineno = lineno;
2391 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002392 p->end_lineno = end_lineno;
2393 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002394 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002395}
2396
2397stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002398Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2399 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002400{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002401 stmt_ty p;
2402 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2403 if (!p)
2404 return NULL;
2405 p->kind = Nonlocal_kind;
2406 p->v.Nonlocal.names = names;
2407 p->lineno = lineno;
2408 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002409 p->end_lineno = end_lineno;
2410 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002411 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002412}
2413
2414stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002415Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2416 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002417{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002418 stmt_ty p;
2419 if (!value) {
2420 PyErr_SetString(PyExc_ValueError,
2421 "field value is required for Expr");
2422 return NULL;
2423 }
2424 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2425 if (!p)
2426 return NULL;
2427 p->kind = Expr_kind;
2428 p->v.Expr.value = value;
2429 p->lineno = lineno;
2430 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002431 p->end_lineno = end_lineno;
2432 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002433 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002434}
2435
2436stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002437Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2438 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002439{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002440 stmt_ty p;
2441 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2442 if (!p)
2443 return NULL;
2444 p->kind = Pass_kind;
2445 p->lineno = lineno;
2446 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002447 p->end_lineno = end_lineno;
2448 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002449 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002450}
2451
2452stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002453Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2454 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002455{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002456 stmt_ty p;
2457 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2458 if (!p)
2459 return NULL;
2460 p->kind = Break_kind;
2461 p->lineno = lineno;
2462 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002463 p->end_lineno = end_lineno;
2464 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002465 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002466}
2467
2468stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002469Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2470 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002471{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002472 stmt_ty p;
2473 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2474 if (!p)
2475 return NULL;
2476 p->kind = Continue_kind;
2477 p->lineno = lineno;
2478 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002479 p->end_lineno = end_lineno;
2480 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002481 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002482}
2483
2484expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002485BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2486 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002488 expr_ty p;
2489 if (!op) {
2490 PyErr_SetString(PyExc_ValueError,
2491 "field op is required for BoolOp");
2492 return NULL;
2493 }
2494 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2495 if (!p)
2496 return NULL;
2497 p->kind = BoolOp_kind;
2498 p->v.BoolOp.op = op;
2499 p->v.BoolOp.values = values;
2500 p->lineno = lineno;
2501 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002502 p->end_lineno = end_lineno;
2503 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002504 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002505}
2506
2507expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002508NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2509 end_lineno, int end_col_offset, PyArena *arena)
2510{
2511 expr_ty p;
2512 if (!target) {
2513 PyErr_SetString(PyExc_ValueError,
2514 "field target is required for NamedExpr");
2515 return NULL;
2516 }
2517 if (!value) {
2518 PyErr_SetString(PyExc_ValueError,
2519 "field value is required for NamedExpr");
2520 return NULL;
2521 }
2522 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2523 if (!p)
2524 return NULL;
2525 p->kind = NamedExpr_kind;
2526 p->v.NamedExpr.target = target;
2527 p->v.NamedExpr.value = value;
2528 p->lineno = lineno;
2529 p->col_offset = col_offset;
2530 p->end_lineno = end_lineno;
2531 p->end_col_offset = end_col_offset;
2532 return p;
2533}
2534
2535expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002536BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002537 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002538{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002539 expr_ty p;
2540 if (!left) {
2541 PyErr_SetString(PyExc_ValueError,
2542 "field left is required for BinOp");
2543 return NULL;
2544 }
2545 if (!op) {
2546 PyErr_SetString(PyExc_ValueError,
2547 "field op is required for BinOp");
2548 return NULL;
2549 }
2550 if (!right) {
2551 PyErr_SetString(PyExc_ValueError,
2552 "field right is required for BinOp");
2553 return NULL;
2554 }
2555 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2556 if (!p)
2557 return NULL;
2558 p->kind = BinOp_kind;
2559 p->v.BinOp.left = left;
2560 p->v.BinOp.op = op;
2561 p->v.BinOp.right = right;
2562 p->lineno = lineno;
2563 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002564 p->end_lineno = end_lineno;
2565 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002566 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002567}
2568
2569expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002570UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2571 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002572{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002573 expr_ty p;
2574 if (!op) {
2575 PyErr_SetString(PyExc_ValueError,
2576 "field op is required for UnaryOp");
2577 return NULL;
2578 }
2579 if (!operand) {
2580 PyErr_SetString(PyExc_ValueError,
2581 "field operand is required for UnaryOp");
2582 return NULL;
2583 }
2584 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2585 if (!p)
2586 return NULL;
2587 p->kind = UnaryOp_kind;
2588 p->v.UnaryOp.op = op;
2589 p->v.UnaryOp.operand = operand;
2590 p->lineno = lineno;
2591 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002592 p->end_lineno = end_lineno;
2593 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002594 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002595}
2596
2597expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002598Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2599 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002600{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002601 expr_ty p;
2602 if (!args) {
2603 PyErr_SetString(PyExc_ValueError,
2604 "field args is required for Lambda");
2605 return NULL;
2606 }
2607 if (!body) {
2608 PyErr_SetString(PyExc_ValueError,
2609 "field body is required for Lambda");
2610 return NULL;
2611 }
2612 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2613 if (!p)
2614 return NULL;
2615 p->kind = Lambda_kind;
2616 p->v.Lambda.args = args;
2617 p->v.Lambda.body = body;
2618 p->lineno = lineno;
2619 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002620 p->end_lineno = end_lineno;
2621 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002622 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002623}
2624
2625expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002626IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002627 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002628{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002629 expr_ty p;
2630 if (!test) {
2631 PyErr_SetString(PyExc_ValueError,
2632 "field test is required for IfExp");
2633 return NULL;
2634 }
2635 if (!body) {
2636 PyErr_SetString(PyExc_ValueError,
2637 "field body is required for IfExp");
2638 return NULL;
2639 }
2640 if (!orelse) {
2641 PyErr_SetString(PyExc_ValueError,
2642 "field orelse is required for IfExp");
2643 return NULL;
2644 }
2645 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2646 if (!p)
2647 return NULL;
2648 p->kind = IfExp_kind;
2649 p->v.IfExp.test = test;
2650 p->v.IfExp.body = body;
2651 p->v.IfExp.orelse = orelse;
2652 p->lineno = lineno;
2653 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002654 p->end_lineno = end_lineno;
2655 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002656 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002657}
2658
2659expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002660Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2661 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002662{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002663 expr_ty p;
2664 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2665 if (!p)
2666 return NULL;
2667 p->kind = Dict_kind;
2668 p->v.Dict.keys = keys;
2669 p->v.Dict.values = values;
2670 p->lineno = lineno;
2671 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002672 p->end_lineno = end_lineno;
2673 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002674 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002675}
2676
2677expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002678Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2679 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002680{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002681 expr_ty p;
2682 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2683 if (!p)
2684 return NULL;
2685 p->kind = Set_kind;
2686 p->v.Set.elts = elts;
2687 p->lineno = lineno;
2688 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002689 p->end_lineno = end_lineno;
2690 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002691 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002692}
2693
2694expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002695ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2696 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002697{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002698 expr_ty p;
2699 if (!elt) {
2700 PyErr_SetString(PyExc_ValueError,
2701 "field elt is required for ListComp");
2702 return NULL;
2703 }
2704 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2705 if (!p)
2706 return NULL;
2707 p->kind = ListComp_kind;
2708 p->v.ListComp.elt = elt;
2709 p->v.ListComp.generators = generators;
2710 p->lineno = lineno;
2711 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002712 p->end_lineno = end_lineno;
2713 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002714 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002715}
2716
2717expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002718SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2719 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002720{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002721 expr_ty p;
2722 if (!elt) {
2723 PyErr_SetString(PyExc_ValueError,
2724 "field elt is required for SetComp");
2725 return NULL;
2726 }
2727 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2728 if (!p)
2729 return NULL;
2730 p->kind = SetComp_kind;
2731 p->v.SetComp.elt = elt;
2732 p->v.SetComp.generators = generators;
2733 p->lineno = lineno;
2734 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002735 p->end_lineno = end_lineno;
2736 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002737 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002738}
2739
2740expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002741DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002742 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002743{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002744 expr_ty p;
2745 if (!key) {
2746 PyErr_SetString(PyExc_ValueError,
2747 "field key is required for DictComp");
2748 return NULL;
2749 }
2750 if (!value) {
2751 PyErr_SetString(PyExc_ValueError,
2752 "field value is required for DictComp");
2753 return NULL;
2754 }
2755 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2756 if (!p)
2757 return NULL;
2758 p->kind = DictComp_kind;
2759 p->v.DictComp.key = key;
2760 p->v.DictComp.value = value;
2761 p->v.DictComp.generators = generators;
2762 p->lineno = lineno;
2763 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002764 p->end_lineno = end_lineno;
2765 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002766 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002767}
2768
2769expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002770GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002771 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002772{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002773 expr_ty p;
2774 if (!elt) {
2775 PyErr_SetString(PyExc_ValueError,
2776 "field elt is required for GeneratorExp");
2777 return NULL;
2778 }
2779 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2780 if (!p)
2781 return NULL;
2782 p->kind = GeneratorExp_kind;
2783 p->v.GeneratorExp.elt = elt;
2784 p->v.GeneratorExp.generators = generators;
2785 p->lineno = lineno;
2786 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002787 p->end_lineno = end_lineno;
2788 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002789 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002790}
2791
2792expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002793Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2794 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002795{
2796 expr_ty p;
2797 if (!value) {
2798 PyErr_SetString(PyExc_ValueError,
2799 "field value is required for Await");
2800 return NULL;
2801 }
2802 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2803 if (!p)
2804 return NULL;
2805 p->kind = Await_kind;
2806 p->v.Await.value = value;
2807 p->lineno = lineno;
2808 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002809 p->end_lineno = end_lineno;
2810 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002811 return p;
2812}
2813
2814expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002815Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2816 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002817{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002818 expr_ty p;
2819 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2820 if (!p)
2821 return NULL;
2822 p->kind = Yield_kind;
2823 p->v.Yield.value = value;
2824 p->lineno = lineno;
2825 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002826 p->end_lineno = end_lineno;
2827 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002828 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002829}
2830
2831expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002832YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2833 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002834{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002835 expr_ty p;
2836 if (!value) {
2837 PyErr_SetString(PyExc_ValueError,
2838 "field value is required for YieldFrom");
2839 return NULL;
2840 }
2841 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2842 if (!p)
2843 return NULL;
2844 p->kind = YieldFrom_kind;
2845 p->v.YieldFrom.value = value;
2846 p->lineno = lineno;
2847 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002848 p->end_lineno = end_lineno;
2849 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002850 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002851}
2852
2853expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002854Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002855 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002856{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002857 expr_ty p;
2858 if (!left) {
2859 PyErr_SetString(PyExc_ValueError,
2860 "field left is required for Compare");
2861 return NULL;
2862 }
2863 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2864 if (!p)
2865 return NULL;
2866 p->kind = Compare_kind;
2867 p->v.Compare.left = left;
2868 p->v.Compare.ops = ops;
2869 p->v.Compare.comparators = comparators;
2870 p->lineno = lineno;
2871 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002872 p->end_lineno = end_lineno;
2873 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002874 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002875}
2876
2877expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002878Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002879 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002880{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002881 expr_ty p;
2882 if (!func) {
2883 PyErr_SetString(PyExc_ValueError,
2884 "field func is required for Call");
2885 return NULL;
2886 }
2887 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2888 if (!p)
2889 return NULL;
2890 p->kind = Call_kind;
2891 p->v.Call.func = func;
2892 p->v.Call.args = args;
2893 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002894 p->lineno = lineno;
2895 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002896 p->end_lineno = end_lineno;
2897 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002898 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002899}
2900
2901expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002902FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2903 int col_offset, int end_lineno, int end_col_offset, PyArena
2904 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002905{
2906 expr_ty p;
2907 if (!value) {
2908 PyErr_SetString(PyExc_ValueError,
2909 "field value is required for FormattedValue");
2910 return NULL;
2911 }
2912 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2913 if (!p)
2914 return NULL;
2915 p->kind = FormattedValue_kind;
2916 p->v.FormattedValue.value = value;
2917 p->v.FormattedValue.conversion = conversion;
2918 p->v.FormattedValue.format_spec = format_spec;
2919 p->lineno = lineno;
2920 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002921 p->end_lineno = end_lineno;
2922 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002923 return p;
2924}
2925
2926expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002927JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
2928 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002929{
2930 expr_ty p;
2931 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2932 if (!p)
2933 return NULL;
2934 p->kind = JoinedStr_kind;
2935 p->v.JoinedStr.values = values;
2936 p->lineno = lineno;
2937 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002938 p->end_lineno = end_lineno;
2939 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04002940 return p;
2941}
2942
2943expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002944Constant(constant value, string kind, int lineno, int col_offset, int
2945 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002946{
2947 expr_ty p;
2948 if (!value) {
2949 PyErr_SetString(PyExc_ValueError,
2950 "field value is required for Constant");
2951 return NULL;
2952 }
2953 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2954 if (!p)
2955 return NULL;
2956 p->kind = Constant_kind;
2957 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07002958 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002959 p->lineno = lineno;
2960 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002961 p->end_lineno = end_lineno;
2962 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01002963 return p;
2964}
2965
2966expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002967Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002968 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002969{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002970 expr_ty p;
2971 if (!value) {
2972 PyErr_SetString(PyExc_ValueError,
2973 "field value is required for Attribute");
2974 return NULL;
2975 }
2976 if (!attr) {
2977 PyErr_SetString(PyExc_ValueError,
2978 "field attr is required for Attribute");
2979 return NULL;
2980 }
2981 if (!ctx) {
2982 PyErr_SetString(PyExc_ValueError,
2983 "field ctx is required for Attribute");
2984 return NULL;
2985 }
2986 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2987 if (!p)
2988 return NULL;
2989 p->kind = Attribute_kind;
2990 p->v.Attribute.value = value;
2991 p->v.Attribute.attr = attr;
2992 p->v.Attribute.ctx = ctx;
2993 p->lineno = lineno;
2994 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002995 p->end_lineno = end_lineno;
2996 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002997 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002998}
2999
3000expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003001Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003002 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003003{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003004 expr_ty p;
3005 if (!value) {
3006 PyErr_SetString(PyExc_ValueError,
3007 "field value is required for Subscript");
3008 return NULL;
3009 }
3010 if (!slice) {
3011 PyErr_SetString(PyExc_ValueError,
3012 "field slice is required for Subscript");
3013 return NULL;
3014 }
3015 if (!ctx) {
3016 PyErr_SetString(PyExc_ValueError,
3017 "field ctx is required for Subscript");
3018 return NULL;
3019 }
3020 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3021 if (!p)
3022 return NULL;
3023 p->kind = Subscript_kind;
3024 p->v.Subscript.value = value;
3025 p->v.Subscript.slice = slice;
3026 p->v.Subscript.ctx = ctx;
3027 p->lineno = lineno;
3028 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003029 p->end_lineno = end_lineno;
3030 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003031 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003032}
3033
3034expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003035Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3036 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003037{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003038 expr_ty p;
3039 if (!value) {
3040 PyErr_SetString(PyExc_ValueError,
3041 "field value is required for Starred");
3042 return NULL;
3043 }
3044 if (!ctx) {
3045 PyErr_SetString(PyExc_ValueError,
3046 "field ctx is required for Starred");
3047 return NULL;
3048 }
3049 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3050 if (!p)
3051 return NULL;
3052 p->kind = Starred_kind;
3053 p->v.Starred.value = value;
3054 p->v.Starred.ctx = ctx;
3055 p->lineno = lineno;
3056 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003057 p->end_lineno = end_lineno;
3058 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003059 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003060}
3061
3062expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003063Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3064 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003065{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003066 expr_ty p;
3067 if (!id) {
3068 PyErr_SetString(PyExc_ValueError,
3069 "field id is required for Name");
3070 return NULL;
3071 }
3072 if (!ctx) {
3073 PyErr_SetString(PyExc_ValueError,
3074 "field ctx is required for Name");
3075 return NULL;
3076 }
3077 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3078 if (!p)
3079 return NULL;
3080 p->kind = Name_kind;
3081 p->v.Name.id = id;
3082 p->v.Name.ctx = ctx;
3083 p->lineno = lineno;
3084 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003085 p->end_lineno = end_lineno;
3086 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003087 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003088}
3089
3090expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003091List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3092 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003093{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003094 expr_ty p;
3095 if (!ctx) {
3096 PyErr_SetString(PyExc_ValueError,
3097 "field ctx is required for List");
3098 return NULL;
3099 }
3100 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3101 if (!p)
3102 return NULL;
3103 p->kind = List_kind;
3104 p->v.List.elts = elts;
3105 p->v.List.ctx = ctx;
3106 p->lineno = lineno;
3107 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003108 p->end_lineno = end_lineno;
3109 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003110 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003111}
3112
3113expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003114Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3115 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003116{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003117 expr_ty p;
3118 if (!ctx) {
3119 PyErr_SetString(PyExc_ValueError,
3120 "field ctx is required for Tuple");
3121 return NULL;
3122 }
3123 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3124 if (!p)
3125 return NULL;
3126 p->kind = Tuple_kind;
3127 p->v.Tuple.elts = elts;
3128 p->v.Tuple.ctx = ctx;
3129 p->lineno = lineno;
3130 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003131 p->end_lineno = end_lineno;
3132 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003133 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003134}
3135
3136slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003137Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003138{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003139 slice_ty p;
3140 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3141 if (!p)
3142 return NULL;
3143 p->kind = Slice_kind;
3144 p->v.Slice.lower = lower;
3145 p->v.Slice.upper = upper;
3146 p->v.Slice.step = step;
3147 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003148}
3149
3150slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003151ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003152{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003153 slice_ty p;
3154 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3155 if (!p)
3156 return NULL;
3157 p->kind = ExtSlice_kind;
3158 p->v.ExtSlice.dims = dims;
3159 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003160}
3161
3162slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003163Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003164{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003165 slice_ty p;
3166 if (!value) {
3167 PyErr_SetString(PyExc_ValueError,
3168 "field value is required for Index");
3169 return NULL;
3170 }
3171 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3172 if (!p)
3173 return NULL;
3174 p->kind = Index_kind;
3175 p->v.Index.value = value;
3176 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003177}
3178
3179comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003180comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3181 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003182{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003183 comprehension_ty p;
3184 if (!target) {
3185 PyErr_SetString(PyExc_ValueError,
3186 "field target is required for comprehension");
3187 return NULL;
3188 }
3189 if (!iter) {
3190 PyErr_SetString(PyExc_ValueError,
3191 "field iter is required for comprehension");
3192 return NULL;
3193 }
3194 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3195 if (!p)
3196 return NULL;
3197 p->target = target;
3198 p->iter = iter;
3199 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003200 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003201 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003202}
3203
3204excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003205ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003206 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003207{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003208 excepthandler_ty p;
3209 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3210 if (!p)
3211 return NULL;
3212 p->kind = ExceptHandler_kind;
3213 p->v.ExceptHandler.type = type;
3214 p->v.ExceptHandler.name = name;
3215 p->v.ExceptHandler.body = body;
3216 p->lineno = lineno;
3217 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003218 p->end_lineno = end_lineno;
3219 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003220 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003221}
3222
3223arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003224arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003225 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3226 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003227{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003228 arguments_ty p;
3229 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3230 if (!p)
3231 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003232 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003233 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003234 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003235 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003236 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003237 p->kwarg = kwarg;
3238 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003239 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003240}
3241
Neal Norwitzc1505362006-12-28 06:47:50 +00003242arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003243arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3244 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003245{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003246 arg_ty p;
3247 if (!arg) {
3248 PyErr_SetString(PyExc_ValueError,
3249 "field arg is required for arg");
3250 return NULL;
3251 }
3252 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3253 if (!p)
3254 return NULL;
3255 p->arg = arg;
3256 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003257 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003258 p->lineno = lineno;
3259 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003260 p->end_lineno = end_lineno;
3261 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003262 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003263}
3264
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003265keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003266keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003267{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003268 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003269 if (!value) {
3270 PyErr_SetString(PyExc_ValueError,
3271 "field value is required for keyword");
3272 return NULL;
3273 }
3274 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3275 if (!p)
3276 return NULL;
3277 p->arg = arg;
3278 p->value = value;
3279 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003280}
3281
3282alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003283alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003284{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003285 alias_ty p;
3286 if (!name) {
3287 PyErr_SetString(PyExc_ValueError,
3288 "field name is required for alias");
3289 return NULL;
3290 }
3291 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3292 if (!p)
3293 return NULL;
3294 p->name = name;
3295 p->asname = asname;
3296 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003297}
3298
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003299withitem_ty
3300withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3301{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003302 withitem_ty p;
3303 if (!context_expr) {
3304 PyErr_SetString(PyExc_ValueError,
3305 "field context_expr is required for withitem");
3306 return NULL;
3307 }
3308 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3309 if (!p)
3310 return NULL;
3311 p->context_expr = context_expr;
3312 p->optional_vars = optional_vars;
3313 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003314}
3315
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003316type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003317TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003318{
3319 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003320 if (!tag) {
3321 PyErr_SetString(PyExc_ValueError,
3322 "field tag is required for TypeIgnore");
3323 return NULL;
3324 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003325 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3326 if (!p)
3327 return NULL;
3328 p->kind = TypeIgnore_kind;
3329 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003330 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003331 return p;
3332}
3333
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003334
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003335PyObject*
3336ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003337{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003338 mod_ty o = (mod_ty)_o;
3339 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003340 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003341 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003342 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003343 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003344
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003345 switch (o->kind) {
3346 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003347 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3348 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003349 if (!result) goto failed;
3350 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3351 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003352 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003353 goto failed;
3354 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003355 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3356 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003357 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3358 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003359 goto failed;
3360 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003361 break;
3362 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003363 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3364 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003365 if (!result) goto failed;
3366 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3367 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003368 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003369 goto failed;
3370 Py_DECREF(value);
3371 break;
3372 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003373 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3374 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003375 if (!result) goto failed;
3376 value = ast2obj_expr(o->v.Expression.body);
3377 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003378 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003379 goto failed;
3380 Py_DECREF(value);
3381 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003382 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003383 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3384 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003385 if (!result) goto failed;
3386 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3387 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003388 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3389 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003390 goto failed;
3391 Py_DECREF(value);
3392 value = ast2obj_expr(o->v.FunctionType.returns);
3393 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003394 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3395 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003396 goto failed;
3397 Py_DECREF(value);
3398 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003399 }
3400 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003401failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003402 Py_XDECREF(value);
3403 Py_XDECREF(result);
3404 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003405}
3406
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003407PyObject*
3408ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003409{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003410 stmt_ty o = (stmt_ty)_o;
3411 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003412 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003413 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003414 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003415 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003416
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003417 switch (o->kind) {
3418 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003419 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3420 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003421 if (!result) goto failed;
3422 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003423 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003424 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003425 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003426 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003427 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003428 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003429 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003430 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003431 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003432 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3433 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003434 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003435 goto failed;
3436 Py_DECREF(value);
3437 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3438 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003439 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3440 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003441 goto failed;
3442 Py_DECREF(value);
3443 value = ast2obj_expr(o->v.FunctionDef.returns);
3444 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003445 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3446 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003447 goto failed;
3448 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003449 value = ast2obj_string(o->v.FunctionDef.type_comment);
3450 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003451 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3452 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003453 goto failed;
3454 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003455 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003456 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003457 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3458 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003459 if (!result) goto failed;
3460 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3461 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003462 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003463 goto failed;
3464 Py_DECREF(value);
3465 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3466 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003467 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003468 goto failed;
3469 Py_DECREF(value);
3470 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3471 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003472 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003473 goto failed;
3474 Py_DECREF(value);
3475 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3476 ast2obj_expr);
3477 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003478 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3479 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003480 goto failed;
3481 Py_DECREF(value);
3482 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3483 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003484 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3485 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003486 goto failed;
3487 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003488 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3489 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003490 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3491 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003492 goto failed;
3493 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003494 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003495 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003496 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3497 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003498 if (!result) goto failed;
3499 value = ast2obj_identifier(o->v.ClassDef.name);
3500 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003501 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003502 goto failed;
3503 Py_DECREF(value);
3504 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3505 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003506 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003507 goto failed;
3508 Py_DECREF(value);
3509 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3510 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003511 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3512 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003513 goto failed;
3514 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003515 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3516 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003517 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003518 goto failed;
3519 Py_DECREF(value);
3520 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3521 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003522 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3523 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003524 goto failed;
3525 Py_DECREF(value);
3526 break;
3527 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003528 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3529 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003530 if (!result) goto failed;
3531 value = ast2obj_expr(o->v.Return.value);
3532 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003533 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003534 goto failed;
3535 Py_DECREF(value);
3536 break;
3537 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003538 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3539 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003540 if (!result) goto failed;
3541 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3542 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003543 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3544 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003545 goto failed;
3546 Py_DECREF(value);
3547 break;
3548 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003549 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3550 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003551 if (!result) goto failed;
3552 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3553 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003554 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3555 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003556 goto failed;
3557 Py_DECREF(value);
3558 value = ast2obj_expr(o->v.Assign.value);
3559 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003560 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003561 goto failed;
3562 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003563 value = ast2obj_string(o->v.Assign.type_comment);
3564 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003565 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3566 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003567 goto failed;
3568 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003569 break;
3570 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003571 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3572 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003573 if (!result) goto failed;
3574 value = ast2obj_expr(o->v.AugAssign.target);
3575 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003576 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3577 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003578 goto failed;
3579 Py_DECREF(value);
3580 value = ast2obj_operator(o->v.AugAssign.op);
3581 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003582 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003583 goto failed;
3584 Py_DECREF(value);
3585 value = ast2obj_expr(o->v.AugAssign.value);
3586 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003587 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003588 goto failed;
3589 Py_DECREF(value);
3590 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003591 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003592 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3593 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003594 if (!result) goto failed;
3595 value = ast2obj_expr(o->v.AnnAssign.target);
3596 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003597 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3598 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003599 goto failed;
3600 Py_DECREF(value);
3601 value = ast2obj_expr(o->v.AnnAssign.annotation);
3602 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003603 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3604 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003605 goto failed;
3606 Py_DECREF(value);
3607 value = ast2obj_expr(o->v.AnnAssign.value);
3608 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003609 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003610 goto failed;
3611 Py_DECREF(value);
3612 value = ast2obj_int(o->v.AnnAssign.simple);
3613 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003614 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3615 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003616 goto failed;
3617 Py_DECREF(value);
3618 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003619 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003620 tp = (PyTypeObject *)astmodulestate_global->For_type;
3621 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003622 if (!result) goto failed;
3623 value = ast2obj_expr(o->v.For.target);
3624 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003625 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3626 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003627 goto failed;
3628 Py_DECREF(value);
3629 value = ast2obj_expr(o->v.For.iter);
3630 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003631 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003632 goto failed;
3633 Py_DECREF(value);
3634 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3635 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003636 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003637 goto failed;
3638 Py_DECREF(value);
3639 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3640 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003641 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3642 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003643 goto failed;
3644 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003645 value = ast2obj_string(o->v.For.type_comment);
3646 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003647 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3648 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003649 goto failed;
3650 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003651 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003652 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003653 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3654 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003655 if (!result) goto failed;
3656 value = ast2obj_expr(o->v.AsyncFor.target);
3657 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003658 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3659 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003660 goto failed;
3661 Py_DECREF(value);
3662 value = ast2obj_expr(o->v.AsyncFor.iter);
3663 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003664 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003665 goto failed;
3666 Py_DECREF(value);
3667 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3668 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003669 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003670 goto failed;
3671 Py_DECREF(value);
3672 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3673 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003674 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3675 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003676 goto failed;
3677 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003678 value = ast2obj_string(o->v.AsyncFor.type_comment);
3679 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003680 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3681 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003682 goto failed;
3683 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003684 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003685 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003686 tp = (PyTypeObject *)astmodulestate_global->While_type;
3687 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003688 if (!result) goto failed;
3689 value = ast2obj_expr(o->v.While.test);
3690 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003691 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003692 goto failed;
3693 Py_DECREF(value);
3694 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3695 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003696 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003697 goto failed;
3698 Py_DECREF(value);
3699 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3700 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003701 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3702 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003703 goto failed;
3704 Py_DECREF(value);
3705 break;
3706 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003707 tp = (PyTypeObject *)astmodulestate_global->If_type;
3708 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003709 if (!result) goto failed;
3710 value = ast2obj_expr(o->v.If.test);
3711 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003712 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003713 goto failed;
3714 Py_DECREF(value);
3715 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3716 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003717 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003718 goto failed;
3719 Py_DECREF(value);
3720 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3721 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003722 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3723 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003724 goto failed;
3725 Py_DECREF(value);
3726 break;
3727 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003728 tp = (PyTypeObject *)astmodulestate_global->With_type;
3729 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003730 if (!result) goto failed;
3731 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3732 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003733 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003734 goto failed;
3735 Py_DECREF(value);
3736 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3737 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003738 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003739 goto failed;
3740 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003741 value = ast2obj_string(o->v.With.type_comment);
3742 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003743 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3744 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003745 goto failed;
3746 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003747 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003748 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003749 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3750 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003751 if (!result) goto failed;
3752 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3753 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003754 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003755 goto failed;
3756 Py_DECREF(value);
3757 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003759 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003760 goto failed;
3761 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003762 value = ast2obj_string(o->v.AsyncWith.type_comment);
3763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003764 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3765 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003766 goto failed;
3767 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003768 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003769 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003770 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3771 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003772 if (!result) goto failed;
3773 value = ast2obj_expr(o->v.Raise.exc);
3774 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003775 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003776 goto failed;
3777 Py_DECREF(value);
3778 value = ast2obj_expr(o->v.Raise.cause);
3779 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003780 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003781 goto failed;
3782 Py_DECREF(value);
3783 break;
3784 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003785 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3786 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003787 if (!result) goto failed;
3788 value = ast2obj_list(o->v.Try.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)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003791 goto failed;
3792 Py_DECREF(value);
3793 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3794 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003795 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3796 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003797 goto failed;
3798 Py_DECREF(value);
3799 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3800 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003801 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3802 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003803 goto failed;
3804 Py_DECREF(value);
3805 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3806 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003807 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3808 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003809 goto failed;
3810 Py_DECREF(value);
3811 break;
3812 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003813 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3814 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003815 if (!result) goto failed;
3816 value = ast2obj_expr(o->v.Assert.test);
3817 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003818 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003819 goto failed;
3820 Py_DECREF(value);
3821 value = ast2obj_expr(o->v.Assert.msg);
3822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003823 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003824 goto failed;
3825 Py_DECREF(value);
3826 break;
3827 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003828 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3829 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003830 if (!result) goto failed;
3831 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003833 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003834 goto failed;
3835 Py_DECREF(value);
3836 break;
3837 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003838 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3839 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003840 if (!result) goto failed;
3841 value = ast2obj_identifier(o->v.ImportFrom.module);
3842 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003843 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3844 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003845 goto failed;
3846 Py_DECREF(value);
3847 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003849 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003850 goto failed;
3851 Py_DECREF(value);
3852 value = ast2obj_int(o->v.ImportFrom.level);
3853 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003854 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003855 goto failed;
3856 Py_DECREF(value);
3857 break;
3858 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003859 tp = (PyTypeObject *)astmodulestate_global->Global_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.Global.names, ast2obj_identifier);
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 Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3870 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003871 if (!result) goto failed;
3872 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003874 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003875 goto failed;
3876 Py_DECREF(value);
3877 break;
3878 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003879 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3880 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003881 if (!result) goto failed;
3882 value = ast2obj_expr(o->v.Expr.value);
3883 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003884 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003885 goto failed;
3886 Py_DECREF(value);
3887 break;
3888 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003889 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3890 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003891 if (!result) goto failed;
3892 break;
3893 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003894 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3895 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003896 if (!result) goto failed;
3897 break;
3898 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003899 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3900 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003901 if (!result) goto failed;
3902 break;
3903 }
3904 value = ast2obj_int(o->lineno);
3905 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003906 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003907 goto failed;
3908 Py_DECREF(value);
3909 value = ast2obj_int(o->col_offset);
3910 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003911 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003912 goto failed;
3913 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003914 value = ast2obj_int(o->end_lineno);
3915 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003916 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003917 goto failed;
3918 Py_DECREF(value);
3919 value = ast2obj_int(o->end_col_offset);
3920 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003921 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
3922 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003923 goto failed;
3924 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003925 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003926failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003927 Py_XDECREF(value);
3928 Py_XDECREF(result);
3929 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003930}
3931
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003932PyObject*
3933ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003934{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003935 expr_ty o = (expr_ty)_o;
3936 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003937 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003938 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003939 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003940 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003941
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003942 switch (o->kind) {
3943 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003944 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
3945 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003946 if (!result) goto failed;
3947 value = ast2obj_boolop(o->v.BoolOp.op);
3948 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003949 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003950 goto failed;
3951 Py_DECREF(value);
3952 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
3953 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003954 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
3955 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003956 goto failed;
3957 Py_DECREF(value);
3958 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003959 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003960 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
3961 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003962 if (!result) goto failed;
3963 value = ast2obj_expr(o->v.NamedExpr.target);
3964 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003965 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3966 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003967 goto failed;
3968 Py_DECREF(value);
3969 value = ast2obj_expr(o->v.NamedExpr.value);
3970 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003971 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07003972 goto failed;
3973 Py_DECREF(value);
3974 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003975 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003976 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
3977 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003978 if (!result) goto failed;
3979 value = ast2obj_expr(o->v.BinOp.left);
3980 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003981 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003982 goto failed;
3983 Py_DECREF(value);
3984 value = ast2obj_operator(o->v.BinOp.op);
3985 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003986 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003987 goto failed;
3988 Py_DECREF(value);
3989 value = ast2obj_expr(o->v.BinOp.right);
3990 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003991 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003992 goto failed;
3993 Py_DECREF(value);
3994 break;
3995 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003996 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
3997 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003998 if (!result) goto failed;
3999 value = ast2obj_unaryop(o->v.UnaryOp.op);
4000 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004001 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004002 goto failed;
4003 Py_DECREF(value);
4004 value = ast2obj_expr(o->v.UnaryOp.operand);
4005 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004006 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4007 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004008 goto failed;
4009 Py_DECREF(value);
4010 break;
4011 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004012 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4013 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004014 if (!result) goto failed;
4015 value = ast2obj_arguments(o->v.Lambda.args);
4016 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004017 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004018 goto failed;
4019 Py_DECREF(value);
4020 value = ast2obj_expr(o->v.Lambda.body);
4021 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004022 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004023 goto failed;
4024 Py_DECREF(value);
4025 break;
4026 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4028 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004029 if (!result) goto failed;
4030 value = ast2obj_expr(o->v.IfExp.test);
4031 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004032 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004033 goto failed;
4034 Py_DECREF(value);
4035 value = ast2obj_expr(o->v.IfExp.body);
4036 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004037 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004038 goto failed;
4039 Py_DECREF(value);
4040 value = ast2obj_expr(o->v.IfExp.orelse);
4041 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004042 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4043 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 goto failed;
4045 Py_DECREF(value);
4046 break;
4047 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004048 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4049 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004050 if (!result) goto failed;
4051 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4052 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004053 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004054 goto failed;
4055 Py_DECREF(value);
4056 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4057 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004058 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4059 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004060 goto failed;
4061 Py_DECREF(value);
4062 break;
4063 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004064 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4065 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004066 if (!result) goto failed;
4067 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4068 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004069 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 goto failed;
4071 Py_DECREF(value);
4072 break;
4073 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004074 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4075 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004076 if (!result) goto failed;
4077 value = ast2obj_expr(o->v.ListComp.elt);
4078 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004079 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004080 goto failed;
4081 Py_DECREF(value);
4082 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4083 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004084 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4085 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004086 goto failed;
4087 Py_DECREF(value);
4088 break;
4089 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004090 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4091 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004092 if (!result) goto failed;
4093 value = ast2obj_expr(o->v.SetComp.elt);
4094 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004095 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004096 goto failed;
4097 Py_DECREF(value);
4098 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4099 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004100 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4101 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 goto failed;
4103 Py_DECREF(value);
4104 break;
4105 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004106 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4107 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004108 if (!result) goto failed;
4109 value = ast2obj_expr(o->v.DictComp.key);
4110 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004111 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004112 goto failed;
4113 Py_DECREF(value);
4114 value = ast2obj_expr(o->v.DictComp.value);
4115 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004116 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004117 goto failed;
4118 Py_DECREF(value);
4119 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4120 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004121 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4122 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004123 goto failed;
4124 Py_DECREF(value);
4125 break;
4126 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004127 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4128 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004129 if (!result) goto failed;
4130 value = ast2obj_expr(o->v.GeneratorExp.elt);
4131 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004132 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004133 goto failed;
4134 Py_DECREF(value);
4135 value = ast2obj_list(o->v.GeneratorExp.generators,
4136 ast2obj_comprehension);
4137 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004138 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4139 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004140 goto failed;
4141 Py_DECREF(value);
4142 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004143 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004144 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4145 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004146 if (!result) goto failed;
4147 value = ast2obj_expr(o->v.Await.value);
4148 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004149 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004150 goto failed;
4151 Py_DECREF(value);
4152 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004153 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004154 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4155 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004156 if (!result) goto failed;
4157 value = ast2obj_expr(o->v.Yield.value);
4158 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004159 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004160 goto failed;
4161 Py_DECREF(value);
4162 break;
4163 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004164 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4165 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004166 if (!result) goto failed;
4167 value = ast2obj_expr(o->v.YieldFrom.value);
4168 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004169 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004170 goto failed;
4171 Py_DECREF(value);
4172 break;
4173 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004174 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4175 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004176 if (!result) goto failed;
4177 value = ast2obj_expr(o->v.Compare.left);
4178 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004179 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004180 goto failed;
4181 Py_DECREF(value);
4182 {
4183 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4184 value = PyList_New(n);
4185 if (!value) goto failed;
4186 for(i = 0; i < n; i++)
4187 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004188 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004189 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004190 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004191 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004192 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004193 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004194 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004195 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4196 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004197 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004198 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004199 break;
4200 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004201 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4202 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004203 if (!result) goto failed;
4204 value = ast2obj_expr(o->v.Call.func);
4205 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004206 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004207 goto failed;
4208 Py_DECREF(value);
4209 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4210 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004211 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004212 goto failed;
4213 Py_DECREF(value);
4214 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4215 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004216 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4217 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004218 goto failed;
4219 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004220 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004221 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004222 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4223 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004224 if (!result) goto failed;
4225 value = ast2obj_expr(o->v.FormattedValue.value);
4226 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004227 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004228 goto failed;
4229 Py_DECREF(value);
4230 value = ast2obj_int(o->v.FormattedValue.conversion);
4231 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004232 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4233 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004234 goto failed;
4235 Py_DECREF(value);
4236 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4237 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004238 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4239 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004240 goto failed;
4241 Py_DECREF(value);
4242 break;
4243 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004244 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4245 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004246 if (!result) goto failed;
4247 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4248 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004249 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4250 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004251 goto failed;
4252 Py_DECREF(value);
4253 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004254 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004255 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4256 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004257 if (!result) goto failed;
4258 value = ast2obj_constant(o->v.Constant.value);
4259 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004260 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004261 goto failed;
4262 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004263 value = ast2obj_string(o->v.Constant.kind);
4264 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004265 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004266 goto failed;
4267 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004268 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004269 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004270 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4271 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004272 if (!result) goto failed;
4273 value = ast2obj_expr(o->v.Attribute.value);
4274 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004275 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004276 goto failed;
4277 Py_DECREF(value);
4278 value = ast2obj_identifier(o->v.Attribute.attr);
4279 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004280 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004281 goto failed;
4282 Py_DECREF(value);
4283 value = ast2obj_expr_context(o->v.Attribute.ctx);
4284 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004285 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004286 goto failed;
4287 Py_DECREF(value);
4288 break;
4289 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004290 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4291 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004292 if (!result) goto failed;
4293 value = ast2obj_expr(o->v.Subscript.value);
4294 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004295 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004296 goto failed;
4297 Py_DECREF(value);
4298 value = ast2obj_slice(o->v.Subscript.slice);
4299 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004300 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004301 goto failed;
4302 Py_DECREF(value);
4303 value = ast2obj_expr_context(o->v.Subscript.ctx);
4304 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004305 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004306 goto failed;
4307 Py_DECREF(value);
4308 break;
4309 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004310 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4311 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 if (!result) goto failed;
4313 value = ast2obj_expr(o->v.Starred.value);
4314 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004315 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004316 goto failed;
4317 Py_DECREF(value);
4318 value = ast2obj_expr_context(o->v.Starred.ctx);
4319 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004320 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004321 goto failed;
4322 Py_DECREF(value);
4323 break;
4324 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004325 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4326 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004327 if (!result) goto failed;
4328 value = ast2obj_identifier(o->v.Name.id);
4329 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004330 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004331 goto failed;
4332 Py_DECREF(value);
4333 value = ast2obj_expr_context(o->v.Name.ctx);
4334 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004335 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004336 goto failed;
4337 Py_DECREF(value);
4338 break;
4339 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004340 tp = (PyTypeObject *)astmodulestate_global->List_type;
4341 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004342 if (!result) goto failed;
4343 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4344 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004345 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004346 goto failed;
4347 Py_DECREF(value);
4348 value = ast2obj_expr_context(o->v.List.ctx);
4349 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004350 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004351 goto failed;
4352 Py_DECREF(value);
4353 break;
4354 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004355 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4356 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004357 if (!result) goto failed;
4358 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4359 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004360 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004361 goto failed;
4362 Py_DECREF(value);
4363 value = ast2obj_expr_context(o->v.Tuple.ctx);
4364 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004365 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 goto failed;
4367 Py_DECREF(value);
4368 break;
4369 }
4370 value = ast2obj_int(o->lineno);
4371 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004372 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004373 goto failed;
4374 Py_DECREF(value);
4375 value = ast2obj_int(o->col_offset);
4376 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004377 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004378 goto failed;
4379 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004380 value = ast2obj_int(o->end_lineno);
4381 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004382 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004383 goto failed;
4384 Py_DECREF(value);
4385 value = ast2obj_int(o->end_col_offset);
4386 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004387 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4388 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004389 goto failed;
4390 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004391 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004392failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004393 Py_XDECREF(value);
4394 Py_XDECREF(result);
4395 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004396}
4397
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004398PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004399{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004400 switch(o) {
4401 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004402 Py_INCREF(astmodulestate_global->Load_singleton);
4403 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004404 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004405 Py_INCREF(astmodulestate_global->Store_singleton);
4406 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004407 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004408 Py_INCREF(astmodulestate_global->Del_singleton);
4409 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004410 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004411 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4412 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004413 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004414 Py_INCREF(astmodulestate_global->AugStore_singleton);
4415 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004416 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004417 Py_INCREF(astmodulestate_global->Param_singleton);
4418 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004419 default:
4420 /* should never happen, but just in case ... */
4421 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4422 return NULL;
4423 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004424}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004425PyObject*
4426ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004427{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004428 slice_ty o = (slice_ty)_o;
4429 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004430 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004431 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004432 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004433 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004434
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004435 switch (o->kind) {
4436 case Slice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004437 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4438 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004439 if (!result) goto failed;
4440 value = ast2obj_expr(o->v.Slice.lower);
4441 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004442 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004443 goto failed;
4444 Py_DECREF(value);
4445 value = ast2obj_expr(o->v.Slice.upper);
4446 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004447 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004448 goto failed;
4449 Py_DECREF(value);
4450 value = ast2obj_expr(o->v.Slice.step);
4451 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004452 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004453 goto failed;
4454 Py_DECREF(value);
4455 break;
4456 case ExtSlice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004457 tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type;
4458 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004459 if (!result) goto failed;
4460 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
4461 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004462 if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004463 goto failed;
4464 Py_DECREF(value);
4465 break;
4466 case Index_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004467 tp = (PyTypeObject *)astmodulestate_global->Index_type;
4468 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004469 if (!result) goto failed;
4470 value = ast2obj_expr(o->v.Index.value);
4471 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004472 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004473 goto failed;
4474 Py_DECREF(value);
4475 break;
4476 }
4477 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004478failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004479 Py_XDECREF(value);
4480 Py_XDECREF(result);
4481 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004482}
4483
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004484PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004485{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004486 switch(o) {
4487 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004488 Py_INCREF(astmodulestate_global->And_singleton);
4489 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004490 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004491 Py_INCREF(astmodulestate_global->Or_singleton);
4492 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004493 default:
4494 /* should never happen, but just in case ... */
4495 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4496 return NULL;
4497 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004498}
4499PyObject* ast2obj_operator(operator_ty o)
4500{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004501 switch(o) {
4502 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004503 Py_INCREF(astmodulestate_global->Add_singleton);
4504 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004505 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004506 Py_INCREF(astmodulestate_global->Sub_singleton);
4507 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004508 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004509 Py_INCREF(astmodulestate_global->Mult_singleton);
4510 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004511 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004512 Py_INCREF(astmodulestate_global->MatMult_singleton);
4513 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004514 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004515 Py_INCREF(astmodulestate_global->Div_singleton);
4516 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004517 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004518 Py_INCREF(astmodulestate_global->Mod_singleton);
4519 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004520 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004521 Py_INCREF(astmodulestate_global->Pow_singleton);
4522 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004523 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004524 Py_INCREF(astmodulestate_global->LShift_singleton);
4525 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004526 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004527 Py_INCREF(astmodulestate_global->RShift_singleton);
4528 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004529 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004530 Py_INCREF(astmodulestate_global->BitOr_singleton);
4531 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004532 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004533 Py_INCREF(astmodulestate_global->BitXor_singleton);
4534 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004535 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004536 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4537 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004538 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004539 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4540 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004541 default:
4542 /* should never happen, but just in case ... */
4543 PyErr_Format(PyExc_SystemError, "unknown operator found");
4544 return NULL;
4545 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004546}
4547PyObject* ast2obj_unaryop(unaryop_ty o)
4548{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004549 switch(o) {
4550 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004551 Py_INCREF(astmodulestate_global->Invert_singleton);
4552 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004553 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004554 Py_INCREF(astmodulestate_global->Not_singleton);
4555 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004556 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004557 Py_INCREF(astmodulestate_global->UAdd_singleton);
4558 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004559 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004560 Py_INCREF(astmodulestate_global->USub_singleton);
4561 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004562 default:
4563 /* should never happen, but just in case ... */
4564 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4565 return NULL;
4566 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004567}
4568PyObject* ast2obj_cmpop(cmpop_ty o)
4569{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004570 switch(o) {
4571 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004572 Py_INCREF(astmodulestate_global->Eq_singleton);
4573 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004574 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004575 Py_INCREF(astmodulestate_global->NotEq_singleton);
4576 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004577 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004578 Py_INCREF(astmodulestate_global->Lt_singleton);
4579 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004580 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004581 Py_INCREF(astmodulestate_global->LtE_singleton);
4582 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004583 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004584 Py_INCREF(astmodulestate_global->Gt_singleton);
4585 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004586 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004587 Py_INCREF(astmodulestate_global->GtE_singleton);
4588 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004589 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004590 Py_INCREF(astmodulestate_global->Is_singleton);
4591 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004592 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004593 Py_INCREF(astmodulestate_global->IsNot_singleton);
4594 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004595 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004596 Py_INCREF(astmodulestate_global->In_singleton);
4597 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004598 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004599 Py_INCREF(astmodulestate_global->NotIn_singleton);
4600 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004601 default:
4602 /* should never happen, but just in case ... */
4603 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4604 return NULL;
4605 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004606}
4607PyObject*
4608ast2obj_comprehension(void* _o)
4609{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004610 comprehension_ty o = (comprehension_ty)_o;
4611 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004612 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004613 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004614 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004615 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004616
Dino Viehlandac46eb42019-09-11 10:16:34 -07004617 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4618 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004619 if (!result) return NULL;
4620 value = ast2obj_expr(o->target);
4621 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004622 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004623 goto failed;
4624 Py_DECREF(value);
4625 value = ast2obj_expr(o->iter);
4626 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004627 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004628 goto failed;
4629 Py_DECREF(value);
4630 value = ast2obj_list(o->ifs, ast2obj_expr);
4631 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004632 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004633 goto failed;
4634 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004635 value = ast2obj_int(o->is_async);
4636 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004637 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004638 goto failed;
4639 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004640 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004641failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004642 Py_XDECREF(value);
4643 Py_XDECREF(result);
4644 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004645}
4646
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004647PyObject*
4648ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004649{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 excepthandler_ty o = (excepthandler_ty)_o;
4651 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004652 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004653 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004654 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004655 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004656
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004657 switch (o->kind) {
4658 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004659 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4660 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004661 if (!result) goto failed;
4662 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004663 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004664 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004665 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004666 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004667 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004668 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004669 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004670 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004671 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4673 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004674 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004675 goto failed;
4676 Py_DECREF(value);
4677 break;
4678 }
4679 value = ast2obj_int(o->lineno);
4680 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004681 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004682 goto failed;
4683 Py_DECREF(value);
4684 value = ast2obj_int(o->col_offset);
4685 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004686 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 goto failed;
4688 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004689 value = ast2obj_int(o->end_lineno);
4690 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004691 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004692 goto failed;
4693 Py_DECREF(value);
4694 value = ast2obj_int(o->end_col_offset);
4695 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004696 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4697 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004698 goto failed;
4699 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004700 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004701failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004702 Py_XDECREF(value);
4703 Py_XDECREF(result);
4704 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004705}
4706
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004707PyObject*
4708ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004709{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004710 arguments_ty o = (arguments_ty)_o;
4711 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004712 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004713 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004714 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004715 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004716
Dino Viehlandac46eb42019-09-11 10:16:34 -07004717 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4718 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004719 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004720 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4721 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004722 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4723 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004724 goto failed;
4725 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004726 value = ast2obj_list(o->args, ast2obj_arg);
4727 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004728 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004729 goto failed;
4730 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004731 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004732 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004733 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004734 goto failed;
4735 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004736 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4737 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004738 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4739 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004740 goto failed;
4741 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004742 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004743 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004744 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4745 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004746 goto failed;
4747 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004748 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004749 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004750 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004751 goto failed;
4752 Py_DECREF(value);
4753 value = ast2obj_list(o->defaults, ast2obj_expr);
4754 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004755 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004756 goto failed;
4757 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004758 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004759failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 Py_XDECREF(value);
4761 Py_XDECREF(result);
4762 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004763}
4764
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004765PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004766ast2obj_arg(void* _o)
4767{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004768 arg_ty o = (arg_ty)_o;
4769 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004770 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004772 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004773 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004774
Dino Viehlandac46eb42019-09-11 10:16:34 -07004775 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4776 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 if (!result) return NULL;
4778 value = ast2obj_identifier(o->arg);
4779 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004780 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004781 goto failed;
4782 Py_DECREF(value);
4783 value = ast2obj_expr(o->annotation);
4784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004785 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4786 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004787 goto failed;
4788 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004789 value = ast2obj_string(o->type_comment);
4790 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004791 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4792 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004793 goto failed;
4794 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004795 value = ast2obj_int(o->lineno);
4796 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004797 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004798 goto failed;
4799 Py_DECREF(value);
4800 value = ast2obj_int(o->col_offset);
4801 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004802 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004803 goto failed;
4804 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004805 value = ast2obj_int(o->end_lineno);
4806 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004807 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004808 goto failed;
4809 Py_DECREF(value);
4810 value = ast2obj_int(o->end_col_offset);
4811 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004812 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4813 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004814 goto failed;
4815 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004816 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004817failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004818 Py_XDECREF(value);
4819 Py_XDECREF(result);
4820 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004821}
4822
4823PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004824ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004825{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004826 keyword_ty o = (keyword_ty)_o;
4827 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004828 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004829 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004830 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004831 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004832
Dino Viehlandac46eb42019-09-11 10:16:34 -07004833 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4834 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004835 if (!result) return NULL;
4836 value = ast2obj_identifier(o->arg);
4837 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004838 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004839 goto failed;
4840 Py_DECREF(value);
4841 value = ast2obj_expr(o->value);
4842 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004843 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004844 goto failed;
4845 Py_DECREF(value);
4846 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004847failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004848 Py_XDECREF(value);
4849 Py_XDECREF(result);
4850 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004851}
4852
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004853PyObject*
4854ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004855{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004856 alias_ty o = (alias_ty)_o;
4857 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004858 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004859 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004860 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004862
Dino Viehlandac46eb42019-09-11 10:16:34 -07004863 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4864 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004865 if (!result) return NULL;
4866 value = ast2obj_identifier(o->name);
4867 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004868 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004869 goto failed;
4870 Py_DECREF(value);
4871 value = ast2obj_identifier(o->asname);
4872 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004873 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004874 goto failed;
4875 Py_DECREF(value);
4876 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004877failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 Py_XDECREF(value);
4879 Py_XDECREF(result);
4880 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004881}
4882
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004883PyObject*
4884ast2obj_withitem(void* _o)
4885{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004886 withitem_ty o = (withitem_ty)_o;
4887 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004888 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004889 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004890 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004892
Dino Viehlandac46eb42019-09-11 10:16:34 -07004893 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4894 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004895 if (!result) return NULL;
4896 value = ast2obj_expr(o->context_expr);
4897 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004898 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4899 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 goto failed;
4901 Py_DECREF(value);
4902 value = ast2obj_expr(o->optional_vars);
4903 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004904 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4905 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004906 goto failed;
4907 Py_DECREF(value);
4908 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004909failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004910 Py_XDECREF(value);
4911 Py_XDECREF(result);
4912 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004913}
4914
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004915PyObject*
4916ast2obj_type_ignore(void* _o)
4917{
4918 type_ignore_ty o = (type_ignore_ty)_o;
4919 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004920 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004921 if (!o) {
4922 Py_RETURN_NONE;
4923 }
4924
4925 switch (o->kind) {
4926 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004927 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
4928 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004929 if (!result) goto failed;
4930 value = ast2obj_int(o->v.TypeIgnore.lineno);
4931 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004932 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
4933 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004934 goto failed;
4935 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004936 value = ast2obj_string(o->v.TypeIgnore.tag);
4937 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004938 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07004939 goto failed;
4940 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004941 break;
4942 }
4943 return result;
4944failed:
4945 Py_XDECREF(value);
4946 Py_XDECREF(result);
4947 return NULL;
4948}
4949
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004950
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004951int
4952obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
4953{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004954 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004955
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004956 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004957 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004958
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004959 if (obj == Py_None) {
4960 *out = NULL;
4961 return 0;
4962 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07004963 tp = astmodulestate_global->Module_type;
4964 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004965 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00004966 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004967 }
4968 if (isinstance) {
4969 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004970 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004971
Dino Viehlandac46eb42019-09-11 10:16:34 -07004972 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02004973 return 1;
4974 }
4975 if (tmp == NULL) {
4976 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
4977 return 1;
4978 }
4979 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004980 int res;
4981 Py_ssize_t len;
4982 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004983 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07004984 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 +02004985 goto failed;
4986 }
4987 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02004988 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 if (body == NULL) goto failed;
4990 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07004991 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03004992 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
4993 Py_INCREF(tmp2);
4994 res = obj2ast_stmt(tmp2, &val, arena);
4995 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004996 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03004997 if (len != PyList_GET_SIZE(tmp)) {
4998 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
4999 goto failed;
5000 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005001 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005002 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005003 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005004 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005005 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5006 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005007 return 1;
5008 }
5009 if (tmp == NULL) {
5010 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5011 return 1;
5012 }
5013 else {
5014 int res;
5015 Py_ssize_t len;
5016 Py_ssize_t i;
5017 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005018 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 -08005019 goto failed;
5020 }
5021 len = PyList_GET_SIZE(tmp);
5022 type_ignores = _Py_asdl_seq_new(len, arena);
5023 if (type_ignores == NULL) goto failed;
5024 for (i = 0; i < len; i++) {
5025 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005026 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5027 Py_INCREF(tmp2);
5028 res = obj2ast_type_ignore(tmp2, &val, arena);
5029 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005030 if (res != 0) goto failed;
5031 if (len != PyList_GET_SIZE(tmp)) {
5032 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5033 goto failed;
5034 }
5035 asdl_seq_SET(type_ignores, i, val);
5036 }
5037 Py_CLEAR(tmp);
5038 }
5039 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005040 if (*out == NULL) goto failed;
5041 return 0;
5042 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005043 tp = astmodulestate_global->Interactive_type;
5044 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005045 if (isinstance == -1) {
5046 return 1;
5047 }
5048 if (isinstance) {
5049 asdl_seq* body;
5050
Dino Viehlandac46eb42019-09-11 10:16:34 -07005051 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005052 return 1;
5053 }
5054 if (tmp == NULL) {
5055 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5056 return 1;
5057 }
5058 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005059 int res;
5060 Py_ssize_t len;
5061 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005062 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005063 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 +02005064 goto failed;
5065 }
5066 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005067 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005068 if (body == NULL) goto failed;
5069 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005070 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005071 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5072 Py_INCREF(tmp2);
5073 res = obj2ast_stmt(tmp2, &val, arena);
5074 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005075 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005076 if (len != PyList_GET_SIZE(tmp)) {
5077 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5078 goto failed;
5079 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005080 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005081 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005082 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005083 }
5084 *out = Interactive(body, arena);
5085 if (*out == NULL) goto failed;
5086 return 0;
5087 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005088 tp = astmodulestate_global->Expression_type;
5089 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005090 if (isinstance == -1) {
5091 return 1;
5092 }
5093 if (isinstance) {
5094 expr_ty body;
5095
Dino Viehlandac46eb42019-09-11 10:16:34 -07005096 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005097 return 1;
5098 }
5099 if (tmp == NULL) {
5100 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5101 return 1;
5102 }
5103 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005104 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005105 res = obj2ast_expr(tmp, &body, arena);
5106 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005107 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005108 }
5109 *out = Expression(body, arena);
5110 if (*out == NULL) goto failed;
5111 return 0;
5112 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005113 tp = astmodulestate_global->FunctionType_type;
5114 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005115 if (isinstance == -1) {
5116 return 1;
5117 }
5118 if (isinstance) {
5119 asdl_seq* argtypes;
5120 expr_ty returns;
5121
Dino Viehlandac46eb42019-09-11 10:16:34 -07005122 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5123 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005124 return 1;
5125 }
5126 if (tmp == NULL) {
5127 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5128 return 1;
5129 }
5130 else {
5131 int res;
5132 Py_ssize_t len;
5133 Py_ssize_t i;
5134 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005135 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 -08005136 goto failed;
5137 }
5138 len = PyList_GET_SIZE(tmp);
5139 argtypes = _Py_asdl_seq_new(len, arena);
5140 if (argtypes == NULL) goto failed;
5141 for (i = 0; i < len; i++) {
5142 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005143 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5144 Py_INCREF(tmp2);
5145 res = obj2ast_expr(tmp2, &val, arena);
5146 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005147 if (res != 0) goto failed;
5148 if (len != PyList_GET_SIZE(tmp)) {
5149 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5150 goto failed;
5151 }
5152 asdl_seq_SET(argtypes, i, val);
5153 }
5154 Py_CLEAR(tmp);
5155 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005156 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5157 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005158 return 1;
5159 }
5160 if (tmp == NULL) {
5161 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5162 return 1;
5163 }
5164 else {
5165 int res;
5166 res = obj2ast_expr(tmp, &returns, arena);
5167 if (res != 0) goto failed;
5168 Py_CLEAR(tmp);
5169 }
5170 *out = FunctionType(argtypes, returns, arena);
5171 if (*out == NULL) goto failed;
5172 return 0;
5173 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005174
5175 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5176 failed:
5177 Py_XDECREF(tmp);
5178 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005179}
5180
5181int
5182obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5183{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005184 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005185
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005186 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005187 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005188 int lineno;
5189 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005190 int end_lineno;
5191 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005192
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005193 if (obj == Py_None) {
5194 *out = NULL;
5195 return 0;
5196 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005197 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005198 return 1;
5199 }
5200 if (tmp == NULL) {
5201 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5202 return 1;
5203 }
5204 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005205 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005206 res = obj2ast_int(tmp, &lineno, arena);
5207 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005208 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005209 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005210 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5211 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005212 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005213 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005214 if (tmp == NULL) {
5215 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5216 return 1;
5217 }
5218 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005219 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005220 res = obj2ast_int(tmp, &col_offset, arena);
5221 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005222 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005224 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5225 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005226 return 1;
5227 }
5228 if (tmp == NULL || tmp == Py_None) {
5229 Py_CLEAR(tmp);
5230 end_lineno = 0;
5231 }
5232 else {
5233 int res;
5234 res = obj2ast_int(tmp, &end_lineno, arena);
5235 if (res != 0) goto failed;
5236 Py_CLEAR(tmp);
5237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005238 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5239 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005240 return 1;
5241 }
5242 if (tmp == NULL || tmp == Py_None) {
5243 Py_CLEAR(tmp);
5244 end_col_offset = 0;
5245 }
5246 else {
5247 int res;
5248 res = obj2ast_int(tmp, &end_col_offset, arena);
5249 if (res != 0) goto failed;
5250 Py_CLEAR(tmp);
5251 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005252 tp = astmodulestate_global->FunctionDef_type;
5253 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005254 if (isinstance == -1) {
5255 return 1;
5256 }
5257 if (isinstance) {
5258 identifier name;
5259 arguments_ty args;
5260 asdl_seq* body;
5261 asdl_seq* decorator_list;
5262 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005263 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005264
Dino Viehlandac46eb42019-09-11 10:16:34 -07005265 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005266 return 1;
5267 }
5268 if (tmp == NULL) {
5269 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5270 return 1;
5271 }
5272 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005273 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005274 res = obj2ast_identifier(tmp, &name, arena);
5275 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005276 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005277 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005278 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005279 return 1;
5280 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005281 if (tmp == NULL) {
5282 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5283 return 1;
5284 }
5285 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005286 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005287 res = obj2ast_arguments(tmp, &args, arena);
5288 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005289 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005290 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005291 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005292 return 1;
5293 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005294 if (tmp == NULL) {
5295 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5296 return 1;
5297 }
5298 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005299 int res;
5300 Py_ssize_t len;
5301 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005302 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005303 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 +02005304 goto failed;
5305 }
5306 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005307 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005308 if (body == NULL) goto failed;
5309 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005310 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005311 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5312 Py_INCREF(tmp2);
5313 res = obj2ast_stmt(tmp2, &val, arena);
5314 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005315 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005316 if (len != PyList_GET_SIZE(tmp)) {
5317 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5318 goto failed;
5319 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005320 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005321 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005322 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005323 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005324 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5325 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005326 return 1;
5327 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005328 if (tmp == NULL) {
5329 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5330 return 1;
5331 }
5332 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005333 int res;
5334 Py_ssize_t len;
5335 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005336 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005337 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 +02005338 goto failed;
5339 }
5340 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005341 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005342 if (decorator_list == NULL) goto failed;
5343 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005344 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005345 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5346 Py_INCREF(tmp2);
5347 res = obj2ast_expr(tmp2, &val, arena);
5348 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005349 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005350 if (len != PyList_GET_SIZE(tmp)) {
5351 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5352 goto failed;
5353 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005354 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005355 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005356 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005357 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005358 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5359 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005360 return 1;
5361 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005362 if (tmp == NULL || tmp == Py_None) {
5363 Py_CLEAR(tmp);
5364 returns = NULL;
5365 }
5366 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005367 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005368 res = obj2ast_expr(tmp, &returns, arena);
5369 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005370 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005371 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005372 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5373 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005374 return 1;
5375 }
5376 if (tmp == NULL || tmp == Py_None) {
5377 Py_CLEAR(tmp);
5378 type_comment = NULL;
5379 }
5380 else {
5381 int res;
5382 res = obj2ast_string(tmp, &type_comment, arena);
5383 if (res != 0) goto failed;
5384 Py_CLEAR(tmp);
5385 }
5386 *out = FunctionDef(name, args, body, decorator_list, returns,
5387 type_comment, lineno, col_offset, end_lineno,
5388 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005389 if (*out == NULL) goto failed;
5390 return 0;
5391 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005392 tp = astmodulestate_global->AsyncFunctionDef_type;
5393 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005394 if (isinstance == -1) {
5395 return 1;
5396 }
5397 if (isinstance) {
5398 identifier name;
5399 arguments_ty args;
5400 asdl_seq* body;
5401 asdl_seq* decorator_list;
5402 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005403 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005404
Dino Viehlandac46eb42019-09-11 10:16:34 -07005405 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005406 return 1;
5407 }
5408 if (tmp == NULL) {
5409 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5410 return 1;
5411 }
5412 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005413 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005414 res = obj2ast_identifier(tmp, &name, arena);
5415 if (res != 0) goto failed;
5416 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005417 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005418 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005419 return 1;
5420 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005421 if (tmp == NULL) {
5422 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5423 return 1;
5424 }
5425 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005426 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005427 res = obj2ast_arguments(tmp, &args, arena);
5428 if (res != 0) goto failed;
5429 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005430 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005431 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005432 return 1;
5433 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005434 if (tmp == NULL) {
5435 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5436 return 1;
5437 }
5438 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005439 int res;
5440 Py_ssize_t len;
5441 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005442 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005443 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 -04005444 goto failed;
5445 }
5446 len = PyList_GET_SIZE(tmp);
5447 body = _Py_asdl_seq_new(len, arena);
5448 if (body == NULL) goto failed;
5449 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005450 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005451 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5452 Py_INCREF(tmp2);
5453 res = obj2ast_stmt(tmp2, &val, arena);
5454 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005455 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005456 if (len != PyList_GET_SIZE(tmp)) {
5457 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5458 goto failed;
5459 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005460 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005461 }
5462 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005463 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005464 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5465 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005466 return 1;
5467 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005468 if (tmp == NULL) {
5469 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5470 return 1;
5471 }
5472 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005473 int res;
5474 Py_ssize_t len;
5475 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005476 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005477 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 -04005478 goto failed;
5479 }
5480 len = PyList_GET_SIZE(tmp);
5481 decorator_list = _Py_asdl_seq_new(len, arena);
5482 if (decorator_list == NULL) goto failed;
5483 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005484 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005485 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5486 Py_INCREF(tmp2);
5487 res = obj2ast_expr(tmp2, &val, arena);
5488 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005489 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005490 if (len != PyList_GET_SIZE(tmp)) {
5491 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5492 goto failed;
5493 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005494 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005495 }
5496 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005497 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005498 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5499 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005500 return 1;
5501 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005502 if (tmp == NULL || tmp == Py_None) {
5503 Py_CLEAR(tmp);
5504 returns = NULL;
5505 }
5506 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005507 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005508 res = obj2ast_expr(tmp, &returns, arena);
5509 if (res != 0) goto failed;
5510 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005511 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005512 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5513 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005514 return 1;
5515 }
5516 if (tmp == NULL || tmp == Py_None) {
5517 Py_CLEAR(tmp);
5518 type_comment = NULL;
5519 }
5520 else {
5521 int res;
5522 res = obj2ast_string(tmp, &type_comment, arena);
5523 if (res != 0) goto failed;
5524 Py_CLEAR(tmp);
5525 }
Yury Selivanov75445082015-05-11 22:57:16 -04005526 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005527 type_comment, lineno, col_offset, end_lineno,
5528 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005529 if (*out == NULL) goto failed;
5530 return 0;
5531 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005532 tp = astmodulestate_global->ClassDef_type;
5533 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005534 if (isinstance == -1) {
5535 return 1;
5536 }
5537 if (isinstance) {
5538 identifier name;
5539 asdl_seq* bases;
5540 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005541 asdl_seq* body;
5542 asdl_seq* decorator_list;
5543
Dino Viehlandac46eb42019-09-11 10:16:34 -07005544 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005545 return 1;
5546 }
5547 if (tmp == NULL) {
5548 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5549 return 1;
5550 }
5551 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005552 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005553 res = obj2ast_identifier(tmp, &name, arena);
5554 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005555 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005556 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005557 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005558 return 1;
5559 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005560 if (tmp == NULL) {
5561 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5562 return 1;
5563 }
5564 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005565 int res;
5566 Py_ssize_t len;
5567 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005568 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005569 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 +02005570 goto failed;
5571 }
5572 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005573 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005574 if (bases == NULL) goto failed;
5575 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005576 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005577 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5578 Py_INCREF(tmp2);
5579 res = obj2ast_expr(tmp2, &val, arena);
5580 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005581 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005582 if (len != PyList_GET_SIZE(tmp)) {
5583 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5584 goto failed;
5585 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005586 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005587 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005588 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005589 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005590 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5591 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005592 return 1;
5593 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005594 if (tmp == NULL) {
5595 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5596 return 1;
5597 }
5598 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005599 int res;
5600 Py_ssize_t len;
5601 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005602 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005603 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 +02005604 goto failed;
5605 }
5606 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005607 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005608 if (keywords == NULL) goto failed;
5609 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005610 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005611 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5612 Py_INCREF(tmp2);
5613 res = obj2ast_keyword(tmp2, &val, arena);
5614 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005615 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005616 if (len != PyList_GET_SIZE(tmp)) {
5617 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5618 goto failed;
5619 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005620 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005621 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005622 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005623 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005624 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005625 return 1;
5626 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005627 if (tmp == NULL) {
5628 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5629 return 1;
5630 }
5631 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005632 int res;
5633 Py_ssize_t len;
5634 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005635 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005636 PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005637 goto failed;
5638 }
5639 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005640 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005641 if (body == NULL) goto failed;
5642 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005643 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005644 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5645 Py_INCREF(tmp2);
5646 res = obj2ast_stmt(tmp2, &val, arena);
5647 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005648 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005649 if (len != PyList_GET_SIZE(tmp)) {
5650 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5651 goto failed;
5652 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005653 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005654 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005655 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005656 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005657 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5658 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005659 return 1;
5660 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005661 if (tmp == NULL) {
5662 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5663 return 1;
5664 }
5665 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005666 int res;
5667 Py_ssize_t len;
5668 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005669 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005670 PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005671 goto failed;
5672 }
5673 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005674 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005675 if (decorator_list == NULL) goto failed;
5676 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005677 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005678 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5679 Py_INCREF(tmp2);
5680 res = obj2ast_expr(tmp2, &val, arena);
5681 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005682 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005683 if (len != PyList_GET_SIZE(tmp)) {
5684 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5685 goto failed;
5686 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005687 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005688 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005689 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005690 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005691 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005692 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005693 if (*out == NULL) goto failed;
5694 return 0;
5695 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005696 tp = astmodulestate_global->Return_type;
5697 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005698 if (isinstance == -1) {
5699 return 1;
5700 }
5701 if (isinstance) {
5702 expr_ty value;
5703
Dino Viehlandac46eb42019-09-11 10:16:34 -07005704 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005705 return 1;
5706 }
5707 if (tmp == NULL || tmp == Py_None) {
5708 Py_CLEAR(tmp);
5709 value = NULL;
5710 }
5711 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005712 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005713 res = obj2ast_expr(tmp, &value, arena);
5714 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005715 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005716 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005717 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5718 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005719 if (*out == NULL) goto failed;
5720 return 0;
5721 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005722 tp = astmodulestate_global->Delete_type;
5723 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005724 if (isinstance == -1) {
5725 return 1;
5726 }
5727 if (isinstance) {
5728 asdl_seq* targets;
5729
Dino Viehlandac46eb42019-09-11 10:16:34 -07005730 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5731 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005732 return 1;
5733 }
5734 if (tmp == NULL) {
5735 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5736 return 1;
5737 }
5738 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005739 int res;
5740 Py_ssize_t len;
5741 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005742 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005743 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 +02005744 goto failed;
5745 }
5746 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005747 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005748 if (targets == NULL) goto failed;
5749 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005750 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005751 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5752 Py_INCREF(tmp2);
5753 res = obj2ast_expr(tmp2, &val, arena);
5754 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005755 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005756 if (len != PyList_GET_SIZE(tmp)) {
5757 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5758 goto failed;
5759 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005760 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005761 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005762 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005763 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005764 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5765 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005766 if (*out == NULL) goto failed;
5767 return 0;
5768 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005769 tp = astmodulestate_global->Assign_type;
5770 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005771 if (isinstance == -1) {
5772 return 1;
5773 }
5774 if (isinstance) {
5775 asdl_seq* targets;
5776 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005777 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005778
Dino Viehlandac46eb42019-09-11 10:16:34 -07005779 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5780 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005781 return 1;
5782 }
5783 if (tmp == NULL) {
5784 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5785 return 1;
5786 }
5787 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005788 int res;
5789 Py_ssize_t len;
5790 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005791 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005792 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 +02005793 goto failed;
5794 }
5795 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005796 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005797 if (targets == NULL) goto failed;
5798 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005799 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005800 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5801 Py_INCREF(tmp2);
5802 res = obj2ast_expr(tmp2, &val, arena);
5803 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005804 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005805 if (len != PyList_GET_SIZE(tmp)) {
5806 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5807 goto failed;
5808 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005809 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005810 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005811 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005812 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005813 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005814 return 1;
5815 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005816 if (tmp == NULL) {
5817 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5818 return 1;
5819 }
5820 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005821 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005822 res = obj2ast_expr(tmp, &value, arena);
5823 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005824 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005825 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005826 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5827 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005828 return 1;
5829 }
5830 if (tmp == NULL || tmp == Py_None) {
5831 Py_CLEAR(tmp);
5832 type_comment = NULL;
5833 }
5834 else {
5835 int res;
5836 res = obj2ast_string(tmp, &type_comment, arena);
5837 if (res != 0) goto failed;
5838 Py_CLEAR(tmp);
5839 }
5840 *out = Assign(targets, value, type_comment, lineno, col_offset,
5841 end_lineno, end_col_offset, 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->AugAssign_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 expr_ty target;
5852 operator_ty op;
5853 expr_ty value;
5854
Dino Viehlandac46eb42019-09-11 10:16:34 -07005855 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5856 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005857 return 1;
5858 }
5859 if (tmp == NULL) {
5860 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5861 return 1;
5862 }
5863 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005864 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005865 res = obj2ast_expr(tmp, &target, arena);
5866 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005867 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005868 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005869 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005870 return 1;
5871 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005872 if (tmp == NULL) {
5873 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5874 return 1;
5875 }
5876 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005877 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005878 res = obj2ast_operator(tmp, &op, arena);
5879 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005880 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005881 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005882 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005883 return 1;
5884 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005885 if (tmp == NULL) {
5886 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5887 return 1;
5888 }
5889 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005890 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005891 res = obj2ast_expr(tmp, &value, arena);
5892 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005893 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005894 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005895 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5896 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005897 if (*out == NULL) goto failed;
5898 return 0;
5899 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005900 tp = astmodulestate_global->AnnAssign_type;
5901 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005902 if (isinstance == -1) {
5903 return 1;
5904 }
5905 if (isinstance) {
5906 expr_ty target;
5907 expr_ty annotation;
5908 expr_ty value;
5909 int simple;
5910
Dino Viehlandac46eb42019-09-11 10:16:34 -07005911 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5912 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005913 return 1;
5914 }
5915 if (tmp == NULL) {
5916 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
5917 return 1;
5918 }
5919 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005920 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005921 res = obj2ast_expr(tmp, &target, arena);
5922 if (res != 0) goto failed;
5923 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005925 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
5926 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005927 return 1;
5928 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005929 if (tmp == NULL) {
5930 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
5931 return 1;
5932 }
5933 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005934 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005935 res = obj2ast_expr(tmp, &annotation, arena);
5936 if (res != 0) goto failed;
5937 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005939 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005940 return 1;
5941 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005942 if (tmp == NULL || tmp == Py_None) {
5943 Py_CLEAR(tmp);
5944 value = NULL;
5945 }
5946 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005947 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005948 res = obj2ast_expr(tmp, &value, arena);
5949 if (res != 0) goto failed;
5950 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005951 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005952 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
5953 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005954 return 1;
5955 }
5956 if (tmp == NULL) {
5957 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
5958 return 1;
5959 }
5960 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005961 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005962 res = obj2ast_int(tmp, &simple, arena);
5963 if (res != 0) goto failed;
5964 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005965 }
5966 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005967 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005968 if (*out == NULL) goto failed;
5969 return 0;
5970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005971 tp = astmodulestate_global->For_type;
5972 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005973 if (isinstance == -1) {
5974 return 1;
5975 }
5976 if (isinstance) {
5977 expr_ty target;
5978 expr_ty iter;
5979 asdl_seq* body;
5980 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005981 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005982
Dino Viehlandac46eb42019-09-11 10:16:34 -07005983 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5984 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005985 return 1;
5986 }
5987 if (tmp == NULL) {
5988 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
5989 return 1;
5990 }
5991 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005992 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005993 res = obj2ast_expr(tmp, &target, arena);
5994 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005995 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005996 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005997 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005998 return 1;
5999 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006000 if (tmp == NULL) {
6001 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6002 return 1;
6003 }
6004 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006005 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006006 res = obj2ast_expr(tmp, &iter, arena);
6007 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006008 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006010 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006011 return 1;
6012 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006013 if (tmp == NULL) {
6014 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6015 return 1;
6016 }
6017 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006018 int res;
6019 Py_ssize_t len;
6020 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006021 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006022 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 +02006023 goto failed;
6024 }
6025 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006026 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006027 if (body == NULL) goto failed;
6028 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006029 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006030 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6031 Py_INCREF(tmp2);
6032 res = obj2ast_stmt(tmp2, &val, arena);
6033 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006034 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006035 if (len != PyList_GET_SIZE(tmp)) {
6036 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6037 goto failed;
6038 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006039 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006040 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006041 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006042 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006043 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6044 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006045 return 1;
6046 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006047 if (tmp == NULL) {
6048 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6049 return 1;
6050 }
6051 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006052 int res;
6053 Py_ssize_t len;
6054 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006055 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006056 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 +02006057 goto failed;
6058 }
6059 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006060 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006061 if (orelse == NULL) goto failed;
6062 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006063 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006064 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6065 Py_INCREF(tmp2);
6066 res = obj2ast_stmt(tmp2, &val, arena);
6067 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006068 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006069 if (len != PyList_GET_SIZE(tmp)) {
6070 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6071 goto failed;
6072 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006073 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006074 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006075 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006076 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006077 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6078 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006079 return 1;
6080 }
6081 if (tmp == NULL || tmp == Py_None) {
6082 Py_CLEAR(tmp);
6083 type_comment = NULL;
6084 }
6085 else {
6086 int res;
6087 res = obj2ast_string(tmp, &type_comment, arena);
6088 if (res != 0) goto failed;
6089 Py_CLEAR(tmp);
6090 }
6091 *out = For(target, iter, body, orelse, type_comment, lineno,
6092 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006093 if (*out == NULL) goto failed;
6094 return 0;
6095 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006096 tp = astmodulestate_global->AsyncFor_type;
6097 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006098 if (isinstance == -1) {
6099 return 1;
6100 }
6101 if (isinstance) {
6102 expr_ty target;
6103 expr_ty iter;
6104 asdl_seq* body;
6105 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006106 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006107
Dino Viehlandac46eb42019-09-11 10:16:34 -07006108 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6109 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006110 return 1;
6111 }
6112 if (tmp == NULL) {
6113 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6114 return 1;
6115 }
6116 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006117 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006118 res = obj2ast_expr(tmp, &target, arena);
6119 if (res != 0) goto failed;
6120 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006121 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006122 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006123 return 1;
6124 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006125 if (tmp == NULL) {
6126 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6127 return 1;
6128 }
6129 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006130 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006131 res = obj2ast_expr(tmp, &iter, arena);
6132 if (res != 0) goto failed;
6133 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006134 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006135 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006136 return 1;
6137 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006138 if (tmp == NULL) {
6139 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6140 return 1;
6141 }
6142 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006143 int res;
6144 Py_ssize_t len;
6145 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006146 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006147 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 -04006148 goto failed;
6149 }
6150 len = PyList_GET_SIZE(tmp);
6151 body = _Py_asdl_seq_new(len, arena);
6152 if (body == NULL) goto failed;
6153 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006154 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006155 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6156 Py_INCREF(tmp2);
6157 res = obj2ast_stmt(tmp2, &val, arena);
6158 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006159 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006160 if (len != PyList_GET_SIZE(tmp)) {
6161 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6162 goto failed;
6163 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006164 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006165 }
6166 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006167 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006168 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6169 {
Yury Selivanov75445082015-05-11 22:57:16 -04006170 return 1;
6171 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006172 if (tmp == NULL) {
6173 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6174 return 1;
6175 }
6176 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006177 int res;
6178 Py_ssize_t len;
6179 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006180 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006181 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 -04006182 goto failed;
6183 }
6184 len = PyList_GET_SIZE(tmp);
6185 orelse = _Py_asdl_seq_new(len, arena);
6186 if (orelse == NULL) goto failed;
6187 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006188 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006189 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6190 Py_INCREF(tmp2);
6191 res = obj2ast_stmt(tmp2, &val, arena);
6192 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006193 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006194 if (len != PyList_GET_SIZE(tmp)) {
6195 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6196 goto failed;
6197 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006198 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006199 }
6200 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006202 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6203 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006204 return 1;
6205 }
6206 if (tmp == NULL || tmp == Py_None) {
6207 Py_CLEAR(tmp);
6208 type_comment = NULL;
6209 }
6210 else {
6211 int res;
6212 res = obj2ast_string(tmp, &type_comment, arena);
6213 if (res != 0) goto failed;
6214 Py_CLEAR(tmp);
6215 }
6216 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6217 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006218 if (*out == NULL) goto failed;
6219 return 0;
6220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006221 tp = astmodulestate_global->While_type;
6222 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006223 if (isinstance == -1) {
6224 return 1;
6225 }
6226 if (isinstance) {
6227 expr_ty test;
6228 asdl_seq* body;
6229 asdl_seq* orelse;
6230
Dino Viehlandac46eb42019-09-11 10:16:34 -07006231 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006232 return 1;
6233 }
6234 if (tmp == NULL) {
6235 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6236 return 1;
6237 }
6238 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006239 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006240 res = obj2ast_expr(tmp, &test, arena);
6241 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006242 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->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006245 return 1;
6246 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006247 if (tmp == NULL) {
6248 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6249 return 1;
6250 }
6251 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006252 int res;
6253 Py_ssize_t len;
6254 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006255 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006256 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 +02006257 goto failed;
6258 }
6259 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006260 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006261 if (body == NULL) goto failed;
6262 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006263 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006264 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6265 Py_INCREF(tmp2);
6266 res = obj2ast_stmt(tmp2, &val, arena);
6267 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006268 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006269 if (len != PyList_GET_SIZE(tmp)) {
6270 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6271 goto failed;
6272 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006273 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006274 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006275 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006277 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6278 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006279 return 1;
6280 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006281 if (tmp == NULL) {
6282 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6283 return 1;
6284 }
6285 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006286 int res;
6287 Py_ssize_t len;
6288 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006289 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006290 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 +02006291 goto failed;
6292 }
6293 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006294 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006295 if (orelse == NULL) goto failed;
6296 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006297 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006298 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6299 Py_INCREF(tmp2);
6300 res = obj2ast_stmt(tmp2, &val, arena);
6301 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006302 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006303 if (len != PyList_GET_SIZE(tmp)) {
6304 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6305 goto failed;
6306 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006307 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006308 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006309 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006310 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006311 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6312 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006313 if (*out == NULL) goto failed;
6314 return 0;
6315 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006316 tp = astmodulestate_global->If_type;
6317 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006318 if (isinstance == -1) {
6319 return 1;
6320 }
6321 if (isinstance) {
6322 expr_ty test;
6323 asdl_seq* body;
6324 asdl_seq* orelse;
6325
Dino Viehlandac46eb42019-09-11 10:16:34 -07006326 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006327 return 1;
6328 }
6329 if (tmp == NULL) {
6330 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6331 return 1;
6332 }
6333 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006334 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006335 res = obj2ast_expr(tmp, &test, arena);
6336 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006337 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006338 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006339 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006340 return 1;
6341 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006342 if (tmp == NULL) {
6343 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6344 return 1;
6345 }
6346 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006347 int res;
6348 Py_ssize_t len;
6349 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006350 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006351 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 +02006352 goto failed;
6353 }
6354 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006355 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006356 if (body == NULL) goto failed;
6357 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006358 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006359 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6360 Py_INCREF(tmp2);
6361 res = obj2ast_stmt(tmp2, &val, arena);
6362 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006363 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006364 if (len != PyList_GET_SIZE(tmp)) {
6365 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6366 goto failed;
6367 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006368 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006369 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006370 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006371 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006372 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6373 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006374 return 1;
6375 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006376 if (tmp == NULL) {
6377 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6378 return 1;
6379 }
6380 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006381 int res;
6382 Py_ssize_t len;
6383 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006384 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006385 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 +02006386 goto failed;
6387 }
6388 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006389 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006390 if (orelse == NULL) goto failed;
6391 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006392 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006393 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6394 Py_INCREF(tmp2);
6395 res = obj2ast_stmt(tmp2, &val, arena);
6396 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006397 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006398 if (len != PyList_GET_SIZE(tmp)) {
6399 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6400 goto failed;
6401 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006402 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006403 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006404 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006405 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006406 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6407 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006408 if (*out == NULL) goto failed;
6409 return 0;
6410 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006411 tp = astmodulestate_global->With_type;
6412 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006413 if (isinstance == -1) {
6414 return 1;
6415 }
6416 if (isinstance) {
6417 asdl_seq* items;
6418 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006419 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006420
Dino Viehlandac46eb42019-09-11 10:16:34 -07006421 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006422 return 1;
6423 }
6424 if (tmp == NULL) {
6425 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6426 return 1;
6427 }
6428 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006429 int res;
6430 Py_ssize_t len;
6431 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006432 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006433 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 +02006434 goto failed;
6435 }
6436 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006437 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006438 if (items == NULL) goto failed;
6439 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006440 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006441 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6442 Py_INCREF(tmp2);
6443 res = obj2ast_withitem(tmp2, &val, arena);
6444 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006445 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006446 if (len != PyList_GET_SIZE(tmp)) {
6447 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6448 goto failed;
6449 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006450 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006451 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006452 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006453 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006454 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006455 return 1;
6456 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006457 if (tmp == NULL) {
6458 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6459 return 1;
6460 }
6461 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006462 int res;
6463 Py_ssize_t len;
6464 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006465 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006466 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 +02006467 goto failed;
6468 }
6469 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006470 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006471 if (body == NULL) goto failed;
6472 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006473 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006474 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6475 Py_INCREF(tmp2);
6476 res = obj2ast_stmt(tmp2, &val, arena);
6477 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006478 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006479 if (len != PyList_GET_SIZE(tmp)) {
6480 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6481 goto failed;
6482 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006483 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006484 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006485 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006486 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006487 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6488 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006489 return 1;
6490 }
6491 if (tmp == NULL || tmp == Py_None) {
6492 Py_CLEAR(tmp);
6493 type_comment = NULL;
6494 }
6495 else {
6496 int res;
6497 res = obj2ast_string(tmp, &type_comment, arena);
6498 if (res != 0) goto failed;
6499 Py_CLEAR(tmp);
6500 }
6501 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006502 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006503 if (*out == NULL) goto failed;
6504 return 0;
6505 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006506 tp = astmodulestate_global->AsyncWith_type;
6507 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006508 if (isinstance == -1) {
6509 return 1;
6510 }
6511 if (isinstance) {
6512 asdl_seq* items;
6513 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006514 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006515
Dino Viehlandac46eb42019-09-11 10:16:34 -07006516 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006517 return 1;
6518 }
6519 if (tmp == NULL) {
6520 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6521 return 1;
6522 }
6523 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006524 int res;
6525 Py_ssize_t len;
6526 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006527 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006528 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 -04006529 goto failed;
6530 }
6531 len = PyList_GET_SIZE(tmp);
6532 items = _Py_asdl_seq_new(len, arena);
6533 if (items == NULL) goto failed;
6534 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006535 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006536 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6537 Py_INCREF(tmp2);
6538 res = obj2ast_withitem(tmp2, &val, arena);
6539 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006540 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006541 if (len != PyList_GET_SIZE(tmp)) {
6542 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6543 goto failed;
6544 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006545 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006546 }
6547 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006548 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006549 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006550 return 1;
6551 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006552 if (tmp == NULL) {
6553 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6554 return 1;
6555 }
6556 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006557 int res;
6558 Py_ssize_t len;
6559 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006560 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006561 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 -04006562 goto failed;
6563 }
6564 len = PyList_GET_SIZE(tmp);
6565 body = _Py_asdl_seq_new(len, arena);
6566 if (body == NULL) goto failed;
6567 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006568 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006569 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6570 Py_INCREF(tmp2);
6571 res = obj2ast_stmt(tmp2, &val, arena);
6572 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006573 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006574 if (len != PyList_GET_SIZE(tmp)) {
6575 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6576 goto failed;
6577 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006578 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006579 }
6580 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006581 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006582 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6583 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006584 return 1;
6585 }
6586 if (tmp == NULL || tmp == Py_None) {
6587 Py_CLEAR(tmp);
6588 type_comment = NULL;
6589 }
6590 else {
6591 int res;
6592 res = obj2ast_string(tmp, &type_comment, arena);
6593 if (res != 0) goto failed;
6594 Py_CLEAR(tmp);
6595 }
6596 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6597 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006598 if (*out == NULL) goto failed;
6599 return 0;
6600 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006601 tp = astmodulestate_global->Raise_type;
6602 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006603 if (isinstance == -1) {
6604 return 1;
6605 }
6606 if (isinstance) {
6607 expr_ty exc;
6608 expr_ty cause;
6609
Dino Viehlandac46eb42019-09-11 10:16:34 -07006610 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006611 return 1;
6612 }
6613 if (tmp == NULL || tmp == Py_None) {
6614 Py_CLEAR(tmp);
6615 exc = NULL;
6616 }
6617 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006618 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006619 res = obj2ast_expr(tmp, &exc, arena);
6620 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006621 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006622 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006623 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006624 return 1;
6625 }
6626 if (tmp == NULL || tmp == Py_None) {
6627 Py_CLEAR(tmp);
6628 cause = NULL;
6629 }
6630 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006631 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006632 res = obj2ast_expr(tmp, &cause, arena);
6633 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006634 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006635 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006636 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6637 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006638 if (*out == NULL) goto failed;
6639 return 0;
6640 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006641 tp = astmodulestate_global->Try_type;
6642 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006643 if (isinstance == -1) {
6644 return 1;
6645 }
6646 if (isinstance) {
6647 asdl_seq* body;
6648 asdl_seq* handlers;
6649 asdl_seq* orelse;
6650 asdl_seq* finalbody;
6651
Dino Viehlandac46eb42019-09-11 10:16:34 -07006652 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006653 return 1;
6654 }
6655 if (tmp == NULL) {
6656 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6657 return 1;
6658 }
6659 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006660 int res;
6661 Py_ssize_t len;
6662 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006663 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006664 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 +02006665 goto failed;
6666 }
6667 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006668 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006669 if (body == NULL) goto failed;
6670 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006671 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006672 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6673 Py_INCREF(tmp2);
6674 res = obj2ast_stmt(tmp2, &val, arena);
6675 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006676 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006677 if (len != PyList_GET_SIZE(tmp)) {
6678 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6679 goto failed;
6680 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006681 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006682 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006683 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006684 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006685 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6686 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006687 return 1;
6688 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006689 if (tmp == NULL) {
6690 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6691 return 1;
6692 }
6693 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006694 int res;
6695 Py_ssize_t len;
6696 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006697 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006698 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 +02006699 goto failed;
6700 }
6701 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006702 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006703 if (handlers == NULL) goto failed;
6704 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006705 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006706 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6707 Py_INCREF(tmp2);
6708 res = obj2ast_excepthandler(tmp2, &val, arena);
6709 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006710 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006711 if (len != PyList_GET_SIZE(tmp)) {
6712 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6713 goto failed;
6714 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006715 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006716 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006717 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006718 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006719 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6720 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006721 return 1;
6722 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006723 if (tmp == NULL) {
6724 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6725 return 1;
6726 }
6727 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006728 int res;
6729 Py_ssize_t len;
6730 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006731 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006732 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 +02006733 goto failed;
6734 }
6735 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006736 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006737 if (orelse == NULL) goto failed;
6738 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006739 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006740 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6741 Py_INCREF(tmp2);
6742 res = obj2ast_stmt(tmp2, &val, arena);
6743 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006744 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006745 if (len != PyList_GET_SIZE(tmp)) {
6746 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6747 goto failed;
6748 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006749 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006750 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006751 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006753 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6754 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006755 return 1;
6756 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006757 if (tmp == NULL) {
6758 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6759 return 1;
6760 }
6761 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006762 int res;
6763 Py_ssize_t len;
6764 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006765 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006766 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 +02006767 goto failed;
6768 }
6769 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006770 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006771 if (finalbody == NULL) goto failed;
6772 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006773 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006774 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6775 Py_INCREF(tmp2);
6776 res = obj2ast_stmt(tmp2, &val, arena);
6777 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006778 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006779 if (len != PyList_GET_SIZE(tmp)) {
6780 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6781 goto failed;
6782 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006783 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006784 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006785 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006786 }
6787 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006788 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006789 if (*out == NULL) goto failed;
6790 return 0;
6791 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006792 tp = astmodulestate_global->Assert_type;
6793 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006794 if (isinstance == -1) {
6795 return 1;
6796 }
6797 if (isinstance) {
6798 expr_ty test;
6799 expr_ty msg;
6800
Dino Viehlandac46eb42019-09-11 10:16:34 -07006801 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006802 return 1;
6803 }
6804 if (tmp == NULL) {
6805 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6806 return 1;
6807 }
6808 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006809 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006810 res = obj2ast_expr(tmp, &test, arena);
6811 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006812 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006813 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006814 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006815 return 1;
6816 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006817 if (tmp == NULL || tmp == Py_None) {
6818 Py_CLEAR(tmp);
6819 msg = NULL;
6820 }
6821 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006822 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006823 res = obj2ast_expr(tmp, &msg, arena);
6824 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006825 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006826 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006827 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6828 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006829 if (*out == NULL) goto failed;
6830 return 0;
6831 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006832 tp = astmodulestate_global->Import_type;
6833 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006834 if (isinstance == -1) {
6835 return 1;
6836 }
6837 if (isinstance) {
6838 asdl_seq* names;
6839
Dino Viehlandac46eb42019-09-11 10:16:34 -07006840 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006841 return 1;
6842 }
6843 if (tmp == NULL) {
6844 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6845 return 1;
6846 }
6847 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006848 int res;
6849 Py_ssize_t len;
6850 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006851 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006852 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 +02006853 goto failed;
6854 }
6855 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006856 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006857 if (names == NULL) goto failed;
6858 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006859 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006860 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6861 Py_INCREF(tmp2);
6862 res = obj2ast_alias(tmp2, &val, arena);
6863 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006864 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006865 if (len != PyList_GET_SIZE(tmp)) {
6866 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6867 goto failed;
6868 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006869 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006870 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006871 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006872 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006873 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6874 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006875 if (*out == NULL) goto failed;
6876 return 0;
6877 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006878 tp = astmodulestate_global->ImportFrom_type;
6879 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006880 if (isinstance == -1) {
6881 return 1;
6882 }
6883 if (isinstance) {
6884 identifier module;
6885 asdl_seq* names;
6886 int level;
6887
Dino Viehlandac46eb42019-09-11 10:16:34 -07006888 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6889 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006890 return 1;
6891 }
6892 if (tmp == NULL || tmp == Py_None) {
6893 Py_CLEAR(tmp);
6894 module = NULL;
6895 }
6896 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006897 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006898 res = obj2ast_identifier(tmp, &module, arena);
6899 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006900 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006901 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006902 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006903 return 1;
6904 }
6905 if (tmp == NULL) {
6906 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
6907 return 1;
6908 }
6909 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006910 int res;
6911 Py_ssize_t len;
6912 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006913 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006914 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 +02006915 goto failed;
6916 }
6917 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006918 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006919 if (names == NULL) goto failed;
6920 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006921 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006922 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6923 Py_INCREF(tmp2);
6924 res = obj2ast_alias(tmp2, &val, arena);
6925 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006926 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006927 if (len != PyList_GET_SIZE(tmp)) {
6928 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
6929 goto failed;
6930 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006931 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006932 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006933 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006934 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006935 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006936 return 1;
6937 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006938 if (tmp == NULL || tmp == Py_None) {
6939 Py_CLEAR(tmp);
6940 level = 0;
6941 }
6942 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006943 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006944 res = obj2ast_int(tmp, &level, arena);
6945 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006946 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006947 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006948 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
6949 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006950 if (*out == NULL) goto failed;
6951 return 0;
6952 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006953 tp = astmodulestate_global->Global_type;
6954 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006955 if (isinstance == -1) {
6956 return 1;
6957 }
6958 if (isinstance) {
6959 asdl_seq* names;
6960
Dino Viehlandac46eb42019-09-11 10:16:34 -07006961 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006962 return 1;
6963 }
6964 if (tmp == NULL) {
6965 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
6966 return 1;
6967 }
6968 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006969 int res;
6970 Py_ssize_t len;
6971 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006972 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006973 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 +02006974 goto failed;
6975 }
6976 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006977 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006978 if (names == NULL) goto failed;
6979 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006980 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006981 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6982 Py_INCREF(tmp2);
6983 res = obj2ast_identifier(tmp2, &val, arena);
6984 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006985 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006986 if (len != PyList_GET_SIZE(tmp)) {
6987 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
6988 goto failed;
6989 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006990 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006991 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006992 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006993 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006994 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
6995 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006996 if (*out == NULL) goto failed;
6997 return 0;
6998 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006999 tp = astmodulestate_global->Nonlocal_type;
7000 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007001 if (isinstance == -1) {
7002 return 1;
7003 }
7004 if (isinstance) {
7005 asdl_seq* names;
7006
Dino Viehlandac46eb42019-09-11 10:16:34 -07007007 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007008 return 1;
7009 }
7010 if (tmp == NULL) {
7011 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7012 return 1;
7013 }
7014 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007015 int res;
7016 Py_ssize_t len;
7017 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007018 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007019 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 +02007020 goto failed;
7021 }
7022 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007023 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007024 if (names == NULL) goto failed;
7025 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007026 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007027 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7028 Py_INCREF(tmp2);
7029 res = obj2ast_identifier(tmp2, &val, arena);
7030 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007031 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007032 if (len != PyList_GET_SIZE(tmp)) {
7033 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7034 goto failed;
7035 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007036 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007037 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007038 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007039 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007040 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7041 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007042 if (*out == NULL) goto failed;
7043 return 0;
7044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007045 tp = astmodulestate_global->Expr_type;
7046 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007047 if (isinstance == -1) {
7048 return 1;
7049 }
7050 if (isinstance) {
7051 expr_ty value;
7052
Dino Viehlandac46eb42019-09-11 10:16:34 -07007053 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007054 return 1;
7055 }
7056 if (tmp == NULL) {
7057 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7058 return 1;
7059 }
7060 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007061 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007062 res = obj2ast_expr(tmp, &value, arena);
7063 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007064 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007065 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007066 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7067 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007068 if (*out == NULL) goto failed;
7069 return 0;
7070 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007071 tp = astmodulestate_global->Pass_type;
7072 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007073 if (isinstance == -1) {
7074 return 1;
7075 }
7076 if (isinstance) {
7077
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007078 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007079 if (*out == NULL) goto failed;
7080 return 0;
7081 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007082 tp = astmodulestate_global->Break_type;
7083 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007084 if (isinstance == -1) {
7085 return 1;
7086 }
7087 if (isinstance) {
7088
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007089 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007090 if (*out == NULL) goto failed;
7091 return 0;
7092 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007093 tp = astmodulestate_global->Continue_type;
7094 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007095 if (isinstance == -1) {
7096 return 1;
7097 }
7098 if (isinstance) {
7099
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007100 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007101 if (*out == NULL) goto failed;
7102 return 0;
7103 }
7104
7105 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7106 failed:
7107 Py_XDECREF(tmp);
7108 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007109}
7110
7111int
7112obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7113{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007114 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007115
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007116 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007117 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007118 int lineno;
7119 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007120 int end_lineno;
7121 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007122
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007123 if (obj == Py_None) {
7124 *out = NULL;
7125 return 0;
7126 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007127 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007128 return 1;
7129 }
7130 if (tmp == NULL) {
7131 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7132 return 1;
7133 }
7134 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007135 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007136 res = obj2ast_int(tmp, &lineno, arena);
7137 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007138 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007139 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007140 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7141 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007142 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007143 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007144 if (tmp == NULL) {
7145 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7146 return 1;
7147 }
7148 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007149 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007150 res = obj2ast_int(tmp, &col_offset, arena);
7151 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007152 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007154 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7155 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007156 return 1;
7157 }
7158 if (tmp == NULL || tmp == Py_None) {
7159 Py_CLEAR(tmp);
7160 end_lineno = 0;
7161 }
7162 else {
7163 int res;
7164 res = obj2ast_int(tmp, &end_lineno, arena);
7165 if (res != 0) goto failed;
7166 Py_CLEAR(tmp);
7167 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007168 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7169 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007170 return 1;
7171 }
7172 if (tmp == NULL || tmp == Py_None) {
7173 Py_CLEAR(tmp);
7174 end_col_offset = 0;
7175 }
7176 else {
7177 int res;
7178 res = obj2ast_int(tmp, &end_col_offset, arena);
7179 if (res != 0) goto failed;
7180 Py_CLEAR(tmp);
7181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007182 tp = astmodulestate_global->BoolOp_type;
7183 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007184 if (isinstance == -1) {
7185 return 1;
7186 }
7187 if (isinstance) {
7188 boolop_ty op;
7189 asdl_seq* values;
7190
Dino Viehlandac46eb42019-09-11 10:16:34 -07007191 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007192 return 1;
7193 }
7194 if (tmp == NULL) {
7195 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7196 return 1;
7197 }
7198 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007199 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007200 res = obj2ast_boolop(tmp, &op, arena);
7201 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007202 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007204 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7205 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007206 return 1;
7207 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007208 if (tmp == NULL) {
7209 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7210 return 1;
7211 }
7212 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007213 int res;
7214 Py_ssize_t len;
7215 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007216 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007217 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 +02007218 goto failed;
7219 }
7220 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007221 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007222 if (values == NULL) goto failed;
7223 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007224 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007225 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7226 Py_INCREF(tmp2);
7227 res = obj2ast_expr(tmp2, &val, arena);
7228 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007229 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007230 if (len != PyList_GET_SIZE(tmp)) {
7231 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7232 goto failed;
7233 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007234 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007235 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007236 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007237 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007238 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7239 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007240 if (*out == NULL) goto failed;
7241 return 0;
7242 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007243 tp = astmodulestate_global->NamedExpr_type;
7244 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007245 if (isinstance == -1) {
7246 return 1;
7247 }
7248 if (isinstance) {
7249 expr_ty target;
7250 expr_ty value;
7251
Dino Viehlandac46eb42019-09-11 10:16:34 -07007252 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7253 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007254 return 1;
7255 }
7256 if (tmp == NULL) {
7257 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7258 return 1;
7259 }
7260 else {
7261 int res;
7262 res = obj2ast_expr(tmp, &target, arena);
7263 if (res != 0) goto failed;
7264 Py_CLEAR(tmp);
7265 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007266 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007267 return 1;
7268 }
7269 if (tmp == NULL) {
7270 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7271 return 1;
7272 }
7273 else {
7274 int res;
7275 res = obj2ast_expr(tmp, &value, arena);
7276 if (res != 0) goto failed;
7277 Py_CLEAR(tmp);
7278 }
7279 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7280 end_col_offset, arena);
7281 if (*out == NULL) goto failed;
7282 return 0;
7283 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007284 tp = astmodulestate_global->BinOp_type;
7285 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007286 if (isinstance == -1) {
7287 return 1;
7288 }
7289 if (isinstance) {
7290 expr_ty left;
7291 operator_ty op;
7292 expr_ty right;
7293
Dino Viehlandac46eb42019-09-11 10:16:34 -07007294 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007295 return 1;
7296 }
7297 if (tmp == NULL) {
7298 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7299 return 1;
7300 }
7301 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007302 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007303 res = obj2ast_expr(tmp, &left, arena);
7304 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007305 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007306 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007307 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007308 return 1;
7309 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007310 if (tmp == NULL) {
7311 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7312 return 1;
7313 }
7314 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007315 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007316 res = obj2ast_operator(tmp, &op, arena);
7317 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007318 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007319 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007320 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007321 return 1;
7322 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007323 if (tmp == NULL) {
7324 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7325 return 1;
7326 }
7327 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007328 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007329 res = obj2ast_expr(tmp, &right, arena);
7330 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007331 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007332 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007333 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7334 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007335 if (*out == NULL) goto failed;
7336 return 0;
7337 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007338 tp = astmodulestate_global->UnaryOp_type;
7339 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007340 if (isinstance == -1) {
7341 return 1;
7342 }
7343 if (isinstance) {
7344 unaryop_ty op;
7345 expr_ty operand;
7346
Dino Viehlandac46eb42019-09-11 10:16:34 -07007347 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007348 return 1;
7349 }
7350 if (tmp == NULL) {
7351 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7352 return 1;
7353 }
7354 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007355 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007356 res = obj2ast_unaryop(tmp, &op, arena);
7357 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007358 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007360 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7361 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007362 return 1;
7363 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007364 if (tmp == NULL) {
7365 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7366 return 1;
7367 }
7368 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007369 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007370 res = obj2ast_expr(tmp, &operand, arena);
7371 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007372 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007373 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007374 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7375 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007376 if (*out == NULL) goto failed;
7377 return 0;
7378 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007379 tp = astmodulestate_global->Lambda_type;
7380 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007381 if (isinstance == -1) {
7382 return 1;
7383 }
7384 if (isinstance) {
7385 arguments_ty args;
7386 expr_ty body;
7387
Dino Viehlandac46eb42019-09-11 10:16:34 -07007388 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007389 return 1;
7390 }
7391 if (tmp == NULL) {
7392 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7393 return 1;
7394 }
7395 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007396 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007397 res = obj2ast_arguments(tmp, &args, arena);
7398 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007399 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007400 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007401 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007402 return 1;
7403 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007404 if (tmp == NULL) {
7405 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7406 return 1;
7407 }
7408 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007409 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007410 res = obj2ast_expr(tmp, &body, arena);
7411 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007412 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007413 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007414 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7415 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007416 if (*out == NULL) goto failed;
7417 return 0;
7418 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007419 tp = astmodulestate_global->IfExp_type;
7420 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007421 if (isinstance == -1) {
7422 return 1;
7423 }
7424 if (isinstance) {
7425 expr_ty test;
7426 expr_ty body;
7427 expr_ty orelse;
7428
Dino Viehlandac46eb42019-09-11 10:16:34 -07007429 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007430 return 1;
7431 }
7432 if (tmp == NULL) {
7433 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7434 return 1;
7435 }
7436 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007437 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007438 res = obj2ast_expr(tmp, &test, arena);
7439 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007440 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007441 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007442 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007443 return 1;
7444 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007445 if (tmp == NULL) {
7446 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7447 return 1;
7448 }
7449 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007450 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007451 res = obj2ast_expr(tmp, &body, arena);
7452 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007453 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007454 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007455 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7456 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007457 return 1;
7458 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007459 if (tmp == NULL) {
7460 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7461 return 1;
7462 }
7463 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007464 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007465 res = obj2ast_expr(tmp, &orelse, arena);
7466 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007467 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007468 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007469 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7470 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007471 if (*out == NULL) goto failed;
7472 return 0;
7473 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007474 tp = astmodulestate_global->Dict_type;
7475 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007476 if (isinstance == -1) {
7477 return 1;
7478 }
7479 if (isinstance) {
7480 asdl_seq* keys;
7481 asdl_seq* values;
7482
Dino Viehlandac46eb42019-09-11 10:16:34 -07007483 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007484 return 1;
7485 }
7486 if (tmp == NULL) {
7487 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7488 return 1;
7489 }
7490 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007491 int res;
7492 Py_ssize_t len;
7493 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007494 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007495 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 +02007496 goto failed;
7497 }
7498 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007499 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007500 if (keys == NULL) goto failed;
7501 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007502 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007503 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7504 Py_INCREF(tmp2);
7505 res = obj2ast_expr(tmp2, &val, arena);
7506 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007508 if (len != PyList_GET_SIZE(tmp)) {
7509 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7510 goto failed;
7511 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007512 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007513 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007514 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007515 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007516 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7517 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007518 return 1;
7519 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007520 if (tmp == NULL) {
7521 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7522 return 1;
7523 }
7524 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007525 int res;
7526 Py_ssize_t len;
7527 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007528 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007529 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 +02007530 goto failed;
7531 }
7532 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007533 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007534 if (values == NULL) goto failed;
7535 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007536 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007537 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7538 Py_INCREF(tmp2);
7539 res = obj2ast_expr(tmp2, &val, arena);
7540 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007541 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007542 if (len != PyList_GET_SIZE(tmp)) {
7543 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7544 goto failed;
7545 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007546 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007547 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007548 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007549 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007550 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7551 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007552 if (*out == NULL) goto failed;
7553 return 0;
7554 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007555 tp = astmodulestate_global->Set_type;
7556 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007557 if (isinstance == -1) {
7558 return 1;
7559 }
7560 if (isinstance) {
7561 asdl_seq* elts;
7562
Dino Viehlandac46eb42019-09-11 10:16:34 -07007563 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007564 return 1;
7565 }
7566 if (tmp == NULL) {
7567 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7568 return 1;
7569 }
7570 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007571 int res;
7572 Py_ssize_t len;
7573 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007574 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007575 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 +02007576 goto failed;
7577 }
7578 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007579 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007580 if (elts == NULL) goto failed;
7581 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007582 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007583 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7584 Py_INCREF(tmp2);
7585 res = obj2ast_expr(tmp2, &val, arena);
7586 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007587 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007588 if (len != PyList_GET_SIZE(tmp)) {
7589 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7590 goto failed;
7591 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007592 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007593 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007594 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007595 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007596 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007597 if (*out == NULL) goto failed;
7598 return 0;
7599 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007600 tp = astmodulestate_global->ListComp_type;
7601 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 if (isinstance == -1) {
7603 return 1;
7604 }
7605 if (isinstance) {
7606 expr_ty elt;
7607 asdl_seq* generators;
7608
Dino Viehlandac46eb42019-09-11 10:16:34 -07007609 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007610 return 1;
7611 }
7612 if (tmp == NULL) {
7613 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7614 return 1;
7615 }
7616 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007617 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007618 res = obj2ast_expr(tmp, &elt, arena);
7619 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007620 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007621 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007622 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7623 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007624 return 1;
7625 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007626 if (tmp == NULL) {
7627 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7628 return 1;
7629 }
7630 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007631 int res;
7632 Py_ssize_t len;
7633 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007634 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007635 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 +02007636 goto failed;
7637 }
7638 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007639 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007640 if (generators == NULL) goto failed;
7641 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007642 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007643 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7644 Py_INCREF(tmp2);
7645 res = obj2ast_comprehension(tmp2, &val, arena);
7646 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007647 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007648 if (len != PyList_GET_SIZE(tmp)) {
7649 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7650 goto failed;
7651 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007652 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007653 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007654 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007655 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007656 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7657 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007658 if (*out == NULL) goto failed;
7659 return 0;
7660 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007661 tp = astmodulestate_global->SetComp_type;
7662 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007663 if (isinstance == -1) {
7664 return 1;
7665 }
7666 if (isinstance) {
7667 expr_ty elt;
7668 asdl_seq* generators;
7669
Dino Viehlandac46eb42019-09-11 10:16:34 -07007670 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007671 return 1;
7672 }
7673 if (tmp == NULL) {
7674 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7675 return 1;
7676 }
7677 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007678 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007679 res = obj2ast_expr(tmp, &elt, arena);
7680 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007681 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007682 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007683 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7684 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007685 return 1;
7686 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007687 if (tmp == NULL) {
7688 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7689 return 1;
7690 }
7691 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007692 int res;
7693 Py_ssize_t len;
7694 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007695 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007696 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 +02007697 goto failed;
7698 }
7699 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007700 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007701 if (generators == NULL) goto failed;
7702 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007703 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007704 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7705 Py_INCREF(tmp2);
7706 res = obj2ast_comprehension(tmp2, &val, arena);
7707 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007708 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007709 if (len != PyList_GET_SIZE(tmp)) {
7710 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7711 goto failed;
7712 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007713 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007714 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007715 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007716 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007717 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7718 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007719 if (*out == NULL) goto failed;
7720 return 0;
7721 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007722 tp = astmodulestate_global->DictComp_type;
7723 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007724 if (isinstance == -1) {
7725 return 1;
7726 }
7727 if (isinstance) {
7728 expr_ty key;
7729 expr_ty value;
7730 asdl_seq* generators;
7731
Dino Viehlandac46eb42019-09-11 10:16:34 -07007732 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007733 return 1;
7734 }
7735 if (tmp == NULL) {
7736 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7737 return 1;
7738 }
7739 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007740 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007741 res = obj2ast_expr(tmp, &key, arena);
7742 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007743 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007744 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007745 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007746 return 1;
7747 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007748 if (tmp == NULL) {
7749 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7750 return 1;
7751 }
7752 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007753 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007754 res = obj2ast_expr(tmp, &value, arena);
7755 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007756 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007757 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007758 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7759 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007760 return 1;
7761 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007762 if (tmp == NULL) {
7763 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7764 return 1;
7765 }
7766 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007767 int res;
7768 Py_ssize_t len;
7769 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007770 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007771 PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007772 goto failed;
7773 }
7774 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007775 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007776 if (generators == NULL) goto failed;
7777 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007778 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007779 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7780 Py_INCREF(tmp2);
7781 res = obj2ast_comprehension(tmp2, &val, arena);
7782 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007783 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007784 if (len != PyList_GET_SIZE(tmp)) {
7785 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7786 goto failed;
7787 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007788 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007789 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007790 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007791 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007792 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7793 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007794 if (*out == NULL) goto failed;
7795 return 0;
7796 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007797 tp = astmodulestate_global->GeneratorExp_type;
7798 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007799 if (isinstance == -1) {
7800 return 1;
7801 }
7802 if (isinstance) {
7803 expr_ty elt;
7804 asdl_seq* generators;
7805
Dino Viehlandac46eb42019-09-11 10:16:34 -07007806 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007807 return 1;
7808 }
7809 if (tmp == NULL) {
7810 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7811 return 1;
7812 }
7813 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007814 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007815 res = obj2ast_expr(tmp, &elt, arena);
7816 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007817 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007818 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007819 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7820 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007821 return 1;
7822 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007823 if (tmp == NULL) {
7824 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7825 return 1;
7826 }
7827 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007828 int res;
7829 Py_ssize_t len;
7830 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007831 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007832 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 +02007833 goto failed;
7834 }
7835 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007836 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007837 if (generators == NULL) goto failed;
7838 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007839 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007840 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7841 Py_INCREF(tmp2);
7842 res = obj2ast_comprehension(tmp2, &val, arena);
7843 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007844 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007845 if (len != PyList_GET_SIZE(tmp)) {
7846 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7847 goto failed;
7848 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007849 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007850 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007851 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007852 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007853 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7854 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007855 if (*out == NULL) goto failed;
7856 return 0;
7857 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007858 tp = astmodulestate_global->Await_type;
7859 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007860 if (isinstance == -1) {
7861 return 1;
7862 }
7863 if (isinstance) {
7864 expr_ty value;
7865
Dino Viehlandac46eb42019-09-11 10:16:34 -07007866 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007867 return 1;
7868 }
7869 if (tmp == NULL) {
7870 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7871 return 1;
7872 }
7873 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007874 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007875 res = obj2ast_expr(tmp, &value, arena);
7876 if (res != 0) goto failed;
7877 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007878 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007879 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7880 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007881 if (*out == NULL) goto failed;
7882 return 0;
7883 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007884 tp = astmodulestate_global->Yield_type;
7885 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007886 if (isinstance == -1) {
7887 return 1;
7888 }
7889 if (isinstance) {
7890 expr_ty value;
7891
Dino Viehlandac46eb42019-09-11 10:16:34 -07007892 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007893 return 1;
7894 }
7895 if (tmp == NULL || tmp == Py_None) {
7896 Py_CLEAR(tmp);
7897 value = NULL;
7898 }
7899 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007900 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007901 res = obj2ast_expr(tmp, &value, arena);
7902 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007903 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007904 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007905 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
7906 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007907 if (*out == NULL) goto failed;
7908 return 0;
7909 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007910 tp = astmodulestate_global->YieldFrom_type;
7911 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007912 if (isinstance == -1) {
7913 return 1;
7914 }
7915 if (isinstance) {
7916 expr_ty value;
7917
Dino Viehlandac46eb42019-09-11 10:16:34 -07007918 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007919 return 1;
7920 }
7921 if (tmp == NULL) {
7922 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
7923 return 1;
7924 }
7925 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007926 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007927 res = obj2ast_expr(tmp, &value, arena);
7928 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007929 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007930 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007931 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
7932 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007933 if (*out == NULL) goto failed;
7934 return 0;
7935 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007936 tp = astmodulestate_global->Compare_type;
7937 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007938 if (isinstance == -1) {
7939 return 1;
7940 }
7941 if (isinstance) {
7942 expr_ty left;
7943 asdl_int_seq* ops;
7944 asdl_seq* comparators;
7945
Dino Viehlandac46eb42019-09-11 10:16:34 -07007946 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007947 return 1;
7948 }
7949 if (tmp == NULL) {
7950 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
7951 return 1;
7952 }
7953 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007954 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007955 res = obj2ast_expr(tmp, &left, arena);
7956 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007957 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007958 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007959 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007960 return 1;
7961 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007962 if (tmp == NULL) {
7963 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
7964 return 1;
7965 }
7966 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007967 int res;
7968 Py_ssize_t len;
7969 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007970 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007971 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 +02007972 goto failed;
7973 }
7974 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007975 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007976 if (ops == NULL) goto failed;
7977 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007978 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007979 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7980 Py_INCREF(tmp2);
7981 res = obj2ast_cmpop(tmp2, &val, arena);
7982 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007983 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007984 if (len != PyList_GET_SIZE(tmp)) {
7985 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
7986 goto failed;
7987 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007988 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007989 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007990 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007991 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007992 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
7993 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007994 return 1;
7995 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007996 if (tmp == NULL) {
7997 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
7998 return 1;
7999 }
8000 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008001 int res;
8002 Py_ssize_t len;
8003 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008004 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008005 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 +02008006 goto failed;
8007 }
8008 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008009 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008010 if (comparators == NULL) goto failed;
8011 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008012 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008013 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8014 Py_INCREF(tmp2);
8015 res = obj2ast_expr(tmp2, &val, arena);
8016 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008017 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008018 if (len != PyList_GET_SIZE(tmp)) {
8019 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8020 goto failed;
8021 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008022 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008023 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008024 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008025 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008026 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8027 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008028 if (*out == NULL) goto failed;
8029 return 0;
8030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008031 tp = astmodulestate_global->Call_type;
8032 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008033 if (isinstance == -1) {
8034 return 1;
8035 }
8036 if (isinstance) {
8037 expr_ty func;
8038 asdl_seq* args;
8039 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008040
Dino Viehlandac46eb42019-09-11 10:16:34 -07008041 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008042 return 1;
8043 }
8044 if (tmp == NULL) {
8045 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8046 return 1;
8047 }
8048 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008049 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008050 res = obj2ast_expr(tmp, &func, arena);
8051 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008052 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008054 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008055 return 1;
8056 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008057 if (tmp == NULL) {
8058 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8059 return 1;
8060 }
8061 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008062 int res;
8063 Py_ssize_t len;
8064 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008065 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008066 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 +02008067 goto failed;
8068 }
8069 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008070 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008071 if (args == NULL) goto failed;
8072 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008073 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008074 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8075 Py_INCREF(tmp2);
8076 res = obj2ast_expr(tmp2, &val, arena);
8077 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008078 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008079 if (len != PyList_GET_SIZE(tmp)) {
8080 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8081 goto failed;
8082 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008083 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008084 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008085 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008087 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8088 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008089 return 1;
8090 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008091 if (tmp == NULL) {
8092 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8093 return 1;
8094 }
8095 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008096 int res;
8097 Py_ssize_t len;
8098 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008099 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008100 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 +02008101 goto failed;
8102 }
8103 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008104 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008105 if (keywords == NULL) goto failed;
8106 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008107 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008108 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8109 Py_INCREF(tmp2);
8110 res = obj2ast_keyword(tmp2, &val, arena);
8111 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008112 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008113 if (len != PyList_GET_SIZE(tmp)) {
8114 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8115 goto failed;
8116 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008117 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008118 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008119 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008120 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008121 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8122 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008123 if (*out == NULL) goto failed;
8124 return 0;
8125 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008126 tp = astmodulestate_global->FormattedValue_type;
8127 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008128 if (isinstance == -1) {
8129 return 1;
8130 }
8131 if (isinstance) {
8132 expr_ty value;
8133 int conversion;
8134 expr_ty format_spec;
8135
Dino Viehlandac46eb42019-09-11 10:16:34 -07008136 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008137 return 1;
8138 }
8139 if (tmp == NULL) {
8140 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8141 return 1;
8142 }
8143 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008144 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008145 res = obj2ast_expr(tmp, &value, arena);
8146 if (res != 0) goto failed;
8147 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008148 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008149 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8150 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008151 return 1;
8152 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008153 if (tmp == NULL || tmp == Py_None) {
8154 Py_CLEAR(tmp);
8155 conversion = 0;
8156 }
8157 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008158 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008159 res = obj2ast_int(tmp, &conversion, arena);
8160 if (res != 0) goto failed;
8161 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008162 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008163 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8164 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008165 return 1;
8166 }
8167 if (tmp == NULL || tmp == Py_None) {
8168 Py_CLEAR(tmp);
8169 format_spec = NULL;
8170 }
8171 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008172 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008173 res = obj2ast_expr(tmp, &format_spec, arena);
8174 if (res != 0) goto failed;
8175 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008176 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008177 *out = FormattedValue(value, conversion, format_spec, lineno,
8178 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008179 if (*out == NULL) goto failed;
8180 return 0;
8181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008182 tp = astmodulestate_global->JoinedStr_type;
8183 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008184 if (isinstance == -1) {
8185 return 1;
8186 }
8187 if (isinstance) {
8188 asdl_seq* values;
8189
Dino Viehlandac46eb42019-09-11 10:16:34 -07008190 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8191 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008192 return 1;
8193 }
8194 if (tmp == NULL) {
8195 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8196 return 1;
8197 }
8198 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008199 int res;
8200 Py_ssize_t len;
8201 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008202 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008203 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 -04008204 goto failed;
8205 }
8206 len = PyList_GET_SIZE(tmp);
8207 values = _Py_asdl_seq_new(len, arena);
8208 if (values == NULL) goto failed;
8209 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008210 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008211 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8212 Py_INCREF(tmp2);
8213 res = obj2ast_expr(tmp2, &val, arena);
8214 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008215 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008216 if (len != PyList_GET_SIZE(tmp)) {
8217 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8218 goto failed;
8219 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008220 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008221 }
8222 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008223 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008224 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8225 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008226 if (*out == NULL) goto failed;
8227 return 0;
8228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008229 tp = astmodulestate_global->Constant_type;
8230 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008231 if (isinstance == -1) {
8232 return 1;
8233 }
8234 if (isinstance) {
8235 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008236 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008237
Dino Viehlandac46eb42019-09-11 10:16:34 -07008238 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008239 return 1;
8240 }
8241 if (tmp == NULL) {
8242 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8243 return 1;
8244 }
8245 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008246 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008247 res = obj2ast_constant(tmp, &value, arena);
8248 if (res != 0) goto failed;
8249 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008251 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008252 return 1;
8253 }
8254 if (tmp == NULL || tmp == Py_None) {
8255 Py_CLEAR(tmp);
8256 kind = NULL;
8257 }
8258 else {
8259 int res;
8260 res = obj2ast_string(tmp, &kind, arena);
8261 if (res != 0) goto failed;
8262 Py_CLEAR(tmp);
8263 }
8264 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8265 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008266 if (*out == NULL) goto failed;
8267 return 0;
8268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008269 tp = astmodulestate_global->Attribute_type;
8270 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008271 if (isinstance == -1) {
8272 return 1;
8273 }
8274 if (isinstance) {
8275 expr_ty value;
8276 identifier attr;
8277 expr_context_ty ctx;
8278
Dino Viehlandac46eb42019-09-11 10:16:34 -07008279 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008280 return 1;
8281 }
8282 if (tmp == NULL) {
8283 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8284 return 1;
8285 }
8286 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008287 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008288 res = obj2ast_expr(tmp, &value, arena);
8289 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008290 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008292 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008293 return 1;
8294 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008295 if (tmp == NULL) {
8296 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8297 return 1;
8298 }
8299 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008300 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008301 res = obj2ast_identifier(tmp, &attr, arena);
8302 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008303 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008305 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008306 return 1;
8307 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008308 if (tmp == NULL) {
8309 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8310 return 1;
8311 }
8312 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008313 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008314 res = obj2ast_expr_context(tmp, &ctx, arena);
8315 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008316 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008317 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008318 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8319 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008320 if (*out == NULL) goto failed;
8321 return 0;
8322 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008323 tp = astmodulestate_global->Subscript_type;
8324 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008325 if (isinstance == -1) {
8326 return 1;
8327 }
8328 if (isinstance) {
8329 expr_ty value;
8330 slice_ty slice;
8331 expr_context_ty ctx;
8332
Dino Viehlandac46eb42019-09-11 10:16:34 -07008333 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008334 return 1;
8335 }
8336 if (tmp == NULL) {
8337 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8338 return 1;
8339 }
8340 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008341 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008342 res = obj2ast_expr(tmp, &value, arena);
8343 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008344 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008345 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008346 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008347 return 1;
8348 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008349 if (tmp == NULL) {
8350 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8351 return 1;
8352 }
8353 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008354 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008355 res = obj2ast_slice(tmp, &slice, arena);
8356 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008357 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008358 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008359 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008360 return 1;
8361 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008362 if (tmp == NULL) {
8363 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8364 return 1;
8365 }
8366 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008367 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008368 res = obj2ast_expr_context(tmp, &ctx, arena);
8369 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008370 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008371 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008372 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8373 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008374 if (*out == NULL) goto failed;
8375 return 0;
8376 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008377 tp = astmodulestate_global->Starred_type;
8378 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008379 if (isinstance == -1) {
8380 return 1;
8381 }
8382 if (isinstance) {
8383 expr_ty value;
8384 expr_context_ty ctx;
8385
Dino Viehlandac46eb42019-09-11 10:16:34 -07008386 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008387 return 1;
8388 }
8389 if (tmp == NULL) {
8390 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8391 return 1;
8392 }
8393 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008394 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008395 res = obj2ast_expr(tmp, &value, arena);
8396 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008397 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008398 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008399 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008400 return 1;
8401 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008402 if (tmp == NULL) {
8403 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8404 return 1;
8405 }
8406 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008407 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008408 res = obj2ast_expr_context(tmp, &ctx, arena);
8409 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008410 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008411 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008412 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8413 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008414 if (*out == NULL) goto failed;
8415 return 0;
8416 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008417 tp = astmodulestate_global->Name_type;
8418 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008419 if (isinstance == -1) {
8420 return 1;
8421 }
8422 if (isinstance) {
8423 identifier id;
8424 expr_context_ty ctx;
8425
Dino Viehlandac46eb42019-09-11 10:16:34 -07008426 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008427 return 1;
8428 }
8429 if (tmp == NULL) {
8430 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8431 return 1;
8432 }
8433 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008434 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008435 res = obj2ast_identifier(tmp, &id, arena);
8436 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008437 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008438 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008439 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008440 return 1;
8441 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008442 if (tmp == NULL) {
8443 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8444 return 1;
8445 }
8446 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008447 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008448 res = obj2ast_expr_context(tmp, &ctx, arena);
8449 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008450 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008451 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008452 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8453 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008454 if (*out == NULL) goto failed;
8455 return 0;
8456 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008457 tp = astmodulestate_global->List_type;
8458 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008459 if (isinstance == -1) {
8460 return 1;
8461 }
8462 if (isinstance) {
8463 asdl_seq* elts;
8464 expr_context_ty ctx;
8465
Dino Viehlandac46eb42019-09-11 10:16:34 -07008466 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008467 return 1;
8468 }
8469 if (tmp == NULL) {
8470 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8471 return 1;
8472 }
8473 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008474 int res;
8475 Py_ssize_t len;
8476 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008477 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008478 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 +02008479 goto failed;
8480 }
8481 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008482 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008483 if (elts == NULL) goto failed;
8484 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008485 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008486 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8487 Py_INCREF(tmp2);
8488 res = obj2ast_expr(tmp2, &val, arena);
8489 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008490 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008491 if (len != PyList_GET_SIZE(tmp)) {
8492 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8493 goto failed;
8494 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008495 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008496 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008497 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008498 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008499 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008500 return 1;
8501 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008502 if (tmp == NULL) {
8503 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8504 return 1;
8505 }
8506 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008507 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008508 res = obj2ast_expr_context(tmp, &ctx, arena);
8509 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008510 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008511 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008512 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8513 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008514 if (*out == NULL) goto failed;
8515 return 0;
8516 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008517 tp = astmodulestate_global->Tuple_type;
8518 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008519 if (isinstance == -1) {
8520 return 1;
8521 }
8522 if (isinstance) {
8523 asdl_seq* elts;
8524 expr_context_ty ctx;
8525
Dino Viehlandac46eb42019-09-11 10:16:34 -07008526 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008527 return 1;
8528 }
8529 if (tmp == NULL) {
8530 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8531 return 1;
8532 }
8533 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008534 int res;
8535 Py_ssize_t len;
8536 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008537 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008538 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 +02008539 goto failed;
8540 }
8541 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008542 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008543 if (elts == NULL) goto failed;
8544 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008545 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008546 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8547 Py_INCREF(tmp2);
8548 res = obj2ast_expr(tmp2, &val, arena);
8549 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008550 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008551 if (len != PyList_GET_SIZE(tmp)) {
8552 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8553 goto failed;
8554 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008555 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008556 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008557 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008558 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008559 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008560 return 1;
8561 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008562 if (tmp == NULL) {
8563 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8564 return 1;
8565 }
8566 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008567 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008568 res = obj2ast_expr_context(tmp, &ctx, arena);
8569 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008570 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008571 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008572 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8573 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008574 if (*out == NULL) goto failed;
8575 return 0;
8576 }
8577
8578 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8579 failed:
8580 Py_XDECREF(tmp);
8581 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008582}
8583
8584int
8585obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8586{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008587 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008588
Dino Viehlandac46eb42019-09-11 10:16:34 -07008589 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008590 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008591 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008592 }
8593 if (isinstance) {
8594 *out = Load;
8595 return 0;
8596 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008597 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008598 if (isinstance == -1) {
8599 return 1;
8600 }
8601 if (isinstance) {
8602 *out = Store;
8603 return 0;
8604 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008605 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008606 if (isinstance == -1) {
8607 return 1;
8608 }
8609 if (isinstance) {
8610 *out = Del;
8611 return 0;
8612 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008613 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008614 if (isinstance == -1) {
8615 return 1;
8616 }
8617 if (isinstance) {
8618 *out = AugLoad;
8619 return 0;
8620 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008621 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008622 if (isinstance == -1) {
8623 return 1;
8624 }
8625 if (isinstance) {
8626 *out = AugStore;
8627 return 0;
8628 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008629 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008630 if (isinstance == -1) {
8631 return 1;
8632 }
8633 if (isinstance) {
8634 *out = Param;
8635 return 0;
8636 }
8637
8638 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8639 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008640}
8641
8642int
8643obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
8644{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008645 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008646
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008647 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008648 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008649
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008650 if (obj == Py_None) {
8651 *out = NULL;
8652 return 0;
8653 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008654 tp = astmodulestate_global->Slice_type;
8655 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008656 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008657 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008658 }
8659 if (isinstance) {
8660 expr_ty lower;
8661 expr_ty upper;
8662 expr_ty step;
8663
Dino Viehlandac46eb42019-09-11 10:16:34 -07008664 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008665 return 1;
8666 }
8667 if (tmp == NULL || tmp == Py_None) {
8668 Py_CLEAR(tmp);
8669 lower = NULL;
8670 }
8671 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008672 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008673 res = obj2ast_expr(tmp, &lower, arena);
8674 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008675 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008676 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008677 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008678 return 1;
8679 }
8680 if (tmp == NULL || tmp == Py_None) {
8681 Py_CLEAR(tmp);
8682 upper = NULL;
8683 }
8684 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008685 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008686 res = obj2ast_expr(tmp, &upper, arena);
8687 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008688 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008689 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008690 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008691 return 1;
8692 }
8693 if (tmp == NULL || tmp == Py_None) {
8694 Py_CLEAR(tmp);
8695 step = NULL;
8696 }
8697 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008698 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008699 res = obj2ast_expr(tmp, &step, arena);
8700 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008701 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008702 }
8703 *out = Slice(lower, upper, step, arena);
8704 if (*out == NULL) goto failed;
8705 return 0;
8706 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008707 tp = astmodulestate_global->ExtSlice_type;
8708 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008709 if (isinstance == -1) {
8710 return 1;
8711 }
8712 if (isinstance) {
8713 asdl_seq* dims;
8714
Dino Viehlandac46eb42019-09-11 10:16:34 -07008715 if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008716 return 1;
8717 }
8718 if (tmp == NULL) {
8719 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
8720 return 1;
8721 }
8722 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008723 int res;
8724 Py_ssize_t len;
8725 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008726 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008727 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 +02008728 goto failed;
8729 }
8730 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008731 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008732 if (dims == NULL) goto failed;
8733 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008734 slice_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008735 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8736 Py_INCREF(tmp2);
8737 res = obj2ast_slice(tmp2, &val, arena);
8738 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008739 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008740 if (len != PyList_GET_SIZE(tmp)) {
8741 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
8742 goto failed;
8743 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008744 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008745 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008746 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008747 }
8748 *out = ExtSlice(dims, arena);
8749 if (*out == NULL) goto failed;
8750 return 0;
8751 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008752 tp = astmodulestate_global->Index_type;
8753 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008754 if (isinstance == -1) {
8755 return 1;
8756 }
8757 if (isinstance) {
8758 expr_ty value;
8759
Dino Viehlandac46eb42019-09-11 10:16:34 -07008760 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008761 return 1;
8762 }
8763 if (tmp == NULL) {
8764 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
8765 return 1;
8766 }
8767 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008768 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008769 res = obj2ast_expr(tmp, &value, arena);
8770 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008771 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008772 }
8773 *out = Index(value, arena);
8774 if (*out == NULL) goto failed;
8775 return 0;
8776 }
8777
8778 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
8779 failed:
8780 Py_XDECREF(tmp);
8781 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008782}
8783
8784int
8785obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8786{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008787 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008788
Dino Viehlandac46eb42019-09-11 10:16:34 -07008789 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008790 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008791 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008792 }
8793 if (isinstance) {
8794 *out = And;
8795 return 0;
8796 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008797 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008798 if (isinstance == -1) {
8799 return 1;
8800 }
8801 if (isinstance) {
8802 *out = Or;
8803 return 0;
8804 }
8805
8806 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8807 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008808}
8809
8810int
8811obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8812{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008813 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008814
Dino Viehlandac46eb42019-09-11 10:16:34 -07008815 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008816 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008817 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008818 }
8819 if (isinstance) {
8820 *out = Add;
8821 return 0;
8822 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008823 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008824 if (isinstance == -1) {
8825 return 1;
8826 }
8827 if (isinstance) {
8828 *out = Sub;
8829 return 0;
8830 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008831 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008832 if (isinstance == -1) {
8833 return 1;
8834 }
8835 if (isinstance) {
8836 *out = Mult;
8837 return 0;
8838 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008839 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008840 if (isinstance == -1) {
8841 return 1;
8842 }
8843 if (isinstance) {
8844 *out = MatMult;
8845 return 0;
8846 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008847 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008848 if (isinstance == -1) {
8849 return 1;
8850 }
8851 if (isinstance) {
8852 *out = Div;
8853 return 0;
8854 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008855 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008856 if (isinstance == -1) {
8857 return 1;
8858 }
8859 if (isinstance) {
8860 *out = Mod;
8861 return 0;
8862 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008863 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008864 if (isinstance == -1) {
8865 return 1;
8866 }
8867 if (isinstance) {
8868 *out = Pow;
8869 return 0;
8870 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008871 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008872 if (isinstance == -1) {
8873 return 1;
8874 }
8875 if (isinstance) {
8876 *out = LShift;
8877 return 0;
8878 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008879 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008880 if (isinstance == -1) {
8881 return 1;
8882 }
8883 if (isinstance) {
8884 *out = RShift;
8885 return 0;
8886 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008887 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008888 if (isinstance == -1) {
8889 return 1;
8890 }
8891 if (isinstance) {
8892 *out = BitOr;
8893 return 0;
8894 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008895 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008896 if (isinstance == -1) {
8897 return 1;
8898 }
8899 if (isinstance) {
8900 *out = BitXor;
8901 return 0;
8902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008903 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008904 if (isinstance == -1) {
8905 return 1;
8906 }
8907 if (isinstance) {
8908 *out = BitAnd;
8909 return 0;
8910 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008911 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008912 if (isinstance == -1) {
8913 return 1;
8914 }
8915 if (isinstance) {
8916 *out = FloorDiv;
8917 return 0;
8918 }
8919
8920 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8921 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008922}
8923
8924int
8925obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8926{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008927 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008928
Dino Viehlandac46eb42019-09-11 10:16:34 -07008929 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008930 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008931 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008932 }
8933 if (isinstance) {
8934 *out = Invert;
8935 return 0;
8936 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008937 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008938 if (isinstance == -1) {
8939 return 1;
8940 }
8941 if (isinstance) {
8942 *out = Not;
8943 return 0;
8944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008945 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008946 if (isinstance == -1) {
8947 return 1;
8948 }
8949 if (isinstance) {
8950 *out = UAdd;
8951 return 0;
8952 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008953 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008954 if (isinstance == -1) {
8955 return 1;
8956 }
8957 if (isinstance) {
8958 *out = USub;
8959 return 0;
8960 }
8961
8962 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
8963 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008964}
8965
8966int
8967obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
8968{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008969 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008970
Dino Viehlandac46eb42019-09-11 10:16:34 -07008971 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008972 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008973 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008974 }
8975 if (isinstance) {
8976 *out = Eq;
8977 return 0;
8978 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008979 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008980 if (isinstance == -1) {
8981 return 1;
8982 }
8983 if (isinstance) {
8984 *out = NotEq;
8985 return 0;
8986 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008987 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008988 if (isinstance == -1) {
8989 return 1;
8990 }
8991 if (isinstance) {
8992 *out = Lt;
8993 return 0;
8994 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008995 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008996 if (isinstance == -1) {
8997 return 1;
8998 }
8999 if (isinstance) {
9000 *out = LtE;
9001 return 0;
9002 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009003 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009004 if (isinstance == -1) {
9005 return 1;
9006 }
9007 if (isinstance) {
9008 *out = Gt;
9009 return 0;
9010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009011 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009012 if (isinstance == -1) {
9013 return 1;
9014 }
9015 if (isinstance) {
9016 *out = GtE;
9017 return 0;
9018 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009019 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009020 if (isinstance == -1) {
9021 return 1;
9022 }
9023 if (isinstance) {
9024 *out = Is;
9025 return 0;
9026 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009027 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009028 if (isinstance == -1) {
9029 return 1;
9030 }
9031 if (isinstance) {
9032 *out = IsNot;
9033 return 0;
9034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009035 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009036 if (isinstance == -1) {
9037 return 1;
9038 }
9039 if (isinstance) {
9040 *out = In;
9041 return 0;
9042 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009043 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009044 if (isinstance == -1) {
9045 return 1;
9046 }
9047 if (isinstance) {
9048 *out = NotIn;
9049 return 0;
9050 }
9051
9052 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9053 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009054}
9055
9056int
9057obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9058{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009059 PyObject* tmp = NULL;
9060 expr_ty target;
9061 expr_ty iter;
9062 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009063 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009064
Dino Viehlandac46eb42019-09-11 10:16:34 -07009065 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009066 return 1;
9067 }
9068 if (tmp == NULL) {
9069 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9070 return 1;
9071 }
9072 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009073 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009074 res = obj2ast_expr(tmp, &target, arena);
9075 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009076 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009078 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009079 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009080 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009081 if (tmp == NULL) {
9082 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9083 return 1;
9084 }
9085 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009086 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009087 res = obj2ast_expr(tmp, &iter, arena);
9088 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009089 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009090 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009091 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009092 return 1;
9093 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009094 if (tmp == NULL) {
9095 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9096 return 1;
9097 }
9098 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009099 int res;
9100 Py_ssize_t len;
9101 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009102 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009103 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 +02009104 goto failed;
9105 }
9106 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009107 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009108 if (ifs == NULL) goto failed;
9109 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009110 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009111 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9112 Py_INCREF(tmp2);
9113 res = obj2ast_expr(tmp2, &val, arena);
9114 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009115 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009116 if (len != PyList_GET_SIZE(tmp)) {
9117 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9118 goto failed;
9119 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009120 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009121 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009122 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009123 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009124 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009125 return 1;
9126 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009127 if (tmp == NULL) {
9128 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9129 return 1;
9130 }
9131 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009132 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009133 res = obj2ast_int(tmp, &is_async, arena);
9134 if (res != 0) goto failed;
9135 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009136 }
9137 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009138 return 0;
9139failed:
9140 Py_XDECREF(tmp);
9141 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009142}
9143
9144int
9145obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9146{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009147 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009148
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009149 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009150 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009151 int lineno;
9152 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009153 int end_lineno;
9154 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009155
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009156 if (obj == Py_None) {
9157 *out = NULL;
9158 return 0;
9159 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009160 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009161 return 1;
9162 }
9163 if (tmp == NULL) {
9164 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9165 return 1;
9166 }
9167 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009168 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009169 res = obj2ast_int(tmp, &lineno, arena);
9170 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009171 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009172 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009173 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9174 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009175 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009176 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009177 if (tmp == NULL) {
9178 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9179 return 1;
9180 }
9181 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009182 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009183 res = obj2ast_int(tmp, &col_offset, arena);
9184 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009185 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009187 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9188 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009189 return 1;
9190 }
9191 if (tmp == NULL || tmp == Py_None) {
9192 Py_CLEAR(tmp);
9193 end_lineno = 0;
9194 }
9195 else {
9196 int res;
9197 res = obj2ast_int(tmp, &end_lineno, arena);
9198 if (res != 0) goto failed;
9199 Py_CLEAR(tmp);
9200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009201 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9202 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009203 return 1;
9204 }
9205 if (tmp == NULL || tmp == Py_None) {
9206 Py_CLEAR(tmp);
9207 end_col_offset = 0;
9208 }
9209 else {
9210 int res;
9211 res = obj2ast_int(tmp, &end_col_offset, arena);
9212 if (res != 0) goto failed;
9213 Py_CLEAR(tmp);
9214 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009215 tp = astmodulestate_global->ExceptHandler_type;
9216 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009217 if (isinstance == -1) {
9218 return 1;
9219 }
9220 if (isinstance) {
9221 expr_ty type;
9222 identifier name;
9223 asdl_seq* body;
9224
Dino Viehlandac46eb42019-09-11 10:16:34 -07009225 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009226 return 1;
9227 }
9228 if (tmp == NULL || tmp == Py_None) {
9229 Py_CLEAR(tmp);
9230 type = NULL;
9231 }
9232 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009233 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009234 res = obj2ast_expr(tmp, &type, arena);
9235 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009236 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009238 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009239 return 1;
9240 }
9241 if (tmp == NULL || tmp == Py_None) {
9242 Py_CLEAR(tmp);
9243 name = NULL;
9244 }
9245 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009246 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009247 res = obj2ast_identifier(tmp, &name, arena);
9248 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009249 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009251 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009252 return 1;
9253 }
9254 if (tmp == NULL) {
9255 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9256 return 1;
9257 }
9258 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009259 int res;
9260 Py_ssize_t len;
9261 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009262 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009263 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 +02009264 goto failed;
9265 }
9266 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009267 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009268 if (body == NULL) goto failed;
9269 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009270 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009271 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9272 Py_INCREF(tmp2);
9273 res = obj2ast_stmt(tmp2, &val, arena);
9274 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009275 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009276 if (len != PyList_GET_SIZE(tmp)) {
9277 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9278 goto failed;
9279 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009280 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009281 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009282 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009283 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009284 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9285 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009286 if (*out == NULL) goto failed;
9287 return 0;
9288 }
9289
9290 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9291 failed:
9292 Py_XDECREF(tmp);
9293 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009294}
9295
9296int
9297obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9298{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009299 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009300 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009301 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009302 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009303 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009304 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009305 arg_ty kwarg;
9306 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009307
Dino Viehlandac46eb42019-09-11 10:16:34 -07009308 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9309 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009310 return 1;
9311 }
9312 if (tmp == NULL) {
9313 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9314 return 1;
9315 }
9316 else {
9317 int res;
9318 Py_ssize_t len;
9319 Py_ssize_t i;
9320 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009321 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 +01009322 goto failed;
9323 }
9324 len = PyList_GET_SIZE(tmp);
9325 posonlyargs = _Py_asdl_seq_new(len, arena);
9326 if (posonlyargs == NULL) goto failed;
9327 for (i = 0; i < len; i++) {
9328 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009329 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9330 Py_INCREF(tmp2);
9331 res = obj2ast_arg(tmp2, &val, arena);
9332 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009333 if (res != 0) goto failed;
9334 if (len != PyList_GET_SIZE(tmp)) {
9335 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9336 goto failed;
9337 }
9338 asdl_seq_SET(posonlyargs, i, val);
9339 }
9340 Py_CLEAR(tmp);
9341 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009342 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009343 return 1;
9344 }
9345 if (tmp == NULL) {
9346 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9347 return 1;
9348 }
9349 else {
9350 int res;
9351 Py_ssize_t len;
9352 Py_ssize_t i;
9353 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009354 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 +02009355 goto failed;
9356 }
9357 len = PyList_GET_SIZE(tmp);
9358 args = _Py_asdl_seq_new(len, arena);
9359 if (args == NULL) goto failed;
9360 for (i = 0; i < len; i++) {
9361 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009362 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9363 Py_INCREF(tmp2);
9364 res = obj2ast_arg(tmp2, &val, arena);
9365 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009366 if (res != 0) goto failed;
9367 if (len != PyList_GET_SIZE(tmp)) {
9368 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9369 goto failed;
9370 }
9371 asdl_seq_SET(args, i, val);
9372 }
9373 Py_CLEAR(tmp);
9374 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009375 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009376 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009377 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009378 if (tmp == NULL || tmp == Py_None) {
9379 Py_CLEAR(tmp);
9380 vararg = NULL;
9381 }
9382 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009383 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009384 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009385 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009386 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009387 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009388 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9389 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009390 return 1;
9391 }
9392 if (tmp == NULL) {
9393 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9394 return 1;
9395 }
9396 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009397 int res;
9398 Py_ssize_t len;
9399 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009400 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009401 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 +02009402 goto failed;
9403 }
9404 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009405 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009406 if (kwonlyargs == NULL) goto failed;
9407 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009408 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009409 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9410 Py_INCREF(tmp2);
9411 res = obj2ast_arg(tmp2, &val, arena);
9412 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009413 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009414 if (len != PyList_GET_SIZE(tmp)) {
9415 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9416 goto failed;
9417 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009418 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009419 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009420 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009421 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009422 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9423 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009424 return 1;
9425 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009426 if (tmp == NULL) {
9427 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9428 return 1;
9429 }
9430 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009431 int res;
9432 Py_ssize_t len;
9433 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009434 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009435 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 +02009436 goto failed;
9437 }
9438 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009439 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009440 if (kw_defaults == NULL) goto failed;
9441 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009442 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009443 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9444 Py_INCREF(tmp2);
9445 res = obj2ast_expr(tmp2, &val, arena);
9446 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009447 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009448 if (len != PyList_GET_SIZE(tmp)) {
9449 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9450 goto failed;
9451 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009452 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009453 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009454 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009455 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009456 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009457 return 1;
9458 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009459 if (tmp == NULL || tmp == Py_None) {
9460 Py_CLEAR(tmp);
9461 kwarg = NULL;
9462 }
9463 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009464 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009465 res = obj2ast_arg(tmp, &kwarg, arena);
9466 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009467 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009468 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009469 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009470 return 1;
9471 }
9472 if (tmp == NULL) {
9473 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9474 return 1;
9475 }
9476 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009477 int res;
9478 Py_ssize_t len;
9479 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009480 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009481 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 +02009482 goto failed;
9483 }
9484 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009485 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009486 if (defaults == NULL) goto failed;
9487 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009488 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009489 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9490 Py_INCREF(tmp2);
9491 res = obj2ast_expr(tmp2, &val, arena);
9492 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009493 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009494 if (len != PyList_GET_SIZE(tmp)) {
9495 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9496 goto failed;
9497 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009498 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009499 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009500 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009501 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009502 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009503 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009504 return 0;
9505failed:
9506 Py_XDECREF(tmp);
9507 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009508}
9509
9510int
9511obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9512{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009513 PyObject* tmp = NULL;
9514 identifier arg;
9515 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009516 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009517 int lineno;
9518 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009519 int end_lineno;
9520 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009521
Dino Viehlandac46eb42019-09-11 10:16:34 -07009522 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009523 return 1;
9524 }
9525 if (tmp == NULL) {
9526 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9527 return 1;
9528 }
9529 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009530 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009531 res = obj2ast_identifier(tmp, &arg, arena);
9532 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009533 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009534 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009535 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9536 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009537 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009538 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009539 if (tmp == NULL || tmp == Py_None) {
9540 Py_CLEAR(tmp);
9541 annotation = NULL;
9542 }
9543 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009544 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009545 res = obj2ast_expr(tmp, &annotation, arena);
9546 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009547 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009548 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009549 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9550 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009551 return 1;
9552 }
9553 if (tmp == NULL || tmp == Py_None) {
9554 Py_CLEAR(tmp);
9555 type_comment = NULL;
9556 }
9557 else {
9558 int res;
9559 res = obj2ast_string(tmp, &type_comment, arena);
9560 if (res != 0) goto failed;
9561 Py_CLEAR(tmp);
9562 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009563 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009564 return 1;
9565 }
9566 if (tmp == NULL) {
9567 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9568 return 1;
9569 }
9570 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009571 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009572 res = obj2ast_int(tmp, &lineno, arena);
9573 if (res != 0) goto failed;
9574 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009575 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009576 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9577 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009578 return 1;
9579 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009580 if (tmp == NULL) {
9581 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9582 return 1;
9583 }
9584 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009585 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009586 res = obj2ast_int(tmp, &col_offset, arena);
9587 if (res != 0) goto failed;
9588 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009589 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009590 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9591 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009592 return 1;
9593 }
9594 if (tmp == NULL || tmp == Py_None) {
9595 Py_CLEAR(tmp);
9596 end_lineno = 0;
9597 }
9598 else {
9599 int res;
9600 res = obj2ast_int(tmp, &end_lineno, arena);
9601 if (res != 0) goto failed;
9602 Py_CLEAR(tmp);
9603 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009604 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9605 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009606 return 1;
9607 }
9608 if (tmp == NULL || tmp == Py_None) {
9609 Py_CLEAR(tmp);
9610 end_col_offset = 0;
9611 }
9612 else {
9613 int res;
9614 res = obj2ast_int(tmp, &end_col_offset, arena);
9615 if (res != 0) goto failed;
9616 Py_CLEAR(tmp);
9617 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009618 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9619 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009620 return 0;
9621failed:
9622 Py_XDECREF(tmp);
9623 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009624}
9625
9626int
9627obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9628{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009629 PyObject* tmp = NULL;
9630 identifier arg;
9631 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009632
Dino Viehlandac46eb42019-09-11 10:16:34 -07009633 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009634 return 1;
9635 }
9636 if (tmp == NULL || tmp == Py_None) {
9637 Py_CLEAR(tmp);
9638 arg = NULL;
9639 }
9640 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009641 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009642 res = obj2ast_identifier(tmp, &arg, arena);
9643 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009644 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009645 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009646 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009647 return 1;
9648 }
9649 if (tmp == NULL) {
9650 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9651 return 1;
9652 }
9653 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009654 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009655 res = obj2ast_expr(tmp, &value, arena);
9656 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009657 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009658 }
9659 *out = keyword(arg, value, arena);
9660 return 0;
9661failed:
9662 Py_XDECREF(tmp);
9663 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009664}
9665
9666int
9667obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9668{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009669 PyObject* tmp = NULL;
9670 identifier name;
9671 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009672
Dino Viehlandac46eb42019-09-11 10:16:34 -07009673 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009674 return 1;
9675 }
9676 if (tmp == NULL) {
9677 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9678 return 1;
9679 }
9680 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009681 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009682 res = obj2ast_identifier(tmp, &name, arena);
9683 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009684 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009685 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009686 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009687 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009688 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009689 if (tmp == NULL || tmp == Py_None) {
9690 Py_CLEAR(tmp);
9691 asname = NULL;
9692 }
9693 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009694 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009695 res = obj2ast_identifier(tmp, &asname, arena);
9696 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009697 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009698 }
9699 *out = alias(name, asname, arena);
9700 return 0;
9701failed:
9702 Py_XDECREF(tmp);
9703 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009704}
9705
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009706int
9707obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9708{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009709 PyObject* tmp = NULL;
9710 expr_ty context_expr;
9711 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009712
Dino Viehlandac46eb42019-09-11 10:16:34 -07009713 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9714 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009715 return 1;
9716 }
9717 if (tmp == NULL) {
9718 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9719 return 1;
9720 }
9721 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009722 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009723 res = obj2ast_expr(tmp, &context_expr, arena);
9724 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009725 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009726 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009727 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9728 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009729 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009730 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009731 if (tmp == NULL || tmp == Py_None) {
9732 Py_CLEAR(tmp);
9733 optional_vars = NULL;
9734 }
9735 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009736 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009737 res = obj2ast_expr(tmp, &optional_vars, arena);
9738 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009739 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009740 }
9741 *out = withitem(context_expr, optional_vars, arena);
9742 return 0;
9743failed:
9744 Py_XDECREF(tmp);
9745 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009746}
9747
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009748int
9749obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9750{
9751 int isinstance;
9752
9753 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009754 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009755
9756 if (obj == Py_None) {
9757 *out = NULL;
9758 return 0;
9759 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009760 tp = astmodulestate_global->TypeIgnore_type;
9761 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009762 if (isinstance == -1) {
9763 return 1;
9764 }
9765 if (isinstance) {
9766 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009767 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009768
Dino Viehlandac46eb42019-09-11 10:16:34 -07009769 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9770 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009771 return 1;
9772 }
9773 if (tmp == NULL) {
9774 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9775 return 1;
9776 }
9777 else {
9778 int res;
9779 res = obj2ast_int(tmp, &lineno, arena);
9780 if (res != 0) goto failed;
9781 Py_CLEAR(tmp);
9782 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009783 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009784 return 1;
9785 }
9786 if (tmp == NULL) {
9787 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9788 return 1;
9789 }
9790 else {
9791 int res;
9792 res = obj2ast_string(tmp, &tag, arena);
9793 if (res != 0) goto failed;
9794 Py_CLEAR(tmp);
9795 }
9796 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009797 if (*out == NULL) goto failed;
9798 return 0;
9799 }
9800
9801 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9802 failed:
9803 Py_XDECREF(tmp);
9804 return 1;
9805}
9806
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009807
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009808PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009809PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009810{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009811 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009812 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009813 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009814 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009815 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9816 goto error;
9817 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009818 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009819 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9820 goto error;
9821 }
9822 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9823 goto error;
9824 }
9825 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9826 goto error;
9827 }
9828 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9829 goto error;
9830 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009831 Py_INCREF(astmodulestate(m)->mod_type);
9832 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009833 0) {
9834 goto error;
9835 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009836 Py_INCREF(astmodulestate(m)->Module_type);
9837 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009838 astmodulestate_global->Interactive_type) < 0) {
9839 goto error;
9840 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009841 Py_INCREF(astmodulestate(m)->Interactive_type);
9842 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009843 astmodulestate_global->Expression_type) < 0) {
9844 goto error;
9845 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009846 Py_INCREF(astmodulestate(m)->Expression_type);
9847 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009848 astmodulestate_global->FunctionType_type) < 0) {
9849 goto error;
9850 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009851 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009852 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9853 goto error;
9854 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009855 Py_INCREF(astmodulestate(m)->stmt_type);
9856 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009857 astmodulestate_global->FunctionDef_type) < 0) {
9858 goto error;
9859 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009860 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9861 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009862 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9863 goto error;
9864 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009865 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9866 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009867 < 0) {
9868 goto error;
9869 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009870 Py_INCREF(astmodulestate(m)->ClassDef_type);
9871 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009872 0) {
9873 goto error;
9874 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009875 Py_INCREF(astmodulestate(m)->Return_type);
9876 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009877 0) {
9878 goto error;
9879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009880 Py_INCREF(astmodulestate(m)->Delete_type);
9881 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009882 0) {
9883 goto error;
9884 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009885 Py_INCREF(astmodulestate(m)->Assign_type);
9886 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009887 astmodulestate_global->AugAssign_type) < 0) {
9888 goto error;
9889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009890 Py_INCREF(astmodulestate(m)->AugAssign_type);
9891 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009892 astmodulestate_global->AnnAssign_type) < 0) {
9893 goto error;
9894 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009895 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009896 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9897 goto error;
9898 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009899 Py_INCREF(astmodulestate(m)->For_type);
9900 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009901 < 0) {
9902 goto error;
9903 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009904 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009905 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
9906 goto error;
9907 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009908 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009909 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
9910 goto error;
9911 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009912 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009913 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
9914 goto error;
9915 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009916 Py_INCREF(astmodulestate(m)->With_type);
9917 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009918 astmodulestate_global->AsyncWith_type) < 0) {
9919 goto error;
9920 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009921 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009922 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
9923 goto error;
9924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009925 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009926 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
9927 goto error;
9928 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009929 Py_INCREF(astmodulestate(m)->Try_type);
9930 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009931 0) {
9932 goto error;
9933 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009934 Py_INCREF(astmodulestate(m)->Assert_type);
9935 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009936 0) {
9937 goto error;
9938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009939 Py_INCREF(astmodulestate(m)->Import_type);
9940 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009941 astmodulestate_global->ImportFrom_type) < 0) {
9942 goto error;
9943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009944 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9945 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009946 0) {
9947 goto error;
9948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009949 Py_INCREF(astmodulestate(m)->Global_type);
9950 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009951 < 0) {
9952 goto error;
9953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009954 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009955 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
9956 goto error;
9957 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009958 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009959 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
9960 goto error;
9961 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009962 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009963 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
9964 goto error;
9965 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009966 Py_INCREF(astmodulestate(m)->Break_type);
9967 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009968 < 0) {
9969 goto error;
9970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009971 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009972 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
9973 goto error;
9974 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009975 Py_INCREF(astmodulestate(m)->expr_type);
9976 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009977 0) {
9978 goto error;
9979 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009980 Py_INCREF(astmodulestate(m)->BoolOp_type);
9981 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009982 astmodulestate_global->NamedExpr_type) < 0) {
9983 goto error;
9984 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009985 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009986 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
9987 goto error;
9988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009989 Py_INCREF(astmodulestate(m)->BinOp_type);
9990 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009991 0) {
9992 goto error;
9993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009994 Py_INCREF(astmodulestate(m)->UnaryOp_type);
9995 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009996 0) {
9997 goto error;
9998 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009999 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010000 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10001 goto error;
10002 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010003 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010004 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10005 goto error;
10006 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010007 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010008 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10009 goto error;
10010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010011 Py_INCREF(astmodulestate(m)->Set_type);
10012 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010013 < 0) {
10014 goto error;
10015 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010016 Py_INCREF(astmodulestate(m)->ListComp_type);
10017 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010018 0) {
10019 goto error;
10020 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010021 Py_INCREF(astmodulestate(m)->SetComp_type);
10022 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010023 < 0) {
10024 goto error;
10025 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010026 Py_INCREF(astmodulestate(m)->DictComp_type);
10027 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010028 astmodulestate_global->GeneratorExp_type) < 0) {
10029 goto error;
10030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010031 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010032 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10033 goto error;
10034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010035 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010036 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10037 goto error;
10038 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010039 Py_INCREF(astmodulestate(m)->Yield_type);
10040 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010041 astmodulestate_global->YieldFrom_type) < 0) {
10042 goto error;
10043 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010044 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10045 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010046 0) {
10047 goto error;
10048 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010049 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010050 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10051 goto error;
10052 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010053 Py_INCREF(astmodulestate(m)->Call_type);
10054 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010055 astmodulestate_global->FormattedValue_type) < 0) {
10056 goto error;
10057 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010058 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10059 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010060 astmodulestate_global->JoinedStr_type) < 0) {
10061 goto error;
10062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010063 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10064 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010065 < 0) {
10066 goto error;
10067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010068 Py_INCREF(astmodulestate(m)->Constant_type);
10069 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010070 astmodulestate_global->Attribute_type) < 0) {
10071 goto error;
10072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010073 Py_INCREF(astmodulestate(m)->Attribute_type);
10074 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010075 astmodulestate_global->Subscript_type) < 0) {
10076 goto error;
10077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010078 Py_INCREF(astmodulestate(m)->Subscript_type);
10079 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010080 0) {
10081 goto error;
10082 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010083 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010084 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10085 goto error;
10086 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010087 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010088 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10089 goto error;
10090 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010091 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010092 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10093 goto error;
10094 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010095 Py_INCREF(astmodulestate(m)->Tuple_type);
10096 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010097 astmodulestate_global->expr_context_type) < 0) {
10098 goto error;
10099 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010100 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010101 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10102 goto error;
10103 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010104 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010105 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10106 goto error;
10107 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010108 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010109 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10110 goto error;
10111 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010112 Py_INCREF(astmodulestate(m)->Del_type);
10113 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010114 0) {
10115 goto error;
10116 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010117 Py_INCREF(astmodulestate(m)->AugLoad_type);
10118 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010119 < 0) {
10120 goto error;
10121 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010122 Py_INCREF(astmodulestate(m)->AugStore_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010123 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) {
10124 goto error;
10125 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010126 Py_INCREF(astmodulestate(m)->Param_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010127 if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) {
10128 goto error;
10129 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010130 Py_INCREF(astmodulestate(m)->slice_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010131 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10132 goto error;
10133 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010134 Py_INCREF(astmodulestate(m)->Slice_type);
10135 if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010136 < 0) {
10137 goto error;
10138 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010139 Py_INCREF(astmodulestate(m)->ExtSlice_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010140 if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) {
10141 goto error;
10142 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010143 Py_INCREF(astmodulestate(m)->Index_type);
10144 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010145 0) {
10146 goto error;
10147 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010148 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010149 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10150 goto error;
10151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010152 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010153 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10154 goto error;
10155 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010156 Py_INCREF(astmodulestate(m)->Or_type);
10157 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010158 < 0) {
10159 goto error;
10160 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010161 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010162 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10163 goto error;
10164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010165 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010166 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10167 goto error;
10168 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010169 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010170 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10171 goto error;
10172 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010173 Py_INCREF(astmodulestate(m)->Mult_type);
10174 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010175 0) {
10176 goto error;
10177 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010178 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010179 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10180 goto error;
10181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010182 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010183 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10184 goto error;
10185 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010186 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010187 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10188 goto error;
10189 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010190 Py_INCREF(astmodulestate(m)->Pow_type);
10191 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010192 0) {
10193 goto error;
10194 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010195 Py_INCREF(astmodulestate(m)->LShift_type);
10196 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010197 0) {
10198 goto error;
10199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010200 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010201 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10202 goto error;
10203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010204 Py_INCREF(astmodulestate(m)->BitOr_type);
10205 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010206 0) {
10207 goto error;
10208 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010209 Py_INCREF(astmodulestate(m)->BitXor_type);
10210 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010211 0) {
10212 goto error;
10213 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010214 Py_INCREF(astmodulestate(m)->BitAnd_type);
10215 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010216 < 0) {
10217 goto error;
10218 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010219 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10220 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010221 0) {
10222 goto error;
10223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010224 Py_INCREF(astmodulestate(m)->unaryop_type);
10225 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010226 0) {
10227 goto error;
10228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010229 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010230 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10231 goto error;
10232 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010233 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010234 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10235 goto error;
10236 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010237 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010238 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10239 goto error;
10240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010241 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010242 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10243 goto error;
10244 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010245 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010246 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10247 goto error;
10248 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010249 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010250 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10251 goto error;
10252 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010253 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010254 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10255 goto error;
10256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010257 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010258 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10259 goto error;
10260 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010261 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010262 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10263 goto error;
10264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010265 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010266 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10267 goto error;
10268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010269 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010270 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10271 goto error;
10272 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010273 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010274 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10275 goto error;
10276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010277 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010278 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10279 goto error;
10280 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010281 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010282 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10283 goto error;
10284 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010285 Py_INCREF(astmodulestate(m)->NotIn_type);
10286 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010287 astmodulestate_global->comprehension_type) < 0) {
10288 goto error;
10289 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010290 Py_INCREF(astmodulestate(m)->comprehension_type);
10291 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010292 astmodulestate_global->excepthandler_type) < 0) {
10293 goto error;
10294 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010295 Py_INCREF(astmodulestate(m)->excepthandler_type);
10296 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010297 astmodulestate_global->ExceptHandler_type) < 0) {
10298 goto error;
10299 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010300 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10301 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010302 astmodulestate_global->arguments_type) < 0) {
10303 goto error;
10304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010305 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010306 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10307 goto error;
10308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010309 Py_INCREF(astmodulestate(m)->arg_type);
10310 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010311 0) {
10312 goto error;
10313 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010314 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010315 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10316 goto error;
10317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010318 Py_INCREF(astmodulestate(m)->alias_type);
10319 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010320 < 0) {
10321 goto error;
10322 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010323 Py_INCREF(astmodulestate(m)->withitem_type);
10324 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010325 astmodulestate_global->type_ignore_type) < 0) {
10326 goto error;
10327 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010328 Py_INCREF(astmodulestate(m)->type_ignore_type);
10329 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010330 astmodulestate_global->TypeIgnore_type) < 0) {
10331 goto error;
10332 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010333 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010334 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010335error:
10336 Py_DECREF(m);
10337 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010338}
10339
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010340
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010341PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010342{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010343 if (!init_types())
10344 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010345 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010346}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010347
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010348/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10349mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010350{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010351 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010352 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010353 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010354
Steve Dowerb82e17e2019-05-23 08:45:22 -070010355 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10356 return NULL;
10357 }
10358
Dino Viehlandac46eb42019-09-11 10:16:34 -070010359 req_type[0] = astmodulestate_global->Module_type;
10360 req_type[1] = astmodulestate_global->Expression_type;
10361 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010362
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010363 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010364
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010365 if (!init_types())
10366 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010367
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010368 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10369 if (isinstance == -1)
10370 return NULL;
10371 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010372 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010373 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010374 return NULL;
10375 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010376
10377 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010378 if (obj2ast_mod(ast, &res, arena) != 0)
10379 return NULL;
10380 else
10381 return res;
10382}
10383
10384int PyAST_Check(PyObject* obj)
10385{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010386 if (!init_types())
10387 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010388 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010389}
10390
Martin v. Löwis5b222132007-06-10 09:51:05 +000010391