blob: 47c88b6741771783450bdc8397812381a178131b [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;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001442 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1443 return 0;
1444 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1445 -1)
1446 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001447 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
1448 FunctionDef_fields, 6);
1449 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001450 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1451 -1)
1452 return 0;
1453 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1454 == -1)
1455 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001456 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1457 state->stmt_type,
1458 AsyncFunctionDef_fields, 6);
1459 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001460 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1461 == -1)
1462 return 0;
1463 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1464 Py_None) == -1)
1465 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001466 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
1467 ClassDef_fields, 5);
1468 if (!state->ClassDef_type) return 0;
1469 state->Return_type = make_type("Return", state->stmt_type, Return_fields,
1470 1);
1471 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001472 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1473 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001474 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields,
1475 1);
1476 if (!state->Delete_type) return 0;
1477 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields,
1478 3);
1479 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001480 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1481 -1)
1482 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001483 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
1484 AugAssign_fields, 3);
1485 if (!state->AugAssign_type) return 0;
1486 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
1487 AnnAssign_fields, 4);
1488 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001489 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1490 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001491 state->For_type = make_type("For", state->stmt_type, For_fields, 5);
1492 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001493 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1494 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001495 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
1496 AsyncFor_fields, 5);
1497 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001498 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1499 -1)
1500 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001501 state->While_type = make_type("While", state->stmt_type, While_fields, 3);
1502 if (!state->While_type) return 0;
1503 state->If_type = make_type("If", state->stmt_type, If_fields, 3);
1504 if (!state->If_type) return 0;
1505 state->With_type = make_type("With", state->stmt_type, With_fields, 3);
1506 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001507 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1508 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001509 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
1510 AsyncWith_fields, 3);
1511 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001512 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1513 == -1)
1514 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001515 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2);
1516 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001517 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1518 return 0;
1519 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1520 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001521 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4);
1522 if (!state->Try_type) return 0;
1523 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields,
1524 2);
1525 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001526 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1527 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001528 state->Import_type = make_type("Import", state->stmt_type, Import_fields,
1529 1);
1530 if (!state->Import_type) return 0;
1531 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
1532 ImportFrom_fields, 3);
1533 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001534 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1535 return 0;
1536 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1537 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001538 state->Global_type = make_type("Global", state->stmt_type, Global_fields,
1539 1);
1540 if (!state->Global_type) return 0;
1541 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
1542 Nonlocal_fields, 1);
1543 if (!state->Nonlocal_type) return 0;
1544 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1);
1545 if (!state->Expr_type) return 0;
1546 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0);
1547 if (!state->Pass_type) return 0;
1548 state->Break_type = make_type("Break", state->stmt_type, NULL, 0);
1549 if (!state->Break_type) return 0;
1550 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0);
1551 if (!state->Continue_type) return 0;
1552 state->expr_type = make_type("expr", state->AST_type, NULL, 0);
1553 if (!state->expr_type) return 0;
1554 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001555 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1556 return 0;
1557 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1558 -1)
1559 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001560 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields,
1561 2);
1562 if (!state->BoolOp_type) return 0;
1563 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
1564 NamedExpr_fields, 2);
1565 if (!state->NamedExpr_type) return 0;
1566 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3);
1567 if (!state->BinOp_type) return 0;
1568 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
1569 UnaryOp_fields, 2);
1570 if (!state->UnaryOp_type) return 0;
1571 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields,
1572 2);
1573 if (!state->Lambda_type) return 0;
1574 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3);
1575 if (!state->IfExp_type) return 0;
1576 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2);
1577 if (!state->Dict_type) return 0;
1578 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1);
1579 if (!state->Set_type) return 0;
1580 state->ListComp_type = make_type("ListComp", state->expr_type,
1581 ListComp_fields, 2);
1582 if (!state->ListComp_type) return 0;
1583 state->SetComp_type = make_type("SetComp", state->expr_type,
1584 SetComp_fields, 2);
1585 if (!state->SetComp_type) return 0;
1586 state->DictComp_type = make_type("DictComp", state->expr_type,
1587 DictComp_fields, 3);
1588 if (!state->DictComp_type) return 0;
1589 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
1590 GeneratorExp_fields, 2);
1591 if (!state->GeneratorExp_type) return 0;
1592 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1);
1593 if (!state->Await_type) return 0;
1594 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1);
1595 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001596 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1597 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001598 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
1599 YieldFrom_fields, 1);
1600 if (!state->YieldFrom_type) return 0;
1601 state->Compare_type = make_type("Compare", state->expr_type,
1602 Compare_fields, 3);
1603 if (!state->Compare_type) return 0;
1604 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3);
1605 if (!state->Call_type) return 0;
1606 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
1607 FormattedValue_fields, 3);
1608 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001609 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1610 Py_None) == -1)
1611 return 0;
1612 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1613 Py_None) == -1)
1614 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001615 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
1616 JoinedStr_fields, 1);
1617 if (!state->JoinedStr_type) return 0;
1618 state->Constant_type = make_type("Constant", state->expr_type,
1619 Constant_fields, 2);
1620 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001621 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1622 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001623 state->Attribute_type = make_type("Attribute", state->expr_type,
1624 Attribute_fields, 3);
1625 if (!state->Attribute_type) return 0;
1626 state->Subscript_type = make_type("Subscript", state->expr_type,
1627 Subscript_fields, 3);
1628 if (!state->Subscript_type) return 0;
1629 state->Starred_type = make_type("Starred", state->expr_type,
1630 Starred_fields, 2);
1631 if (!state->Starred_type) return 0;
1632 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2);
1633 if (!state->Name_type) return 0;
1634 state->List_type = make_type("List", state->expr_type, List_fields, 2);
1635 if (!state->List_type) return 0;
1636 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2);
1637 if (!state->Tuple_type) return 0;
1638 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
1639 0);
1640 if (!state->expr_context_type) return 0;
1641 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
1642 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0);
1643 if (!state->Load_type) return 0;
1644 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1645 NULL, NULL);
1646 if (!state->Load_singleton) return 0;
1647 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0);
1648 if (!state->Store_type) return 0;
1649 state->Store_singleton = PyType_GenericNew((PyTypeObject
1650 *)state->Store_type, NULL, NULL);
1651 if (!state->Store_singleton) return 0;
1652 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0);
1653 if (!state->Del_type) return 0;
1654 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1655 NULL, NULL);
1656 if (!state->Del_singleton) return 0;
1657 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
1658 0);
1659 if (!state->AugLoad_type) return 0;
1660 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1661 *)state->AugLoad_type, NULL,
1662 NULL);
1663 if (!state->AugLoad_singleton) return 0;
1664 state->AugStore_type = make_type("AugStore", state->expr_context_type,
1665 NULL, 0);
1666 if (!state->AugStore_type) return 0;
1667 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1668 *)state->AugStore_type, NULL,
1669 NULL);
1670 if (!state->AugStore_singleton) return 0;
1671 state->Param_type = make_type("Param", state->expr_context_type, NULL, 0);
1672 if (!state->Param_type) return 0;
1673 state->Param_singleton = PyType_GenericNew((PyTypeObject
1674 *)state->Param_type, NULL, NULL);
1675 if (!state->Param_singleton) return 0;
1676 state->slice_type = make_type("slice", state->AST_type, NULL, 0);
1677 if (!state->slice_type) return 0;
1678 if (!add_attributes(state->slice_type, NULL, 0)) return 0;
1679 state->Slice_type = make_type("Slice", state->slice_type, Slice_fields, 3);
1680 if (!state->Slice_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001681 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1682 return 0;
1683 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1684 return 0;
1685 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1686 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001687 state->ExtSlice_type = make_type("ExtSlice", state->slice_type,
1688 ExtSlice_fields, 1);
1689 if (!state->ExtSlice_type) return 0;
1690 state->Index_type = make_type("Index", state->slice_type, Index_fields, 1);
1691 if (!state->Index_type) return 0;
1692 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0);
1693 if (!state->boolop_type) return 0;
1694 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
1695 state->And_type = make_type("And", state->boolop_type, NULL, 0);
1696 if (!state->And_type) return 0;
1697 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1698 NULL, NULL);
1699 if (!state->And_singleton) return 0;
1700 state->Or_type = make_type("Or", state->boolop_type, NULL, 0);
1701 if (!state->Or_type) return 0;
1702 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1703 NULL, NULL);
1704 if (!state->Or_singleton) return 0;
1705 state->operator_type = make_type("operator", state->AST_type, NULL, 0);
1706 if (!state->operator_type) return 0;
1707 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
1708 state->Add_type = make_type("Add", state->operator_type, NULL, 0);
1709 if (!state->Add_type) return 0;
1710 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1711 NULL, NULL);
1712 if (!state->Add_singleton) return 0;
1713 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0);
1714 if (!state->Sub_type) return 0;
1715 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1716 NULL, NULL);
1717 if (!state->Sub_singleton) return 0;
1718 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0);
1719 if (!state->Mult_type) return 0;
1720 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1721 NULL, NULL);
1722 if (!state->Mult_singleton) return 0;
1723 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0);
1724 if (!state->MatMult_type) return 0;
1725 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1726 *)state->MatMult_type, NULL,
1727 NULL);
1728 if (!state->MatMult_singleton) return 0;
1729 state->Div_type = make_type("Div", state->operator_type, NULL, 0);
1730 if (!state->Div_type) return 0;
1731 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1732 NULL, NULL);
1733 if (!state->Div_singleton) return 0;
1734 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0);
1735 if (!state->Mod_type) return 0;
1736 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1737 NULL, NULL);
1738 if (!state->Mod_singleton) return 0;
1739 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0);
1740 if (!state->Pow_type) return 0;
1741 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1742 NULL, NULL);
1743 if (!state->Pow_singleton) return 0;
1744 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0);
1745 if (!state->LShift_type) return 0;
1746 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1747 *)state->LShift_type, NULL,
1748 NULL);
1749 if (!state->LShift_singleton) return 0;
1750 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0);
1751 if (!state->RShift_type) return 0;
1752 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1753 *)state->RShift_type, NULL,
1754 NULL);
1755 if (!state->RShift_singleton) return 0;
1756 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0);
1757 if (!state->BitOr_type) return 0;
1758 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1759 *)state->BitOr_type, NULL, NULL);
1760 if (!state->BitOr_singleton) return 0;
1761 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0);
1762 if (!state->BitXor_type) return 0;
1763 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1764 *)state->BitXor_type, NULL,
1765 NULL);
1766 if (!state->BitXor_singleton) return 0;
1767 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0);
1768 if (!state->BitAnd_type) return 0;
1769 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1770 *)state->BitAnd_type, NULL,
1771 NULL);
1772 if (!state->BitAnd_singleton) return 0;
1773 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0);
1774 if (!state->FloorDiv_type) return 0;
1775 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1776 *)state->FloorDiv_type, NULL,
1777 NULL);
1778 if (!state->FloorDiv_singleton) return 0;
1779 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0);
1780 if (!state->unaryop_type) return 0;
1781 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
1782 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0);
1783 if (!state->Invert_type) return 0;
1784 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1785 *)state->Invert_type, NULL,
1786 NULL);
1787 if (!state->Invert_singleton) return 0;
1788 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0);
1789 if (!state->Not_type) return 0;
1790 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1791 NULL, NULL);
1792 if (!state->Not_singleton) return 0;
1793 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0);
1794 if (!state->UAdd_type) return 0;
1795 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1796 NULL, NULL);
1797 if (!state->UAdd_singleton) return 0;
1798 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0);
1799 if (!state->USub_type) return 0;
1800 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1801 NULL, NULL);
1802 if (!state->USub_singleton) return 0;
1803 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0);
1804 if (!state->cmpop_type) return 0;
1805 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
1806 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0);
1807 if (!state->Eq_type) return 0;
1808 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1809 NULL, NULL);
1810 if (!state->Eq_singleton) return 0;
1811 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0);
1812 if (!state->NotEq_type) return 0;
1813 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1814 *)state->NotEq_type, NULL, NULL);
1815 if (!state->NotEq_singleton) return 0;
1816 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0);
1817 if (!state->Lt_type) return 0;
1818 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1819 NULL, NULL);
1820 if (!state->Lt_singleton) return 0;
1821 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0);
1822 if (!state->LtE_type) return 0;
1823 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1824 NULL, NULL);
1825 if (!state->LtE_singleton) return 0;
1826 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0);
1827 if (!state->Gt_type) return 0;
1828 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1829 NULL, NULL);
1830 if (!state->Gt_singleton) return 0;
1831 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0);
1832 if (!state->GtE_type) return 0;
1833 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1834 NULL, NULL);
1835 if (!state->GtE_singleton) return 0;
1836 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0);
1837 if (!state->Is_type) return 0;
1838 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1839 NULL, NULL);
1840 if (!state->Is_singleton) return 0;
1841 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0);
1842 if (!state->IsNot_type) return 0;
1843 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1844 *)state->IsNot_type, NULL, NULL);
1845 if (!state->IsNot_singleton) return 0;
1846 state->In_type = make_type("In", state->cmpop_type, NULL, 0);
1847 if (!state->In_type) return 0;
1848 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1849 NULL, NULL);
1850 if (!state->In_singleton) return 0;
1851 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0);
1852 if (!state->NotIn_type) return 0;
1853 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1854 *)state->NotIn_type, NULL, NULL);
1855 if (!state->NotIn_singleton) return 0;
1856 state->comprehension_type = make_type("comprehension", state->AST_type,
1857 comprehension_fields, 4);
1858 if (!state->comprehension_type) return 0;
1859 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1860 state->excepthandler_type = make_type("excepthandler", state->AST_type,
1861 NULL, 0);
1862 if (!state->excepthandler_type) return 0;
1863 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1864 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001865 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1866 == -1)
1867 return 0;
1868 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1869 Py_None) == -1)
1870 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001871 state->ExceptHandler_type = make_type("ExceptHandler",
1872 state->excepthandler_type,
1873 ExceptHandler_fields, 3);
1874 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001875 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1876 return 0;
1877 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1878 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001879 state->arguments_type = make_type("arguments", state->AST_type,
1880 arguments_fields, 7);
1881 if (!state->arguments_type) return 0;
1882 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001883 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1884 return 0;
1885 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1886 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001887 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3);
1888 if (!state->arg_type) return 0;
1889 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001890 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1891 return 0;
1892 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1893 return 0;
1894 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1895 return 0;
1896 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1897 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001898 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
1899 2);
1900 if (!state->keyword_type) return 0;
1901 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001902 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1903 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001904 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2);
1905 if (!state->alias_type) return 0;
1906 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001907 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1908 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001909 state->withitem_type = make_type("withitem", state->AST_type,
1910 withitem_fields, 2);
1911 if (!state->withitem_type) return 0;
1912 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001913 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
1914 == -1)
1915 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001916 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL,
1917 0);
1918 if (!state->type_ignore_type) return 0;
1919 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
1920 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
1921 TypeIgnore_fields, 2);
1922 if (!state->TypeIgnore_type) return 0;
1923 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001924 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001925}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00001926
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001927static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
1928static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
1929static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
1930static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
1931 arena);
1932static int obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena);
1933static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
1934static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
1935static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
1936static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
1937static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
1938 arena);
1939static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
1940 arena);
1941static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
1942static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
1943static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
1944static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001945static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001946static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
1947 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001948
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001949mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001950Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001951{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001952 mod_ty p;
1953 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1954 if (!p)
1955 return NULL;
1956 p->kind = Module_kind;
1957 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001958 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001959 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001960}
1961
1962mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001963Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001964{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001965 mod_ty p;
1966 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1967 if (!p)
1968 return NULL;
1969 p->kind = Interactive_kind;
1970 p->v.Interactive.body = body;
1971 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001972}
1973
1974mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00001975Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001976{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001977 mod_ty p;
1978 if (!body) {
1979 PyErr_SetString(PyExc_ValueError,
1980 "field body is required for Expression");
1981 return NULL;
1982 }
1983 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
1984 if (!p)
1985 return NULL;
1986 p->kind = Expression_kind;
1987 p->v.Expression.body = body;
1988 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00001989}
1990
1991mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001992FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
1993{
1994 mod_ty p;
1995 if (!returns) {
1996 PyErr_SetString(PyExc_ValueError,
1997 "field returns is required for FunctionType");
1998 return NULL;
1999 }
2000 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2001 if (!p)
2002 return NULL;
2003 p->kind = FunctionType_kind;
2004 p->v.FunctionType.argtypes = argtypes;
2005 p->v.FunctionType.returns = returns;
2006 return p;
2007}
2008
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002009stmt_ty
2010FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002011 decorator_list, expr_ty returns, string type_comment, int lineno,
2012 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002013{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002014 stmt_ty p;
2015 if (!name) {
2016 PyErr_SetString(PyExc_ValueError,
2017 "field name is required for FunctionDef");
2018 return NULL;
2019 }
2020 if (!args) {
2021 PyErr_SetString(PyExc_ValueError,
2022 "field args is required for FunctionDef");
2023 return NULL;
2024 }
2025 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2026 if (!p)
2027 return NULL;
2028 p->kind = FunctionDef_kind;
2029 p->v.FunctionDef.name = name;
2030 p->v.FunctionDef.args = args;
2031 p->v.FunctionDef.body = body;
2032 p->v.FunctionDef.decorator_list = decorator_list;
2033 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002034 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002035 p->lineno = lineno;
2036 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002037 p->end_lineno = end_lineno;
2038 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002039 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002040}
2041
2042stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002043AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002044 * decorator_list, expr_ty returns, string type_comment, int
2045 lineno, int col_offset, int end_lineno, int end_col_offset,
2046 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002047{
2048 stmt_ty p;
2049 if (!name) {
2050 PyErr_SetString(PyExc_ValueError,
2051 "field name is required for AsyncFunctionDef");
2052 return NULL;
2053 }
2054 if (!args) {
2055 PyErr_SetString(PyExc_ValueError,
2056 "field args is required for AsyncFunctionDef");
2057 return NULL;
2058 }
2059 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2060 if (!p)
2061 return NULL;
2062 p->kind = AsyncFunctionDef_kind;
2063 p->v.AsyncFunctionDef.name = name;
2064 p->v.AsyncFunctionDef.args = args;
2065 p->v.AsyncFunctionDef.body = body;
2066 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2067 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002068 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002069 p->lineno = lineno;
2070 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002071 p->end_lineno = end_lineno;
2072 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002073 return p;
2074}
2075
2076stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002077ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002078 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2079 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002080{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002081 stmt_ty p;
2082 if (!name) {
2083 PyErr_SetString(PyExc_ValueError,
2084 "field name is required for ClassDef");
2085 return NULL;
2086 }
2087 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2088 if (!p)
2089 return NULL;
2090 p->kind = ClassDef_kind;
2091 p->v.ClassDef.name = name;
2092 p->v.ClassDef.bases = bases;
2093 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002094 p->v.ClassDef.body = body;
2095 p->v.ClassDef.decorator_list = decorator_list;
2096 p->lineno = lineno;
2097 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002098 p->end_lineno = end_lineno;
2099 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002100 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002101}
2102
2103stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002104Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2105 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002106{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002107 stmt_ty p;
2108 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2109 if (!p)
2110 return NULL;
2111 p->kind = Return_kind;
2112 p->v.Return.value = value;
2113 p->lineno = lineno;
2114 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002115 p->end_lineno = end_lineno;
2116 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002117 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002118}
2119
2120stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002121Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2122 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002123{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002124 stmt_ty p;
2125 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2126 if (!p)
2127 return NULL;
2128 p->kind = Delete_kind;
2129 p->v.Delete.targets = targets;
2130 p->lineno = lineno;
2131 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002132 p->end_lineno = end_lineno;
2133 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002134 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002135}
2136
2137stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002138Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2139 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002140{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002141 stmt_ty p;
2142 if (!value) {
2143 PyErr_SetString(PyExc_ValueError,
2144 "field value is required for Assign");
2145 return NULL;
2146 }
2147 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2148 if (!p)
2149 return NULL;
2150 p->kind = Assign_kind;
2151 p->v.Assign.targets = targets;
2152 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002153 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002154 p->lineno = lineno;
2155 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002156 p->end_lineno = end_lineno;
2157 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002158 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002159}
2160
2161stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002162AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002163 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002164{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002165 stmt_ty p;
2166 if (!target) {
2167 PyErr_SetString(PyExc_ValueError,
2168 "field target is required for AugAssign");
2169 return NULL;
2170 }
2171 if (!op) {
2172 PyErr_SetString(PyExc_ValueError,
2173 "field op is required for AugAssign");
2174 return NULL;
2175 }
2176 if (!value) {
2177 PyErr_SetString(PyExc_ValueError,
2178 "field value is required for AugAssign");
2179 return NULL;
2180 }
2181 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2182 if (!p)
2183 return NULL;
2184 p->kind = AugAssign_kind;
2185 p->v.AugAssign.target = target;
2186 p->v.AugAssign.op = op;
2187 p->v.AugAssign.value = value;
2188 p->lineno = lineno;
2189 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002190 p->end_lineno = end_lineno;
2191 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002192 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002193}
2194
2195stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002196AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002197 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2198 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002199{
2200 stmt_ty p;
2201 if (!target) {
2202 PyErr_SetString(PyExc_ValueError,
2203 "field target is required for AnnAssign");
2204 return NULL;
2205 }
2206 if (!annotation) {
2207 PyErr_SetString(PyExc_ValueError,
2208 "field annotation is required for AnnAssign");
2209 return NULL;
2210 }
2211 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2212 if (!p)
2213 return NULL;
2214 p->kind = AnnAssign_kind;
2215 p->v.AnnAssign.target = target;
2216 p->v.AnnAssign.annotation = annotation;
2217 p->v.AnnAssign.value = value;
2218 p->v.AnnAssign.simple = simple;
2219 p->lineno = lineno;
2220 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002221 p->end_lineno = end_lineno;
2222 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002223 return p;
2224}
2225
2226stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002227For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2228 type_comment, int lineno, int col_offset, int end_lineno, int
2229 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002230{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002231 stmt_ty p;
2232 if (!target) {
2233 PyErr_SetString(PyExc_ValueError,
2234 "field target is required for For");
2235 return NULL;
2236 }
2237 if (!iter) {
2238 PyErr_SetString(PyExc_ValueError,
2239 "field iter is required for For");
2240 return NULL;
2241 }
2242 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2243 if (!p)
2244 return NULL;
2245 p->kind = For_kind;
2246 p->v.For.target = target;
2247 p->v.For.iter = iter;
2248 p->v.For.body = body;
2249 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002250 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002251 p->lineno = lineno;
2252 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002253 p->end_lineno = end_lineno;
2254 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002255 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002256}
2257
2258stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002259AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2260 string type_comment, int lineno, int col_offset, int end_lineno, int
2261 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002262{
2263 stmt_ty p;
2264 if (!target) {
2265 PyErr_SetString(PyExc_ValueError,
2266 "field target is required for AsyncFor");
2267 return NULL;
2268 }
2269 if (!iter) {
2270 PyErr_SetString(PyExc_ValueError,
2271 "field iter is required for AsyncFor");
2272 return NULL;
2273 }
2274 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2275 if (!p)
2276 return NULL;
2277 p->kind = AsyncFor_kind;
2278 p->v.AsyncFor.target = target;
2279 p->v.AsyncFor.iter = iter;
2280 p->v.AsyncFor.body = body;
2281 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002282 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002283 p->lineno = lineno;
2284 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002285 p->end_lineno = end_lineno;
2286 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002287 return p;
2288}
2289
2290stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002291While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002292 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002293{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002294 stmt_ty p;
2295 if (!test) {
2296 PyErr_SetString(PyExc_ValueError,
2297 "field test is required for While");
2298 return NULL;
2299 }
2300 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2301 if (!p)
2302 return NULL;
2303 p->kind = While_kind;
2304 p->v.While.test = test;
2305 p->v.While.body = body;
2306 p->v.While.orelse = orelse;
2307 p->lineno = lineno;
2308 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002309 p->end_lineno = end_lineno;
2310 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002311 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002312}
2313
2314stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002315If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002316 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002317{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002318 stmt_ty p;
2319 if (!test) {
2320 PyErr_SetString(PyExc_ValueError,
2321 "field test is required for If");
2322 return NULL;
2323 }
2324 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2325 if (!p)
2326 return NULL;
2327 p->kind = If_kind;
2328 p->v.If.test = test;
2329 p->v.If.body = body;
2330 p->v.If.orelse = orelse;
2331 p->lineno = lineno;
2332 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002333 p->end_lineno = end_lineno;
2334 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002335 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002336}
2337
2338stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002339With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2340 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002341{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002342 stmt_ty p;
2343 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2344 if (!p)
2345 return NULL;
2346 p->kind = With_kind;
2347 p->v.With.items = items;
2348 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002349 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002350 p->lineno = lineno;
2351 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002352 p->end_lineno = end_lineno;
2353 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002354 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002355}
2356
2357stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002358AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2359 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002360{
2361 stmt_ty p;
2362 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2363 if (!p)
2364 return NULL;
2365 p->kind = AsyncWith_kind;
2366 p->v.AsyncWith.items = items;
2367 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002368 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002369 p->lineno = lineno;
2370 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002371 p->end_lineno = end_lineno;
2372 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002373 return p;
2374}
2375
2376stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002377Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2378 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002379{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002380 stmt_ty p;
2381 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2382 if (!p)
2383 return NULL;
2384 p->kind = Raise_kind;
2385 p->v.Raise.exc = exc;
2386 p->v.Raise.cause = cause;
2387 p->lineno = lineno;
2388 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002389 p->end_lineno = end_lineno;
2390 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002391 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002392}
2393
2394stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002395Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002396 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2397 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002398{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002399 stmt_ty p;
2400 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2401 if (!p)
2402 return NULL;
2403 p->kind = Try_kind;
2404 p->v.Try.body = body;
2405 p->v.Try.handlers = handlers;
2406 p->v.Try.orelse = orelse;
2407 p->v.Try.finalbody = finalbody;
2408 p->lineno = lineno;
2409 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002410 p->end_lineno = end_lineno;
2411 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002412 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002413}
2414
2415stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002416Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2417 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002418{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002419 stmt_ty p;
2420 if (!test) {
2421 PyErr_SetString(PyExc_ValueError,
2422 "field test is required for Assert");
2423 return NULL;
2424 }
2425 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2426 if (!p)
2427 return NULL;
2428 p->kind = Assert_kind;
2429 p->v.Assert.test = test;
2430 p->v.Assert.msg = msg;
2431 p->lineno = lineno;
2432 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002433 p->end_lineno = end_lineno;
2434 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002435 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002436}
2437
2438stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002439Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2440 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002441{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002442 stmt_ty p;
2443 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2444 if (!p)
2445 return NULL;
2446 p->kind = Import_kind;
2447 p->v.Import.names = names;
2448 p->lineno = lineno;
2449 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002450 p->end_lineno = end_lineno;
2451 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002452 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002453}
2454
2455stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002456ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002457 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002458{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002459 stmt_ty p;
2460 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2461 if (!p)
2462 return NULL;
2463 p->kind = ImportFrom_kind;
2464 p->v.ImportFrom.module = module;
2465 p->v.ImportFrom.names = names;
2466 p->v.ImportFrom.level = level;
2467 p->lineno = lineno;
2468 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002469 p->end_lineno = end_lineno;
2470 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002471 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002472}
2473
2474stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002475Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2476 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002477{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002478 stmt_ty p;
2479 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2480 if (!p)
2481 return NULL;
2482 p->kind = Global_kind;
2483 p->v.Global.names = names;
2484 p->lineno = lineno;
2485 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002486 p->end_lineno = end_lineno;
2487 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002488 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002489}
2490
2491stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002492Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2493 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002494{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002495 stmt_ty p;
2496 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2497 if (!p)
2498 return NULL;
2499 p->kind = Nonlocal_kind;
2500 p->v.Nonlocal.names = names;
2501 p->lineno = lineno;
2502 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002503 p->end_lineno = end_lineno;
2504 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002505 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002506}
2507
2508stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002509Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2510 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002511{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002512 stmt_ty p;
2513 if (!value) {
2514 PyErr_SetString(PyExc_ValueError,
2515 "field value is required for Expr");
2516 return NULL;
2517 }
2518 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2519 if (!p)
2520 return NULL;
2521 p->kind = Expr_kind;
2522 p->v.Expr.value = value;
2523 p->lineno = lineno;
2524 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002525 p->end_lineno = end_lineno;
2526 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002527 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002528}
2529
2530stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002531Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2532 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002533{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002534 stmt_ty p;
2535 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2536 if (!p)
2537 return NULL;
2538 p->kind = Pass_kind;
2539 p->lineno = lineno;
2540 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002541 p->end_lineno = end_lineno;
2542 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002543 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002544}
2545
2546stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002547Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2548 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002549{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002550 stmt_ty p;
2551 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2552 if (!p)
2553 return NULL;
2554 p->kind = Break_kind;
2555 p->lineno = lineno;
2556 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002557 p->end_lineno = end_lineno;
2558 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002559 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002560}
2561
2562stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002563Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2564 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002565{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002566 stmt_ty p;
2567 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2568 if (!p)
2569 return NULL;
2570 p->kind = Continue_kind;
2571 p->lineno = lineno;
2572 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002573 p->end_lineno = end_lineno;
2574 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002575 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002576}
2577
2578expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002579BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2580 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002581{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002582 expr_ty p;
2583 if (!op) {
2584 PyErr_SetString(PyExc_ValueError,
2585 "field op is required for BoolOp");
2586 return NULL;
2587 }
2588 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2589 if (!p)
2590 return NULL;
2591 p->kind = BoolOp_kind;
2592 p->v.BoolOp.op = op;
2593 p->v.BoolOp.values = values;
2594 p->lineno = lineno;
2595 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002596 p->end_lineno = end_lineno;
2597 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002598 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002599}
2600
2601expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002602NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2603 end_lineno, int end_col_offset, PyArena *arena)
2604{
2605 expr_ty p;
2606 if (!target) {
2607 PyErr_SetString(PyExc_ValueError,
2608 "field target is required for NamedExpr");
2609 return NULL;
2610 }
2611 if (!value) {
2612 PyErr_SetString(PyExc_ValueError,
2613 "field value is required for NamedExpr");
2614 return NULL;
2615 }
2616 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2617 if (!p)
2618 return NULL;
2619 p->kind = NamedExpr_kind;
2620 p->v.NamedExpr.target = target;
2621 p->v.NamedExpr.value = value;
2622 p->lineno = lineno;
2623 p->col_offset = col_offset;
2624 p->end_lineno = end_lineno;
2625 p->end_col_offset = end_col_offset;
2626 return p;
2627}
2628
2629expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002630BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002631 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002632{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002633 expr_ty p;
2634 if (!left) {
2635 PyErr_SetString(PyExc_ValueError,
2636 "field left is required for BinOp");
2637 return NULL;
2638 }
2639 if (!op) {
2640 PyErr_SetString(PyExc_ValueError,
2641 "field op is required for BinOp");
2642 return NULL;
2643 }
2644 if (!right) {
2645 PyErr_SetString(PyExc_ValueError,
2646 "field right is required for BinOp");
2647 return NULL;
2648 }
2649 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2650 if (!p)
2651 return NULL;
2652 p->kind = BinOp_kind;
2653 p->v.BinOp.left = left;
2654 p->v.BinOp.op = op;
2655 p->v.BinOp.right = right;
2656 p->lineno = lineno;
2657 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002658 p->end_lineno = end_lineno;
2659 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002660 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002661}
2662
2663expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002664UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2665 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002666{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002667 expr_ty p;
2668 if (!op) {
2669 PyErr_SetString(PyExc_ValueError,
2670 "field op is required for UnaryOp");
2671 return NULL;
2672 }
2673 if (!operand) {
2674 PyErr_SetString(PyExc_ValueError,
2675 "field operand is required for UnaryOp");
2676 return NULL;
2677 }
2678 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2679 if (!p)
2680 return NULL;
2681 p->kind = UnaryOp_kind;
2682 p->v.UnaryOp.op = op;
2683 p->v.UnaryOp.operand = operand;
2684 p->lineno = lineno;
2685 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002686 p->end_lineno = end_lineno;
2687 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002688 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002689}
2690
2691expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002692Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2693 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002694{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002695 expr_ty p;
2696 if (!args) {
2697 PyErr_SetString(PyExc_ValueError,
2698 "field args is required for Lambda");
2699 return NULL;
2700 }
2701 if (!body) {
2702 PyErr_SetString(PyExc_ValueError,
2703 "field body is required for Lambda");
2704 return NULL;
2705 }
2706 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2707 if (!p)
2708 return NULL;
2709 p->kind = Lambda_kind;
2710 p->v.Lambda.args = args;
2711 p->v.Lambda.body = body;
2712 p->lineno = lineno;
2713 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002714 p->end_lineno = end_lineno;
2715 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002716 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002717}
2718
2719expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002720IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002721 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002722{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002723 expr_ty p;
2724 if (!test) {
2725 PyErr_SetString(PyExc_ValueError,
2726 "field test is required for IfExp");
2727 return NULL;
2728 }
2729 if (!body) {
2730 PyErr_SetString(PyExc_ValueError,
2731 "field body is required for IfExp");
2732 return NULL;
2733 }
2734 if (!orelse) {
2735 PyErr_SetString(PyExc_ValueError,
2736 "field orelse is required for IfExp");
2737 return NULL;
2738 }
2739 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2740 if (!p)
2741 return NULL;
2742 p->kind = IfExp_kind;
2743 p->v.IfExp.test = test;
2744 p->v.IfExp.body = body;
2745 p->v.IfExp.orelse = orelse;
2746 p->lineno = lineno;
2747 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002748 p->end_lineno = end_lineno;
2749 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002750 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002751}
2752
2753expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002754Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2755 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002756{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002757 expr_ty p;
2758 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2759 if (!p)
2760 return NULL;
2761 p->kind = Dict_kind;
2762 p->v.Dict.keys = keys;
2763 p->v.Dict.values = values;
2764 p->lineno = lineno;
2765 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002766 p->end_lineno = end_lineno;
2767 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002768 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002769}
2770
2771expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002772Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2773 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002774{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002775 expr_ty p;
2776 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2777 if (!p)
2778 return NULL;
2779 p->kind = Set_kind;
2780 p->v.Set.elts = elts;
2781 p->lineno = lineno;
2782 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002783 p->end_lineno = end_lineno;
2784 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002785 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002786}
2787
2788expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002789ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2790 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002791{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002792 expr_ty p;
2793 if (!elt) {
2794 PyErr_SetString(PyExc_ValueError,
2795 "field elt is required for ListComp");
2796 return NULL;
2797 }
2798 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2799 if (!p)
2800 return NULL;
2801 p->kind = ListComp_kind;
2802 p->v.ListComp.elt = elt;
2803 p->v.ListComp.generators = generators;
2804 p->lineno = lineno;
2805 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002806 p->end_lineno = end_lineno;
2807 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002808 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002809}
2810
2811expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002812SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2813 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002814{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002815 expr_ty p;
2816 if (!elt) {
2817 PyErr_SetString(PyExc_ValueError,
2818 "field elt is required for SetComp");
2819 return NULL;
2820 }
2821 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2822 if (!p)
2823 return NULL;
2824 p->kind = SetComp_kind;
2825 p->v.SetComp.elt = elt;
2826 p->v.SetComp.generators = generators;
2827 p->lineno = lineno;
2828 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002829 p->end_lineno = end_lineno;
2830 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002831 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002832}
2833
2834expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002835DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002836 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002837{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002838 expr_ty p;
2839 if (!key) {
2840 PyErr_SetString(PyExc_ValueError,
2841 "field key is required for DictComp");
2842 return NULL;
2843 }
2844 if (!value) {
2845 PyErr_SetString(PyExc_ValueError,
2846 "field value is required for DictComp");
2847 return NULL;
2848 }
2849 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2850 if (!p)
2851 return NULL;
2852 p->kind = DictComp_kind;
2853 p->v.DictComp.key = key;
2854 p->v.DictComp.value = value;
2855 p->v.DictComp.generators = generators;
2856 p->lineno = lineno;
2857 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002858 p->end_lineno = end_lineno;
2859 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002860 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002861}
2862
2863expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002864GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002865 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002866{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002867 expr_ty p;
2868 if (!elt) {
2869 PyErr_SetString(PyExc_ValueError,
2870 "field elt is required for GeneratorExp");
2871 return NULL;
2872 }
2873 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2874 if (!p)
2875 return NULL;
2876 p->kind = GeneratorExp_kind;
2877 p->v.GeneratorExp.elt = elt;
2878 p->v.GeneratorExp.generators = generators;
2879 p->lineno = lineno;
2880 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002881 p->end_lineno = end_lineno;
2882 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002883 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002884}
2885
2886expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002887Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2888 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002889{
2890 expr_ty p;
2891 if (!value) {
2892 PyErr_SetString(PyExc_ValueError,
2893 "field value is required for Await");
2894 return NULL;
2895 }
2896 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2897 if (!p)
2898 return NULL;
2899 p->kind = Await_kind;
2900 p->v.Await.value = value;
2901 p->lineno = lineno;
2902 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002903 p->end_lineno = end_lineno;
2904 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002905 return p;
2906}
2907
2908expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002909Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2910 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002911{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002912 expr_ty p;
2913 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2914 if (!p)
2915 return NULL;
2916 p->kind = Yield_kind;
2917 p->v.Yield.value = value;
2918 p->lineno = lineno;
2919 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002920 p->end_lineno = end_lineno;
2921 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002922 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002923}
2924
2925expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002926YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
2927 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05002928{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002929 expr_ty p;
2930 if (!value) {
2931 PyErr_SetString(PyExc_ValueError,
2932 "field value is required for YieldFrom");
2933 return NULL;
2934 }
2935 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2936 if (!p)
2937 return NULL;
2938 p->kind = YieldFrom_kind;
2939 p->v.YieldFrom.value = value;
2940 p->lineno = lineno;
2941 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002942 p->end_lineno = end_lineno;
2943 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002944 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05002945}
2946
2947expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00002948Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002949 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002950{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002951 expr_ty p;
2952 if (!left) {
2953 PyErr_SetString(PyExc_ValueError,
2954 "field left is required for Compare");
2955 return NULL;
2956 }
2957 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2958 if (!p)
2959 return NULL;
2960 p->kind = Compare_kind;
2961 p->v.Compare.left = left;
2962 p->v.Compare.ops = ops;
2963 p->v.Compare.comparators = comparators;
2964 p->lineno = lineno;
2965 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002966 p->end_lineno = end_lineno;
2967 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002968 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002969}
2970
2971expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002972Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002973 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002974{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002975 expr_ty p;
2976 if (!func) {
2977 PyErr_SetString(PyExc_ValueError,
2978 "field func is required for Call");
2979 return NULL;
2980 }
2981 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2982 if (!p)
2983 return NULL;
2984 p->kind = Call_kind;
2985 p->v.Call.func = func;
2986 p->v.Call.args = args;
2987 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002988 p->lineno = lineno;
2989 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002990 p->end_lineno = end_lineno;
2991 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002992 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002993}
2994
2995expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04002996FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
2997 int col_offset, int end_lineno, int end_col_offset, PyArena
2998 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04002999{
3000 expr_ty p;
3001 if (!value) {
3002 PyErr_SetString(PyExc_ValueError,
3003 "field value is required for FormattedValue");
3004 return NULL;
3005 }
3006 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3007 if (!p)
3008 return NULL;
3009 p->kind = FormattedValue_kind;
3010 p->v.FormattedValue.value = value;
3011 p->v.FormattedValue.conversion = conversion;
3012 p->v.FormattedValue.format_spec = format_spec;
3013 p->lineno = lineno;
3014 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003015 p->end_lineno = end_lineno;
3016 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003017 return p;
3018}
3019
3020expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003021JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3022 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003023{
3024 expr_ty p;
3025 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3026 if (!p)
3027 return NULL;
3028 p->kind = JoinedStr_kind;
3029 p->v.JoinedStr.values = values;
3030 p->lineno = lineno;
3031 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003032 p->end_lineno = end_lineno;
3033 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003034 return p;
3035}
3036
3037expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003038Constant(constant value, string kind, int lineno, int col_offset, int
3039 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003040{
3041 expr_ty p;
3042 if (!value) {
3043 PyErr_SetString(PyExc_ValueError,
3044 "field value is required for Constant");
3045 return NULL;
3046 }
3047 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3048 if (!p)
3049 return NULL;
3050 p->kind = Constant_kind;
3051 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003052 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003053 p->lineno = lineno;
3054 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003055 p->end_lineno = end_lineno;
3056 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003057 return p;
3058}
3059
3060expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003061Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003062 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003063{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003064 expr_ty p;
3065 if (!value) {
3066 PyErr_SetString(PyExc_ValueError,
3067 "field value is required for Attribute");
3068 return NULL;
3069 }
3070 if (!attr) {
3071 PyErr_SetString(PyExc_ValueError,
3072 "field attr is required for Attribute");
3073 return NULL;
3074 }
3075 if (!ctx) {
3076 PyErr_SetString(PyExc_ValueError,
3077 "field ctx is required for Attribute");
3078 return NULL;
3079 }
3080 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3081 if (!p)
3082 return NULL;
3083 p->kind = Attribute_kind;
3084 p->v.Attribute.value = value;
3085 p->v.Attribute.attr = attr;
3086 p->v.Attribute.ctx = ctx;
3087 p->lineno = lineno;
3088 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003089 p->end_lineno = end_lineno;
3090 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003091 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003092}
3093
3094expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003095Subscript(expr_ty value, slice_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003096 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003097{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003098 expr_ty p;
3099 if (!value) {
3100 PyErr_SetString(PyExc_ValueError,
3101 "field value is required for Subscript");
3102 return NULL;
3103 }
3104 if (!slice) {
3105 PyErr_SetString(PyExc_ValueError,
3106 "field slice is required for Subscript");
3107 return NULL;
3108 }
3109 if (!ctx) {
3110 PyErr_SetString(PyExc_ValueError,
3111 "field ctx is required for Subscript");
3112 return NULL;
3113 }
3114 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3115 if (!p)
3116 return NULL;
3117 p->kind = Subscript_kind;
3118 p->v.Subscript.value = value;
3119 p->v.Subscript.slice = slice;
3120 p->v.Subscript.ctx = ctx;
3121 p->lineno = lineno;
3122 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003123 p->end_lineno = end_lineno;
3124 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003125 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003126}
3127
3128expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003129Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3130 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003131{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003132 expr_ty p;
3133 if (!value) {
3134 PyErr_SetString(PyExc_ValueError,
3135 "field value is required for Starred");
3136 return NULL;
3137 }
3138 if (!ctx) {
3139 PyErr_SetString(PyExc_ValueError,
3140 "field ctx is required for Starred");
3141 return NULL;
3142 }
3143 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3144 if (!p)
3145 return NULL;
3146 p->kind = Starred_kind;
3147 p->v.Starred.value = value;
3148 p->v.Starred.ctx = ctx;
3149 p->lineno = lineno;
3150 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003151 p->end_lineno = end_lineno;
3152 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003153 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003154}
3155
3156expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003157Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3158 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003159{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003160 expr_ty p;
3161 if (!id) {
3162 PyErr_SetString(PyExc_ValueError,
3163 "field id is required for Name");
3164 return NULL;
3165 }
3166 if (!ctx) {
3167 PyErr_SetString(PyExc_ValueError,
3168 "field ctx is required for Name");
3169 return NULL;
3170 }
3171 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3172 if (!p)
3173 return NULL;
3174 p->kind = Name_kind;
3175 p->v.Name.id = id;
3176 p->v.Name.ctx = ctx;
3177 p->lineno = lineno;
3178 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003179 p->end_lineno = end_lineno;
3180 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003181 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003182}
3183
3184expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003185List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3186 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003187{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003188 expr_ty p;
3189 if (!ctx) {
3190 PyErr_SetString(PyExc_ValueError,
3191 "field ctx is required for List");
3192 return NULL;
3193 }
3194 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3195 if (!p)
3196 return NULL;
3197 p->kind = List_kind;
3198 p->v.List.elts = elts;
3199 p->v.List.ctx = ctx;
3200 p->lineno = lineno;
3201 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003202 p->end_lineno = end_lineno;
3203 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003204 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003205}
3206
3207expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003208Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3209 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003210{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003211 expr_ty p;
3212 if (!ctx) {
3213 PyErr_SetString(PyExc_ValueError,
3214 "field ctx is required for Tuple");
3215 return NULL;
3216 }
3217 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3218 if (!p)
3219 return NULL;
3220 p->kind = Tuple_kind;
3221 p->v.Tuple.elts = elts;
3222 p->v.Tuple.ctx = ctx;
3223 p->lineno = lineno;
3224 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003225 p->end_lineno = end_lineno;
3226 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003227 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003228}
3229
3230slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003231Slice(expr_ty lower, expr_ty upper, expr_ty step, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003232{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003233 slice_ty p;
3234 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3235 if (!p)
3236 return NULL;
3237 p->kind = Slice_kind;
3238 p->v.Slice.lower = lower;
3239 p->v.Slice.upper = upper;
3240 p->v.Slice.step = step;
3241 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003242}
3243
3244slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003245ExtSlice(asdl_seq * dims, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003246{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003247 slice_ty p;
3248 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3249 if (!p)
3250 return NULL;
3251 p->kind = ExtSlice_kind;
3252 p->v.ExtSlice.dims = dims;
3253 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003254}
3255
3256slice_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003257Index(expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003258{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003259 slice_ty p;
3260 if (!value) {
3261 PyErr_SetString(PyExc_ValueError,
3262 "field value is required for Index");
3263 return NULL;
3264 }
3265 p = (slice_ty)PyArena_Malloc(arena, sizeof(*p));
3266 if (!p)
3267 return NULL;
3268 p->kind = Index_kind;
3269 p->v.Index.value = value;
3270 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003271}
3272
3273comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003274comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3275 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003276{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003277 comprehension_ty p;
3278 if (!target) {
3279 PyErr_SetString(PyExc_ValueError,
3280 "field target is required for comprehension");
3281 return NULL;
3282 }
3283 if (!iter) {
3284 PyErr_SetString(PyExc_ValueError,
3285 "field iter is required for comprehension");
3286 return NULL;
3287 }
3288 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3289 if (!p)
3290 return NULL;
3291 p->target = target;
3292 p->iter = iter;
3293 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003294 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003295 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003296}
3297
3298excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003299ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003300 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003301{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003302 excepthandler_ty p;
3303 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3304 if (!p)
3305 return NULL;
3306 p->kind = ExceptHandler_kind;
3307 p->v.ExceptHandler.type = type;
3308 p->v.ExceptHandler.name = name;
3309 p->v.ExceptHandler.body = body;
3310 p->lineno = lineno;
3311 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003312 p->end_lineno = end_lineno;
3313 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003314 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003315}
3316
3317arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003318arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003319 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3320 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003321{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003322 arguments_ty p;
3323 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3324 if (!p)
3325 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003326 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003327 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003328 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003329 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003330 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003331 p->kwarg = kwarg;
3332 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003333 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003334}
3335
Neal Norwitzc1505362006-12-28 06:47:50 +00003336arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003337arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3338 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003339{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003340 arg_ty p;
3341 if (!arg) {
3342 PyErr_SetString(PyExc_ValueError,
3343 "field arg is required for arg");
3344 return NULL;
3345 }
3346 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3347 if (!p)
3348 return NULL;
3349 p->arg = arg;
3350 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003351 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003352 p->lineno = lineno;
3353 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003354 p->end_lineno = end_lineno;
3355 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003356 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003357}
3358
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003359keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003360keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003361{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003362 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003363 if (!value) {
3364 PyErr_SetString(PyExc_ValueError,
3365 "field value is required for keyword");
3366 return NULL;
3367 }
3368 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3369 if (!p)
3370 return NULL;
3371 p->arg = arg;
3372 p->value = value;
3373 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003374}
3375
3376alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003377alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003378{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003379 alias_ty p;
3380 if (!name) {
3381 PyErr_SetString(PyExc_ValueError,
3382 "field name is required for alias");
3383 return NULL;
3384 }
3385 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3386 if (!p)
3387 return NULL;
3388 p->name = name;
3389 p->asname = asname;
3390 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003391}
3392
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003393withitem_ty
3394withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3395{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003396 withitem_ty p;
3397 if (!context_expr) {
3398 PyErr_SetString(PyExc_ValueError,
3399 "field context_expr is required for withitem");
3400 return NULL;
3401 }
3402 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3403 if (!p)
3404 return NULL;
3405 p->context_expr = context_expr;
3406 p->optional_vars = optional_vars;
3407 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003408}
3409
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003410type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003411TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003412{
3413 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003414 if (!tag) {
3415 PyErr_SetString(PyExc_ValueError,
3416 "field tag is required for TypeIgnore");
3417 return NULL;
3418 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003419 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3420 if (!p)
3421 return NULL;
3422 p->kind = TypeIgnore_kind;
3423 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003424 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003425 return p;
3426}
3427
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003428
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003429PyObject*
3430ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003431{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003432 mod_ty o = (mod_ty)_o;
3433 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003434 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003435 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003436 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003437 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003438
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003439 switch (o->kind) {
3440 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003441 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3442 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003443 if (!result) goto failed;
3444 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3445 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003446 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -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_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3450 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003451 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
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;
3456 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003457 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3458 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003459 if (!result) goto failed;
3460 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3461 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003462 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003463 goto failed;
3464 Py_DECREF(value);
3465 break;
3466 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003467 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3468 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003469 if (!result) goto failed;
3470 value = ast2obj_expr(o->v.Expression.body);
3471 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003472 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003473 goto failed;
3474 Py_DECREF(value);
3475 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003476 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003477 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3478 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003479 if (!result) goto failed;
3480 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3481 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003482 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3483 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003484 goto failed;
3485 Py_DECREF(value);
3486 value = ast2obj_expr(o->v.FunctionType.returns);
3487 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003488 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3489 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003490 goto failed;
3491 Py_DECREF(value);
3492 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003493 }
3494 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003495failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003496 Py_XDECREF(value);
3497 Py_XDECREF(result);
3498 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003499}
3500
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003501PyObject*
3502ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003503{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003504 stmt_ty o = (stmt_ty)_o;
3505 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003506 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003507 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003508 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003509 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003510
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003511 switch (o->kind) {
3512 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003513 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3514 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003515 if (!result) goto failed;
3516 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003517 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003518 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003519 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003520 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003521 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003522 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003523 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003524 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003525 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003526 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3527 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003528 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003529 goto failed;
3530 Py_DECREF(value);
3531 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3532 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003533 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3534 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003535 goto failed;
3536 Py_DECREF(value);
3537 value = ast2obj_expr(o->v.FunctionDef.returns);
3538 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003539 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3540 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003541 goto failed;
3542 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003543 value = ast2obj_string(o->v.FunctionDef.type_comment);
3544 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003545 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3546 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003547 goto failed;
3548 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003549 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003550 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003551 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3552 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003553 if (!result) goto failed;
3554 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3555 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003556 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003557 goto failed;
3558 Py_DECREF(value);
3559 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3560 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003561 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003562 goto failed;
3563 Py_DECREF(value);
3564 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3565 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003566 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003567 goto failed;
3568 Py_DECREF(value);
3569 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3570 ast2obj_expr);
3571 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003572 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3573 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003574 goto failed;
3575 Py_DECREF(value);
3576 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3577 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003578 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3579 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003580 goto failed;
3581 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003582 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3583 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003584 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3585 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003586 goto failed;
3587 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003588 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003589 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003590 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3591 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003592 if (!result) goto failed;
3593 value = ast2obj_identifier(o->v.ClassDef.name);
3594 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003595 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003596 goto failed;
3597 Py_DECREF(value);
3598 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3599 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003600 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003601 goto failed;
3602 Py_DECREF(value);
3603 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3604 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003605 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3606 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003607 goto failed;
3608 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003609 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3610 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003611 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003612 goto failed;
3613 Py_DECREF(value);
3614 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3615 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003616 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3617 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003618 goto failed;
3619 Py_DECREF(value);
3620 break;
3621 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003622 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3623 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003624 if (!result) goto failed;
3625 value = ast2obj_expr(o->v.Return.value);
3626 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003627 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003628 goto failed;
3629 Py_DECREF(value);
3630 break;
3631 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003632 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3633 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003634 if (!result) goto failed;
3635 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3636 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003637 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3638 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003639 goto failed;
3640 Py_DECREF(value);
3641 break;
3642 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003643 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3644 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003645 if (!result) goto failed;
3646 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3647 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003648 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3649 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003650 goto failed;
3651 Py_DECREF(value);
3652 value = ast2obj_expr(o->v.Assign.value);
3653 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003654 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003655 goto failed;
3656 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003657 value = ast2obj_string(o->v.Assign.type_comment);
3658 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003659 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3660 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003661 goto failed;
3662 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003663 break;
3664 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003665 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3666 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003667 if (!result) goto failed;
3668 value = ast2obj_expr(o->v.AugAssign.target);
3669 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003670 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3671 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003672 goto failed;
3673 Py_DECREF(value);
3674 value = ast2obj_operator(o->v.AugAssign.op);
3675 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003676 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003677 goto failed;
3678 Py_DECREF(value);
3679 value = ast2obj_expr(o->v.AugAssign.value);
3680 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003681 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003682 goto failed;
3683 Py_DECREF(value);
3684 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003685 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003686 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3687 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003688 if (!result) goto failed;
3689 value = ast2obj_expr(o->v.AnnAssign.target);
3690 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003691 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3692 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003693 goto failed;
3694 Py_DECREF(value);
3695 value = ast2obj_expr(o->v.AnnAssign.annotation);
3696 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003697 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3698 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003699 goto failed;
3700 Py_DECREF(value);
3701 value = ast2obj_expr(o->v.AnnAssign.value);
3702 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003703 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003704 goto failed;
3705 Py_DECREF(value);
3706 value = ast2obj_int(o->v.AnnAssign.simple);
3707 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003708 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3709 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003710 goto failed;
3711 Py_DECREF(value);
3712 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003713 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003714 tp = (PyTypeObject *)astmodulestate_global->For_type;
3715 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003716 if (!result) goto failed;
3717 value = ast2obj_expr(o->v.For.target);
3718 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003719 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3720 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003721 goto failed;
3722 Py_DECREF(value);
3723 value = ast2obj_expr(o->v.For.iter);
3724 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003725 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003726 goto failed;
3727 Py_DECREF(value);
3728 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3729 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003730 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003731 goto failed;
3732 Py_DECREF(value);
3733 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3734 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003735 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3736 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003737 goto failed;
3738 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003739 value = ast2obj_string(o->v.For.type_comment);
3740 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003741 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3742 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003743 goto failed;
3744 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003745 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003746 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003747 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3748 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003749 if (!result) goto failed;
3750 value = ast2obj_expr(o->v.AsyncFor.target);
3751 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003752 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3753 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003754 goto failed;
3755 Py_DECREF(value);
3756 value = ast2obj_expr(o->v.AsyncFor.iter);
3757 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003758 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003759 goto failed;
3760 Py_DECREF(value);
3761 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003763 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003764 goto failed;
3765 Py_DECREF(value);
3766 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3767 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003768 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3769 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003770 goto failed;
3771 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003772 value = ast2obj_string(o->v.AsyncFor.type_comment);
3773 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003774 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3775 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003776 goto failed;
3777 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003778 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003779 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003780 tp = (PyTypeObject *)astmodulestate_global->While_type;
3781 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003782 if (!result) goto failed;
3783 value = ast2obj_expr(o->v.While.test);
3784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003785 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003786 goto failed;
3787 Py_DECREF(value);
3788 value = ast2obj_list(o->v.While.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.While.orelse, ast2obj_stmt);
3794 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003795 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3796 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003797 goto failed;
3798 Py_DECREF(value);
3799 break;
3800 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003801 tp = (PyTypeObject *)astmodulestate_global->If_type;
3802 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003803 if (!result) goto failed;
3804 value = ast2obj_expr(o->v.If.test);
3805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003806 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003807 goto failed;
3808 Py_DECREF(value);
3809 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3810 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003811 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003812 goto failed;
3813 Py_DECREF(value);
3814 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3815 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003816 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3817 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003818 goto failed;
3819 Py_DECREF(value);
3820 break;
3821 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003822 tp = (PyTypeObject *)astmodulestate_global->With_type;
3823 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003824 if (!result) goto failed;
3825 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3826 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003827 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003828 goto failed;
3829 Py_DECREF(value);
3830 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3831 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003832 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003833 goto failed;
3834 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003835 value = ast2obj_string(o->v.With.type_comment);
3836 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003837 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3838 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003839 goto failed;
3840 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003841 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003842 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003843 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3844 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003845 if (!result) goto failed;
3846 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3847 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003848 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003849 goto failed;
3850 Py_DECREF(value);
3851 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3852 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003853 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003854 goto failed;
3855 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003856 value = ast2obj_string(o->v.AsyncWith.type_comment);
3857 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003858 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3859 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003860 goto failed;
3861 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003862 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003863 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003864 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3865 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003866 if (!result) goto failed;
3867 value = ast2obj_expr(o->v.Raise.exc);
3868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003870 goto failed;
3871 Py_DECREF(value);
3872 value = ast2obj_expr(o->v.Raise.cause);
3873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003874 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003875 goto failed;
3876 Py_DECREF(value);
3877 break;
3878 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003879 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3880 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003881 if (!result) goto failed;
3882 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3883 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003884 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003885 goto failed;
3886 Py_DECREF(value);
3887 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3888 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003889 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3890 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003891 goto failed;
3892 Py_DECREF(value);
3893 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003895 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3896 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003897 goto failed;
3898 Py_DECREF(value);
3899 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3900 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003901 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3902 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003903 goto failed;
3904 Py_DECREF(value);
3905 break;
3906 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003907 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3908 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003909 if (!result) goto failed;
3910 value = ast2obj_expr(o->v.Assert.test);
3911 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003912 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003913 goto failed;
3914 Py_DECREF(value);
3915 value = ast2obj_expr(o->v.Assert.msg);
3916 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003917 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003918 goto failed;
3919 Py_DECREF(value);
3920 break;
3921 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003922 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3923 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003924 if (!result) goto failed;
3925 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3926 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003927 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003928 goto failed;
3929 Py_DECREF(value);
3930 break;
3931 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003932 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3933 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003934 if (!result) goto failed;
3935 value = ast2obj_identifier(o->v.ImportFrom.module);
3936 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003937 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
3938 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003939 goto failed;
3940 Py_DECREF(value);
3941 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
3942 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003943 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003944 goto failed;
3945 Py_DECREF(value);
3946 value = ast2obj_int(o->v.ImportFrom.level);
3947 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003948 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003949 goto failed;
3950 Py_DECREF(value);
3951 break;
3952 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003953 tp = (PyTypeObject *)astmodulestate_global->Global_type;
3954 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003955 if (!result) goto failed;
3956 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
3957 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003958 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003959 goto failed;
3960 Py_DECREF(value);
3961 break;
3962 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003963 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
3964 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003965 if (!result) goto failed;
3966 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
3967 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003968 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003969 goto failed;
3970 Py_DECREF(value);
3971 break;
3972 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003973 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
3974 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003975 if (!result) goto failed;
3976 value = ast2obj_expr(o->v.Expr.value);
3977 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003978 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003979 goto failed;
3980 Py_DECREF(value);
3981 break;
3982 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003983 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
3984 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003985 if (!result) goto failed;
3986 break;
3987 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003988 tp = (PyTypeObject *)astmodulestate_global->Break_type;
3989 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003990 if (!result) goto failed;
3991 break;
3992 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003993 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
3994 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003995 if (!result) goto failed;
3996 break;
3997 }
3998 value = ast2obj_int(o->lineno);
3999 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004000 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004001 goto failed;
4002 Py_DECREF(value);
4003 value = ast2obj_int(o->col_offset);
4004 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004005 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004006 goto failed;
4007 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004008 value = ast2obj_int(o->end_lineno);
4009 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004010 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004011 goto failed;
4012 Py_DECREF(value);
4013 value = ast2obj_int(o->end_col_offset);
4014 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004015 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4016 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004017 goto failed;
4018 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004019 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004020failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004021 Py_XDECREF(value);
4022 Py_XDECREF(result);
4023 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004024}
4025
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004026PyObject*
4027ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004028{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004029 expr_ty o = (expr_ty)_o;
4030 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004031 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004032 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004033 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004034 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004035
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004036 switch (o->kind) {
4037 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004038 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4039 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 if (!result) goto failed;
4041 value = ast2obj_boolop(o->v.BoolOp.op);
4042 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004043 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 goto failed;
4045 Py_DECREF(value);
4046 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4047 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004048 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4049 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004050 goto failed;
4051 Py_DECREF(value);
4052 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004053 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004054 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4055 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004056 if (!result) goto failed;
4057 value = ast2obj_expr(o->v.NamedExpr.target);
4058 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004059 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4060 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004061 goto failed;
4062 Py_DECREF(value);
4063 value = ast2obj_expr(o->v.NamedExpr.value);
4064 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004065 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004066 goto failed;
4067 Py_DECREF(value);
4068 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004069 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004070 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4071 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004072 if (!result) goto failed;
4073 value = ast2obj_expr(o->v.BinOp.left);
4074 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004075 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004076 goto failed;
4077 Py_DECREF(value);
4078 value = ast2obj_operator(o->v.BinOp.op);
4079 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004080 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004081 goto failed;
4082 Py_DECREF(value);
4083 value = ast2obj_expr(o->v.BinOp.right);
4084 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004085 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004086 goto failed;
4087 Py_DECREF(value);
4088 break;
4089 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004090 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4091 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004092 if (!result) goto failed;
4093 value = ast2obj_unaryop(o->v.UnaryOp.op);
4094 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004095 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004096 goto failed;
4097 Py_DECREF(value);
4098 value = ast2obj_expr(o->v.UnaryOp.operand);
4099 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004100 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4101 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 goto failed;
4103 Py_DECREF(value);
4104 break;
4105 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004106 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4107 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004108 if (!result) goto failed;
4109 value = ast2obj_arguments(o->v.Lambda.args);
4110 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004111 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004112 goto failed;
4113 Py_DECREF(value);
4114 value = ast2obj_expr(o->v.Lambda.body);
4115 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004116 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004117 goto failed;
4118 Py_DECREF(value);
4119 break;
4120 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004121 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4122 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004123 if (!result) goto failed;
4124 value = ast2obj_expr(o->v.IfExp.test);
4125 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004126 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004127 goto failed;
4128 Py_DECREF(value);
4129 value = ast2obj_expr(o->v.IfExp.body);
4130 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004131 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004132 goto failed;
4133 Py_DECREF(value);
4134 value = ast2obj_expr(o->v.IfExp.orelse);
4135 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004136 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4137 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004138 goto failed;
4139 Py_DECREF(value);
4140 break;
4141 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004142 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4143 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004144 if (!result) goto failed;
4145 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4146 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004147 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004148 goto failed;
4149 Py_DECREF(value);
4150 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4151 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004152 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4153 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004154 goto failed;
4155 Py_DECREF(value);
4156 break;
4157 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004158 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4159 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004160 if (!result) goto failed;
4161 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4162 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004163 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004164 goto failed;
4165 Py_DECREF(value);
4166 break;
4167 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004168 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4169 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004170 if (!result) goto failed;
4171 value = ast2obj_expr(o->v.ListComp.elt);
4172 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004173 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004174 goto failed;
4175 Py_DECREF(value);
4176 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4177 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004178 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4179 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004180 goto failed;
4181 Py_DECREF(value);
4182 break;
4183 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004184 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4185 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004186 if (!result) goto failed;
4187 value = ast2obj_expr(o->v.SetComp.elt);
4188 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004189 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004190 goto failed;
4191 Py_DECREF(value);
4192 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4193 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004194 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4195 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004196 goto failed;
4197 Py_DECREF(value);
4198 break;
4199 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004200 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4201 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004202 if (!result) goto failed;
4203 value = ast2obj_expr(o->v.DictComp.key);
4204 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004205 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004206 goto failed;
4207 Py_DECREF(value);
4208 value = ast2obj_expr(o->v.DictComp.value);
4209 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004210 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004211 goto failed;
4212 Py_DECREF(value);
4213 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4214 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004215 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4216 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004217 goto failed;
4218 Py_DECREF(value);
4219 break;
4220 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004221 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4222 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004223 if (!result) goto failed;
4224 value = ast2obj_expr(o->v.GeneratorExp.elt);
4225 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004226 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004227 goto failed;
4228 Py_DECREF(value);
4229 value = ast2obj_list(o->v.GeneratorExp.generators,
4230 ast2obj_comprehension);
4231 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004232 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4233 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004234 goto failed;
4235 Py_DECREF(value);
4236 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004237 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004238 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4239 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004240 if (!result) goto failed;
4241 value = ast2obj_expr(o->v.Await.value);
4242 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004243 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004244 goto failed;
4245 Py_DECREF(value);
4246 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004247 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004248 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4249 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004250 if (!result) goto failed;
4251 value = ast2obj_expr(o->v.Yield.value);
4252 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004253 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004254 goto failed;
4255 Py_DECREF(value);
4256 break;
4257 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004258 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4259 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004260 if (!result) goto failed;
4261 value = ast2obj_expr(o->v.YieldFrom.value);
4262 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004263 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004264 goto failed;
4265 Py_DECREF(value);
4266 break;
4267 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004268 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4269 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004270 if (!result) goto failed;
4271 value = ast2obj_expr(o->v.Compare.left);
4272 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004273 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004274 goto failed;
4275 Py_DECREF(value);
4276 {
4277 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4278 value = PyList_New(n);
4279 if (!value) goto failed;
4280 for(i = 0; i < n; i++)
4281 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004282 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004283 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004284 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004285 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004286 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004287 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004288 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004289 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4290 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004291 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004292 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004293 break;
4294 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004295 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4296 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004297 if (!result) goto failed;
4298 value = ast2obj_expr(o->v.Call.func);
4299 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004300 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004301 goto failed;
4302 Py_DECREF(value);
4303 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4304 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004305 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004306 goto failed;
4307 Py_DECREF(value);
4308 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4309 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004310 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4311 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 goto failed;
4313 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004314 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004315 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004316 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4317 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004318 if (!result) goto failed;
4319 value = ast2obj_expr(o->v.FormattedValue.value);
4320 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004321 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004322 goto failed;
4323 Py_DECREF(value);
4324 value = ast2obj_int(o->v.FormattedValue.conversion);
4325 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004326 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4327 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004328 goto failed;
4329 Py_DECREF(value);
4330 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4331 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004332 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4333 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004334 goto failed;
4335 Py_DECREF(value);
4336 break;
4337 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004338 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4339 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004340 if (!result) goto failed;
4341 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4342 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004343 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4344 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004345 goto failed;
4346 Py_DECREF(value);
4347 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004348 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004349 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4350 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004351 if (!result) goto failed;
4352 value = ast2obj_constant(o->v.Constant.value);
4353 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004354 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004355 goto failed;
4356 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004357 value = ast2obj_string(o->v.Constant.kind);
4358 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004359 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004360 goto failed;
4361 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004362 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004363 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004364 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4365 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 if (!result) goto failed;
4367 value = ast2obj_expr(o->v.Attribute.value);
4368 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004369 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004370 goto failed;
4371 Py_DECREF(value);
4372 value = ast2obj_identifier(o->v.Attribute.attr);
4373 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004374 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004375 goto failed;
4376 Py_DECREF(value);
4377 value = ast2obj_expr_context(o->v.Attribute.ctx);
4378 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004379 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004380 goto failed;
4381 Py_DECREF(value);
4382 break;
4383 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004384 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4385 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004386 if (!result) goto failed;
4387 value = ast2obj_expr(o->v.Subscript.value);
4388 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004389 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004390 goto failed;
4391 Py_DECREF(value);
4392 value = ast2obj_slice(o->v.Subscript.slice);
4393 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004394 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004395 goto failed;
4396 Py_DECREF(value);
4397 value = ast2obj_expr_context(o->v.Subscript.ctx);
4398 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004399 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004400 goto failed;
4401 Py_DECREF(value);
4402 break;
4403 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004404 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4405 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004406 if (!result) goto failed;
4407 value = ast2obj_expr(o->v.Starred.value);
4408 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004409 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004410 goto failed;
4411 Py_DECREF(value);
4412 value = ast2obj_expr_context(o->v.Starred.ctx);
4413 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004414 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004415 goto failed;
4416 Py_DECREF(value);
4417 break;
4418 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004419 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4420 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004421 if (!result) goto failed;
4422 value = ast2obj_identifier(o->v.Name.id);
4423 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004424 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004425 goto failed;
4426 Py_DECREF(value);
4427 value = ast2obj_expr_context(o->v.Name.ctx);
4428 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004429 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004430 goto failed;
4431 Py_DECREF(value);
4432 break;
4433 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004434 tp = (PyTypeObject *)astmodulestate_global->List_type;
4435 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004436 if (!result) goto failed;
4437 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4438 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004439 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004440 goto failed;
4441 Py_DECREF(value);
4442 value = ast2obj_expr_context(o->v.List.ctx);
4443 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004444 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004445 goto failed;
4446 Py_DECREF(value);
4447 break;
4448 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004449 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4450 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004451 if (!result) goto failed;
4452 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4453 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004454 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004455 goto failed;
4456 Py_DECREF(value);
4457 value = ast2obj_expr_context(o->v.Tuple.ctx);
4458 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004459 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004460 goto failed;
4461 Py_DECREF(value);
4462 break;
4463 }
4464 value = ast2obj_int(o->lineno);
4465 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004466 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004467 goto failed;
4468 Py_DECREF(value);
4469 value = ast2obj_int(o->col_offset);
4470 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004471 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004472 goto failed;
4473 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004474 value = ast2obj_int(o->end_lineno);
4475 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004476 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004477 goto failed;
4478 Py_DECREF(value);
4479 value = ast2obj_int(o->end_col_offset);
4480 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004481 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4482 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004483 goto failed;
4484 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004485 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004486failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004487 Py_XDECREF(value);
4488 Py_XDECREF(result);
4489 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004490}
4491
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004492PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004493{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004494 switch(o) {
4495 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004496 Py_INCREF(astmodulestate_global->Load_singleton);
4497 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004498 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004499 Py_INCREF(astmodulestate_global->Store_singleton);
4500 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004501 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004502 Py_INCREF(astmodulestate_global->Del_singleton);
4503 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004504 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004505 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4506 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004507 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004508 Py_INCREF(astmodulestate_global->AugStore_singleton);
4509 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 case Param:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004511 Py_INCREF(astmodulestate_global->Param_singleton);
4512 return astmodulestate_global->Param_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004513 default:
4514 /* should never happen, but just in case ... */
4515 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4516 return NULL;
4517 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004518}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004519PyObject*
4520ast2obj_slice(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004521{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004522 slice_ty o = (slice_ty)_o;
4523 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004524 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004525 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004526 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004527 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004528
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004529 switch (o->kind) {
4530 case Slice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004531 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4532 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004533 if (!result) goto failed;
4534 value = ast2obj_expr(o->v.Slice.lower);
4535 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004536 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004537 goto failed;
4538 Py_DECREF(value);
4539 value = ast2obj_expr(o->v.Slice.upper);
4540 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004541 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004542 goto failed;
4543 Py_DECREF(value);
4544 value = ast2obj_expr(o->v.Slice.step);
4545 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004546 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004547 goto failed;
4548 Py_DECREF(value);
4549 break;
4550 case ExtSlice_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004551 tp = (PyTypeObject *)astmodulestate_global->ExtSlice_type;
4552 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004553 if (!result) goto failed;
4554 value = ast2obj_list(o->v.ExtSlice.dims, ast2obj_slice);
4555 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004556 if (PyObject_SetAttr(result, astmodulestate_global->dims, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004557 goto failed;
4558 Py_DECREF(value);
4559 break;
4560 case Index_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004561 tp = (PyTypeObject *)astmodulestate_global->Index_type;
4562 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004563 if (!result) goto failed;
4564 value = ast2obj_expr(o->v.Index.value);
4565 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004566 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004567 goto failed;
4568 Py_DECREF(value);
4569 break;
4570 }
4571 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004572failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004573 Py_XDECREF(value);
4574 Py_XDECREF(result);
4575 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004576}
4577
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004578PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004579{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004580 switch(o) {
4581 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004582 Py_INCREF(astmodulestate_global->And_singleton);
4583 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004584 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004585 Py_INCREF(astmodulestate_global->Or_singleton);
4586 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004587 default:
4588 /* should never happen, but just in case ... */
4589 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4590 return NULL;
4591 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004592}
4593PyObject* ast2obj_operator(operator_ty o)
4594{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004595 switch(o) {
4596 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004597 Py_INCREF(astmodulestate_global->Add_singleton);
4598 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004599 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004600 Py_INCREF(astmodulestate_global->Sub_singleton);
4601 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004602 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004603 Py_INCREF(astmodulestate_global->Mult_singleton);
4604 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004605 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004606 Py_INCREF(astmodulestate_global->MatMult_singleton);
4607 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004608 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004609 Py_INCREF(astmodulestate_global->Div_singleton);
4610 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004611 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004612 Py_INCREF(astmodulestate_global->Mod_singleton);
4613 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004614 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004615 Py_INCREF(astmodulestate_global->Pow_singleton);
4616 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004617 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004618 Py_INCREF(astmodulestate_global->LShift_singleton);
4619 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004621 Py_INCREF(astmodulestate_global->RShift_singleton);
4622 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004623 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004624 Py_INCREF(astmodulestate_global->BitOr_singleton);
4625 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004626 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004627 Py_INCREF(astmodulestate_global->BitXor_singleton);
4628 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004629 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004630 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4631 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004632 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004633 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4634 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004635 default:
4636 /* should never happen, but just in case ... */
4637 PyErr_Format(PyExc_SystemError, "unknown operator found");
4638 return NULL;
4639 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004640}
4641PyObject* ast2obj_unaryop(unaryop_ty o)
4642{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004643 switch(o) {
4644 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004645 Py_INCREF(astmodulestate_global->Invert_singleton);
4646 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004647 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004648 Py_INCREF(astmodulestate_global->Not_singleton);
4649 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004651 Py_INCREF(astmodulestate_global->UAdd_singleton);
4652 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004653 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004654 Py_INCREF(astmodulestate_global->USub_singleton);
4655 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004656 default:
4657 /* should never happen, but just in case ... */
4658 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4659 return NULL;
4660 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004661}
4662PyObject* ast2obj_cmpop(cmpop_ty o)
4663{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004664 switch(o) {
4665 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004666 Py_INCREF(astmodulestate_global->Eq_singleton);
4667 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004668 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004669 Py_INCREF(astmodulestate_global->NotEq_singleton);
4670 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004671 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004672 Py_INCREF(astmodulestate_global->Lt_singleton);
4673 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004674 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004675 Py_INCREF(astmodulestate_global->LtE_singleton);
4676 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004677 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004678 Py_INCREF(astmodulestate_global->Gt_singleton);
4679 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004680 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004681 Py_INCREF(astmodulestate_global->GtE_singleton);
4682 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004684 Py_INCREF(astmodulestate_global->Is_singleton);
4685 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004686 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004687 Py_INCREF(astmodulestate_global->IsNot_singleton);
4688 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004689 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004690 Py_INCREF(astmodulestate_global->In_singleton);
4691 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004692 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004693 Py_INCREF(astmodulestate_global->NotIn_singleton);
4694 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004695 default:
4696 /* should never happen, but just in case ... */
4697 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4698 return NULL;
4699 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004700}
4701PyObject*
4702ast2obj_comprehension(void* _o)
4703{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004704 comprehension_ty o = (comprehension_ty)_o;
4705 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004706 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004707 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004708 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004709 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004710
Dino Viehlandac46eb42019-09-11 10:16:34 -07004711 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4712 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004713 if (!result) return NULL;
4714 value = ast2obj_expr(o->target);
4715 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004716 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004717 goto failed;
4718 Py_DECREF(value);
4719 value = ast2obj_expr(o->iter);
4720 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004721 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004722 goto failed;
4723 Py_DECREF(value);
4724 value = ast2obj_list(o->ifs, ast2obj_expr);
4725 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004726 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004727 goto failed;
4728 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004729 value = ast2obj_int(o->is_async);
4730 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004731 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004732 goto failed;
4733 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004734 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004735failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004736 Py_XDECREF(value);
4737 Py_XDECREF(result);
4738 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004739}
4740
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004741PyObject*
4742ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004743{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004744 excepthandler_ty o = (excepthandler_ty)_o;
4745 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004746 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004747 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004748 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004749 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004750
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004751 switch (o->kind) {
4752 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004753 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4754 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004755 if (!result) goto failed;
4756 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004757 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004758 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004759 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004760 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004761 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004763 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004764 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004765 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004766 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4767 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004768 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004769 goto failed;
4770 Py_DECREF(value);
4771 break;
4772 }
4773 value = ast2obj_int(o->lineno);
4774 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004775 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004776 goto failed;
4777 Py_DECREF(value);
4778 value = ast2obj_int(o->col_offset);
4779 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004780 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004781 goto failed;
4782 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004783 value = ast2obj_int(o->end_lineno);
4784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004785 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004786 goto failed;
4787 Py_DECREF(value);
4788 value = ast2obj_int(o->end_col_offset);
4789 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004790 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4791 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004792 goto failed;
4793 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004794 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004795failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004796 Py_XDECREF(value);
4797 Py_XDECREF(result);
4798 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004799}
4800
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004801PyObject*
4802ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004803{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004804 arguments_ty o = (arguments_ty)_o;
4805 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004806 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004807 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004808 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004809 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004810
Dino Viehlandac46eb42019-09-11 10:16:34 -07004811 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4812 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004813 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004814 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4815 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004816 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4817 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004818 goto failed;
4819 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004820 value = ast2obj_list(o->args, ast2obj_arg);
4821 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004822 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004823 goto failed;
4824 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004825 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004826 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004827 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004828 goto failed;
4829 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004830 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4831 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004832 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4833 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004834 goto failed;
4835 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004836 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004837 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004838 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4839 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004840 goto failed;
4841 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004842 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004843 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004844 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004845 goto failed;
4846 Py_DECREF(value);
4847 value = ast2obj_list(o->defaults, ast2obj_expr);
4848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004849 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004850 goto failed;
4851 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004852 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004853failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004854 Py_XDECREF(value);
4855 Py_XDECREF(result);
4856 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004857}
4858
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004859PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004860ast2obj_arg(void* _o)
4861{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004862 arg_ty o = (arg_ty)_o;
4863 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004864 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004865 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004866 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004867 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004868
Dino Viehlandac46eb42019-09-11 10:16:34 -07004869 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4870 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004871 if (!result) return NULL;
4872 value = ast2obj_identifier(o->arg);
4873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004874 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004875 goto failed;
4876 Py_DECREF(value);
4877 value = ast2obj_expr(o->annotation);
4878 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004879 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4880 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004881 goto failed;
4882 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004883 value = ast2obj_string(o->type_comment);
4884 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004885 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4886 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004887 goto failed;
4888 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004889 value = ast2obj_int(o->lineno);
4890 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004891 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004892 goto failed;
4893 Py_DECREF(value);
4894 value = ast2obj_int(o->col_offset);
4895 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004896 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004897 goto failed;
4898 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004899 value = ast2obj_int(o->end_lineno);
4900 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004901 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004902 goto failed;
4903 Py_DECREF(value);
4904 value = ast2obj_int(o->end_col_offset);
4905 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004906 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4907 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004908 goto failed;
4909 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004910 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004911failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004912 Py_XDECREF(value);
4913 Py_XDECREF(result);
4914 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004915}
4916
4917PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004918ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004919{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004920 keyword_ty o = (keyword_ty)_o;
4921 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004922 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004923 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004924 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004925 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004926
Dino Viehlandac46eb42019-09-11 10:16:34 -07004927 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4928 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004929 if (!result) return NULL;
4930 value = ast2obj_identifier(o->arg);
4931 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004932 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004933 goto failed;
4934 Py_DECREF(value);
4935 value = ast2obj_expr(o->value);
4936 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004937 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004938 goto failed;
4939 Py_DECREF(value);
4940 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004941failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004942 Py_XDECREF(value);
4943 Py_XDECREF(result);
4944 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004945}
4946
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004947PyObject*
4948ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004949{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004950 alias_ty o = (alias_ty)_o;
4951 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004952 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004953 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004954 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004955 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004956
Dino Viehlandac46eb42019-09-11 10:16:34 -07004957 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4958 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004959 if (!result) return NULL;
4960 value = ast2obj_identifier(o->name);
4961 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004962 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004963 goto failed;
4964 Py_DECREF(value);
4965 value = ast2obj_identifier(o->asname);
4966 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004967 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004968 goto failed;
4969 Py_DECREF(value);
4970 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004971failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004972 Py_XDECREF(value);
4973 Py_XDECREF(result);
4974 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004975}
4976
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004977PyObject*
4978ast2obj_withitem(void* _o)
4979{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004980 withitem_ty o = (withitem_ty)_o;
4981 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004982 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004983 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004984 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004985 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004986
Dino Viehlandac46eb42019-09-11 10:16:34 -07004987 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
4988 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 if (!result) return NULL;
4990 value = ast2obj_expr(o->context_expr);
4991 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004992 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
4993 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004994 goto failed;
4995 Py_DECREF(value);
4996 value = ast2obj_expr(o->optional_vars);
4997 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004998 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
4999 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005000 goto failed;
5001 Py_DECREF(value);
5002 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005003failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005004 Py_XDECREF(value);
5005 Py_XDECREF(result);
5006 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005007}
5008
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005009PyObject*
5010ast2obj_type_ignore(void* _o)
5011{
5012 type_ignore_ty o = (type_ignore_ty)_o;
5013 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005014 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005015 if (!o) {
5016 Py_RETURN_NONE;
5017 }
5018
5019 switch (o->kind) {
5020 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005021 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5022 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005023 if (!result) goto failed;
5024 value = ast2obj_int(o->v.TypeIgnore.lineno);
5025 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005026 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5027 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005028 goto failed;
5029 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005030 value = ast2obj_string(o->v.TypeIgnore.tag);
5031 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005032 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005033 goto failed;
5034 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005035 break;
5036 }
5037 return result;
5038failed:
5039 Py_XDECREF(value);
5040 Py_XDECREF(result);
5041 return NULL;
5042}
5043
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005044
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005045int
5046obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5047{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005048 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005049
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005050 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005051 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005052
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005053 if (obj == Py_None) {
5054 *out = NULL;
5055 return 0;
5056 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005057 tp = astmodulestate_global->Module_type;
5058 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005059 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005060 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005061 }
5062 if (isinstance) {
5063 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005064 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005065
Dino Viehlandac46eb42019-09-11 10:16:34 -07005066 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005067 return 1;
5068 }
5069 if (tmp == NULL) {
5070 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5071 return 1;
5072 }
5073 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005074 int res;
5075 Py_ssize_t len;
5076 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005077 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005078 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 +02005079 goto failed;
5080 }
5081 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005082 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005083 if (body == NULL) goto failed;
5084 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005085 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005086 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5087 Py_INCREF(tmp2);
5088 res = obj2ast_stmt(tmp2, &val, arena);
5089 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005090 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005091 if (len != PyList_GET_SIZE(tmp)) {
5092 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5093 goto failed;
5094 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005095 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005096 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005097 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005098 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005099 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5100 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005101 return 1;
5102 }
5103 if (tmp == NULL) {
5104 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5105 return 1;
5106 }
5107 else {
5108 int res;
5109 Py_ssize_t len;
5110 Py_ssize_t i;
5111 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005112 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 -08005113 goto failed;
5114 }
5115 len = PyList_GET_SIZE(tmp);
5116 type_ignores = _Py_asdl_seq_new(len, arena);
5117 if (type_ignores == NULL) goto failed;
5118 for (i = 0; i < len; i++) {
5119 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005120 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5121 Py_INCREF(tmp2);
5122 res = obj2ast_type_ignore(tmp2, &val, arena);
5123 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005124 if (res != 0) goto failed;
5125 if (len != PyList_GET_SIZE(tmp)) {
5126 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5127 goto failed;
5128 }
5129 asdl_seq_SET(type_ignores, i, val);
5130 }
5131 Py_CLEAR(tmp);
5132 }
5133 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005134 if (*out == NULL) goto failed;
5135 return 0;
5136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005137 tp = astmodulestate_global->Interactive_type;
5138 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005139 if (isinstance == -1) {
5140 return 1;
5141 }
5142 if (isinstance) {
5143 asdl_seq* body;
5144
Dino Viehlandac46eb42019-09-11 10:16:34 -07005145 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005146 return 1;
5147 }
5148 if (tmp == NULL) {
5149 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5150 return 1;
5151 }
5152 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005153 int res;
5154 Py_ssize_t len;
5155 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005156 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005157 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 +02005158 goto failed;
5159 }
5160 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005161 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005162 if (body == NULL) goto failed;
5163 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005164 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005165 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5166 Py_INCREF(tmp2);
5167 res = obj2ast_stmt(tmp2, &val, arena);
5168 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005169 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005170 if (len != PyList_GET_SIZE(tmp)) {
5171 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5172 goto failed;
5173 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005174 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005175 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005176 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005177 }
5178 *out = Interactive(body, arena);
5179 if (*out == NULL) goto failed;
5180 return 0;
5181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005182 tp = astmodulestate_global->Expression_type;
5183 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005184 if (isinstance == -1) {
5185 return 1;
5186 }
5187 if (isinstance) {
5188 expr_ty body;
5189
Dino Viehlandac46eb42019-09-11 10:16:34 -07005190 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005191 return 1;
5192 }
5193 if (tmp == NULL) {
5194 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5195 return 1;
5196 }
5197 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005198 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005199 res = obj2ast_expr(tmp, &body, arena);
5200 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005201 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005202 }
5203 *out = Expression(body, arena);
5204 if (*out == NULL) goto failed;
5205 return 0;
5206 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005207 tp = astmodulestate_global->FunctionType_type;
5208 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005209 if (isinstance == -1) {
5210 return 1;
5211 }
5212 if (isinstance) {
5213 asdl_seq* argtypes;
5214 expr_ty returns;
5215
Dino Viehlandac46eb42019-09-11 10:16:34 -07005216 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5217 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005218 return 1;
5219 }
5220 if (tmp == NULL) {
5221 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5222 return 1;
5223 }
5224 else {
5225 int res;
5226 Py_ssize_t len;
5227 Py_ssize_t i;
5228 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005229 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 -08005230 goto failed;
5231 }
5232 len = PyList_GET_SIZE(tmp);
5233 argtypes = _Py_asdl_seq_new(len, arena);
5234 if (argtypes == NULL) goto failed;
5235 for (i = 0; i < len; i++) {
5236 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005237 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5238 Py_INCREF(tmp2);
5239 res = obj2ast_expr(tmp2, &val, arena);
5240 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005241 if (res != 0) goto failed;
5242 if (len != PyList_GET_SIZE(tmp)) {
5243 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5244 goto failed;
5245 }
5246 asdl_seq_SET(argtypes, i, val);
5247 }
5248 Py_CLEAR(tmp);
5249 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005250 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5251 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005252 return 1;
5253 }
5254 if (tmp == NULL) {
5255 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5256 return 1;
5257 }
5258 else {
5259 int res;
5260 res = obj2ast_expr(tmp, &returns, arena);
5261 if (res != 0) goto failed;
5262 Py_CLEAR(tmp);
5263 }
5264 *out = FunctionType(argtypes, returns, arena);
5265 if (*out == NULL) goto failed;
5266 return 0;
5267 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005268
5269 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5270 failed:
5271 Py_XDECREF(tmp);
5272 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005273}
5274
5275int
5276obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5277{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005278 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005279
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005280 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005281 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005282 int lineno;
5283 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005284 int end_lineno;
5285 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005286
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005287 if (obj == Py_None) {
5288 *out = NULL;
5289 return 0;
5290 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005291 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005292 return 1;
5293 }
5294 if (tmp == NULL) {
5295 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5296 return 1;
5297 }
5298 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005299 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005300 res = obj2ast_int(tmp, &lineno, arena);
5301 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005302 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005303 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005304 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5305 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005306 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005307 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005308 if (tmp == NULL) {
5309 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5310 return 1;
5311 }
5312 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005313 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005314 res = obj2ast_int(tmp, &col_offset, arena);
5315 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005316 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005318 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5319 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005320 return 1;
5321 }
5322 if (tmp == NULL || tmp == Py_None) {
5323 Py_CLEAR(tmp);
5324 end_lineno = 0;
5325 }
5326 else {
5327 int res;
5328 res = obj2ast_int(tmp, &end_lineno, arena);
5329 if (res != 0) goto failed;
5330 Py_CLEAR(tmp);
5331 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005332 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5333 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005334 return 1;
5335 }
5336 if (tmp == NULL || tmp == Py_None) {
5337 Py_CLEAR(tmp);
5338 end_col_offset = 0;
5339 }
5340 else {
5341 int res;
5342 res = obj2ast_int(tmp, &end_col_offset, arena);
5343 if (res != 0) goto failed;
5344 Py_CLEAR(tmp);
5345 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005346 tp = astmodulestate_global->FunctionDef_type;
5347 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005348 if (isinstance == -1) {
5349 return 1;
5350 }
5351 if (isinstance) {
5352 identifier name;
5353 arguments_ty args;
5354 asdl_seq* body;
5355 asdl_seq* decorator_list;
5356 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005357 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005358
Dino Viehlandac46eb42019-09-11 10:16:34 -07005359 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005360 return 1;
5361 }
5362 if (tmp == NULL) {
5363 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5364 return 1;
5365 }
5366 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005367 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005368 res = obj2ast_identifier(tmp, &name, arena);
5369 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005370 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005371 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005372 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005373 return 1;
5374 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005375 if (tmp == NULL) {
5376 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5377 return 1;
5378 }
5379 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005380 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005381 res = obj2ast_arguments(tmp, &args, arena);
5382 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005383 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005384 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005385 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005386 return 1;
5387 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005388 if (tmp == NULL) {
5389 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5390 return 1;
5391 }
5392 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005393 int res;
5394 Py_ssize_t len;
5395 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005396 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005397 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 +02005398 goto failed;
5399 }
5400 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005401 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005402 if (body == NULL) goto failed;
5403 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005404 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005405 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5406 Py_INCREF(tmp2);
5407 res = obj2ast_stmt(tmp2, &val, arena);
5408 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005409 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005410 if (len != PyList_GET_SIZE(tmp)) {
5411 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5412 goto failed;
5413 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005414 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005415 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005416 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->decorator_list,
5419 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005420 return 1;
5421 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005422 if (tmp == NULL) {
5423 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5424 return 1;
5425 }
5426 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005427 int res;
5428 Py_ssize_t len;
5429 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005430 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005431 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 +02005432 goto failed;
5433 }
5434 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005435 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005436 if (decorator_list == NULL) goto failed;
5437 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005438 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005439 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5440 Py_INCREF(tmp2);
5441 res = obj2ast_expr(tmp2, &val, arena);
5442 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005443 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005444 if (len != PyList_GET_SIZE(tmp)) {
5445 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5446 goto failed;
5447 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005448 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005449 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005450 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005451 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005452 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5453 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005454 return 1;
5455 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005456 if (tmp == NULL || tmp == Py_None) {
5457 Py_CLEAR(tmp);
5458 returns = NULL;
5459 }
5460 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005461 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005462 res = obj2ast_expr(tmp, &returns, arena);
5463 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005464 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005465 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005466 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5467 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005468 return 1;
5469 }
5470 if (tmp == NULL || tmp == Py_None) {
5471 Py_CLEAR(tmp);
5472 type_comment = NULL;
5473 }
5474 else {
5475 int res;
5476 res = obj2ast_string(tmp, &type_comment, arena);
5477 if (res != 0) goto failed;
5478 Py_CLEAR(tmp);
5479 }
5480 *out = FunctionDef(name, args, body, decorator_list, returns,
5481 type_comment, lineno, col_offset, end_lineno,
5482 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005483 if (*out == NULL) goto failed;
5484 return 0;
5485 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005486 tp = astmodulestate_global->AsyncFunctionDef_type;
5487 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005488 if (isinstance == -1) {
5489 return 1;
5490 }
5491 if (isinstance) {
5492 identifier name;
5493 arguments_ty args;
5494 asdl_seq* body;
5495 asdl_seq* decorator_list;
5496 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005497 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005498
Dino Viehlandac46eb42019-09-11 10:16:34 -07005499 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005500 return 1;
5501 }
5502 if (tmp == NULL) {
5503 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5504 return 1;
5505 }
5506 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005507 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005508 res = obj2ast_identifier(tmp, &name, arena);
5509 if (res != 0) goto failed;
5510 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005511 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005512 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005513 return 1;
5514 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005515 if (tmp == NULL) {
5516 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5517 return 1;
5518 }
5519 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005520 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005521 res = obj2ast_arguments(tmp, &args, arena);
5522 if (res != 0) goto failed;
5523 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005524 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005525 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005526 return 1;
5527 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005528 if (tmp == NULL) {
5529 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5530 return 1;
5531 }
5532 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005533 int res;
5534 Py_ssize_t len;
5535 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005536 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005537 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 -04005538 goto failed;
5539 }
5540 len = PyList_GET_SIZE(tmp);
5541 body = _Py_asdl_seq_new(len, arena);
5542 if (body == NULL) goto failed;
5543 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005544 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005545 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5546 Py_INCREF(tmp2);
5547 res = obj2ast_stmt(tmp2, &val, arena);
5548 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005549 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005550 if (len != PyList_GET_SIZE(tmp)) {
5551 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5552 goto failed;
5553 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005554 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005555 }
5556 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005557 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005558 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5559 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005560 return 1;
5561 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005562 if (tmp == NULL) {
5563 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5564 return 1;
5565 }
5566 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005567 int res;
5568 Py_ssize_t len;
5569 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005570 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005571 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 -04005572 goto failed;
5573 }
5574 len = PyList_GET_SIZE(tmp);
5575 decorator_list = _Py_asdl_seq_new(len, arena);
5576 if (decorator_list == NULL) goto failed;
5577 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005578 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005579 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5580 Py_INCREF(tmp2);
5581 res = obj2ast_expr(tmp2, &val, arena);
5582 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005583 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005584 if (len != PyList_GET_SIZE(tmp)) {
5585 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5586 goto failed;
5587 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005588 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005589 }
5590 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005591 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005592 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5593 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005594 return 1;
5595 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005596 if (tmp == NULL || tmp == Py_None) {
5597 Py_CLEAR(tmp);
5598 returns = NULL;
5599 }
5600 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005601 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005602 res = obj2ast_expr(tmp, &returns, arena);
5603 if (res != 0) goto failed;
5604 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005605 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005606 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5607 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005608 return 1;
5609 }
5610 if (tmp == NULL || tmp == Py_None) {
5611 Py_CLEAR(tmp);
5612 type_comment = NULL;
5613 }
5614 else {
5615 int res;
5616 res = obj2ast_string(tmp, &type_comment, arena);
5617 if (res != 0) goto failed;
5618 Py_CLEAR(tmp);
5619 }
Yury Selivanov75445082015-05-11 22:57:16 -04005620 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005621 type_comment, lineno, col_offset, end_lineno,
5622 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005623 if (*out == NULL) goto failed;
5624 return 0;
5625 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005626 tp = astmodulestate_global->ClassDef_type;
5627 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005628 if (isinstance == -1) {
5629 return 1;
5630 }
5631 if (isinstance) {
5632 identifier name;
5633 asdl_seq* bases;
5634 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005635 asdl_seq* body;
5636 asdl_seq* decorator_list;
5637
Dino Viehlandac46eb42019-09-11 10:16:34 -07005638 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005639 return 1;
5640 }
5641 if (tmp == NULL) {
5642 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5643 return 1;
5644 }
5645 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005646 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005647 res = obj2ast_identifier(tmp, &name, arena);
5648 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005649 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005650 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005651 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005652 return 1;
5653 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005654 if (tmp == NULL) {
5655 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5656 return 1;
5657 }
5658 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005659 int res;
5660 Py_ssize_t len;
5661 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005662 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005663 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 +02005664 goto failed;
5665 }
5666 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005667 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005668 if (bases == NULL) goto failed;
5669 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005670 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005671 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5672 Py_INCREF(tmp2);
5673 res = obj2ast_expr(tmp2, &val, arena);
5674 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005675 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005676 if (len != PyList_GET_SIZE(tmp)) {
5677 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5678 goto failed;
5679 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005680 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005681 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005682 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005683 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005684 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5685 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005686 return 1;
5687 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005688 if (tmp == NULL) {
5689 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5690 return 1;
5691 }
5692 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005693 int res;
5694 Py_ssize_t len;
5695 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005696 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005697 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 +02005698 goto failed;
5699 }
5700 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005701 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005702 if (keywords == NULL) goto failed;
5703 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005704 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005705 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5706 Py_INCREF(tmp2);
5707 res = obj2ast_keyword(tmp2, &val, arena);
5708 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005709 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005710 if (len != PyList_GET_SIZE(tmp)) {
5711 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5712 goto failed;
5713 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005714 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005715 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005716 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005717 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005718 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005719 return 1;
5720 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005721 if (tmp == NULL) {
5722 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5723 return 1;
5724 }
5725 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005726 int res;
5727 Py_ssize_t len;
5728 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005729 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005730 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 +02005731 goto failed;
5732 }
5733 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005734 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005735 if (body == NULL) goto failed;
5736 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005737 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005738 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5739 Py_INCREF(tmp2);
5740 res = obj2ast_stmt(tmp2, &val, arena);
5741 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005742 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005743 if (len != PyList_GET_SIZE(tmp)) {
5744 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5745 goto failed;
5746 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005747 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005748 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005749 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005750 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005751 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5752 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005753 return 1;
5754 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005755 if (tmp == NULL) {
5756 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5757 return 1;
5758 }
5759 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005760 int res;
5761 Py_ssize_t len;
5762 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005763 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005764 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 +02005765 goto failed;
5766 }
5767 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005768 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005769 if (decorator_list == NULL) goto failed;
5770 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005771 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005772 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5773 Py_INCREF(tmp2);
5774 res = obj2ast_expr(tmp2, &val, arena);
5775 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005776 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005777 if (len != PyList_GET_SIZE(tmp)) {
5778 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5779 goto failed;
5780 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005781 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005782 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005783 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005784 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005785 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005786 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005787 if (*out == NULL) goto failed;
5788 return 0;
5789 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005790 tp = astmodulestate_global->Return_type;
5791 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005792 if (isinstance == -1) {
5793 return 1;
5794 }
5795 if (isinstance) {
5796 expr_ty value;
5797
Dino Viehlandac46eb42019-09-11 10:16:34 -07005798 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005799 return 1;
5800 }
5801 if (tmp == NULL || tmp == Py_None) {
5802 Py_CLEAR(tmp);
5803 value = NULL;
5804 }
5805 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005806 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005807 res = obj2ast_expr(tmp, &value, arena);
5808 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005809 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005810 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005811 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5812 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005813 if (*out == NULL) goto failed;
5814 return 0;
5815 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005816 tp = astmodulestate_global->Delete_type;
5817 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005818 if (isinstance == -1) {
5819 return 1;
5820 }
5821 if (isinstance) {
5822 asdl_seq* targets;
5823
Dino Viehlandac46eb42019-09-11 10:16:34 -07005824 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5825 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005826 return 1;
5827 }
5828 if (tmp == NULL) {
5829 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5830 return 1;
5831 }
5832 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005833 int res;
5834 Py_ssize_t len;
5835 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005836 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005837 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 +02005838 goto failed;
5839 }
5840 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005841 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005842 if (targets == NULL) goto failed;
5843 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005844 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005845 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5846 Py_INCREF(tmp2);
5847 res = obj2ast_expr(tmp2, &val, arena);
5848 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005849 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005850 if (len != PyList_GET_SIZE(tmp)) {
5851 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5852 goto failed;
5853 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005854 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005855 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005856 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005857 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005858 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5859 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005860 if (*out == NULL) goto failed;
5861 return 0;
5862 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005863 tp = astmodulestate_global->Assign_type;
5864 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005865 if (isinstance == -1) {
5866 return 1;
5867 }
5868 if (isinstance) {
5869 asdl_seq* targets;
5870 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005871 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005872
Dino Viehlandac46eb42019-09-11 10:16:34 -07005873 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5874 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005875 return 1;
5876 }
5877 if (tmp == NULL) {
5878 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5879 return 1;
5880 }
5881 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005882 int res;
5883 Py_ssize_t len;
5884 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005885 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005886 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 +02005887 goto failed;
5888 }
5889 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005890 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005891 if (targets == NULL) goto failed;
5892 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005893 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005894 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5895 Py_INCREF(tmp2);
5896 res = obj2ast_expr(tmp2, &val, arena);
5897 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005898 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005899 if (len != PyList_GET_SIZE(tmp)) {
5900 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5901 goto failed;
5902 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005903 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005904 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005905 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005906 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005907 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005908 return 1;
5909 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005910 if (tmp == NULL) {
5911 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5912 return 1;
5913 }
5914 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005915 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005916 res = obj2ast_expr(tmp, &value, arena);
5917 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005918 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005919 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005920 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5921 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005922 return 1;
5923 }
5924 if (tmp == NULL || tmp == Py_None) {
5925 Py_CLEAR(tmp);
5926 type_comment = NULL;
5927 }
5928 else {
5929 int res;
5930 res = obj2ast_string(tmp, &type_comment, arena);
5931 if (res != 0) goto failed;
5932 Py_CLEAR(tmp);
5933 }
5934 *out = Assign(targets, value, type_comment, lineno, col_offset,
5935 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005936 if (*out == NULL) goto failed;
5937 return 0;
5938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005939 tp = astmodulestate_global->AugAssign_type;
5940 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005941 if (isinstance == -1) {
5942 return 1;
5943 }
5944 if (isinstance) {
5945 expr_ty target;
5946 operator_ty op;
5947 expr_ty value;
5948
Dino Viehlandac46eb42019-09-11 10:16:34 -07005949 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5950 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005951 return 1;
5952 }
5953 if (tmp == NULL) {
5954 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5955 return 1;
5956 }
5957 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005958 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005959 res = obj2ast_expr(tmp, &target, arena);
5960 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005961 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005962 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005963 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005964 return 1;
5965 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005966 if (tmp == NULL) {
5967 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5968 return 1;
5969 }
5970 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005971 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005972 res = obj2ast_operator(tmp, &op, arena);
5973 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005974 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005975 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005976 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005977 return 1;
5978 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005979 if (tmp == NULL) {
5980 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5981 return 1;
5982 }
5983 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005984 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005985 res = obj2ast_expr(tmp, &value, arena);
5986 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005987 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005988 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005989 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
5990 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005991 if (*out == NULL) goto failed;
5992 return 0;
5993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005994 tp = astmodulestate_global->AnnAssign_type;
5995 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07005996 if (isinstance == -1) {
5997 return 1;
5998 }
5999 if (isinstance) {
6000 expr_ty target;
6001 expr_ty annotation;
6002 expr_ty value;
6003 int simple;
6004
Dino Viehlandac46eb42019-09-11 10:16:34 -07006005 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6006 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006007 return 1;
6008 }
6009 if (tmp == NULL) {
6010 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6011 return 1;
6012 }
6013 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006014 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006015 res = obj2ast_expr(tmp, &target, arena);
6016 if (res != 0) goto failed;
6017 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006018 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006019 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6020 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006021 return 1;
6022 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006023 if (tmp == NULL) {
6024 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6025 return 1;
6026 }
6027 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006028 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006029 res = obj2ast_expr(tmp, &annotation, arena);
6030 if (res != 0) goto failed;
6031 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006032 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006033 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006034 return 1;
6035 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006036 if (tmp == NULL || tmp == Py_None) {
6037 Py_CLEAR(tmp);
6038 value = NULL;
6039 }
6040 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006041 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006042 res = obj2ast_expr(tmp, &value, arena);
6043 if (res != 0) goto failed;
6044 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006045 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006046 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6047 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006048 return 1;
6049 }
6050 if (tmp == NULL) {
6051 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6052 return 1;
6053 }
6054 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006055 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006056 res = obj2ast_int(tmp, &simple, arena);
6057 if (res != 0) goto failed;
6058 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006059 }
6060 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006061 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006062 if (*out == NULL) goto failed;
6063 return 0;
6064 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006065 tp = astmodulestate_global->For_type;
6066 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006067 if (isinstance == -1) {
6068 return 1;
6069 }
6070 if (isinstance) {
6071 expr_ty target;
6072 expr_ty iter;
6073 asdl_seq* body;
6074 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006075 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006076
Dino Viehlandac46eb42019-09-11 10:16:34 -07006077 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6078 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006079 return 1;
6080 }
6081 if (tmp == NULL) {
6082 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6083 return 1;
6084 }
6085 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006086 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006087 res = obj2ast_expr(tmp, &target, arena);
6088 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006089 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006090 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006091 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006092 return 1;
6093 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006094 if (tmp == NULL) {
6095 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6096 return 1;
6097 }
6098 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006099 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006100 res = obj2ast_expr(tmp, &iter, arena);
6101 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006102 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006103 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006104 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006105 return 1;
6106 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006107 if (tmp == NULL) {
6108 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6109 return 1;
6110 }
6111 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006112 int res;
6113 Py_ssize_t len;
6114 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006115 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006116 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 +02006117 goto failed;
6118 }
6119 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006120 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006121 if (body == NULL) goto failed;
6122 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006123 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006124 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6125 Py_INCREF(tmp2);
6126 res = obj2ast_stmt(tmp2, &val, arena);
6127 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006128 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006129 if (len != PyList_GET_SIZE(tmp)) {
6130 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6131 goto failed;
6132 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006133 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006134 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006135 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006137 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6138 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006139 return 1;
6140 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006141 if (tmp == NULL) {
6142 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6143 return 1;
6144 }
6145 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006146 int res;
6147 Py_ssize_t len;
6148 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006149 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006150 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 +02006151 goto failed;
6152 }
6153 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006154 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006155 if (orelse == NULL) goto failed;
6156 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006157 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006158 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6159 Py_INCREF(tmp2);
6160 res = obj2ast_stmt(tmp2, &val, arena);
6161 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006162 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006163 if (len != PyList_GET_SIZE(tmp)) {
6164 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6165 goto failed;
6166 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006167 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006168 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006169 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006170 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006171 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6172 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006173 return 1;
6174 }
6175 if (tmp == NULL || tmp == Py_None) {
6176 Py_CLEAR(tmp);
6177 type_comment = NULL;
6178 }
6179 else {
6180 int res;
6181 res = obj2ast_string(tmp, &type_comment, arena);
6182 if (res != 0) goto failed;
6183 Py_CLEAR(tmp);
6184 }
6185 *out = For(target, iter, body, orelse, type_comment, lineno,
6186 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006187 if (*out == NULL) goto failed;
6188 return 0;
6189 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006190 tp = astmodulestate_global->AsyncFor_type;
6191 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006192 if (isinstance == -1) {
6193 return 1;
6194 }
6195 if (isinstance) {
6196 expr_ty target;
6197 expr_ty iter;
6198 asdl_seq* body;
6199 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006200 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006201
Dino Viehlandac46eb42019-09-11 10:16:34 -07006202 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6203 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006204 return 1;
6205 }
6206 if (tmp == NULL) {
6207 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6208 return 1;
6209 }
6210 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006211 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006212 res = obj2ast_expr(tmp, &target, arena);
6213 if (res != 0) goto failed;
6214 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006215 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006216 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006217 return 1;
6218 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006219 if (tmp == NULL) {
6220 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6221 return 1;
6222 }
6223 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006224 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006225 res = obj2ast_expr(tmp, &iter, arena);
6226 if (res != 0) goto failed;
6227 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006229 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006230 return 1;
6231 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006232 if (tmp == NULL) {
6233 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6234 return 1;
6235 }
6236 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006237 int res;
6238 Py_ssize_t len;
6239 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006240 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006241 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 -04006242 goto failed;
6243 }
6244 len = PyList_GET_SIZE(tmp);
6245 body = _Py_asdl_seq_new(len, arena);
6246 if (body == NULL) goto failed;
6247 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006248 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006249 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6250 Py_INCREF(tmp2);
6251 res = obj2ast_stmt(tmp2, &val, arena);
6252 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006253 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006254 if (len != PyList_GET_SIZE(tmp)) {
6255 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6256 goto failed;
6257 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006258 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006259 }
6260 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006261 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006262 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6263 {
Yury Selivanov75445082015-05-11 22:57:16 -04006264 return 1;
6265 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006266 if (tmp == NULL) {
6267 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6268 return 1;
6269 }
6270 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006271 int res;
6272 Py_ssize_t len;
6273 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006274 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006275 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 -04006276 goto failed;
6277 }
6278 len = PyList_GET_SIZE(tmp);
6279 orelse = _Py_asdl_seq_new(len, arena);
6280 if (orelse == NULL) goto failed;
6281 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006282 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006283 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6284 Py_INCREF(tmp2);
6285 res = obj2ast_stmt(tmp2, &val, arena);
6286 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006287 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006288 if (len != PyList_GET_SIZE(tmp)) {
6289 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6290 goto failed;
6291 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006292 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006293 }
6294 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006295 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006296 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6297 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006298 return 1;
6299 }
6300 if (tmp == NULL || tmp == Py_None) {
6301 Py_CLEAR(tmp);
6302 type_comment = NULL;
6303 }
6304 else {
6305 int res;
6306 res = obj2ast_string(tmp, &type_comment, arena);
6307 if (res != 0) goto failed;
6308 Py_CLEAR(tmp);
6309 }
6310 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6311 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006312 if (*out == NULL) goto failed;
6313 return 0;
6314 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006315 tp = astmodulestate_global->While_type;
6316 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006317 if (isinstance == -1) {
6318 return 1;
6319 }
6320 if (isinstance) {
6321 expr_ty test;
6322 asdl_seq* body;
6323 asdl_seq* orelse;
6324
Dino Viehlandac46eb42019-09-11 10:16:34 -07006325 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006326 return 1;
6327 }
6328 if (tmp == NULL) {
6329 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6330 return 1;
6331 }
6332 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006333 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006334 res = obj2ast_expr(tmp, &test, arena);
6335 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006336 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006337 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006338 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006339 return 1;
6340 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006341 if (tmp == NULL) {
6342 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6343 return 1;
6344 }
6345 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006346 int res;
6347 Py_ssize_t len;
6348 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006349 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006350 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 +02006351 goto failed;
6352 }
6353 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006354 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006355 if (body == NULL) goto failed;
6356 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006357 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006358 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6359 Py_INCREF(tmp2);
6360 res = obj2ast_stmt(tmp2, &val, arena);
6361 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006362 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006363 if (len != PyList_GET_SIZE(tmp)) {
6364 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6365 goto failed;
6366 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006367 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006368 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006369 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006370 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006371 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6372 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006373 return 1;
6374 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006375 if (tmp == NULL) {
6376 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6377 return 1;
6378 }
6379 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006380 int res;
6381 Py_ssize_t len;
6382 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006383 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006384 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 +02006385 goto failed;
6386 }
6387 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006388 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006389 if (orelse == NULL) goto failed;
6390 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006391 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006392 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6393 Py_INCREF(tmp2);
6394 res = obj2ast_stmt(tmp2, &val, arena);
6395 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006396 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006397 if (len != PyList_GET_SIZE(tmp)) {
6398 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6399 goto failed;
6400 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006401 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006402 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006403 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006404 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006405 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6406 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006407 if (*out == NULL) goto failed;
6408 return 0;
6409 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006410 tp = astmodulestate_global->If_type;
6411 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006412 if (isinstance == -1) {
6413 return 1;
6414 }
6415 if (isinstance) {
6416 expr_ty test;
6417 asdl_seq* body;
6418 asdl_seq* orelse;
6419
Dino Viehlandac46eb42019-09-11 10:16:34 -07006420 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006421 return 1;
6422 }
6423 if (tmp == NULL) {
6424 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6425 return 1;
6426 }
6427 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006428 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006429 res = obj2ast_expr(tmp, &test, arena);
6430 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006431 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006432 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006433 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006434 return 1;
6435 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006436 if (tmp == NULL) {
6437 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6438 return 1;
6439 }
6440 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006441 int res;
6442 Py_ssize_t len;
6443 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006444 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006445 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 +02006446 goto failed;
6447 }
6448 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006449 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006450 if (body == NULL) goto failed;
6451 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006452 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006453 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6454 Py_INCREF(tmp2);
6455 res = obj2ast_stmt(tmp2, &val, arena);
6456 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006457 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006458 if (len != PyList_GET_SIZE(tmp)) {
6459 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6460 goto failed;
6461 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006462 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006463 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006464 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006465 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006466 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6467 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006468 return 1;
6469 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006470 if (tmp == NULL) {
6471 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6472 return 1;
6473 }
6474 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006475 int res;
6476 Py_ssize_t len;
6477 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006478 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006479 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 +02006480 goto failed;
6481 }
6482 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006483 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006484 if (orelse == NULL) goto failed;
6485 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006486 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006487 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6488 Py_INCREF(tmp2);
6489 res = obj2ast_stmt(tmp2, &val, arena);
6490 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006491 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006492 if (len != PyList_GET_SIZE(tmp)) {
6493 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6494 goto failed;
6495 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006496 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006497 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006498 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006499 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006500 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6501 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006502 if (*out == NULL) goto failed;
6503 return 0;
6504 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006505 tp = astmodulestate_global->With_type;
6506 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006507 if (isinstance == -1) {
6508 return 1;
6509 }
6510 if (isinstance) {
6511 asdl_seq* items;
6512 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006513 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006514
Dino Viehlandac46eb42019-09-11 10:16:34 -07006515 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006516 return 1;
6517 }
6518 if (tmp == NULL) {
6519 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6520 return 1;
6521 }
6522 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006523 int res;
6524 Py_ssize_t len;
6525 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006526 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006527 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 +02006528 goto failed;
6529 }
6530 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006531 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006532 if (items == NULL) goto failed;
6533 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006534 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006535 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6536 Py_INCREF(tmp2);
6537 res = obj2ast_withitem(tmp2, &val, arena);
6538 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006539 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006540 if (len != PyList_GET_SIZE(tmp)) {
6541 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6542 goto failed;
6543 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006544 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006545 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006546 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006547 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006548 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006549 return 1;
6550 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006551 if (tmp == NULL) {
6552 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6553 return 1;
6554 }
6555 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006556 int res;
6557 Py_ssize_t len;
6558 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006559 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006560 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 +02006561 goto failed;
6562 }
6563 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006564 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006565 if (body == NULL) goto failed;
6566 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006567 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006568 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6569 Py_INCREF(tmp2);
6570 res = obj2ast_stmt(tmp2, &val, arena);
6571 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006572 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006573 if (len != PyList_GET_SIZE(tmp)) {
6574 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6575 goto failed;
6576 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006577 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006578 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006579 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006580 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006581 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6582 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006583 return 1;
6584 }
6585 if (tmp == NULL || tmp == Py_None) {
6586 Py_CLEAR(tmp);
6587 type_comment = NULL;
6588 }
6589 else {
6590 int res;
6591 res = obj2ast_string(tmp, &type_comment, arena);
6592 if (res != 0) goto failed;
6593 Py_CLEAR(tmp);
6594 }
6595 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006596 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006597 if (*out == NULL) goto failed;
6598 return 0;
6599 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006600 tp = astmodulestate_global->AsyncWith_type;
6601 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006602 if (isinstance == -1) {
6603 return 1;
6604 }
6605 if (isinstance) {
6606 asdl_seq* items;
6607 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006608 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006609
Dino Viehlandac46eb42019-09-11 10:16:34 -07006610 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006611 return 1;
6612 }
6613 if (tmp == NULL) {
6614 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6615 return 1;
6616 }
6617 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006618 int res;
6619 Py_ssize_t len;
6620 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006621 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006622 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 -04006623 goto failed;
6624 }
6625 len = PyList_GET_SIZE(tmp);
6626 items = _Py_asdl_seq_new(len, arena);
6627 if (items == NULL) goto failed;
6628 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006629 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006630 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6631 Py_INCREF(tmp2);
6632 res = obj2ast_withitem(tmp2, &val, arena);
6633 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006634 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006635 if (len != PyList_GET_SIZE(tmp)) {
6636 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6637 goto failed;
6638 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006639 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006640 }
6641 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006643 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006644 return 1;
6645 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006646 if (tmp == NULL) {
6647 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6648 return 1;
6649 }
6650 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006651 int res;
6652 Py_ssize_t len;
6653 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006654 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006655 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 -04006656 goto failed;
6657 }
6658 len = PyList_GET_SIZE(tmp);
6659 body = _Py_asdl_seq_new(len, arena);
6660 if (body == NULL) goto failed;
6661 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006662 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006663 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6664 Py_INCREF(tmp2);
6665 res = obj2ast_stmt(tmp2, &val, arena);
6666 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006667 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006668 if (len != PyList_GET_SIZE(tmp)) {
6669 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6670 goto failed;
6671 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006672 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006673 }
6674 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006675 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006676 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6677 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006678 return 1;
6679 }
6680 if (tmp == NULL || tmp == Py_None) {
6681 Py_CLEAR(tmp);
6682 type_comment = NULL;
6683 }
6684 else {
6685 int res;
6686 res = obj2ast_string(tmp, &type_comment, arena);
6687 if (res != 0) goto failed;
6688 Py_CLEAR(tmp);
6689 }
6690 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6691 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006692 if (*out == NULL) goto failed;
6693 return 0;
6694 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006695 tp = astmodulestate_global->Raise_type;
6696 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006697 if (isinstance == -1) {
6698 return 1;
6699 }
6700 if (isinstance) {
6701 expr_ty exc;
6702 expr_ty cause;
6703
Dino Viehlandac46eb42019-09-11 10:16:34 -07006704 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006705 return 1;
6706 }
6707 if (tmp == NULL || tmp == Py_None) {
6708 Py_CLEAR(tmp);
6709 exc = NULL;
6710 }
6711 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006712 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006713 res = obj2ast_expr(tmp, &exc, arena);
6714 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006715 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006716 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006717 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006718 return 1;
6719 }
6720 if (tmp == NULL || tmp == Py_None) {
6721 Py_CLEAR(tmp);
6722 cause = NULL;
6723 }
6724 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006725 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006726 res = obj2ast_expr(tmp, &cause, arena);
6727 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006728 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006729 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006730 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6731 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006732 if (*out == NULL) goto failed;
6733 return 0;
6734 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006735 tp = astmodulestate_global->Try_type;
6736 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006737 if (isinstance == -1) {
6738 return 1;
6739 }
6740 if (isinstance) {
6741 asdl_seq* body;
6742 asdl_seq* handlers;
6743 asdl_seq* orelse;
6744 asdl_seq* finalbody;
6745
Dino Viehlandac46eb42019-09-11 10:16:34 -07006746 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006747 return 1;
6748 }
6749 if (tmp == NULL) {
6750 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6751 return 1;
6752 }
6753 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006754 int res;
6755 Py_ssize_t len;
6756 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006757 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006758 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 +02006759 goto failed;
6760 }
6761 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006762 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006763 if (body == NULL) goto failed;
6764 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006765 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006766 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6767 Py_INCREF(tmp2);
6768 res = obj2ast_stmt(tmp2, &val, arena);
6769 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006770 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006771 if (len != PyList_GET_SIZE(tmp)) {
6772 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6773 goto failed;
6774 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006775 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006776 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006777 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006778 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006779 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6780 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006781 return 1;
6782 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006783 if (tmp == NULL) {
6784 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6785 return 1;
6786 }
6787 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006788 int res;
6789 Py_ssize_t len;
6790 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006792 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 +02006793 goto failed;
6794 }
6795 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006796 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006797 if (handlers == NULL) goto failed;
6798 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006799 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006800 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6801 Py_INCREF(tmp2);
6802 res = obj2ast_excepthandler(tmp2, &val, arena);
6803 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006804 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006805 if (len != PyList_GET_SIZE(tmp)) {
6806 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6807 goto failed;
6808 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006809 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006810 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006811 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006812 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006813 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6814 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006815 return 1;
6816 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006817 if (tmp == NULL) {
6818 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6819 return 1;
6820 }
6821 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006822 int res;
6823 Py_ssize_t len;
6824 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006825 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006826 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 +02006827 goto failed;
6828 }
6829 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006830 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006831 if (orelse == NULL) goto failed;
6832 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006833 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006834 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6835 Py_INCREF(tmp2);
6836 res = obj2ast_stmt(tmp2, &val, arena);
6837 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006838 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006839 if (len != PyList_GET_SIZE(tmp)) {
6840 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6841 goto failed;
6842 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006843 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006844 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006845 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006846 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006847 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6848 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006849 return 1;
6850 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006851 if (tmp == NULL) {
6852 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6853 return 1;
6854 }
6855 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006856 int res;
6857 Py_ssize_t len;
6858 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006859 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006860 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 +02006861 goto failed;
6862 }
6863 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006864 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006865 if (finalbody == NULL) goto failed;
6866 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006867 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006868 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6869 Py_INCREF(tmp2);
6870 res = obj2ast_stmt(tmp2, &val, arena);
6871 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006872 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006873 if (len != PyList_GET_SIZE(tmp)) {
6874 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6875 goto failed;
6876 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006877 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006878 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006879 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006880 }
6881 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006882 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006883 if (*out == NULL) goto failed;
6884 return 0;
6885 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006886 tp = astmodulestate_global->Assert_type;
6887 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006888 if (isinstance == -1) {
6889 return 1;
6890 }
6891 if (isinstance) {
6892 expr_ty test;
6893 expr_ty msg;
6894
Dino Viehlandac46eb42019-09-11 10:16:34 -07006895 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006896 return 1;
6897 }
6898 if (tmp == NULL) {
6899 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6900 return 1;
6901 }
6902 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006903 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006904 res = obj2ast_expr(tmp, &test, arena);
6905 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006906 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006907 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006908 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006909 return 1;
6910 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006911 if (tmp == NULL || tmp == Py_None) {
6912 Py_CLEAR(tmp);
6913 msg = NULL;
6914 }
6915 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006916 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006917 res = obj2ast_expr(tmp, &msg, arena);
6918 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006919 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006920 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006921 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6922 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006923 if (*out == NULL) goto failed;
6924 return 0;
6925 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006926 tp = astmodulestate_global->Import_type;
6927 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006928 if (isinstance == -1) {
6929 return 1;
6930 }
6931 if (isinstance) {
6932 asdl_seq* names;
6933
Dino Viehlandac46eb42019-09-11 10:16:34 -07006934 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006935 return 1;
6936 }
6937 if (tmp == NULL) {
6938 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6939 return 1;
6940 }
6941 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006942 int res;
6943 Py_ssize_t len;
6944 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006945 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006946 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 +02006947 goto failed;
6948 }
6949 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006950 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006951 if (names == NULL) goto failed;
6952 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006953 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006954 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6955 Py_INCREF(tmp2);
6956 res = obj2ast_alias(tmp2, &val, arena);
6957 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006958 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006959 if (len != PyList_GET_SIZE(tmp)) {
6960 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6961 goto failed;
6962 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006963 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006964 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006965 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006966 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006967 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6968 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006969 if (*out == NULL) goto failed;
6970 return 0;
6971 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006972 tp = astmodulestate_global->ImportFrom_type;
6973 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 if (isinstance == -1) {
6975 return 1;
6976 }
6977 if (isinstance) {
6978 identifier module;
6979 asdl_seq* names;
6980 int level;
6981
Dino Viehlandac46eb42019-09-11 10:16:34 -07006982 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
6983 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006984 return 1;
6985 }
6986 if (tmp == NULL || tmp == Py_None) {
6987 Py_CLEAR(tmp);
6988 module = NULL;
6989 }
6990 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006991 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006992 res = obj2ast_identifier(tmp, &module, arena);
6993 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006994 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006995 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006996 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006997 return 1;
6998 }
6999 if (tmp == NULL) {
7000 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7001 return 1;
7002 }
7003 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007004 int res;
7005 Py_ssize_t len;
7006 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007007 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007008 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 +02007009 goto failed;
7010 }
7011 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007012 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007013 if (names == NULL) goto failed;
7014 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007015 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007016 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7017 Py_INCREF(tmp2);
7018 res = obj2ast_alias(tmp2, &val, arena);
7019 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007020 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007021 if (len != PyList_GET_SIZE(tmp)) {
7022 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7023 goto failed;
7024 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007025 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007026 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007027 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007028 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007029 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007030 return 1;
7031 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007032 if (tmp == NULL || tmp == Py_None) {
7033 Py_CLEAR(tmp);
7034 level = 0;
7035 }
7036 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007037 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007038 res = obj2ast_int(tmp, &level, arena);
7039 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007040 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007041 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007042 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7043 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007044 if (*out == NULL) goto failed;
7045 return 0;
7046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007047 tp = astmodulestate_global->Global_type;
7048 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007049 if (isinstance == -1) {
7050 return 1;
7051 }
7052 if (isinstance) {
7053 asdl_seq* names;
7054
Dino Viehlandac46eb42019-09-11 10:16:34 -07007055 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007056 return 1;
7057 }
7058 if (tmp == NULL) {
7059 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7060 return 1;
7061 }
7062 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007063 int res;
7064 Py_ssize_t len;
7065 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007066 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007067 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 +02007068 goto failed;
7069 }
7070 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007071 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007072 if (names == NULL) goto failed;
7073 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007074 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007075 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7076 Py_INCREF(tmp2);
7077 res = obj2ast_identifier(tmp2, &val, arena);
7078 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007079 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007080 if (len != PyList_GET_SIZE(tmp)) {
7081 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7082 goto failed;
7083 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007084 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007085 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007086 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007087 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007088 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7089 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->Nonlocal_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 asdl_seq* names;
7100
Dino Viehlandac46eb42019-09-11 10:16:34 -07007101 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007102 return 1;
7103 }
7104 if (tmp == NULL) {
7105 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7106 return 1;
7107 }
7108 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007109 int res;
7110 Py_ssize_t len;
7111 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007112 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007113 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 +02007114 goto failed;
7115 }
7116 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007117 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007118 if (names == NULL) goto failed;
7119 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007120 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007121 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7122 Py_INCREF(tmp2);
7123 res = obj2ast_identifier(tmp2, &val, arena);
7124 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007125 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007126 if (len != PyList_GET_SIZE(tmp)) {
7127 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7128 goto failed;
7129 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007130 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007131 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007132 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007133 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007134 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7135 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007136 if (*out == NULL) goto failed;
7137 return 0;
7138 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007139 tp = astmodulestate_global->Expr_type;
7140 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007141 if (isinstance == -1) {
7142 return 1;
7143 }
7144 if (isinstance) {
7145 expr_ty value;
7146
Dino Viehlandac46eb42019-09-11 10:16:34 -07007147 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007148 return 1;
7149 }
7150 if (tmp == NULL) {
7151 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7152 return 1;
7153 }
7154 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007155 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007156 res = obj2ast_expr(tmp, &value, arena);
7157 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007158 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007159 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007160 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7161 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007162 if (*out == NULL) goto failed;
7163 return 0;
7164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007165 tp = astmodulestate_global->Pass_type;
7166 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007167 if (isinstance == -1) {
7168 return 1;
7169 }
7170 if (isinstance) {
7171
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007172 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007173 if (*out == NULL) goto failed;
7174 return 0;
7175 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007176 tp = astmodulestate_global->Break_type;
7177 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007178 if (isinstance == -1) {
7179 return 1;
7180 }
7181 if (isinstance) {
7182
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007183 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007184 if (*out == NULL) goto failed;
7185 return 0;
7186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007187 tp = astmodulestate_global->Continue_type;
7188 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007189 if (isinstance == -1) {
7190 return 1;
7191 }
7192 if (isinstance) {
7193
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007194 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007195 if (*out == NULL) goto failed;
7196 return 0;
7197 }
7198
7199 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7200 failed:
7201 Py_XDECREF(tmp);
7202 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007203}
7204
7205int
7206obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7207{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007208 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007209
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007210 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007211 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007212 int lineno;
7213 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007214 int end_lineno;
7215 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007216
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007217 if (obj == Py_None) {
7218 *out = NULL;
7219 return 0;
7220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007221 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007222 return 1;
7223 }
7224 if (tmp == NULL) {
7225 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7226 return 1;
7227 }
7228 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007229 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007230 res = obj2ast_int(tmp, &lineno, arena);
7231 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007232 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007234 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7235 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007236 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007237 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007238 if (tmp == NULL) {
7239 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7240 return 1;
7241 }
7242 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007243 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007244 res = obj2ast_int(tmp, &col_offset, arena);
7245 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007246 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007247 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007248 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7249 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007250 return 1;
7251 }
7252 if (tmp == NULL || tmp == Py_None) {
7253 Py_CLEAR(tmp);
7254 end_lineno = 0;
7255 }
7256 else {
7257 int res;
7258 res = obj2ast_int(tmp, &end_lineno, arena);
7259 if (res != 0) goto failed;
7260 Py_CLEAR(tmp);
7261 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007262 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7263 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007264 return 1;
7265 }
7266 if (tmp == NULL || tmp == Py_None) {
7267 Py_CLEAR(tmp);
7268 end_col_offset = 0;
7269 }
7270 else {
7271 int res;
7272 res = obj2ast_int(tmp, &end_col_offset, arena);
7273 if (res != 0) goto failed;
7274 Py_CLEAR(tmp);
7275 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007276 tp = astmodulestate_global->BoolOp_type;
7277 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007278 if (isinstance == -1) {
7279 return 1;
7280 }
7281 if (isinstance) {
7282 boolop_ty op;
7283 asdl_seq* values;
7284
Dino Viehlandac46eb42019-09-11 10:16:34 -07007285 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007286 return 1;
7287 }
7288 if (tmp == NULL) {
7289 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7290 return 1;
7291 }
7292 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007293 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007294 res = obj2ast_boolop(tmp, &op, arena);
7295 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007296 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007297 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007298 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7299 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007300 return 1;
7301 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007302 if (tmp == NULL) {
7303 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7304 return 1;
7305 }
7306 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007307 int res;
7308 Py_ssize_t len;
7309 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007310 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007311 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 +02007312 goto failed;
7313 }
7314 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007315 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007316 if (values == NULL) goto failed;
7317 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007318 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007319 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7320 Py_INCREF(tmp2);
7321 res = obj2ast_expr(tmp2, &val, arena);
7322 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007323 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007324 if (len != PyList_GET_SIZE(tmp)) {
7325 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7326 goto failed;
7327 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007328 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007329 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007330 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007331 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007332 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7333 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007334 if (*out == NULL) goto failed;
7335 return 0;
7336 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007337 tp = astmodulestate_global->NamedExpr_type;
7338 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007339 if (isinstance == -1) {
7340 return 1;
7341 }
7342 if (isinstance) {
7343 expr_ty target;
7344 expr_ty value;
7345
Dino Viehlandac46eb42019-09-11 10:16:34 -07007346 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7347 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007348 return 1;
7349 }
7350 if (tmp == NULL) {
7351 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7352 return 1;
7353 }
7354 else {
7355 int res;
7356 res = obj2ast_expr(tmp, &target, arena);
7357 if (res != 0) goto failed;
7358 Py_CLEAR(tmp);
7359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007360 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007361 return 1;
7362 }
7363 if (tmp == NULL) {
7364 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7365 return 1;
7366 }
7367 else {
7368 int res;
7369 res = obj2ast_expr(tmp, &value, arena);
7370 if (res != 0) goto failed;
7371 Py_CLEAR(tmp);
7372 }
7373 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7374 end_col_offset, arena);
7375 if (*out == NULL) goto failed;
7376 return 0;
7377 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007378 tp = astmodulestate_global->BinOp_type;
7379 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007380 if (isinstance == -1) {
7381 return 1;
7382 }
7383 if (isinstance) {
7384 expr_ty left;
7385 operator_ty op;
7386 expr_ty right;
7387
Dino Viehlandac46eb42019-09-11 10:16:34 -07007388 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007389 return 1;
7390 }
7391 if (tmp == NULL) {
7392 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
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_expr(tmp, &left, 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->op, &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 \"op\" missing from BinOp");
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_operator(tmp, &op, arena);
7411 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007412 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007413 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007414 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007415 return 1;
7416 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007417 if (tmp == NULL) {
7418 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7419 return 1;
7420 }
7421 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007422 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007423 res = obj2ast_expr(tmp, &right, arena);
7424 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007425 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007426 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007427 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7428 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007429 if (*out == NULL) goto failed;
7430 return 0;
7431 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007432 tp = astmodulestate_global->UnaryOp_type;
7433 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007434 if (isinstance == -1) {
7435 return 1;
7436 }
7437 if (isinstance) {
7438 unaryop_ty op;
7439 expr_ty operand;
7440
Dino Viehlandac46eb42019-09-11 10:16:34 -07007441 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007442 return 1;
7443 }
7444 if (tmp == NULL) {
7445 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7446 return 1;
7447 }
7448 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007449 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007450 res = obj2ast_unaryop(tmp, &op, arena);
7451 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007452 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007453 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007454 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7455 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007456 return 1;
7457 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007458 if (tmp == NULL) {
7459 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7460 return 1;
7461 }
7462 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007463 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007464 res = obj2ast_expr(tmp, &operand, arena);
7465 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007466 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007467 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007468 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7469 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007470 if (*out == NULL) goto failed;
7471 return 0;
7472 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007473 tp = astmodulestate_global->Lambda_type;
7474 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007475 if (isinstance == -1) {
7476 return 1;
7477 }
7478 if (isinstance) {
7479 arguments_ty args;
7480 expr_ty body;
7481
Dino Viehlandac46eb42019-09-11 10:16:34 -07007482 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007483 return 1;
7484 }
7485 if (tmp == NULL) {
7486 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7487 return 1;
7488 }
7489 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007490 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007491 res = obj2ast_arguments(tmp, &args, arena);
7492 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007493 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007494 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007495 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007496 return 1;
7497 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007498 if (tmp == NULL) {
7499 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7500 return 1;
7501 }
7502 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007503 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007504 res = obj2ast_expr(tmp, &body, arena);
7505 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007506 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007508 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7509 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007510 if (*out == NULL) goto failed;
7511 return 0;
7512 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007513 tp = astmodulestate_global->IfExp_type;
7514 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007515 if (isinstance == -1) {
7516 return 1;
7517 }
7518 if (isinstance) {
7519 expr_ty test;
7520 expr_ty body;
7521 expr_ty orelse;
7522
Dino Viehlandac46eb42019-09-11 10:16:34 -07007523 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007524 return 1;
7525 }
7526 if (tmp == NULL) {
7527 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7528 return 1;
7529 }
7530 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007531 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007532 res = obj2ast_expr(tmp, &test, arena);
7533 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007534 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007535 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007536 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007537 return 1;
7538 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007539 if (tmp == NULL) {
7540 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7541 return 1;
7542 }
7543 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007544 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007545 res = obj2ast_expr(tmp, &body, arena);
7546 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007547 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007548 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007549 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7550 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007551 return 1;
7552 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007553 if (tmp == NULL) {
7554 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7555 return 1;
7556 }
7557 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007558 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007559 res = obj2ast_expr(tmp, &orelse, arena);
7560 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007561 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007562 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007563 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7564 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007565 if (*out == NULL) goto failed;
7566 return 0;
7567 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007568 tp = astmodulestate_global->Dict_type;
7569 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007570 if (isinstance == -1) {
7571 return 1;
7572 }
7573 if (isinstance) {
7574 asdl_seq* keys;
7575 asdl_seq* values;
7576
Dino Viehlandac46eb42019-09-11 10:16:34 -07007577 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007578 return 1;
7579 }
7580 if (tmp == NULL) {
7581 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7582 return 1;
7583 }
7584 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007585 int res;
7586 Py_ssize_t len;
7587 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007588 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007589 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 +02007590 goto failed;
7591 }
7592 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007593 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007594 if (keys == NULL) goto failed;
7595 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007596 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007597 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7598 Py_INCREF(tmp2);
7599 res = obj2ast_expr(tmp2, &val, arena);
7600 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007601 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007602 if (len != PyList_GET_SIZE(tmp)) {
7603 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7604 goto failed;
7605 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007606 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007607 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007608 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007609 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007610 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7611 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007612 return 1;
7613 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007614 if (tmp == NULL) {
7615 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7616 return 1;
7617 }
7618 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007619 int res;
7620 Py_ssize_t len;
7621 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007622 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007623 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 +02007624 goto failed;
7625 }
7626 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007627 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007628 if (values == NULL) goto failed;
7629 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007630 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007631 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7632 Py_INCREF(tmp2);
7633 res = obj2ast_expr(tmp2, &val, arena);
7634 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007635 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007636 if (len != PyList_GET_SIZE(tmp)) {
7637 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7638 goto failed;
7639 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007640 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007641 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007642 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007643 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007644 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7645 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007646 if (*out == NULL) goto failed;
7647 return 0;
7648 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007649 tp = astmodulestate_global->Set_type;
7650 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007651 if (isinstance == -1) {
7652 return 1;
7653 }
7654 if (isinstance) {
7655 asdl_seq* elts;
7656
Dino Viehlandac46eb42019-09-11 10:16:34 -07007657 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007658 return 1;
7659 }
7660 if (tmp == NULL) {
7661 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7662 return 1;
7663 }
7664 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007665 int res;
7666 Py_ssize_t len;
7667 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007668 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007669 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 +02007670 goto failed;
7671 }
7672 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007673 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007674 if (elts == NULL) goto failed;
7675 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007676 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007677 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7678 Py_INCREF(tmp2);
7679 res = obj2ast_expr(tmp2, &val, arena);
7680 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007681 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007682 if (len != PyList_GET_SIZE(tmp)) {
7683 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7684 goto failed;
7685 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007686 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007687 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007688 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007689 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007690 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007691 if (*out == NULL) goto failed;
7692 return 0;
7693 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007694 tp = astmodulestate_global->ListComp_type;
7695 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007696 if (isinstance == -1) {
7697 return 1;
7698 }
7699 if (isinstance) {
7700 expr_ty elt;
7701 asdl_seq* generators;
7702
Dino Viehlandac46eb42019-09-11 10:16:34 -07007703 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007704 return 1;
7705 }
7706 if (tmp == NULL) {
7707 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7708 return 1;
7709 }
7710 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007711 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007712 res = obj2ast_expr(tmp, &elt, arena);
7713 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007714 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007715 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007716 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7717 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007718 return 1;
7719 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007720 if (tmp == NULL) {
7721 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7722 return 1;
7723 }
7724 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007725 int res;
7726 Py_ssize_t len;
7727 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007728 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007729 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 +02007730 goto failed;
7731 }
7732 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007733 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007734 if (generators == NULL) goto failed;
7735 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007736 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007737 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7738 Py_INCREF(tmp2);
7739 res = obj2ast_comprehension(tmp2, &val, arena);
7740 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007741 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007742 if (len != PyList_GET_SIZE(tmp)) {
7743 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7744 goto failed;
7745 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007746 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007747 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007748 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007749 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007750 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7751 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007752 if (*out == NULL) goto failed;
7753 return 0;
7754 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007755 tp = astmodulestate_global->SetComp_type;
7756 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007757 if (isinstance == -1) {
7758 return 1;
7759 }
7760 if (isinstance) {
7761 expr_ty elt;
7762 asdl_seq* generators;
7763
Dino Viehlandac46eb42019-09-11 10:16:34 -07007764 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007765 return 1;
7766 }
7767 if (tmp == NULL) {
7768 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7769 return 1;
7770 }
7771 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007772 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007773 res = obj2ast_expr(tmp, &elt, arena);
7774 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007775 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007776 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007777 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7778 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007779 return 1;
7780 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007781 if (tmp == NULL) {
7782 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7783 return 1;
7784 }
7785 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007786 int res;
7787 Py_ssize_t len;
7788 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007789 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007790 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 +02007791 goto failed;
7792 }
7793 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007794 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007795 if (generators == NULL) goto failed;
7796 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007797 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007798 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7799 Py_INCREF(tmp2);
7800 res = obj2ast_comprehension(tmp2, &val, arena);
7801 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007802 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007803 if (len != PyList_GET_SIZE(tmp)) {
7804 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7805 goto failed;
7806 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007807 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007808 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007809 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007810 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007811 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7812 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007813 if (*out == NULL) goto failed;
7814 return 0;
7815 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007816 tp = astmodulestate_global->DictComp_type;
7817 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007818 if (isinstance == -1) {
7819 return 1;
7820 }
7821 if (isinstance) {
7822 expr_ty key;
7823 expr_ty value;
7824 asdl_seq* generators;
7825
Dino Viehlandac46eb42019-09-11 10:16:34 -07007826 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007827 return 1;
7828 }
7829 if (tmp == NULL) {
7830 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7831 return 1;
7832 }
7833 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007834 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007835 res = obj2ast_expr(tmp, &key, arena);
7836 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007837 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007838 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007839 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007840 return 1;
7841 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007842 if (tmp == NULL) {
7843 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7844 return 1;
7845 }
7846 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007847 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007848 res = obj2ast_expr(tmp, &value, arena);
7849 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007850 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007851 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007852 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7853 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007854 return 1;
7855 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007856 if (tmp == NULL) {
7857 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7858 return 1;
7859 }
7860 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007861 int res;
7862 Py_ssize_t len;
7863 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007864 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007865 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 +02007866 goto failed;
7867 }
7868 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007869 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007870 if (generators == NULL) goto failed;
7871 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007872 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007873 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7874 Py_INCREF(tmp2);
7875 res = obj2ast_comprehension(tmp2, &val, arena);
7876 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007877 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007878 if (len != PyList_GET_SIZE(tmp)) {
7879 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7880 goto failed;
7881 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007882 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007883 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007884 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007885 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007886 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7887 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007888 if (*out == NULL) goto failed;
7889 return 0;
7890 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007891 tp = astmodulestate_global->GeneratorExp_type;
7892 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007893 if (isinstance == -1) {
7894 return 1;
7895 }
7896 if (isinstance) {
7897 expr_ty elt;
7898 asdl_seq* generators;
7899
Dino Viehlandac46eb42019-09-11 10:16:34 -07007900 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007901 return 1;
7902 }
7903 if (tmp == NULL) {
7904 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7905 return 1;
7906 }
7907 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007908 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007909 res = obj2ast_expr(tmp, &elt, arena);
7910 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007911 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007912 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007913 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7914 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007915 return 1;
7916 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007917 if (tmp == NULL) {
7918 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7919 return 1;
7920 }
7921 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007922 int res;
7923 Py_ssize_t len;
7924 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007925 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007926 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 +02007927 goto failed;
7928 }
7929 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007930 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007931 if (generators == NULL) goto failed;
7932 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007933 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007934 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7935 Py_INCREF(tmp2);
7936 res = obj2ast_comprehension(tmp2, &val, arena);
7937 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007938 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007939 if (len != PyList_GET_SIZE(tmp)) {
7940 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7941 goto failed;
7942 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007943 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007944 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007945 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007946 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007947 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7948 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007949 if (*out == NULL) goto failed;
7950 return 0;
7951 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007952 tp = astmodulestate_global->Await_type;
7953 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007954 if (isinstance == -1) {
7955 return 1;
7956 }
7957 if (isinstance) {
7958 expr_ty value;
7959
Dino Viehlandac46eb42019-09-11 10:16:34 -07007960 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007961 return 1;
7962 }
7963 if (tmp == NULL) {
7964 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7965 return 1;
7966 }
7967 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007968 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007969 res = obj2ast_expr(tmp, &value, arena);
7970 if (res != 0) goto failed;
7971 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007972 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007973 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7974 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007975 if (*out == NULL) goto failed;
7976 return 0;
7977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007978 tp = astmodulestate_global->Yield_type;
7979 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007980 if (isinstance == -1) {
7981 return 1;
7982 }
7983 if (isinstance) {
7984 expr_ty value;
7985
Dino Viehlandac46eb42019-09-11 10:16:34 -07007986 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007987 return 1;
7988 }
7989 if (tmp == NULL || tmp == Py_None) {
7990 Py_CLEAR(tmp);
7991 value = NULL;
7992 }
7993 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007994 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007995 res = obj2ast_expr(tmp, &value, arena);
7996 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007997 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007998 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007999 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8000 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008001 if (*out == NULL) goto failed;
8002 return 0;
8003 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008004 tp = astmodulestate_global->YieldFrom_type;
8005 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008006 if (isinstance == -1) {
8007 return 1;
8008 }
8009 if (isinstance) {
8010 expr_ty value;
8011
Dino Viehlandac46eb42019-09-11 10:16:34 -07008012 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008013 return 1;
8014 }
8015 if (tmp == NULL) {
8016 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8017 return 1;
8018 }
8019 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008020 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008021 res = obj2ast_expr(tmp, &value, arena);
8022 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008023 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008024 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008025 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8026 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008027 if (*out == NULL) goto failed;
8028 return 0;
8029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008030 tp = astmodulestate_global->Compare_type;
8031 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008032 if (isinstance == -1) {
8033 return 1;
8034 }
8035 if (isinstance) {
8036 expr_ty left;
8037 asdl_int_seq* ops;
8038 asdl_seq* comparators;
8039
Dino Viehlandac46eb42019-09-11 10:16:34 -07008040 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008041 return 1;
8042 }
8043 if (tmp == NULL) {
8044 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8045 return 1;
8046 }
8047 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008048 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008049 res = obj2ast_expr(tmp, &left, arena);
8050 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008051 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008052 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008053 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008054 return 1;
8055 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008056 if (tmp == NULL) {
8057 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8058 return 1;
8059 }
8060 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008061 int res;
8062 Py_ssize_t len;
8063 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008064 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008065 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 +02008066 goto failed;
8067 }
8068 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008069 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008070 if (ops == NULL) goto failed;
8071 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008072 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008073 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8074 Py_INCREF(tmp2);
8075 res = obj2ast_cmpop(tmp2, &val, arena);
8076 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008077 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008078 if (len != PyList_GET_SIZE(tmp)) {
8079 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8080 goto failed;
8081 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008082 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008083 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008084 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008086 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8087 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008088 return 1;
8089 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008090 if (tmp == NULL) {
8091 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8092 return 1;
8093 }
8094 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008095 int res;
8096 Py_ssize_t len;
8097 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008098 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008099 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 +02008100 goto failed;
8101 }
8102 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008103 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008104 if (comparators == NULL) goto failed;
8105 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008106 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008107 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8108 Py_INCREF(tmp2);
8109 res = obj2ast_expr(tmp2, &val, arena);
8110 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008111 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008112 if (len != PyList_GET_SIZE(tmp)) {
8113 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8114 goto failed;
8115 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008116 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008117 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008118 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008119 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008120 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8121 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008122 if (*out == NULL) goto failed;
8123 return 0;
8124 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008125 tp = astmodulestate_global->Call_type;
8126 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008127 if (isinstance == -1) {
8128 return 1;
8129 }
8130 if (isinstance) {
8131 expr_ty func;
8132 asdl_seq* args;
8133 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008134
Dino Viehlandac46eb42019-09-11 10:16:34 -07008135 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008136 return 1;
8137 }
8138 if (tmp == NULL) {
8139 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8140 return 1;
8141 }
8142 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008143 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008144 res = obj2ast_expr(tmp, &func, arena);
8145 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008146 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008147 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008148 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008149 return 1;
8150 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008151 if (tmp == NULL) {
8152 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8153 return 1;
8154 }
8155 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008156 int res;
8157 Py_ssize_t len;
8158 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008159 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008160 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 +02008161 goto failed;
8162 }
8163 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008164 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008165 if (args == NULL) goto failed;
8166 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008167 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008168 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8169 Py_INCREF(tmp2);
8170 res = obj2ast_expr(tmp2, &val, arena);
8171 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008172 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008173 if (len != PyList_GET_SIZE(tmp)) {
8174 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8175 goto failed;
8176 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008177 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008178 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008179 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008180 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008181 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8182 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008183 return 1;
8184 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008185 if (tmp == NULL) {
8186 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8187 return 1;
8188 }
8189 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008190 int res;
8191 Py_ssize_t len;
8192 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008193 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008194 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 +02008195 goto failed;
8196 }
8197 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008198 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008199 if (keywords == NULL) goto failed;
8200 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008201 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008202 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8203 Py_INCREF(tmp2);
8204 res = obj2ast_keyword(tmp2, &val, arena);
8205 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008206 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008207 if (len != PyList_GET_SIZE(tmp)) {
8208 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8209 goto failed;
8210 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008211 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008212 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008213 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008214 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008215 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8216 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008217 if (*out == NULL) goto failed;
8218 return 0;
8219 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008220 tp = astmodulestate_global->FormattedValue_type;
8221 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008222 if (isinstance == -1) {
8223 return 1;
8224 }
8225 if (isinstance) {
8226 expr_ty value;
8227 int conversion;
8228 expr_ty format_spec;
8229
Dino Viehlandac46eb42019-09-11 10:16:34 -07008230 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008231 return 1;
8232 }
8233 if (tmp == NULL) {
8234 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8235 return 1;
8236 }
8237 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008238 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008239 res = obj2ast_expr(tmp, &value, arena);
8240 if (res != 0) goto failed;
8241 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008242 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008243 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8244 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008245 return 1;
8246 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008247 if (tmp == NULL || tmp == Py_None) {
8248 Py_CLEAR(tmp);
8249 conversion = 0;
8250 }
8251 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008252 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008253 res = obj2ast_int(tmp, &conversion, arena);
8254 if (res != 0) goto failed;
8255 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008257 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8258 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008259 return 1;
8260 }
8261 if (tmp == NULL || tmp == Py_None) {
8262 Py_CLEAR(tmp);
8263 format_spec = NULL;
8264 }
8265 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008266 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008267 res = obj2ast_expr(tmp, &format_spec, arena);
8268 if (res != 0) goto failed;
8269 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008270 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008271 *out = FormattedValue(value, conversion, format_spec, lineno,
8272 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008273 if (*out == NULL) goto failed;
8274 return 0;
8275 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008276 tp = astmodulestate_global->JoinedStr_type;
8277 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008278 if (isinstance == -1) {
8279 return 1;
8280 }
8281 if (isinstance) {
8282 asdl_seq* values;
8283
Dino Viehlandac46eb42019-09-11 10:16:34 -07008284 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8285 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008286 return 1;
8287 }
8288 if (tmp == NULL) {
8289 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8290 return 1;
8291 }
8292 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008293 int res;
8294 Py_ssize_t len;
8295 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008296 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008297 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 -04008298 goto failed;
8299 }
8300 len = PyList_GET_SIZE(tmp);
8301 values = _Py_asdl_seq_new(len, arena);
8302 if (values == NULL) goto failed;
8303 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008304 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008305 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8306 Py_INCREF(tmp2);
8307 res = obj2ast_expr(tmp2, &val, arena);
8308 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008309 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008310 if (len != PyList_GET_SIZE(tmp)) {
8311 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8312 goto failed;
8313 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008314 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008315 }
8316 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008317 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008318 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8319 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008320 if (*out == NULL) goto failed;
8321 return 0;
8322 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008323 tp = astmodulestate_global->Constant_type;
8324 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008325 if (isinstance == -1) {
8326 return 1;
8327 }
8328 if (isinstance) {
8329 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008330 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008331
Dino Viehlandac46eb42019-09-11 10:16:34 -07008332 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008333 return 1;
8334 }
8335 if (tmp == NULL) {
8336 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8337 return 1;
8338 }
8339 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008340 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008341 res = obj2ast_constant(tmp, &value, arena);
8342 if (res != 0) goto failed;
8343 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008344 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008345 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008346 return 1;
8347 }
8348 if (tmp == NULL || tmp == Py_None) {
8349 Py_CLEAR(tmp);
8350 kind = NULL;
8351 }
8352 else {
8353 int res;
8354 res = obj2ast_string(tmp, &kind, arena);
8355 if (res != 0) goto failed;
8356 Py_CLEAR(tmp);
8357 }
8358 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8359 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008360 if (*out == NULL) goto failed;
8361 return 0;
8362 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008363 tp = astmodulestate_global->Attribute_type;
8364 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008365 if (isinstance == -1) {
8366 return 1;
8367 }
8368 if (isinstance) {
8369 expr_ty value;
8370 identifier attr;
8371 expr_context_ty ctx;
8372
Dino Viehlandac46eb42019-09-11 10:16:34 -07008373 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008374 return 1;
8375 }
8376 if (tmp == NULL) {
8377 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8378 return 1;
8379 }
8380 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008381 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008382 res = obj2ast_expr(tmp, &value, arena);
8383 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008384 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008385 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008386 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008387 return 1;
8388 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008389 if (tmp == NULL) {
8390 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
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_identifier(tmp, &attr, 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 Attribute");
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 = Attribute(value, attr, 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->Subscript_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 expr_ty value;
8424 slice_ty slice;
8425 expr_context_ty ctx;
8426
Dino Viehlandac46eb42019-09-11 10:16:34 -07008427 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008428 return 1;
8429 }
8430 if (tmp == NULL) {
8431 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8432 return 1;
8433 }
8434 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008435 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008436 res = obj2ast_expr(tmp, &value, arena);
8437 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008438 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008439 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008440 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008441 return 1;
8442 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008443 if (tmp == NULL) {
8444 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8445 return 1;
8446 }
8447 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008448 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008449 res = obj2ast_slice(tmp, &slice, arena);
8450 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008451 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008452 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008453 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008454 return 1;
8455 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008456 if (tmp == NULL) {
8457 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8458 return 1;
8459 }
8460 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008461 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008462 res = obj2ast_expr_context(tmp, &ctx, arena);
8463 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008464 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008465 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008466 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8467 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008468 if (*out == NULL) goto failed;
8469 return 0;
8470 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008471 tp = astmodulestate_global->Starred_type;
8472 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008473 if (isinstance == -1) {
8474 return 1;
8475 }
8476 if (isinstance) {
8477 expr_ty value;
8478 expr_context_ty ctx;
8479
Dino Viehlandac46eb42019-09-11 10:16:34 -07008480 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008481 return 1;
8482 }
8483 if (tmp == NULL) {
8484 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8485 return 1;
8486 }
8487 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008488 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008489 res = obj2ast_expr(tmp, &value, arena);
8490 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008491 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008492 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008493 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008494 return 1;
8495 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008496 if (tmp == NULL) {
8497 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8498 return 1;
8499 }
8500 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008501 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008502 res = obj2ast_expr_context(tmp, &ctx, arena);
8503 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008504 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008505 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008506 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8507 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008508 if (*out == NULL) goto failed;
8509 return 0;
8510 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008511 tp = astmodulestate_global->Name_type;
8512 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008513 if (isinstance == -1) {
8514 return 1;
8515 }
8516 if (isinstance) {
8517 identifier id;
8518 expr_context_ty ctx;
8519
Dino Viehlandac46eb42019-09-11 10:16:34 -07008520 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008521 return 1;
8522 }
8523 if (tmp == NULL) {
8524 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8525 return 1;
8526 }
8527 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008528 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008529 res = obj2ast_identifier(tmp, &id, arena);
8530 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008531 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008532 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008533 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008534 return 1;
8535 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008536 if (tmp == NULL) {
8537 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8538 return 1;
8539 }
8540 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008541 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008542 res = obj2ast_expr_context(tmp, &ctx, arena);
8543 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008544 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008545 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008546 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8547 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008548 if (*out == NULL) goto failed;
8549 return 0;
8550 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008551 tp = astmodulestate_global->List_type;
8552 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008553 if (isinstance == -1) {
8554 return 1;
8555 }
8556 if (isinstance) {
8557 asdl_seq* elts;
8558 expr_context_ty ctx;
8559
Dino Viehlandac46eb42019-09-11 10:16:34 -07008560 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008561 return 1;
8562 }
8563 if (tmp == NULL) {
8564 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8565 return 1;
8566 }
8567 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008568 int res;
8569 Py_ssize_t len;
8570 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008571 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008572 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 +02008573 goto failed;
8574 }
8575 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008576 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008577 if (elts == NULL) goto failed;
8578 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008579 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008580 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8581 Py_INCREF(tmp2);
8582 res = obj2ast_expr(tmp2, &val, arena);
8583 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008584 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008585 if (len != PyList_GET_SIZE(tmp)) {
8586 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8587 goto failed;
8588 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008589 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008590 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008591 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008592 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008593 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008594 return 1;
8595 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008596 if (tmp == NULL) {
8597 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8598 return 1;
8599 }
8600 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008601 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008602 res = obj2ast_expr_context(tmp, &ctx, arena);
8603 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008604 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008605 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008606 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8607 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008608 if (*out == NULL) goto failed;
8609 return 0;
8610 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008611 tp = astmodulestate_global->Tuple_type;
8612 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008613 if (isinstance == -1) {
8614 return 1;
8615 }
8616 if (isinstance) {
8617 asdl_seq* elts;
8618 expr_context_ty ctx;
8619
Dino Viehlandac46eb42019-09-11 10:16:34 -07008620 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008621 return 1;
8622 }
8623 if (tmp == NULL) {
8624 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8625 return 1;
8626 }
8627 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008628 int res;
8629 Py_ssize_t len;
8630 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008631 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008632 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 +02008633 goto failed;
8634 }
8635 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008636 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008637 if (elts == NULL) goto failed;
8638 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008639 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008640 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8641 Py_INCREF(tmp2);
8642 res = obj2ast_expr(tmp2, &val, arena);
8643 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008644 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008645 if (len != PyList_GET_SIZE(tmp)) {
8646 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8647 goto failed;
8648 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008649 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008650 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008651 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008652 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008653 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008654 return 1;
8655 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008656 if (tmp == NULL) {
8657 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8658 return 1;
8659 }
8660 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008661 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008662 res = obj2ast_expr_context(tmp, &ctx, arena);
8663 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008664 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008665 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008666 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8667 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008668 if (*out == NULL) goto failed;
8669 return 0;
8670 }
8671
8672 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8673 failed:
8674 Py_XDECREF(tmp);
8675 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008676}
8677
8678int
8679obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8680{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008681 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008682
Dino Viehlandac46eb42019-09-11 10:16:34 -07008683 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008684 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008685 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008686 }
8687 if (isinstance) {
8688 *out = Load;
8689 return 0;
8690 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008691 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008692 if (isinstance == -1) {
8693 return 1;
8694 }
8695 if (isinstance) {
8696 *out = Store;
8697 return 0;
8698 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008699 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008700 if (isinstance == -1) {
8701 return 1;
8702 }
8703 if (isinstance) {
8704 *out = Del;
8705 return 0;
8706 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008707 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008708 if (isinstance == -1) {
8709 return 1;
8710 }
8711 if (isinstance) {
8712 *out = AugLoad;
8713 return 0;
8714 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008715 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008716 if (isinstance == -1) {
8717 return 1;
8718 }
8719 if (isinstance) {
8720 *out = AugStore;
8721 return 0;
8722 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008723 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Param_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008724 if (isinstance == -1) {
8725 return 1;
8726 }
8727 if (isinstance) {
8728 *out = Param;
8729 return 0;
8730 }
8731
8732 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8733 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008734}
8735
8736int
8737obj2ast_slice(PyObject* obj, slice_ty* out, PyArena* arena)
8738{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008739 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008740
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008741 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07008742 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008743
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008744 if (obj == Py_None) {
8745 *out = NULL;
8746 return 0;
8747 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008748 tp = astmodulestate_global->Slice_type;
8749 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008750 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008751 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008752 }
8753 if (isinstance) {
8754 expr_ty lower;
8755 expr_ty upper;
8756 expr_ty step;
8757
Dino Viehlandac46eb42019-09-11 10:16:34 -07008758 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008759 return 1;
8760 }
8761 if (tmp == NULL || tmp == Py_None) {
8762 Py_CLEAR(tmp);
8763 lower = NULL;
8764 }
8765 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008766 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008767 res = obj2ast_expr(tmp, &lower, arena);
8768 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008769 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008770 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008771 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008772 return 1;
8773 }
8774 if (tmp == NULL || tmp == Py_None) {
8775 Py_CLEAR(tmp);
8776 upper = NULL;
8777 }
8778 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008779 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008780 res = obj2ast_expr(tmp, &upper, arena);
8781 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008782 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008783 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008784 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008785 return 1;
8786 }
8787 if (tmp == NULL || tmp == Py_None) {
8788 Py_CLEAR(tmp);
8789 step = NULL;
8790 }
8791 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008792 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008793 res = obj2ast_expr(tmp, &step, arena);
8794 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008795 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008796 }
8797 *out = Slice(lower, upper, step, arena);
8798 if (*out == NULL) goto failed;
8799 return 0;
8800 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008801 tp = astmodulestate_global->ExtSlice_type;
8802 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008803 if (isinstance == -1) {
8804 return 1;
8805 }
8806 if (isinstance) {
8807 asdl_seq* dims;
8808
Dino Viehlandac46eb42019-09-11 10:16:34 -07008809 if (_PyObject_LookupAttr(obj, astmodulestate_global->dims, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008810 return 1;
8811 }
8812 if (tmp == NULL) {
8813 PyErr_SetString(PyExc_TypeError, "required field \"dims\" missing from ExtSlice");
8814 return 1;
8815 }
8816 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008817 int res;
8818 Py_ssize_t len;
8819 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008820 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008821 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 +02008822 goto failed;
8823 }
8824 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008825 dims = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008826 if (dims == NULL) goto failed;
8827 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008828 slice_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008829 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8830 Py_INCREF(tmp2);
8831 res = obj2ast_slice(tmp2, &val, arena);
8832 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008833 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008834 if (len != PyList_GET_SIZE(tmp)) {
8835 PyErr_SetString(PyExc_RuntimeError, "ExtSlice field \"dims\" changed size during iteration");
8836 goto failed;
8837 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008838 asdl_seq_SET(dims, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008839 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008840 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008841 }
8842 *out = ExtSlice(dims, arena);
8843 if (*out == NULL) goto failed;
8844 return 0;
8845 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008846 tp = astmodulestate_global->Index_type;
8847 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008848 if (isinstance == -1) {
8849 return 1;
8850 }
8851 if (isinstance) {
8852 expr_ty value;
8853
Dino Viehlandac46eb42019-09-11 10:16:34 -07008854 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008855 return 1;
8856 }
8857 if (tmp == NULL) {
8858 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Index");
8859 return 1;
8860 }
8861 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008862 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008863 res = obj2ast_expr(tmp, &value, arena);
8864 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008865 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008866 }
8867 *out = Index(value, arena);
8868 if (*out == NULL) goto failed;
8869 return 0;
8870 }
8871
8872 PyErr_Format(PyExc_TypeError, "expected some sort of slice, but got %R", obj);
8873 failed:
8874 Py_XDECREF(tmp);
8875 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008876}
8877
8878int
8879obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8880{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008881 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008882
Dino Viehlandac46eb42019-09-11 10:16:34 -07008883 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008884 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008885 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008886 }
8887 if (isinstance) {
8888 *out = And;
8889 return 0;
8890 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008891 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008892 if (isinstance == -1) {
8893 return 1;
8894 }
8895 if (isinstance) {
8896 *out = Or;
8897 return 0;
8898 }
8899
8900 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8901 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008902}
8903
8904int
8905obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8906{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008907 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008908
Dino Viehlandac46eb42019-09-11 10:16:34 -07008909 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008910 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008911 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008912 }
8913 if (isinstance) {
8914 *out = Add;
8915 return 0;
8916 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008917 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008918 if (isinstance == -1) {
8919 return 1;
8920 }
8921 if (isinstance) {
8922 *out = Sub;
8923 return 0;
8924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008925 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008926 if (isinstance == -1) {
8927 return 1;
8928 }
8929 if (isinstance) {
8930 *out = Mult;
8931 return 0;
8932 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008933 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008934 if (isinstance == -1) {
8935 return 1;
8936 }
8937 if (isinstance) {
8938 *out = MatMult;
8939 return 0;
8940 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008941 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008942 if (isinstance == -1) {
8943 return 1;
8944 }
8945 if (isinstance) {
8946 *out = Div;
8947 return 0;
8948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008949 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008950 if (isinstance == -1) {
8951 return 1;
8952 }
8953 if (isinstance) {
8954 *out = Mod;
8955 return 0;
8956 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008957 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008958 if (isinstance == -1) {
8959 return 1;
8960 }
8961 if (isinstance) {
8962 *out = Pow;
8963 return 0;
8964 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008965 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008966 if (isinstance == -1) {
8967 return 1;
8968 }
8969 if (isinstance) {
8970 *out = LShift;
8971 return 0;
8972 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008973 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008974 if (isinstance == -1) {
8975 return 1;
8976 }
8977 if (isinstance) {
8978 *out = RShift;
8979 return 0;
8980 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008981 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008982 if (isinstance == -1) {
8983 return 1;
8984 }
8985 if (isinstance) {
8986 *out = BitOr;
8987 return 0;
8988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008989 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008990 if (isinstance == -1) {
8991 return 1;
8992 }
8993 if (isinstance) {
8994 *out = BitXor;
8995 return 0;
8996 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008997 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008998 if (isinstance == -1) {
8999 return 1;
9000 }
9001 if (isinstance) {
9002 *out = BitAnd;
9003 return 0;
9004 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009005 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009006 if (isinstance == -1) {
9007 return 1;
9008 }
9009 if (isinstance) {
9010 *out = FloorDiv;
9011 return 0;
9012 }
9013
9014 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
9015 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009016}
9017
9018int
9019obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
9020{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009021 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009022
Dino Viehlandac46eb42019-09-11 10:16:34 -07009023 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009024 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009025 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009026 }
9027 if (isinstance) {
9028 *out = Invert;
9029 return 0;
9030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009031 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009032 if (isinstance == -1) {
9033 return 1;
9034 }
9035 if (isinstance) {
9036 *out = Not;
9037 return 0;
9038 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009039 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009040 if (isinstance == -1) {
9041 return 1;
9042 }
9043 if (isinstance) {
9044 *out = UAdd;
9045 return 0;
9046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009047 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009048 if (isinstance == -1) {
9049 return 1;
9050 }
9051 if (isinstance) {
9052 *out = USub;
9053 return 0;
9054 }
9055
9056 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9057 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009058}
9059
9060int
9061obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9062{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009063 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009064
Dino Viehlandac46eb42019-09-11 10:16:34 -07009065 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009066 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009067 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009068 }
9069 if (isinstance) {
9070 *out = Eq;
9071 return 0;
9072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009073 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009074 if (isinstance == -1) {
9075 return 1;
9076 }
9077 if (isinstance) {
9078 *out = NotEq;
9079 return 0;
9080 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009081 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009082 if (isinstance == -1) {
9083 return 1;
9084 }
9085 if (isinstance) {
9086 *out = Lt;
9087 return 0;
9088 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009089 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009090 if (isinstance == -1) {
9091 return 1;
9092 }
9093 if (isinstance) {
9094 *out = LtE;
9095 return 0;
9096 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009097 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009098 if (isinstance == -1) {
9099 return 1;
9100 }
9101 if (isinstance) {
9102 *out = Gt;
9103 return 0;
9104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009105 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009106 if (isinstance == -1) {
9107 return 1;
9108 }
9109 if (isinstance) {
9110 *out = GtE;
9111 return 0;
9112 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009113 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009114 if (isinstance == -1) {
9115 return 1;
9116 }
9117 if (isinstance) {
9118 *out = Is;
9119 return 0;
9120 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009121 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009122 if (isinstance == -1) {
9123 return 1;
9124 }
9125 if (isinstance) {
9126 *out = IsNot;
9127 return 0;
9128 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009129 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009130 if (isinstance == -1) {
9131 return 1;
9132 }
9133 if (isinstance) {
9134 *out = In;
9135 return 0;
9136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009137 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009138 if (isinstance == -1) {
9139 return 1;
9140 }
9141 if (isinstance) {
9142 *out = NotIn;
9143 return 0;
9144 }
9145
9146 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9147 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009148}
9149
9150int
9151obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9152{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009153 PyObject* tmp = NULL;
9154 expr_ty target;
9155 expr_ty iter;
9156 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009157 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009158
Dino Viehlandac46eb42019-09-11 10:16:34 -07009159 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009160 return 1;
9161 }
9162 if (tmp == NULL) {
9163 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9164 return 1;
9165 }
9166 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009167 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009168 res = obj2ast_expr(tmp, &target, arena);
9169 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009170 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009171 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009172 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009173 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009174 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009175 if (tmp == NULL) {
9176 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9177 return 1;
9178 }
9179 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009180 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009181 res = obj2ast_expr(tmp, &iter, arena);
9182 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009183 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009184 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009185 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009186 return 1;
9187 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009188 if (tmp == NULL) {
9189 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9190 return 1;
9191 }
9192 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009193 int res;
9194 Py_ssize_t len;
9195 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009196 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009197 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 +02009198 goto failed;
9199 }
9200 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009201 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009202 if (ifs == NULL) goto failed;
9203 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009204 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009205 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9206 Py_INCREF(tmp2);
9207 res = obj2ast_expr(tmp2, &val, arena);
9208 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009209 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009210 if (len != PyList_GET_SIZE(tmp)) {
9211 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9212 goto failed;
9213 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009214 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009215 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009216 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009217 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009218 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009219 return 1;
9220 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009221 if (tmp == NULL) {
9222 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9223 return 1;
9224 }
9225 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009226 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009227 res = obj2ast_int(tmp, &is_async, arena);
9228 if (res != 0) goto failed;
9229 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009230 }
9231 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009232 return 0;
9233failed:
9234 Py_XDECREF(tmp);
9235 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009236}
9237
9238int
9239obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9240{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009241 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009242
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009243 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009244 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009245 int lineno;
9246 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009247 int end_lineno;
9248 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009249
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009250 if (obj == Py_None) {
9251 *out = NULL;
9252 return 0;
9253 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009254 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009255 return 1;
9256 }
9257 if (tmp == NULL) {
9258 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9259 return 1;
9260 }
9261 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009262 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009263 res = obj2ast_int(tmp, &lineno, arena);
9264 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009265 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009266 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009267 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9268 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009269 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009270 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009271 if (tmp == NULL) {
9272 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9273 return 1;
9274 }
9275 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009276 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009277 res = obj2ast_int(tmp, &col_offset, arena);
9278 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009279 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009280 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009281 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9282 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009283 return 1;
9284 }
9285 if (tmp == NULL || tmp == Py_None) {
9286 Py_CLEAR(tmp);
9287 end_lineno = 0;
9288 }
9289 else {
9290 int res;
9291 res = obj2ast_int(tmp, &end_lineno, arena);
9292 if (res != 0) goto failed;
9293 Py_CLEAR(tmp);
9294 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009295 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9296 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009297 return 1;
9298 }
9299 if (tmp == NULL || tmp == Py_None) {
9300 Py_CLEAR(tmp);
9301 end_col_offset = 0;
9302 }
9303 else {
9304 int res;
9305 res = obj2ast_int(tmp, &end_col_offset, arena);
9306 if (res != 0) goto failed;
9307 Py_CLEAR(tmp);
9308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009309 tp = astmodulestate_global->ExceptHandler_type;
9310 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009311 if (isinstance == -1) {
9312 return 1;
9313 }
9314 if (isinstance) {
9315 expr_ty type;
9316 identifier name;
9317 asdl_seq* body;
9318
Dino Viehlandac46eb42019-09-11 10:16:34 -07009319 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009320 return 1;
9321 }
9322 if (tmp == NULL || tmp == Py_None) {
9323 Py_CLEAR(tmp);
9324 type = NULL;
9325 }
9326 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009327 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009328 res = obj2ast_expr(tmp, &type, arena);
9329 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009330 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009331 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009332 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009333 return 1;
9334 }
9335 if (tmp == NULL || tmp == Py_None) {
9336 Py_CLEAR(tmp);
9337 name = NULL;
9338 }
9339 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009340 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009341 res = obj2ast_identifier(tmp, &name, arena);
9342 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009343 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009344 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009345 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009346 return 1;
9347 }
9348 if (tmp == NULL) {
9349 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9350 return 1;
9351 }
9352 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009353 int res;
9354 Py_ssize_t len;
9355 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009356 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009357 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 +02009358 goto failed;
9359 }
9360 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009361 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009362 if (body == NULL) goto failed;
9363 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009364 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009365 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9366 Py_INCREF(tmp2);
9367 res = obj2ast_stmt(tmp2, &val, arena);
9368 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009369 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009370 if (len != PyList_GET_SIZE(tmp)) {
9371 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9372 goto failed;
9373 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009374 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009375 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009376 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009377 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009378 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9379 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009380 if (*out == NULL) goto failed;
9381 return 0;
9382 }
9383
9384 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9385 failed:
9386 Py_XDECREF(tmp);
9387 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009388}
9389
9390int
9391obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9392{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009393 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009394 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009395 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009396 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009397 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009398 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009399 arg_ty kwarg;
9400 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009401
Dino Viehlandac46eb42019-09-11 10:16:34 -07009402 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9403 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009404 return 1;
9405 }
9406 if (tmp == NULL) {
9407 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9408 return 1;
9409 }
9410 else {
9411 int res;
9412 Py_ssize_t len;
9413 Py_ssize_t i;
9414 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009415 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 +01009416 goto failed;
9417 }
9418 len = PyList_GET_SIZE(tmp);
9419 posonlyargs = _Py_asdl_seq_new(len, arena);
9420 if (posonlyargs == NULL) goto failed;
9421 for (i = 0; i < len; i++) {
9422 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009423 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9424 Py_INCREF(tmp2);
9425 res = obj2ast_arg(tmp2, &val, arena);
9426 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009427 if (res != 0) goto failed;
9428 if (len != PyList_GET_SIZE(tmp)) {
9429 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9430 goto failed;
9431 }
9432 asdl_seq_SET(posonlyargs, i, val);
9433 }
9434 Py_CLEAR(tmp);
9435 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009436 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009437 return 1;
9438 }
9439 if (tmp == NULL) {
9440 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9441 return 1;
9442 }
9443 else {
9444 int res;
9445 Py_ssize_t len;
9446 Py_ssize_t i;
9447 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009448 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 +02009449 goto failed;
9450 }
9451 len = PyList_GET_SIZE(tmp);
9452 args = _Py_asdl_seq_new(len, arena);
9453 if (args == NULL) goto failed;
9454 for (i = 0; i < len; i++) {
9455 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009456 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9457 Py_INCREF(tmp2);
9458 res = obj2ast_arg(tmp2, &val, arena);
9459 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009460 if (res != 0) goto failed;
9461 if (len != PyList_GET_SIZE(tmp)) {
9462 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9463 goto failed;
9464 }
9465 asdl_seq_SET(args, i, val);
9466 }
9467 Py_CLEAR(tmp);
9468 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009469 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009470 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009471 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009472 if (tmp == NULL || tmp == Py_None) {
9473 Py_CLEAR(tmp);
9474 vararg = NULL;
9475 }
9476 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009477 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009478 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009479 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009480 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009481 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009482 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9483 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009484 return 1;
9485 }
9486 if (tmp == NULL) {
9487 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9488 return 1;
9489 }
9490 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009491 int res;
9492 Py_ssize_t len;
9493 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009494 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009495 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 +02009496 goto failed;
9497 }
9498 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009499 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009500 if (kwonlyargs == NULL) goto failed;
9501 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009502 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009503 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9504 Py_INCREF(tmp2);
9505 res = obj2ast_arg(tmp2, &val, arena);
9506 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009507 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009508 if (len != PyList_GET_SIZE(tmp)) {
9509 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9510 goto failed;
9511 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009512 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009513 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009514 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009515 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009516 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9517 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009518 return 1;
9519 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009520 if (tmp == NULL) {
9521 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9522 return 1;
9523 }
9524 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009525 int res;
9526 Py_ssize_t len;
9527 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009528 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009529 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 +02009530 goto failed;
9531 }
9532 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009533 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009534 if (kw_defaults == NULL) goto failed;
9535 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009536 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009537 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9538 Py_INCREF(tmp2);
9539 res = obj2ast_expr(tmp2, &val, arena);
9540 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009541 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009542 if (len != PyList_GET_SIZE(tmp)) {
9543 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9544 goto failed;
9545 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009546 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009547 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009548 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009549 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009550 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009551 return 1;
9552 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009553 if (tmp == NULL || tmp == Py_None) {
9554 Py_CLEAR(tmp);
9555 kwarg = NULL;
9556 }
9557 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009558 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009559 res = obj2ast_arg(tmp, &kwarg, arena);
9560 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009561 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009562 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009563 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009564 return 1;
9565 }
9566 if (tmp == NULL) {
9567 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9568 return 1;
9569 }
9570 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009571 int res;
9572 Py_ssize_t len;
9573 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009574 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009575 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 +02009576 goto failed;
9577 }
9578 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009579 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009580 if (defaults == NULL) goto failed;
9581 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009582 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009583 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9584 Py_INCREF(tmp2);
9585 res = obj2ast_expr(tmp2, &val, arena);
9586 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009587 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009588 if (len != PyList_GET_SIZE(tmp)) {
9589 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9590 goto failed;
9591 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009592 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009593 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009594 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009595 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009596 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009597 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009598 return 0;
9599failed:
9600 Py_XDECREF(tmp);
9601 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009602}
9603
9604int
9605obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9606{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009607 PyObject* tmp = NULL;
9608 identifier arg;
9609 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009610 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009611 int lineno;
9612 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009613 int end_lineno;
9614 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009615
Dino Viehlandac46eb42019-09-11 10:16:34 -07009616 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009617 return 1;
9618 }
9619 if (tmp == NULL) {
9620 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9621 return 1;
9622 }
9623 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009624 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009625 res = obj2ast_identifier(tmp, &arg, arena);
9626 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009627 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009628 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009629 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9630 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009631 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009632 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009633 if (tmp == NULL || tmp == Py_None) {
9634 Py_CLEAR(tmp);
9635 annotation = NULL;
9636 }
9637 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009638 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009639 res = obj2ast_expr(tmp, &annotation, arena);
9640 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009641 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009643 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9644 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009645 return 1;
9646 }
9647 if (tmp == NULL || tmp == Py_None) {
9648 Py_CLEAR(tmp);
9649 type_comment = NULL;
9650 }
9651 else {
9652 int res;
9653 res = obj2ast_string(tmp, &type_comment, arena);
9654 if (res != 0) goto failed;
9655 Py_CLEAR(tmp);
9656 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009657 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009658 return 1;
9659 }
9660 if (tmp == NULL) {
9661 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9662 return 1;
9663 }
9664 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009665 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009666 res = obj2ast_int(tmp, &lineno, arena);
9667 if (res != 0) goto failed;
9668 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009669 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009670 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9671 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009672 return 1;
9673 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009674 if (tmp == NULL) {
9675 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9676 return 1;
9677 }
9678 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009679 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009680 res = obj2ast_int(tmp, &col_offset, arena);
9681 if (res != 0) goto failed;
9682 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009683 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009684 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9685 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009686 return 1;
9687 }
9688 if (tmp == NULL || tmp == Py_None) {
9689 Py_CLEAR(tmp);
9690 end_lineno = 0;
9691 }
9692 else {
9693 int res;
9694 res = obj2ast_int(tmp, &end_lineno, arena);
9695 if (res != 0) goto failed;
9696 Py_CLEAR(tmp);
9697 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009698 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9699 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009700 return 1;
9701 }
9702 if (tmp == NULL || tmp == Py_None) {
9703 Py_CLEAR(tmp);
9704 end_col_offset = 0;
9705 }
9706 else {
9707 int res;
9708 res = obj2ast_int(tmp, &end_col_offset, arena);
9709 if (res != 0) goto failed;
9710 Py_CLEAR(tmp);
9711 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009712 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9713 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009714 return 0;
9715failed:
9716 Py_XDECREF(tmp);
9717 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009718}
9719
9720int
9721obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9722{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009723 PyObject* tmp = NULL;
9724 identifier arg;
9725 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009726
Dino Viehlandac46eb42019-09-11 10:16:34 -07009727 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009728 return 1;
9729 }
9730 if (tmp == NULL || tmp == Py_None) {
9731 Py_CLEAR(tmp);
9732 arg = NULL;
9733 }
9734 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009735 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009736 res = obj2ast_identifier(tmp, &arg, arena);
9737 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009738 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009739 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009740 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009741 return 1;
9742 }
9743 if (tmp == NULL) {
9744 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9745 return 1;
9746 }
9747 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009748 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009749 res = obj2ast_expr(tmp, &value, arena);
9750 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009751 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009752 }
9753 *out = keyword(arg, value, arena);
9754 return 0;
9755failed:
9756 Py_XDECREF(tmp);
9757 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009758}
9759
9760int
9761obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9762{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009763 PyObject* tmp = NULL;
9764 identifier name;
9765 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009766
Dino Viehlandac46eb42019-09-11 10:16:34 -07009767 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009768 return 1;
9769 }
9770 if (tmp == NULL) {
9771 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9772 return 1;
9773 }
9774 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009775 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009776 res = obj2ast_identifier(tmp, &name, arena);
9777 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009778 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009779 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009780 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009781 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009782 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009783 if (tmp == NULL || tmp == Py_None) {
9784 Py_CLEAR(tmp);
9785 asname = NULL;
9786 }
9787 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009788 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009789 res = obj2ast_identifier(tmp, &asname, arena);
9790 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009791 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009792 }
9793 *out = alias(name, asname, arena);
9794 return 0;
9795failed:
9796 Py_XDECREF(tmp);
9797 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009798}
9799
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009800int
9801obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9802{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009803 PyObject* tmp = NULL;
9804 expr_ty context_expr;
9805 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009806
Dino Viehlandac46eb42019-09-11 10:16:34 -07009807 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9808 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009809 return 1;
9810 }
9811 if (tmp == NULL) {
9812 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9813 return 1;
9814 }
9815 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009816 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009817 res = obj2ast_expr(tmp, &context_expr, arena);
9818 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009819 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009820 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009821 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9822 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009823 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009824 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009825 if (tmp == NULL || tmp == Py_None) {
9826 Py_CLEAR(tmp);
9827 optional_vars = NULL;
9828 }
9829 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009830 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009831 res = obj2ast_expr(tmp, &optional_vars, arena);
9832 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009833 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009834 }
9835 *out = withitem(context_expr, optional_vars, arena);
9836 return 0;
9837failed:
9838 Py_XDECREF(tmp);
9839 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009840}
9841
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009842int
9843obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9844{
9845 int isinstance;
9846
9847 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009848 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009849
9850 if (obj == Py_None) {
9851 *out = NULL;
9852 return 0;
9853 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009854 tp = astmodulestate_global->TypeIgnore_type;
9855 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009856 if (isinstance == -1) {
9857 return 1;
9858 }
9859 if (isinstance) {
9860 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009861 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009862
Dino Viehlandac46eb42019-09-11 10:16:34 -07009863 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9864 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009865 return 1;
9866 }
9867 if (tmp == NULL) {
9868 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9869 return 1;
9870 }
9871 else {
9872 int res;
9873 res = obj2ast_int(tmp, &lineno, arena);
9874 if (res != 0) goto failed;
9875 Py_CLEAR(tmp);
9876 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009877 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009878 return 1;
9879 }
9880 if (tmp == NULL) {
9881 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9882 return 1;
9883 }
9884 else {
9885 int res;
9886 res = obj2ast_string(tmp, &tag, arena);
9887 if (res != 0) goto failed;
9888 Py_CLEAR(tmp);
9889 }
9890 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009891 if (*out == NULL) goto failed;
9892 return 0;
9893 }
9894
9895 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9896 failed:
9897 Py_XDECREF(tmp);
9898 return 1;
9899}
9900
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009901
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009902PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009903PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009904{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009905 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009906 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009907 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009908 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009909 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9910 goto error;
9911 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009912 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009913 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9914 goto error;
9915 }
9916 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9917 goto error;
9918 }
9919 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9920 goto error;
9921 }
9922 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9923 goto error;
9924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009925 Py_INCREF(astmodulestate(m)->mod_type);
9926 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009927 0) {
9928 goto error;
9929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009930 Py_INCREF(astmodulestate(m)->Module_type);
9931 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009932 astmodulestate_global->Interactive_type) < 0) {
9933 goto error;
9934 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009935 Py_INCREF(astmodulestate(m)->Interactive_type);
9936 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009937 astmodulestate_global->Expression_type) < 0) {
9938 goto error;
9939 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009940 Py_INCREF(astmodulestate(m)->Expression_type);
9941 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009942 astmodulestate_global->FunctionType_type) < 0) {
9943 goto error;
9944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009945 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009946 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9947 goto error;
9948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009949 Py_INCREF(astmodulestate(m)->stmt_type);
9950 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009951 astmodulestate_global->FunctionDef_type) < 0) {
9952 goto error;
9953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009954 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9955 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009956 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9957 goto error;
9958 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009959 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9960 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009961 < 0) {
9962 goto error;
9963 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009964 Py_INCREF(astmodulestate(m)->ClassDef_type);
9965 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009966 0) {
9967 goto error;
9968 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009969 Py_INCREF(astmodulestate(m)->Return_type);
9970 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009971 0) {
9972 goto error;
9973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009974 Py_INCREF(astmodulestate(m)->Delete_type);
9975 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009976 0) {
9977 goto error;
9978 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009979 Py_INCREF(astmodulestate(m)->Assign_type);
9980 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009981 astmodulestate_global->AugAssign_type) < 0) {
9982 goto error;
9983 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009984 Py_INCREF(astmodulestate(m)->AugAssign_type);
9985 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009986 astmodulestate_global->AnnAssign_type) < 0) {
9987 goto error;
9988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009989 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009990 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9991 goto error;
9992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009993 Py_INCREF(astmodulestate(m)->For_type);
9994 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009995 < 0) {
9996 goto error;
9997 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009998 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009999 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
10000 goto error;
10001 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010002 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010003 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
10004 goto error;
10005 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010006 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010007 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
10008 goto error;
10009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010010 Py_INCREF(astmodulestate(m)->With_type);
10011 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010012 astmodulestate_global->AsyncWith_type) < 0) {
10013 goto error;
10014 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010015 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010016 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
10017 goto error;
10018 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010019 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010020 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
10021 goto error;
10022 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010023 Py_INCREF(astmodulestate(m)->Try_type);
10024 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010025 0) {
10026 goto error;
10027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010028 Py_INCREF(astmodulestate(m)->Assert_type);
10029 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010030 0) {
10031 goto error;
10032 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010033 Py_INCREF(astmodulestate(m)->Import_type);
10034 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010035 astmodulestate_global->ImportFrom_type) < 0) {
10036 goto error;
10037 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010038 Py_INCREF(astmodulestate(m)->ImportFrom_type);
10039 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010040 0) {
10041 goto error;
10042 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010043 Py_INCREF(astmodulestate(m)->Global_type);
10044 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010045 < 0) {
10046 goto error;
10047 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010048 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010049 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10050 goto error;
10051 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010052 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010053 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10054 goto error;
10055 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010056 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010057 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10058 goto error;
10059 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010060 Py_INCREF(astmodulestate(m)->Break_type);
10061 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010062 < 0) {
10063 goto error;
10064 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010065 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010066 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10067 goto error;
10068 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010069 Py_INCREF(astmodulestate(m)->expr_type);
10070 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010071 0) {
10072 goto error;
10073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010074 Py_INCREF(astmodulestate(m)->BoolOp_type);
10075 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010076 astmodulestate_global->NamedExpr_type) < 0) {
10077 goto error;
10078 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010079 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010080 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10081 goto error;
10082 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010083 Py_INCREF(astmodulestate(m)->BinOp_type);
10084 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010085 0) {
10086 goto error;
10087 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010088 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10089 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010090 0) {
10091 goto error;
10092 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010093 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010094 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10095 goto error;
10096 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010097 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010098 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10099 goto error;
10100 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010101 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010102 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10103 goto error;
10104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010105 Py_INCREF(astmodulestate(m)->Set_type);
10106 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010107 < 0) {
10108 goto error;
10109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010110 Py_INCREF(astmodulestate(m)->ListComp_type);
10111 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010112 0) {
10113 goto error;
10114 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010115 Py_INCREF(astmodulestate(m)->SetComp_type);
10116 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010117 < 0) {
10118 goto error;
10119 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010120 Py_INCREF(astmodulestate(m)->DictComp_type);
10121 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010122 astmodulestate_global->GeneratorExp_type) < 0) {
10123 goto error;
10124 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010125 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010126 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10127 goto error;
10128 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010129 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010130 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10131 goto error;
10132 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010133 Py_INCREF(astmodulestate(m)->Yield_type);
10134 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010135 astmodulestate_global->YieldFrom_type) < 0) {
10136 goto error;
10137 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010138 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10139 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010140 0) {
10141 goto error;
10142 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010143 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010144 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10145 goto error;
10146 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010147 Py_INCREF(astmodulestate(m)->Call_type);
10148 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010149 astmodulestate_global->FormattedValue_type) < 0) {
10150 goto error;
10151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010152 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10153 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010154 astmodulestate_global->JoinedStr_type) < 0) {
10155 goto error;
10156 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010157 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10158 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010159 < 0) {
10160 goto error;
10161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010162 Py_INCREF(astmodulestate(m)->Constant_type);
10163 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010164 astmodulestate_global->Attribute_type) < 0) {
10165 goto error;
10166 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010167 Py_INCREF(astmodulestate(m)->Attribute_type);
10168 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010169 astmodulestate_global->Subscript_type) < 0) {
10170 goto error;
10171 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010172 Py_INCREF(astmodulestate(m)->Subscript_type);
10173 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010174 0) {
10175 goto error;
10176 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010177 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010178 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10179 goto error;
10180 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010181 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010182 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10183 goto error;
10184 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010185 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010186 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10187 goto error;
10188 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010189 Py_INCREF(astmodulestate(m)->Tuple_type);
10190 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010191 astmodulestate_global->expr_context_type) < 0) {
10192 goto error;
10193 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010194 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010195 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10196 goto error;
10197 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010198 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010199 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10200 goto error;
10201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010202 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010203 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10204 goto error;
10205 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010206 Py_INCREF(astmodulestate(m)->Del_type);
10207 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010208 0) {
10209 goto error;
10210 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010211 Py_INCREF(astmodulestate(m)->AugLoad_type);
10212 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010213 < 0) {
10214 goto error;
10215 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010216 Py_INCREF(astmodulestate(m)->AugStore_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010217 if (PyModule_AddObject(m, "Param", astmodulestate_global->Param_type) < 0) {
10218 goto error;
10219 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010220 Py_INCREF(astmodulestate(m)->Param_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010221 if (PyModule_AddObject(m, "slice", astmodulestate_global->slice_type) < 0) {
10222 goto error;
10223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010224 Py_INCREF(astmodulestate(m)->slice_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010225 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10226 goto error;
10227 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010228 Py_INCREF(astmodulestate(m)->Slice_type);
10229 if (PyModule_AddObject(m, "ExtSlice", astmodulestate_global->ExtSlice_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010230 < 0) {
10231 goto error;
10232 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010233 Py_INCREF(astmodulestate(m)->ExtSlice_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010234 if (PyModule_AddObject(m, "Index", astmodulestate_global->Index_type) < 0) {
10235 goto error;
10236 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010237 Py_INCREF(astmodulestate(m)->Index_type);
10238 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010239 0) {
10240 goto error;
10241 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010242 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010243 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10244 goto error;
10245 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010246 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010247 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10248 goto error;
10249 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010250 Py_INCREF(astmodulestate(m)->Or_type);
10251 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010252 < 0) {
10253 goto error;
10254 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010255 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010256 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10257 goto error;
10258 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010259 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010260 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10261 goto error;
10262 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010263 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010264 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10265 goto error;
10266 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010267 Py_INCREF(astmodulestate(m)->Mult_type);
10268 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010269 0) {
10270 goto error;
10271 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010272 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010273 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10274 goto error;
10275 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010276 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010277 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10278 goto error;
10279 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010280 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010281 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10282 goto error;
10283 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010284 Py_INCREF(astmodulestate(m)->Pow_type);
10285 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010286 0) {
10287 goto error;
10288 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010289 Py_INCREF(astmodulestate(m)->LShift_type);
10290 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010291 0) {
10292 goto error;
10293 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010294 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010295 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10296 goto error;
10297 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010298 Py_INCREF(astmodulestate(m)->BitOr_type);
10299 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010300 0) {
10301 goto error;
10302 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010303 Py_INCREF(astmodulestate(m)->BitXor_type);
10304 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010305 0) {
10306 goto error;
10307 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010308 Py_INCREF(astmodulestate(m)->BitAnd_type);
10309 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010310 < 0) {
10311 goto error;
10312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010313 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10314 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010315 0) {
10316 goto error;
10317 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010318 Py_INCREF(astmodulestate(m)->unaryop_type);
10319 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_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)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010324 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10325 goto error;
10326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010327 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010328 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10329 goto error;
10330 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010331 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010332 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10333 goto error;
10334 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010335 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010336 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10337 goto error;
10338 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010339 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010340 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10341 goto error;
10342 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010343 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010344 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10345 goto error;
10346 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010347 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010348 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10349 goto error;
10350 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010351 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010352 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10353 goto error;
10354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010355 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010356 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10357 goto error;
10358 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010359 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010360 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10361 goto error;
10362 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010363 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010364 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10365 goto error;
10366 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010367 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010368 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10369 goto error;
10370 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010371 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010372 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10373 goto error;
10374 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010375 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010376 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10377 goto error;
10378 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010379 Py_INCREF(astmodulestate(m)->NotIn_type);
10380 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010381 astmodulestate_global->comprehension_type) < 0) {
10382 goto error;
10383 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010384 Py_INCREF(astmodulestate(m)->comprehension_type);
10385 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010386 astmodulestate_global->excepthandler_type) < 0) {
10387 goto error;
10388 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010389 Py_INCREF(astmodulestate(m)->excepthandler_type);
10390 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010391 astmodulestate_global->ExceptHandler_type) < 0) {
10392 goto error;
10393 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010394 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10395 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010396 astmodulestate_global->arguments_type) < 0) {
10397 goto error;
10398 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010399 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010400 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10401 goto error;
10402 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010403 Py_INCREF(astmodulestate(m)->arg_type);
10404 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010405 0) {
10406 goto error;
10407 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010408 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010409 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10410 goto error;
10411 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010412 Py_INCREF(astmodulestate(m)->alias_type);
10413 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010414 < 0) {
10415 goto error;
10416 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010417 Py_INCREF(astmodulestate(m)->withitem_type);
10418 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010419 astmodulestate_global->type_ignore_type) < 0) {
10420 goto error;
10421 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010422 Py_INCREF(astmodulestate(m)->type_ignore_type);
10423 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010424 astmodulestate_global->TypeIgnore_type) < 0) {
10425 goto error;
10426 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010427 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010428 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010429error:
10430 Py_DECREF(m);
10431 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010432}
10433
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010434
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010435PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010436{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010437 if (!init_types())
10438 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010439 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010440}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010441
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010442/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10443mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010444{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010445 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010446 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010447 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010448
Steve Dowerb82e17e2019-05-23 08:45:22 -070010449 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10450 return NULL;
10451 }
10452
Dino Viehlandac46eb42019-09-11 10:16:34 -070010453 req_type[0] = astmodulestate_global->Module_type;
10454 req_type[1] = astmodulestate_global->Expression_type;
10455 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010456
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010457 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010458
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010459 if (!init_types())
10460 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010461
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010462 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10463 if (isinstance == -1)
10464 return NULL;
10465 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010466 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010467 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010468 return NULL;
10469 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010470
10471 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010472 if (obj2ast_mod(ast, &res, arena) != 0)
10473 return NULL;
10474 else
10475 return res;
10476}
10477
10478int PyAST_Check(PyObject* obj)
10479{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010480 if (!init_types())
10481 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010482 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010483}
10484
Martin v. Löwis5b222132007-06-10 09:51:05 +000010485