blob: 96ecc31f7a34704972e5e77288a5c21affebc4ec [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;
Dino Viehlandac46eb42019-09-11 10:16:34 -070055 PyObject *FloorDiv_singleton;
56 PyObject *FloorDiv_type;
57 PyObject *For_type;
58 PyObject *FormattedValue_type;
59 PyObject *FunctionDef_type;
60 PyObject *FunctionType_type;
61 PyObject *GeneratorExp_type;
62 PyObject *Global_type;
63 PyObject *GtE_singleton;
64 PyObject *GtE_type;
65 PyObject *Gt_singleton;
66 PyObject *Gt_type;
67 PyObject *IfExp_type;
68 PyObject *If_type;
69 PyObject *ImportFrom_type;
70 PyObject *Import_type;
71 PyObject *In_singleton;
72 PyObject *In_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070073 PyObject *Interactive_type;
74 PyObject *Invert_singleton;
75 PyObject *Invert_type;
76 PyObject *IsNot_singleton;
77 PyObject *IsNot_type;
78 PyObject *Is_singleton;
79 PyObject *Is_type;
80 PyObject *JoinedStr_type;
81 PyObject *LShift_singleton;
82 PyObject *LShift_type;
83 PyObject *Lambda_type;
84 PyObject *ListComp_type;
85 PyObject *List_type;
86 PyObject *Load_singleton;
87 PyObject *Load_type;
88 PyObject *LtE_singleton;
89 PyObject *LtE_type;
90 PyObject *Lt_singleton;
91 PyObject *Lt_type;
92 PyObject *MatMult_singleton;
93 PyObject *MatMult_type;
94 PyObject *Mod_singleton;
95 PyObject *Mod_type;
96 PyObject *Module_type;
97 PyObject *Mult_singleton;
98 PyObject *Mult_type;
99 PyObject *Name_type;
100 PyObject *NamedExpr_type;
101 PyObject *Nonlocal_type;
102 PyObject *NotEq_singleton;
103 PyObject *NotEq_type;
104 PyObject *NotIn_singleton;
105 PyObject *NotIn_type;
106 PyObject *Not_singleton;
107 PyObject *Not_type;
108 PyObject *Or_singleton;
109 PyObject *Or_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700110 PyObject *Pass_type;
111 PyObject *Pow_singleton;
112 PyObject *Pow_type;
113 PyObject *RShift_singleton;
114 PyObject *RShift_type;
115 PyObject *Raise_type;
116 PyObject *Return_type;
117 PyObject *SetComp_type;
118 PyObject *Set_type;
119 PyObject *Slice_type;
120 PyObject *Starred_type;
121 PyObject *Store_singleton;
122 PyObject *Store_type;
123 PyObject *Sub_singleton;
124 PyObject *Sub_type;
125 PyObject *Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700126 PyObject *Try_type;
127 PyObject *Tuple_type;
128 PyObject *TypeIgnore_type;
129 PyObject *UAdd_singleton;
130 PyObject *UAdd_type;
131 PyObject *USub_singleton;
132 PyObject *USub_type;
133 PyObject *UnaryOp_type;
134 PyObject *While_type;
135 PyObject *With_type;
136 PyObject *YieldFrom_type;
137 PyObject *Yield_type;
138 PyObject *__dict__;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300139 PyObject *__doc__;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700140 PyObject *__module__;
141 PyObject *_ast;
142 PyObject *_attributes;
143 PyObject *_fields;
144 PyObject *alias_type;
145 PyObject *annotation;
146 PyObject *arg;
147 PyObject *arg_type;
148 PyObject *args;
149 PyObject *argtypes;
150 PyObject *arguments_type;
151 PyObject *asname;
152 PyObject *attr;
153 PyObject *bases;
154 PyObject *body;
155 PyObject *boolop_type;
156 PyObject *cause;
157 PyObject *cmpop_type;
158 PyObject *col_offset;
159 PyObject *comparators;
160 PyObject *comprehension_type;
161 PyObject *context_expr;
162 PyObject *conversion;
163 PyObject *ctx;
164 PyObject *decorator_list;
165 PyObject *defaults;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700166 PyObject *elt;
167 PyObject *elts;
168 PyObject *end_col_offset;
169 PyObject *end_lineno;
170 PyObject *exc;
171 PyObject *excepthandler_type;
172 PyObject *expr_context_type;
173 PyObject *expr_type;
174 PyObject *finalbody;
175 PyObject *format_spec;
176 PyObject *func;
177 PyObject *generators;
178 PyObject *handlers;
179 PyObject *id;
180 PyObject *ifs;
181 PyObject *is_async;
182 PyObject *items;
183 PyObject *iter;
184 PyObject *key;
185 PyObject *keys;
186 PyObject *keyword_type;
187 PyObject *keywords;
188 PyObject *kind;
189 PyObject *kw_defaults;
190 PyObject *kwarg;
191 PyObject *kwonlyargs;
192 PyObject *left;
193 PyObject *level;
194 PyObject *lineno;
195 PyObject *lower;
196 PyObject *mod_type;
197 PyObject *module;
198 PyObject *msg;
199 PyObject *name;
200 PyObject *names;
201 PyObject *op;
202 PyObject *operand;
203 PyObject *operator_type;
204 PyObject *ops;
205 PyObject *optional_vars;
206 PyObject *orelse;
207 PyObject *posonlyargs;
208 PyObject *returns;
209 PyObject *right;
210 PyObject *simple;
211 PyObject *slice;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700212 PyObject *step;
213 PyObject *stmt_type;
214 PyObject *tag;
215 PyObject *target;
216 PyObject *targets;
217 PyObject *test;
218 PyObject *type;
219 PyObject *type_comment;
220 PyObject *type_ignore_type;
221 PyObject *type_ignores;
222 PyObject *unaryop_type;
223 PyObject *upper;
224 PyObject *value;
225 PyObject *values;
226 PyObject *vararg;
227 PyObject *withitem_type;
228} astmodulestate;
229
230
231#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
232
233static int astmodule_clear(PyObject *module)
234{
235 Py_CLEAR(astmodulestate(module)->AST_type);
236 Py_CLEAR(astmodulestate(module)->Add_singleton);
237 Py_CLEAR(astmodulestate(module)->Add_type);
238 Py_CLEAR(astmodulestate(module)->And_singleton);
239 Py_CLEAR(astmodulestate(module)->And_type);
240 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
241 Py_CLEAR(astmodulestate(module)->Assert_type);
242 Py_CLEAR(astmodulestate(module)->Assign_type);
243 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
244 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
245 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
246 Py_CLEAR(astmodulestate(module)->Attribute_type);
247 Py_CLEAR(astmodulestate(module)->AugAssign_type);
248 Py_CLEAR(astmodulestate(module)->AugLoad_singleton);
249 Py_CLEAR(astmodulestate(module)->AugLoad_type);
250 Py_CLEAR(astmodulestate(module)->AugStore_singleton);
251 Py_CLEAR(astmodulestate(module)->AugStore_type);
252 Py_CLEAR(astmodulestate(module)->Await_type);
253 Py_CLEAR(astmodulestate(module)->BinOp_type);
254 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
255 Py_CLEAR(astmodulestate(module)->BitAnd_type);
256 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
257 Py_CLEAR(astmodulestate(module)->BitOr_type);
258 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
259 Py_CLEAR(astmodulestate(module)->BitXor_type);
260 Py_CLEAR(astmodulestate(module)->BoolOp_type);
261 Py_CLEAR(astmodulestate(module)->Break_type);
262 Py_CLEAR(astmodulestate(module)->Call_type);
263 Py_CLEAR(astmodulestate(module)->ClassDef_type);
264 Py_CLEAR(astmodulestate(module)->Compare_type);
265 Py_CLEAR(astmodulestate(module)->Constant_type);
266 Py_CLEAR(astmodulestate(module)->Continue_type);
267 Py_CLEAR(astmodulestate(module)->Del_singleton);
268 Py_CLEAR(astmodulestate(module)->Del_type);
269 Py_CLEAR(astmodulestate(module)->Delete_type);
270 Py_CLEAR(astmodulestate(module)->DictComp_type);
271 Py_CLEAR(astmodulestate(module)->Dict_type);
272 Py_CLEAR(astmodulestate(module)->Div_singleton);
273 Py_CLEAR(astmodulestate(module)->Div_type);
274 Py_CLEAR(astmodulestate(module)->Eq_singleton);
275 Py_CLEAR(astmodulestate(module)->Eq_type);
276 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
277 Py_CLEAR(astmodulestate(module)->Expr_type);
278 Py_CLEAR(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700279 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
280 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
281 Py_CLEAR(astmodulestate(module)->For_type);
282 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
283 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
284 Py_CLEAR(astmodulestate(module)->FunctionType_type);
285 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
286 Py_CLEAR(astmodulestate(module)->Global_type);
287 Py_CLEAR(astmodulestate(module)->GtE_singleton);
288 Py_CLEAR(astmodulestate(module)->GtE_type);
289 Py_CLEAR(astmodulestate(module)->Gt_singleton);
290 Py_CLEAR(astmodulestate(module)->Gt_type);
291 Py_CLEAR(astmodulestate(module)->IfExp_type);
292 Py_CLEAR(astmodulestate(module)->If_type);
293 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
294 Py_CLEAR(astmodulestate(module)->Import_type);
295 Py_CLEAR(astmodulestate(module)->In_singleton);
296 Py_CLEAR(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700297 Py_CLEAR(astmodulestate(module)->Interactive_type);
298 Py_CLEAR(astmodulestate(module)->Invert_singleton);
299 Py_CLEAR(astmodulestate(module)->Invert_type);
300 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
301 Py_CLEAR(astmodulestate(module)->IsNot_type);
302 Py_CLEAR(astmodulestate(module)->Is_singleton);
303 Py_CLEAR(astmodulestate(module)->Is_type);
304 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
305 Py_CLEAR(astmodulestate(module)->LShift_singleton);
306 Py_CLEAR(astmodulestate(module)->LShift_type);
307 Py_CLEAR(astmodulestate(module)->Lambda_type);
308 Py_CLEAR(astmodulestate(module)->ListComp_type);
309 Py_CLEAR(astmodulestate(module)->List_type);
310 Py_CLEAR(astmodulestate(module)->Load_singleton);
311 Py_CLEAR(astmodulestate(module)->Load_type);
312 Py_CLEAR(astmodulestate(module)->LtE_singleton);
313 Py_CLEAR(astmodulestate(module)->LtE_type);
314 Py_CLEAR(astmodulestate(module)->Lt_singleton);
315 Py_CLEAR(astmodulestate(module)->Lt_type);
316 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
317 Py_CLEAR(astmodulestate(module)->MatMult_type);
318 Py_CLEAR(astmodulestate(module)->Mod_singleton);
319 Py_CLEAR(astmodulestate(module)->Mod_type);
320 Py_CLEAR(astmodulestate(module)->Module_type);
321 Py_CLEAR(astmodulestate(module)->Mult_singleton);
322 Py_CLEAR(astmodulestate(module)->Mult_type);
323 Py_CLEAR(astmodulestate(module)->Name_type);
324 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
325 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
326 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
327 Py_CLEAR(astmodulestate(module)->NotEq_type);
328 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
329 Py_CLEAR(astmodulestate(module)->NotIn_type);
330 Py_CLEAR(astmodulestate(module)->Not_singleton);
331 Py_CLEAR(astmodulestate(module)->Not_type);
332 Py_CLEAR(astmodulestate(module)->Or_singleton);
333 Py_CLEAR(astmodulestate(module)->Or_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700334 Py_CLEAR(astmodulestate(module)->Pass_type);
335 Py_CLEAR(astmodulestate(module)->Pow_singleton);
336 Py_CLEAR(astmodulestate(module)->Pow_type);
337 Py_CLEAR(astmodulestate(module)->RShift_singleton);
338 Py_CLEAR(astmodulestate(module)->RShift_type);
339 Py_CLEAR(astmodulestate(module)->Raise_type);
340 Py_CLEAR(astmodulestate(module)->Return_type);
341 Py_CLEAR(astmodulestate(module)->SetComp_type);
342 Py_CLEAR(astmodulestate(module)->Set_type);
343 Py_CLEAR(astmodulestate(module)->Slice_type);
344 Py_CLEAR(astmodulestate(module)->Starred_type);
345 Py_CLEAR(astmodulestate(module)->Store_singleton);
346 Py_CLEAR(astmodulestate(module)->Store_type);
347 Py_CLEAR(astmodulestate(module)->Sub_singleton);
348 Py_CLEAR(astmodulestate(module)->Sub_type);
349 Py_CLEAR(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700350 Py_CLEAR(astmodulestate(module)->Try_type);
351 Py_CLEAR(astmodulestate(module)->Tuple_type);
352 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
353 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
354 Py_CLEAR(astmodulestate(module)->UAdd_type);
355 Py_CLEAR(astmodulestate(module)->USub_singleton);
356 Py_CLEAR(astmodulestate(module)->USub_type);
357 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
358 Py_CLEAR(astmodulestate(module)->While_type);
359 Py_CLEAR(astmodulestate(module)->With_type);
360 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
361 Py_CLEAR(astmodulestate(module)->Yield_type);
362 Py_CLEAR(astmodulestate(module)->__dict__);
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300363 Py_CLEAR(astmodulestate(module)->__doc__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700364 Py_CLEAR(astmodulestate(module)->__module__);
365 Py_CLEAR(astmodulestate(module)->_ast);
366 Py_CLEAR(astmodulestate(module)->_attributes);
367 Py_CLEAR(astmodulestate(module)->_fields);
368 Py_CLEAR(astmodulestate(module)->alias_type);
369 Py_CLEAR(astmodulestate(module)->annotation);
370 Py_CLEAR(astmodulestate(module)->arg);
371 Py_CLEAR(astmodulestate(module)->arg_type);
372 Py_CLEAR(astmodulestate(module)->args);
373 Py_CLEAR(astmodulestate(module)->argtypes);
374 Py_CLEAR(astmodulestate(module)->arguments_type);
375 Py_CLEAR(astmodulestate(module)->asname);
376 Py_CLEAR(astmodulestate(module)->attr);
377 Py_CLEAR(astmodulestate(module)->bases);
378 Py_CLEAR(astmodulestate(module)->body);
379 Py_CLEAR(astmodulestate(module)->boolop_type);
380 Py_CLEAR(astmodulestate(module)->cause);
381 Py_CLEAR(astmodulestate(module)->cmpop_type);
382 Py_CLEAR(astmodulestate(module)->col_offset);
383 Py_CLEAR(astmodulestate(module)->comparators);
384 Py_CLEAR(astmodulestate(module)->comprehension_type);
385 Py_CLEAR(astmodulestate(module)->context_expr);
386 Py_CLEAR(astmodulestate(module)->conversion);
387 Py_CLEAR(astmodulestate(module)->ctx);
388 Py_CLEAR(astmodulestate(module)->decorator_list);
389 Py_CLEAR(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700390 Py_CLEAR(astmodulestate(module)->elt);
391 Py_CLEAR(astmodulestate(module)->elts);
392 Py_CLEAR(astmodulestate(module)->end_col_offset);
393 Py_CLEAR(astmodulestate(module)->end_lineno);
394 Py_CLEAR(astmodulestate(module)->exc);
395 Py_CLEAR(astmodulestate(module)->excepthandler_type);
396 Py_CLEAR(astmodulestate(module)->expr_context_type);
397 Py_CLEAR(astmodulestate(module)->expr_type);
398 Py_CLEAR(astmodulestate(module)->finalbody);
399 Py_CLEAR(astmodulestate(module)->format_spec);
400 Py_CLEAR(astmodulestate(module)->func);
401 Py_CLEAR(astmodulestate(module)->generators);
402 Py_CLEAR(astmodulestate(module)->handlers);
403 Py_CLEAR(astmodulestate(module)->id);
404 Py_CLEAR(astmodulestate(module)->ifs);
405 Py_CLEAR(astmodulestate(module)->is_async);
406 Py_CLEAR(astmodulestate(module)->items);
407 Py_CLEAR(astmodulestate(module)->iter);
408 Py_CLEAR(astmodulestate(module)->key);
409 Py_CLEAR(astmodulestate(module)->keys);
410 Py_CLEAR(astmodulestate(module)->keyword_type);
411 Py_CLEAR(astmodulestate(module)->keywords);
412 Py_CLEAR(astmodulestate(module)->kind);
413 Py_CLEAR(astmodulestate(module)->kw_defaults);
414 Py_CLEAR(astmodulestate(module)->kwarg);
415 Py_CLEAR(astmodulestate(module)->kwonlyargs);
416 Py_CLEAR(astmodulestate(module)->left);
417 Py_CLEAR(astmodulestate(module)->level);
418 Py_CLEAR(astmodulestate(module)->lineno);
419 Py_CLEAR(astmodulestate(module)->lower);
420 Py_CLEAR(astmodulestate(module)->mod_type);
421 Py_CLEAR(astmodulestate(module)->module);
422 Py_CLEAR(astmodulestate(module)->msg);
423 Py_CLEAR(astmodulestate(module)->name);
424 Py_CLEAR(astmodulestate(module)->names);
425 Py_CLEAR(astmodulestate(module)->op);
426 Py_CLEAR(astmodulestate(module)->operand);
427 Py_CLEAR(astmodulestate(module)->operator_type);
428 Py_CLEAR(astmodulestate(module)->ops);
429 Py_CLEAR(astmodulestate(module)->optional_vars);
430 Py_CLEAR(astmodulestate(module)->orelse);
431 Py_CLEAR(astmodulestate(module)->posonlyargs);
432 Py_CLEAR(astmodulestate(module)->returns);
433 Py_CLEAR(astmodulestate(module)->right);
434 Py_CLEAR(astmodulestate(module)->simple);
435 Py_CLEAR(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700436 Py_CLEAR(astmodulestate(module)->step);
437 Py_CLEAR(astmodulestate(module)->stmt_type);
438 Py_CLEAR(astmodulestate(module)->tag);
439 Py_CLEAR(astmodulestate(module)->target);
440 Py_CLEAR(astmodulestate(module)->targets);
441 Py_CLEAR(astmodulestate(module)->test);
442 Py_CLEAR(astmodulestate(module)->type);
443 Py_CLEAR(astmodulestate(module)->type_comment);
444 Py_CLEAR(astmodulestate(module)->type_ignore_type);
445 Py_CLEAR(astmodulestate(module)->type_ignores);
446 Py_CLEAR(astmodulestate(module)->unaryop_type);
447 Py_CLEAR(astmodulestate(module)->upper);
448 Py_CLEAR(astmodulestate(module)->value);
449 Py_CLEAR(astmodulestate(module)->values);
450 Py_CLEAR(astmodulestate(module)->vararg);
451 Py_CLEAR(astmodulestate(module)->withitem_type);
452
453 return 0;
454}
455
456static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
457{
458 Py_VISIT(astmodulestate(module)->AST_type);
459 Py_VISIT(astmodulestate(module)->Add_singleton);
460 Py_VISIT(astmodulestate(module)->Add_type);
461 Py_VISIT(astmodulestate(module)->And_singleton);
462 Py_VISIT(astmodulestate(module)->And_type);
463 Py_VISIT(astmodulestate(module)->AnnAssign_type);
464 Py_VISIT(astmodulestate(module)->Assert_type);
465 Py_VISIT(astmodulestate(module)->Assign_type);
466 Py_VISIT(astmodulestate(module)->AsyncFor_type);
467 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
468 Py_VISIT(astmodulestate(module)->AsyncWith_type);
469 Py_VISIT(astmodulestate(module)->Attribute_type);
470 Py_VISIT(astmodulestate(module)->AugAssign_type);
471 Py_VISIT(astmodulestate(module)->AugLoad_singleton);
472 Py_VISIT(astmodulestate(module)->AugLoad_type);
473 Py_VISIT(astmodulestate(module)->AugStore_singleton);
474 Py_VISIT(astmodulestate(module)->AugStore_type);
475 Py_VISIT(astmodulestate(module)->Await_type);
476 Py_VISIT(astmodulestate(module)->BinOp_type);
477 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
478 Py_VISIT(astmodulestate(module)->BitAnd_type);
479 Py_VISIT(astmodulestate(module)->BitOr_singleton);
480 Py_VISIT(astmodulestate(module)->BitOr_type);
481 Py_VISIT(astmodulestate(module)->BitXor_singleton);
482 Py_VISIT(astmodulestate(module)->BitXor_type);
483 Py_VISIT(astmodulestate(module)->BoolOp_type);
484 Py_VISIT(astmodulestate(module)->Break_type);
485 Py_VISIT(astmodulestate(module)->Call_type);
486 Py_VISIT(astmodulestate(module)->ClassDef_type);
487 Py_VISIT(astmodulestate(module)->Compare_type);
488 Py_VISIT(astmodulestate(module)->Constant_type);
489 Py_VISIT(astmodulestate(module)->Continue_type);
490 Py_VISIT(astmodulestate(module)->Del_singleton);
491 Py_VISIT(astmodulestate(module)->Del_type);
492 Py_VISIT(astmodulestate(module)->Delete_type);
493 Py_VISIT(astmodulestate(module)->DictComp_type);
494 Py_VISIT(astmodulestate(module)->Dict_type);
495 Py_VISIT(astmodulestate(module)->Div_singleton);
496 Py_VISIT(astmodulestate(module)->Div_type);
497 Py_VISIT(astmodulestate(module)->Eq_singleton);
498 Py_VISIT(astmodulestate(module)->Eq_type);
499 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
500 Py_VISIT(astmodulestate(module)->Expr_type);
501 Py_VISIT(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700502 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
503 Py_VISIT(astmodulestate(module)->FloorDiv_type);
504 Py_VISIT(astmodulestate(module)->For_type);
505 Py_VISIT(astmodulestate(module)->FormattedValue_type);
506 Py_VISIT(astmodulestate(module)->FunctionDef_type);
507 Py_VISIT(astmodulestate(module)->FunctionType_type);
508 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
509 Py_VISIT(astmodulestate(module)->Global_type);
510 Py_VISIT(astmodulestate(module)->GtE_singleton);
511 Py_VISIT(astmodulestate(module)->GtE_type);
512 Py_VISIT(astmodulestate(module)->Gt_singleton);
513 Py_VISIT(astmodulestate(module)->Gt_type);
514 Py_VISIT(astmodulestate(module)->IfExp_type);
515 Py_VISIT(astmodulestate(module)->If_type);
516 Py_VISIT(astmodulestate(module)->ImportFrom_type);
517 Py_VISIT(astmodulestate(module)->Import_type);
518 Py_VISIT(astmodulestate(module)->In_singleton);
519 Py_VISIT(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700520 Py_VISIT(astmodulestate(module)->Interactive_type);
521 Py_VISIT(astmodulestate(module)->Invert_singleton);
522 Py_VISIT(astmodulestate(module)->Invert_type);
523 Py_VISIT(astmodulestate(module)->IsNot_singleton);
524 Py_VISIT(astmodulestate(module)->IsNot_type);
525 Py_VISIT(astmodulestate(module)->Is_singleton);
526 Py_VISIT(astmodulestate(module)->Is_type);
527 Py_VISIT(astmodulestate(module)->JoinedStr_type);
528 Py_VISIT(astmodulestate(module)->LShift_singleton);
529 Py_VISIT(astmodulestate(module)->LShift_type);
530 Py_VISIT(astmodulestate(module)->Lambda_type);
531 Py_VISIT(astmodulestate(module)->ListComp_type);
532 Py_VISIT(astmodulestate(module)->List_type);
533 Py_VISIT(astmodulestate(module)->Load_singleton);
534 Py_VISIT(astmodulestate(module)->Load_type);
535 Py_VISIT(astmodulestate(module)->LtE_singleton);
536 Py_VISIT(astmodulestate(module)->LtE_type);
537 Py_VISIT(astmodulestate(module)->Lt_singleton);
538 Py_VISIT(astmodulestate(module)->Lt_type);
539 Py_VISIT(astmodulestate(module)->MatMult_singleton);
540 Py_VISIT(astmodulestate(module)->MatMult_type);
541 Py_VISIT(astmodulestate(module)->Mod_singleton);
542 Py_VISIT(astmodulestate(module)->Mod_type);
543 Py_VISIT(astmodulestate(module)->Module_type);
544 Py_VISIT(astmodulestate(module)->Mult_singleton);
545 Py_VISIT(astmodulestate(module)->Mult_type);
546 Py_VISIT(astmodulestate(module)->Name_type);
547 Py_VISIT(astmodulestate(module)->NamedExpr_type);
548 Py_VISIT(astmodulestate(module)->Nonlocal_type);
549 Py_VISIT(astmodulestate(module)->NotEq_singleton);
550 Py_VISIT(astmodulestate(module)->NotEq_type);
551 Py_VISIT(astmodulestate(module)->NotIn_singleton);
552 Py_VISIT(astmodulestate(module)->NotIn_type);
553 Py_VISIT(astmodulestate(module)->Not_singleton);
554 Py_VISIT(astmodulestate(module)->Not_type);
555 Py_VISIT(astmodulestate(module)->Or_singleton);
556 Py_VISIT(astmodulestate(module)->Or_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700557 Py_VISIT(astmodulestate(module)->Pass_type);
558 Py_VISIT(astmodulestate(module)->Pow_singleton);
559 Py_VISIT(astmodulestate(module)->Pow_type);
560 Py_VISIT(astmodulestate(module)->RShift_singleton);
561 Py_VISIT(astmodulestate(module)->RShift_type);
562 Py_VISIT(astmodulestate(module)->Raise_type);
563 Py_VISIT(astmodulestate(module)->Return_type);
564 Py_VISIT(astmodulestate(module)->SetComp_type);
565 Py_VISIT(astmodulestate(module)->Set_type);
566 Py_VISIT(astmodulestate(module)->Slice_type);
567 Py_VISIT(astmodulestate(module)->Starred_type);
568 Py_VISIT(astmodulestate(module)->Store_singleton);
569 Py_VISIT(astmodulestate(module)->Store_type);
570 Py_VISIT(astmodulestate(module)->Sub_singleton);
571 Py_VISIT(astmodulestate(module)->Sub_type);
572 Py_VISIT(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700573 Py_VISIT(astmodulestate(module)->Try_type);
574 Py_VISIT(astmodulestate(module)->Tuple_type);
575 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
576 Py_VISIT(astmodulestate(module)->UAdd_singleton);
577 Py_VISIT(astmodulestate(module)->UAdd_type);
578 Py_VISIT(astmodulestate(module)->USub_singleton);
579 Py_VISIT(astmodulestate(module)->USub_type);
580 Py_VISIT(astmodulestate(module)->UnaryOp_type);
581 Py_VISIT(astmodulestate(module)->While_type);
582 Py_VISIT(astmodulestate(module)->With_type);
583 Py_VISIT(astmodulestate(module)->YieldFrom_type);
584 Py_VISIT(astmodulestate(module)->Yield_type);
585 Py_VISIT(astmodulestate(module)->__dict__);
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300586 Py_VISIT(astmodulestate(module)->__doc__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700587 Py_VISIT(astmodulestate(module)->__module__);
588 Py_VISIT(astmodulestate(module)->_ast);
589 Py_VISIT(astmodulestate(module)->_attributes);
590 Py_VISIT(astmodulestate(module)->_fields);
591 Py_VISIT(astmodulestate(module)->alias_type);
592 Py_VISIT(astmodulestate(module)->annotation);
593 Py_VISIT(astmodulestate(module)->arg);
594 Py_VISIT(astmodulestate(module)->arg_type);
595 Py_VISIT(astmodulestate(module)->args);
596 Py_VISIT(astmodulestate(module)->argtypes);
597 Py_VISIT(astmodulestate(module)->arguments_type);
598 Py_VISIT(astmodulestate(module)->asname);
599 Py_VISIT(astmodulestate(module)->attr);
600 Py_VISIT(astmodulestate(module)->bases);
601 Py_VISIT(astmodulestate(module)->body);
602 Py_VISIT(astmodulestate(module)->boolop_type);
603 Py_VISIT(astmodulestate(module)->cause);
604 Py_VISIT(astmodulestate(module)->cmpop_type);
605 Py_VISIT(astmodulestate(module)->col_offset);
606 Py_VISIT(astmodulestate(module)->comparators);
607 Py_VISIT(astmodulestate(module)->comprehension_type);
608 Py_VISIT(astmodulestate(module)->context_expr);
609 Py_VISIT(astmodulestate(module)->conversion);
610 Py_VISIT(astmodulestate(module)->ctx);
611 Py_VISIT(astmodulestate(module)->decorator_list);
612 Py_VISIT(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700613 Py_VISIT(astmodulestate(module)->elt);
614 Py_VISIT(astmodulestate(module)->elts);
615 Py_VISIT(astmodulestate(module)->end_col_offset);
616 Py_VISIT(astmodulestate(module)->end_lineno);
617 Py_VISIT(astmodulestate(module)->exc);
618 Py_VISIT(astmodulestate(module)->excepthandler_type);
619 Py_VISIT(astmodulestate(module)->expr_context_type);
620 Py_VISIT(astmodulestate(module)->expr_type);
621 Py_VISIT(astmodulestate(module)->finalbody);
622 Py_VISIT(astmodulestate(module)->format_spec);
623 Py_VISIT(astmodulestate(module)->func);
624 Py_VISIT(astmodulestate(module)->generators);
625 Py_VISIT(astmodulestate(module)->handlers);
626 Py_VISIT(astmodulestate(module)->id);
627 Py_VISIT(astmodulestate(module)->ifs);
628 Py_VISIT(astmodulestate(module)->is_async);
629 Py_VISIT(astmodulestate(module)->items);
630 Py_VISIT(astmodulestate(module)->iter);
631 Py_VISIT(astmodulestate(module)->key);
632 Py_VISIT(astmodulestate(module)->keys);
633 Py_VISIT(astmodulestate(module)->keyword_type);
634 Py_VISIT(astmodulestate(module)->keywords);
635 Py_VISIT(astmodulestate(module)->kind);
636 Py_VISIT(astmodulestate(module)->kw_defaults);
637 Py_VISIT(astmodulestate(module)->kwarg);
638 Py_VISIT(astmodulestate(module)->kwonlyargs);
639 Py_VISIT(astmodulestate(module)->left);
640 Py_VISIT(astmodulestate(module)->level);
641 Py_VISIT(astmodulestate(module)->lineno);
642 Py_VISIT(astmodulestate(module)->lower);
643 Py_VISIT(astmodulestate(module)->mod_type);
644 Py_VISIT(astmodulestate(module)->module);
645 Py_VISIT(astmodulestate(module)->msg);
646 Py_VISIT(astmodulestate(module)->name);
647 Py_VISIT(astmodulestate(module)->names);
648 Py_VISIT(astmodulestate(module)->op);
649 Py_VISIT(astmodulestate(module)->operand);
650 Py_VISIT(astmodulestate(module)->operator_type);
651 Py_VISIT(astmodulestate(module)->ops);
652 Py_VISIT(astmodulestate(module)->optional_vars);
653 Py_VISIT(astmodulestate(module)->orelse);
654 Py_VISIT(astmodulestate(module)->posonlyargs);
655 Py_VISIT(astmodulestate(module)->returns);
656 Py_VISIT(astmodulestate(module)->right);
657 Py_VISIT(astmodulestate(module)->simple);
658 Py_VISIT(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700659 Py_VISIT(astmodulestate(module)->step);
660 Py_VISIT(astmodulestate(module)->stmt_type);
661 Py_VISIT(astmodulestate(module)->tag);
662 Py_VISIT(astmodulestate(module)->target);
663 Py_VISIT(astmodulestate(module)->targets);
664 Py_VISIT(astmodulestate(module)->test);
665 Py_VISIT(astmodulestate(module)->type);
666 Py_VISIT(astmodulestate(module)->type_comment);
667 Py_VISIT(astmodulestate(module)->type_ignore_type);
668 Py_VISIT(astmodulestate(module)->type_ignores);
669 Py_VISIT(astmodulestate(module)->unaryop_type);
670 Py_VISIT(astmodulestate(module)->upper);
671 Py_VISIT(astmodulestate(module)->value);
672 Py_VISIT(astmodulestate(module)->values);
673 Py_VISIT(astmodulestate(module)->vararg);
674 Py_VISIT(astmodulestate(module)->withitem_type);
675
676 return 0;
677}
678
679static void astmodule_free(void* module) {
680 astmodule_clear((PyObject*)module);
681}
682
683static struct PyModuleDef _astmodule = {
684 PyModuleDef_HEAD_INIT,
685 "_ast",
686 NULL,
687 sizeof(astmodulestate),
688 NULL,
689 NULL,
690 astmodule_traverse,
691 astmodule_clear,
692 astmodule_free,
693};
694
695#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
696
697static int init_identifiers(void)
698{
699 astmodulestate *state = astmodulestate_global;
700 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300701 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700702 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
703 if ((state->_ast = PyUnicode_InternFromString("_ast")) == NULL) return 0;
704 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
705 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
706 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
707 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
708 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
709 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
710 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
711 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
712 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
713 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
714 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
715 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
716 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
717 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
718 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
719 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
720 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
721 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700722 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
723 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
724 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
725 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
726 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
727 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
728 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
729 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
730 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
731 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
732 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
733 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
734 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
735 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
736 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
737 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
738 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
739 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
740 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
741 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
742 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
743 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
744 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
745 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
746 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
747 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
748 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
749 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
750 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
751 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
752 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
753 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
754 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
755 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
756 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
757 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
758 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
759 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
760 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
761 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
762 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
763 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
764 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
765 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
766 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
767 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
768 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
769 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
770 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
771 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
772 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
773 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
774 return 1;
775};
776
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000777static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300778static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200779 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800780 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000781};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300782static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200783 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000784};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300785static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200786 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000787};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300788static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800789 "argtypes",
790 "returns",
791};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300792static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200793 "lineno",
794 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000795 "end_lineno",
796 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000797};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000798static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300799static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200800 "name",
801 "args",
802 "body",
803 "decorator_list",
804 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800805 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000806};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300807static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400808 "name",
809 "args",
810 "body",
811 "decorator_list",
812 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800813 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400814};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300815static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200816 "name",
817 "bases",
818 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200819 "body",
820 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000821};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300822static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200823 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000824};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300825static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200826 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000827};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300828static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200829 "targets",
830 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800831 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000832};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300833static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200834 "target",
835 "op",
836 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000837};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300838static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700839 "target",
840 "annotation",
841 "value",
842 "simple",
843};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300844static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200845 "target",
846 "iter",
847 "body",
848 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800849 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000850};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300851static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400852 "target",
853 "iter",
854 "body",
855 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800856 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400857};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300858static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200859 "test",
860 "body",
861 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000862};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300863static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200864 "test",
865 "body",
866 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000867};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300868static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200869 "items",
870 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800871 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000872};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300873static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400874 "items",
875 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800876 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400877};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300878static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200879 "exc",
880 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000881};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300882static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200883 "body",
884 "handlers",
885 "orelse",
886 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000887};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300888static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200889 "test",
890 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000891};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300892static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200893 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000894};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300895static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200896 "module",
897 "names",
898 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000899};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300900static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200901 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000902};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300903static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200904 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000905};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300906static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200907 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000908};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300909static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200910 "lineno",
911 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000912 "end_lineno",
913 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000914};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000915static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300916static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200917 "op",
918 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000919};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300920static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700921 "target",
922 "value",
923};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300924static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200925 "left",
926 "op",
927 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000928};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300929static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200930 "op",
931 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000932};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300933static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200934 "args",
935 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000936};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300937static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200938 "test",
939 "body",
940 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000941};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300942static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200943 "keys",
944 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000945};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300946static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200947 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000948};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300949static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200950 "elt",
951 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000952};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300953static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200954 "elt",
955 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000956};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300957static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200958 "key",
959 "value",
960 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000961};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300962static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200963 "elt",
964 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000965};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300966static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400967 "value",
968};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300969static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200970 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500971};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300972static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200973 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000974};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300975static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200976 "left",
977 "ops",
978 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000979};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300980static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200981 "func",
982 "args",
983 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000984};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300985static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400986 "value",
987 "conversion",
988 "format_spec",
989};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300990static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400991 "values",
992};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300993static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100994 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -0700995 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100996};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300997static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200998 "value",
999 "attr",
1000 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001001};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001002static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001003 "value",
1004 "slice",
1005 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001006};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001007static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001008 "value",
1009 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +00001010};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001011static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001012 "id",
1013 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001014};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001015static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001016 "elts",
1017 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001018};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001019static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001020 "elts",
1021 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001022};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001023static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001024 "lower",
1025 "upper",
1026 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001027};
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001028static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001029static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001030static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001031static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001032static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001033static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001034static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001035 "target",
1036 "iter",
1037 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001038 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001039};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001040static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001041 "lineno",
1042 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001043 "end_lineno",
1044 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001045};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001046static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001047static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001048 "type",
1049 "name",
1050 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001051};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001052static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001053static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001054 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001055 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001056 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001057 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001058 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001059 "kwarg",
1060 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001061};
Neal Norwitzc1505362006-12-28 06:47:50 +00001062static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001063static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001064 "lineno",
1065 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001066 "end_lineno",
1067 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001068};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001069static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001070 "arg",
1071 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001072 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001073};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001074static PyObject* ast2obj_keyword(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001075static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001076 "arg",
1077 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001078};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001079static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001080static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001081 "name",
1082 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001083};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001084static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001085static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001086 "context_expr",
1087 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001088};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001089static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001090static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001091 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001092 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001093};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001094
1095
INADA Naokifc489082017-01-25 22:33:43 +09001096
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001097typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001098 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001099 PyObject *dict;
1100} AST_object;
1101
Benjamin Peterson1767e022012-03-14 21:50:29 -05001102static void
1103ast_dealloc(AST_object *self)
1104{
INADA Naokia6296d32017-08-24 14:55:17 +09001105 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001106 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001107 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001108 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001109 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1110 assert(free_func != NULL);
1111 free_func(self);
1112 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001113}
1114
Neal Norwitz207c9f32008-03-31 04:42:11 +00001115static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001116ast_traverse(AST_object *self, visitproc visit, void *arg)
1117{
1118 Py_VISIT(self->dict);
1119 return 0;
1120}
1121
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001122static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001123ast_clear(AST_object *self)
1124{
1125 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001126 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001127}
1128
1129static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001130ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1131{
1132 Py_ssize_t i, numfields = 0;
1133 int res = -1;
1134 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001135 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001136 goto cleanup;
1137 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001138 if (fields) {
1139 numfields = PySequence_Size(fields);
1140 if (numfields == -1)
1141 goto cleanup;
1142 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001143
Neal Norwitz207c9f32008-03-31 04:42:11 +00001144 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001145 if (numfields < PyTuple_GET_SIZE(args)) {
1146 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1147 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001148 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001149 numfields, numfields == 1 ? "" : "s");
1150 res = -1;
1151 goto cleanup;
1152 }
1153 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1154 /* cannot be reached when fields is NULL */
1155 PyObject *name = PySequence_GetItem(fields, i);
1156 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001157 res = -1;
1158 goto cleanup;
1159 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001160 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1161 Py_DECREF(name);
1162 if (res < 0)
1163 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001164 }
1165 if (kw) {
1166 i = 0; /* needed by PyDict_Next */
1167 while (PyDict_Next(kw, &i, &key, &value)) {
1168 res = PyObject_SetAttr(self, key, value);
1169 if (res < 0)
1170 goto cleanup;
1171 }
1172 }
1173 cleanup:
1174 Py_XDECREF(fields);
1175 return res;
1176}
1177
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001178/* Pickling support */
1179static PyObject *
1180ast_type_reduce(PyObject *self, PyObject *unused)
1181{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001182 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001183 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001184 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001185 }
1186 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001187 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001188 }
1189 return Py_BuildValue("O()", Py_TYPE(self));
1190}
1191
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001192static PyMemberDef ast_type_members[] = {
1193 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1194 {NULL} /* Sentinel */
1195};
1196
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001197static PyMethodDef ast_type_methods[] = {
1198 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1199 {NULL}
1200};
1201
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001202static PyGetSetDef ast_type_getsets[] = {
1203 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1204 {NULL}
1205};
1206
Dino Viehlandac46eb42019-09-11 10:16:34 -07001207static PyType_Slot AST_type_slots[] = {
1208 {Py_tp_dealloc, ast_dealloc},
1209 {Py_tp_getattro, PyObject_GenericGetAttr},
1210 {Py_tp_setattro, PyObject_GenericSetAttr},
1211 {Py_tp_traverse, ast_traverse},
1212 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001213 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001214 {Py_tp_methods, ast_type_methods},
1215 {Py_tp_getset, ast_type_getsets},
1216 {Py_tp_init, ast_type_init},
1217 {Py_tp_alloc, PyType_GenericAlloc},
1218 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001219 {Py_tp_free, PyObject_GC_Del},
1220 {0, 0},
1221};
1222
1223static PyType_Spec AST_type_spec = {
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001224 "_ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001225 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001226 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001227 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1228 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001229};
1230
Dino Viehlandac46eb42019-09-11 10:16:34 -07001231static PyObject *
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001232make_type(const char *type, PyObject* base, const char* const* fields, int num_fields, const char *doc)
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001233{
1234 PyObject *fnames, *result;
1235 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001236 fnames = PyTuple_New(num_fields);
1237 if (!fnames) return NULL;
1238 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001239 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001240 if (!field) {
1241 Py_DECREF(fnames);
1242 return NULL;
1243 }
1244 PyTuple_SET_ITEM(fnames, i, field);
1245 }
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001246 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +09001247 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001248 astmodulestate_global->_fields, fnames,
1249 astmodulestate_global->__module__,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001250 astmodulestate_global->_ast,
1251 astmodulestate_global->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001252 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001253 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001254}
1255
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001256static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001257add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001258{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001259 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001260 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001261 if (!l)
1262 return 0;
1263 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001264 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001265 if (!s) {
1266 Py_DECREF(l);
1267 return 0;
1268 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001269 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001270 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001271 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001272 Py_DECREF(l);
1273 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001274}
1275
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001276/* Conversion AST -> Python */
1277
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001278static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1279{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001280 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001281 PyObject *result = PyList_New(n);
1282 PyObject *value;
1283 if (!result)
1284 return NULL;
1285 for (i = 0; i < n; i++) {
1286 value = func(asdl_seq_GET(seq, i));
1287 if (!value) {
1288 Py_DECREF(result);
1289 return NULL;
1290 }
1291 PyList_SET_ITEM(result, i, value);
1292 }
1293 return result;
1294}
1295
1296static PyObject* ast2obj_object(void *o)
1297{
1298 if (!o)
1299 o = Py_None;
1300 Py_INCREF((PyObject*)o);
1301 return (PyObject*)o;
1302}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001303#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001304#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001305#define ast2obj_identifier ast2obj_object
1306#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001307#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001308
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001309static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001310{
Christian Heimes217cfd12007-12-02 14:31:20 +00001311 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001312}
1313
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001314/* Conversion Python -> AST */
1315
1316static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1317{
1318 if (obj == Py_None)
1319 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001320 if (obj) {
1321 if (PyArena_AddPyObject(arena, obj) < 0) {
1322 *out = NULL;
1323 return -1;
1324 }
1325 Py_INCREF(obj);
1326 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001327 *out = obj;
1328 return 0;
1329}
1330
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001331static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1332{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001333 if (PyArena_AddPyObject(arena, obj) < 0) {
1334 *out = NULL;
1335 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001336 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001337 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001338 *out = obj;
1339 return 0;
1340}
1341
Benjamin Peterson180e6352011-07-22 11:09:07 -05001342static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001343{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001344 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1345 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001346 return 1;
1347 }
1348 return obj2ast_object(obj, out, arena);
1349}
1350
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001351static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1352{
1353 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1354 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1355 return 1;
1356 }
1357 return obj2ast_object(obj, out, arena);
1358}
1359
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001360static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1361{
1362 int i;
1363 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001364 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001365 return 1;
1366 }
1367
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001368 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001369 if (i == -1 && PyErr_Occurred())
1370 return 1;
1371 *out = i;
1372 return 0;
1373}
1374
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001375static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001376{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001377 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001378 empty_tuple = PyTuple_New(0);
1379 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001380 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1381 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001382 Py_XDECREF(empty_tuple);
1383 return -1;
1384 }
1385 Py_DECREF(empty_tuple);
1386 return 0;
1387}
1388
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001389
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001390static int init_types(void)
1391{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001392 PyObject *m;
1393 if (PyState_FindModule(&_astmodule) == NULL) {
1394 m = PyModule_Create(&_astmodule);
1395 if (!m) return 0;
1396 PyState_AddModule(m, &_astmodule);
1397 }
1398 astmodulestate *state = astmodulestate_global;
1399 if (state->initialized) return 1;
1400 if (init_identifiers() < 0) return 0;
1401 state->AST_type = PyType_FromSpec(&AST_type_spec);
1402 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001403 if (add_ast_fields() < 0) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001404 state->mod_type = make_type("mod", state->AST_type, NULL, 0,
1405 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1406 " | Interactive(stmt* body)\n"
1407 " | Expression(expr body)\n"
1408 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001409 if (!state->mod_type) return 0;
1410 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001411 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2,
1412 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001413 if (!state->Module_type) return 0;
1414 state->Interactive_type = make_type("Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001415 Interactive_fields, 1,
1416 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001417 if (!state->Interactive_type) return 0;
1418 state->Expression_type = make_type("Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001419 Expression_fields, 1,
1420 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001421 if (!state->Expression_type) return 0;
1422 state->FunctionType_type = make_type("FunctionType", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001423 FunctionType_fields, 2,
1424 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001425 if (!state->FunctionType_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001426 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0,
1427 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1428 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1429 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1430 " | Return(expr? value)\n"
1431 " | Delete(expr* targets)\n"
1432 " | Assign(expr* targets, expr value, string? type_comment)\n"
1433 " | AugAssign(expr target, operator op, expr value)\n"
1434 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1435 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1436 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1437 " | While(expr test, stmt* body, stmt* orelse)\n"
1438 " | If(expr test, stmt* body, stmt* orelse)\n"
1439 " | With(withitem* items, stmt* body, string? type_comment)\n"
1440 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1441 " | Raise(expr? exc, expr? cause)\n"
1442 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1443 " | Assert(expr test, expr? msg)\n"
1444 " | Import(alias* names)\n"
1445 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1446 " | Global(identifier* names)\n"
1447 " | Nonlocal(identifier* names)\n"
1448 " | Expr(expr value)\n"
1449 " | Pass\n"
1450 " | Break\n"
1451 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001452 if (!state->stmt_type) return 0;
1453 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001454 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1455 return 0;
1456 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1457 -1)
1458 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001459 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001460 FunctionDef_fields, 6,
1461 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001462 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001463 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1464 -1)
1465 return 0;
1466 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1467 == -1)
1468 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001469 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1470 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001471 AsyncFunctionDef_fields, 6,
1472 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001473 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001474 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1475 == -1)
1476 return 0;
1477 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1478 Py_None) == -1)
1479 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001480 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001481 ClassDef_fields, 5,
1482 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001483 if (!state->ClassDef_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001484 state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1,
1485 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001486 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001487 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1488 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001489 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1,
1490 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001491 if (!state->Delete_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001492 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3,
1493 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001494 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001495 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1496 -1)
1497 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001498 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001499 AugAssign_fields, 3,
1500 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001501 if (!state->AugAssign_type) return 0;
1502 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001503 AnnAssign_fields, 4,
1504 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001505 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001506 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1507 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001508 state->For_type = make_type("For", state->stmt_type, For_fields, 5,
1509 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001510 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001511 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1512 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001513 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001514 AsyncFor_fields, 5,
1515 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001516 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001517 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1518 -1)
1519 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001520 state->While_type = make_type("While", state->stmt_type, While_fields, 3,
1521 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001522 if (!state->While_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001523 state->If_type = make_type("If", state->stmt_type, If_fields, 3,
1524 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001525 if (!state->If_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001526 state->With_type = make_type("With", state->stmt_type, With_fields, 3,
1527 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001528 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001529 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1530 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001531 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001532 AsyncWith_fields, 3,
1533 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001534 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001535 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1536 == -1)
1537 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001538 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2,
1539 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001540 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001541 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1542 return 0;
1543 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1544 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001545 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4,
1546 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001547 if (!state->Try_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001548 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2,
1549 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001550 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001551 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1552 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001553 state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1,
1554 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001555 if (!state->Import_type) return 0;
1556 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001557 ImportFrom_fields, 3,
1558 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001559 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001560 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1561 return 0;
1562 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1563 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001564 state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1,
1565 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001566 if (!state->Global_type) return 0;
1567 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001568 Nonlocal_fields, 1,
1569 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001570 if (!state->Nonlocal_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001571 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1,
1572 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001573 if (!state->Expr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001574 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0,
1575 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001576 if (!state->Pass_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001577 state->Break_type = make_type("Break", state->stmt_type, NULL, 0,
1578 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001579 if (!state->Break_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001580 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0,
1581 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001582 if (!state->Continue_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001583 state->expr_type = make_type("expr", state->AST_type, NULL, 0,
1584 "expr = BoolOp(boolop op, expr* values)\n"
1585 " | NamedExpr(expr target, expr value)\n"
1586 " | BinOp(expr left, operator op, expr right)\n"
1587 " | UnaryOp(unaryop op, expr operand)\n"
1588 " | Lambda(arguments args, expr body)\n"
1589 " | IfExp(expr test, expr body, expr orelse)\n"
1590 " | Dict(expr* keys, expr* values)\n"
1591 " | Set(expr* elts)\n"
1592 " | ListComp(expr elt, comprehension* generators)\n"
1593 " | SetComp(expr elt, comprehension* generators)\n"
1594 " | DictComp(expr key, expr value, comprehension* generators)\n"
1595 " | GeneratorExp(expr elt, comprehension* generators)\n"
1596 " | Await(expr value)\n"
1597 " | Yield(expr? value)\n"
1598 " | YieldFrom(expr value)\n"
1599 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1600 " | Call(expr func, expr* args, keyword* keywords)\n"
1601 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1602 " | JoinedStr(expr* values)\n"
1603 " | Constant(constant value, string? kind)\n"
1604 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1605 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1606 " | Starred(expr value, expr_context ctx)\n"
1607 " | Name(identifier id, expr_context ctx)\n"
1608 " | List(expr* elts, expr_context ctx)\n"
1609 " | Tuple(expr* elts, expr_context ctx)\n"
1610 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001611 if (!state->expr_type) return 0;
1612 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001613 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1614 return 0;
1615 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1616 -1)
1617 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001618 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2,
1619 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001620 if (!state->BoolOp_type) return 0;
1621 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001622 NamedExpr_fields, 2,
1623 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001624 if (!state->NamedExpr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001625 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3,
1626 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001627 if (!state->BinOp_type) return 0;
1628 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001629 UnaryOp_fields, 2,
1630 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001631 if (!state->UnaryOp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001632 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2,
1633 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001634 if (!state->Lambda_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001635 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3,
1636 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001637 if (!state->IfExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001638 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2,
1639 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001640 if (!state->Dict_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001641 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1,
1642 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001643 if (!state->Set_type) return 0;
1644 state->ListComp_type = make_type("ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001645 ListComp_fields, 2,
1646 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001647 if (!state->ListComp_type) return 0;
1648 state->SetComp_type = make_type("SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001649 SetComp_fields, 2,
1650 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001651 if (!state->SetComp_type) return 0;
1652 state->DictComp_type = make_type("DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001653 DictComp_fields, 3,
1654 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001655 if (!state->DictComp_type) return 0;
1656 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001657 GeneratorExp_fields, 2,
1658 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001659 if (!state->GeneratorExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001660 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1,
1661 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001662 if (!state->Await_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001663 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1,
1664 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001665 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001666 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1667 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001668 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001669 YieldFrom_fields, 1,
1670 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001671 if (!state->YieldFrom_type) return 0;
1672 state->Compare_type = make_type("Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001673 Compare_fields, 3,
1674 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001675 if (!state->Compare_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001676 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3,
1677 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001678 if (!state->Call_type) return 0;
1679 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001680 FormattedValue_fields, 3,
1681 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001682 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001683 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1684 Py_None) == -1)
1685 return 0;
1686 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1687 Py_None) == -1)
1688 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001689 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001690 JoinedStr_fields, 1,
1691 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001692 if (!state->JoinedStr_type) return 0;
1693 state->Constant_type = make_type("Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001694 Constant_fields, 2,
1695 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001696 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001697 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1698 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001699 state->Attribute_type = make_type("Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001700 Attribute_fields, 3,
1701 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001702 if (!state->Attribute_type) return 0;
1703 state->Subscript_type = make_type("Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001704 Subscript_fields, 3,
1705 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001706 if (!state->Subscript_type) return 0;
1707 state->Starred_type = make_type("Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001708 Starred_fields, 2,
1709 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001710 if (!state->Starred_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001711 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2,
1712 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001713 if (!state->Name_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001714 state->List_type = make_type("List", state->expr_type, List_fields, 2,
1715 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001716 if (!state->List_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001717 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2,
1718 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001719 if (!state->Tuple_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001720 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3,
1721 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001722 if (!state->Slice_type) return 0;
1723 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1724 return 0;
1725 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1726 return 0;
1727 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1728 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001729 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001730 0,
1731 "expr_context = Load | Store | Del | AugLoad | AugStore");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001732 if (!state->expr_context_type) return 0;
1733 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001734 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0,
1735 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001736 if (!state->Load_type) return 0;
1737 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1738 NULL, NULL);
1739 if (!state->Load_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001740 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0,
1741 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001742 if (!state->Store_type) return 0;
1743 state->Store_singleton = PyType_GenericNew((PyTypeObject
1744 *)state->Store_type, NULL, NULL);
1745 if (!state->Store_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001746 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0,
1747 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001748 if (!state->Del_type) return 0;
1749 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1750 NULL, NULL);
1751 if (!state->Del_singleton) return 0;
1752 state->AugLoad_type = make_type("AugLoad", state->expr_context_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001753 0,
1754 "AugLoad");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001755 if (!state->AugLoad_type) return 0;
1756 state->AugLoad_singleton = PyType_GenericNew((PyTypeObject
1757 *)state->AugLoad_type, NULL,
1758 NULL);
1759 if (!state->AugLoad_singleton) return 0;
1760 state->AugStore_type = make_type("AugStore", state->expr_context_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001761 NULL, 0,
1762 "AugStore");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001763 if (!state->AugStore_type) return 0;
1764 state->AugStore_singleton = PyType_GenericNew((PyTypeObject
1765 *)state->AugStore_type, NULL,
1766 NULL);
1767 if (!state->AugStore_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001768 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0,
1769 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001770 if (!state->boolop_type) return 0;
1771 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001772 state->And_type = make_type("And", state->boolop_type, NULL, 0,
1773 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001774 if (!state->And_type) return 0;
1775 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1776 NULL, NULL);
1777 if (!state->And_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001778 state->Or_type = make_type("Or", state->boolop_type, NULL, 0,
1779 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001780 if (!state->Or_type) return 0;
1781 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1782 NULL, NULL);
1783 if (!state->Or_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001784 state->operator_type = make_type("operator", state->AST_type, NULL, 0,
1785 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001786 if (!state->operator_type) return 0;
1787 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001788 state->Add_type = make_type("Add", state->operator_type, NULL, 0,
1789 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001790 if (!state->Add_type) return 0;
1791 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1792 NULL, NULL);
1793 if (!state->Add_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001794 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0,
1795 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001796 if (!state->Sub_type) return 0;
1797 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1798 NULL, NULL);
1799 if (!state->Sub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001800 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0,
1801 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001802 if (!state->Mult_type) return 0;
1803 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1804 NULL, NULL);
1805 if (!state->Mult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001806 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0,
1807 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001808 if (!state->MatMult_type) return 0;
1809 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1810 *)state->MatMult_type, NULL,
1811 NULL);
1812 if (!state->MatMult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001813 state->Div_type = make_type("Div", state->operator_type, NULL, 0,
1814 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001815 if (!state->Div_type) return 0;
1816 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1817 NULL, NULL);
1818 if (!state->Div_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001819 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0,
1820 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001821 if (!state->Mod_type) return 0;
1822 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1823 NULL, NULL);
1824 if (!state->Mod_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001825 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0,
1826 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001827 if (!state->Pow_type) return 0;
1828 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1829 NULL, NULL);
1830 if (!state->Pow_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001831 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0,
1832 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001833 if (!state->LShift_type) return 0;
1834 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1835 *)state->LShift_type, NULL,
1836 NULL);
1837 if (!state->LShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001838 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0,
1839 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001840 if (!state->RShift_type) return 0;
1841 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1842 *)state->RShift_type, NULL,
1843 NULL);
1844 if (!state->RShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001845 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0,
1846 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001847 if (!state->BitOr_type) return 0;
1848 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1849 *)state->BitOr_type, NULL, NULL);
1850 if (!state->BitOr_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001851 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0,
1852 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001853 if (!state->BitXor_type) return 0;
1854 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1855 *)state->BitXor_type, NULL,
1856 NULL);
1857 if (!state->BitXor_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001858 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0,
1859 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001860 if (!state->BitAnd_type) return 0;
1861 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1862 *)state->BitAnd_type, NULL,
1863 NULL);
1864 if (!state->BitAnd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001865 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0,
1866 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001867 if (!state->FloorDiv_type) return 0;
1868 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1869 *)state->FloorDiv_type, NULL,
1870 NULL);
1871 if (!state->FloorDiv_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001872 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0,
1873 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001874 if (!state->unaryop_type) return 0;
1875 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001876 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0,
1877 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001878 if (!state->Invert_type) return 0;
1879 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1880 *)state->Invert_type, NULL,
1881 NULL);
1882 if (!state->Invert_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001883 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0,
1884 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001885 if (!state->Not_type) return 0;
1886 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1887 NULL, NULL);
1888 if (!state->Not_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001889 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0,
1890 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001891 if (!state->UAdd_type) return 0;
1892 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1893 NULL, NULL);
1894 if (!state->UAdd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001895 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0,
1896 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001897 if (!state->USub_type) return 0;
1898 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1899 NULL, NULL);
1900 if (!state->USub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001901 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0,
1902 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001903 if (!state->cmpop_type) return 0;
1904 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001905 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0,
1906 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001907 if (!state->Eq_type) return 0;
1908 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1909 NULL, NULL);
1910 if (!state->Eq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001911 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0,
1912 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001913 if (!state->NotEq_type) return 0;
1914 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1915 *)state->NotEq_type, NULL, NULL);
1916 if (!state->NotEq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001917 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0,
1918 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001919 if (!state->Lt_type) return 0;
1920 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1921 NULL, NULL);
1922 if (!state->Lt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001923 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0,
1924 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001925 if (!state->LtE_type) return 0;
1926 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1927 NULL, NULL);
1928 if (!state->LtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001929 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0,
1930 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001931 if (!state->Gt_type) return 0;
1932 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1933 NULL, NULL);
1934 if (!state->Gt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001935 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0,
1936 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001937 if (!state->GtE_type) return 0;
1938 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1939 NULL, NULL);
1940 if (!state->GtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001941 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0,
1942 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001943 if (!state->Is_type) return 0;
1944 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1945 NULL, NULL);
1946 if (!state->Is_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001947 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0,
1948 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001949 if (!state->IsNot_type) return 0;
1950 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1951 *)state->IsNot_type, NULL, NULL);
1952 if (!state->IsNot_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001953 state->In_type = make_type("In", state->cmpop_type, NULL, 0,
1954 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001955 if (!state->In_type) return 0;
1956 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1957 NULL, NULL);
1958 if (!state->In_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001959 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0,
1960 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001961 if (!state->NotIn_type) return 0;
1962 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1963 *)state->NotIn_type, NULL, NULL);
1964 if (!state->NotIn_singleton) return 0;
1965 state->comprehension_type = make_type("comprehension", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001966 comprehension_fields, 4,
1967 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001968 if (!state->comprehension_type) return 0;
1969 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1970 state->excepthandler_type = make_type("excepthandler", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001971 NULL, 0,
1972 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001973 if (!state->excepthandler_type) return 0;
1974 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1975 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001976 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1977 == -1)
1978 return 0;
1979 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1980 Py_None) == -1)
1981 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001982 state->ExceptHandler_type = make_type("ExceptHandler",
1983 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001984 ExceptHandler_fields, 3,
1985 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001986 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001987 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1988 return 0;
1989 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1990 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001991 state->arguments_type = make_type("arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001992 arguments_fields, 7,
1993 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001994 if (!state->arguments_type) return 0;
1995 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001996 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1997 return 0;
1998 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1999 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002000 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3,
2001 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002002 if (!state->arg_type) return 0;
2003 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002004 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
2005 return 0;
2006 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
2007 return 0;
2008 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
2009 return 0;
2010 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
2011 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002012 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002013 2,
2014 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002015 if (!state->keyword_type) return 0;
2016 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002017 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
2018 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002019 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2,
2020 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002021 if (!state->alias_type) return 0;
2022 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002023 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
2024 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002025 state->withitem_type = make_type("withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002026 withitem_fields, 2,
2027 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002028 if (!state->withitem_type) return 0;
2029 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002030 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
2031 == -1)
2032 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002033 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0,
2034 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002035 if (!state->type_ignore_type) return 0;
2036 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
2037 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002038 TypeIgnore_fields, 2,
2039 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002040 if (!state->TypeIgnore_type) return 0;
2041 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002042 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002043}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002044
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002045static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2046static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
2047static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
2048static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
2049 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002050static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
2051static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
2052static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
2053static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
2054static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
2055 arena);
2056static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
2057 arena);
2058static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
2059static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
2060static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
2061static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002062static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002063static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
2064 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002065
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002066mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002067Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002068{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002069 mod_ty p;
2070 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2071 if (!p)
2072 return NULL;
2073 p->kind = Module_kind;
2074 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002075 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002076 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002077}
2078
2079mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002080Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002081{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002082 mod_ty p;
2083 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2084 if (!p)
2085 return NULL;
2086 p->kind = Interactive_kind;
2087 p->v.Interactive.body = body;
2088 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002089}
2090
2091mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002092Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002093{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002094 mod_ty p;
2095 if (!body) {
2096 PyErr_SetString(PyExc_ValueError,
2097 "field body is required for Expression");
2098 return NULL;
2099 }
2100 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2101 if (!p)
2102 return NULL;
2103 p->kind = Expression_kind;
2104 p->v.Expression.body = body;
2105 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002106}
2107
2108mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002109FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
2110{
2111 mod_ty p;
2112 if (!returns) {
2113 PyErr_SetString(PyExc_ValueError,
2114 "field returns is required for FunctionType");
2115 return NULL;
2116 }
2117 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2118 if (!p)
2119 return NULL;
2120 p->kind = FunctionType_kind;
2121 p->v.FunctionType.argtypes = argtypes;
2122 p->v.FunctionType.returns = returns;
2123 return p;
2124}
2125
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002126stmt_ty
2127FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002128 decorator_list, expr_ty returns, string type_comment, int lineno,
2129 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002130{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002131 stmt_ty p;
2132 if (!name) {
2133 PyErr_SetString(PyExc_ValueError,
2134 "field name is required for FunctionDef");
2135 return NULL;
2136 }
2137 if (!args) {
2138 PyErr_SetString(PyExc_ValueError,
2139 "field args is required for FunctionDef");
2140 return NULL;
2141 }
2142 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2143 if (!p)
2144 return NULL;
2145 p->kind = FunctionDef_kind;
2146 p->v.FunctionDef.name = name;
2147 p->v.FunctionDef.args = args;
2148 p->v.FunctionDef.body = body;
2149 p->v.FunctionDef.decorator_list = decorator_list;
2150 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002151 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002152 p->lineno = lineno;
2153 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002154 p->end_lineno = end_lineno;
2155 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002156 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002157}
2158
2159stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002160AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002161 * decorator_list, expr_ty returns, string type_comment, int
2162 lineno, int col_offset, int end_lineno, int end_col_offset,
2163 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002164{
2165 stmt_ty p;
2166 if (!name) {
2167 PyErr_SetString(PyExc_ValueError,
2168 "field name is required for AsyncFunctionDef");
2169 return NULL;
2170 }
2171 if (!args) {
2172 PyErr_SetString(PyExc_ValueError,
2173 "field args is required for AsyncFunctionDef");
2174 return NULL;
2175 }
2176 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2177 if (!p)
2178 return NULL;
2179 p->kind = AsyncFunctionDef_kind;
2180 p->v.AsyncFunctionDef.name = name;
2181 p->v.AsyncFunctionDef.args = args;
2182 p->v.AsyncFunctionDef.body = body;
2183 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2184 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002185 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002186 p->lineno = lineno;
2187 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002188 p->end_lineno = end_lineno;
2189 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002190 return p;
2191}
2192
2193stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002194ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002195 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2196 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002197{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002198 stmt_ty p;
2199 if (!name) {
2200 PyErr_SetString(PyExc_ValueError,
2201 "field name is required for ClassDef");
2202 return NULL;
2203 }
2204 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2205 if (!p)
2206 return NULL;
2207 p->kind = ClassDef_kind;
2208 p->v.ClassDef.name = name;
2209 p->v.ClassDef.bases = bases;
2210 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002211 p->v.ClassDef.body = body;
2212 p->v.ClassDef.decorator_list = decorator_list;
2213 p->lineno = lineno;
2214 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002215 p->end_lineno = end_lineno;
2216 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002217 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002218}
2219
2220stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002221Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2222 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002223{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002224 stmt_ty p;
2225 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2226 if (!p)
2227 return NULL;
2228 p->kind = Return_kind;
2229 p->v.Return.value = value;
2230 p->lineno = lineno;
2231 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002232 p->end_lineno = end_lineno;
2233 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002234 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002235}
2236
2237stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002238Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2239 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002240{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002241 stmt_ty p;
2242 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2243 if (!p)
2244 return NULL;
2245 p->kind = Delete_kind;
2246 p->v.Delete.targets = targets;
2247 p->lineno = lineno;
2248 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002249 p->end_lineno = end_lineno;
2250 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002251 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002252}
2253
2254stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002255Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2256 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002257{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002258 stmt_ty p;
2259 if (!value) {
2260 PyErr_SetString(PyExc_ValueError,
2261 "field value is required for Assign");
2262 return NULL;
2263 }
2264 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2265 if (!p)
2266 return NULL;
2267 p->kind = Assign_kind;
2268 p->v.Assign.targets = targets;
2269 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002270 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002271 p->lineno = lineno;
2272 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002273 p->end_lineno = end_lineno;
2274 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002275 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002276}
2277
2278stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002279AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002280 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002281{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002282 stmt_ty p;
2283 if (!target) {
2284 PyErr_SetString(PyExc_ValueError,
2285 "field target is required for AugAssign");
2286 return NULL;
2287 }
2288 if (!op) {
2289 PyErr_SetString(PyExc_ValueError,
2290 "field op is required for AugAssign");
2291 return NULL;
2292 }
2293 if (!value) {
2294 PyErr_SetString(PyExc_ValueError,
2295 "field value is required for AugAssign");
2296 return NULL;
2297 }
2298 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2299 if (!p)
2300 return NULL;
2301 p->kind = AugAssign_kind;
2302 p->v.AugAssign.target = target;
2303 p->v.AugAssign.op = op;
2304 p->v.AugAssign.value = value;
2305 p->lineno = lineno;
2306 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002307 p->end_lineno = end_lineno;
2308 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002309 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002310}
2311
2312stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002313AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002314 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2315 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002316{
2317 stmt_ty p;
2318 if (!target) {
2319 PyErr_SetString(PyExc_ValueError,
2320 "field target is required for AnnAssign");
2321 return NULL;
2322 }
2323 if (!annotation) {
2324 PyErr_SetString(PyExc_ValueError,
2325 "field annotation is required for AnnAssign");
2326 return NULL;
2327 }
2328 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2329 if (!p)
2330 return NULL;
2331 p->kind = AnnAssign_kind;
2332 p->v.AnnAssign.target = target;
2333 p->v.AnnAssign.annotation = annotation;
2334 p->v.AnnAssign.value = value;
2335 p->v.AnnAssign.simple = simple;
2336 p->lineno = lineno;
2337 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002338 p->end_lineno = end_lineno;
2339 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002340 return p;
2341}
2342
2343stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002344For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2345 type_comment, int lineno, int col_offset, int end_lineno, int
2346 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002347{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002348 stmt_ty p;
2349 if (!target) {
2350 PyErr_SetString(PyExc_ValueError,
2351 "field target is required for For");
2352 return NULL;
2353 }
2354 if (!iter) {
2355 PyErr_SetString(PyExc_ValueError,
2356 "field iter is required for For");
2357 return NULL;
2358 }
2359 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2360 if (!p)
2361 return NULL;
2362 p->kind = For_kind;
2363 p->v.For.target = target;
2364 p->v.For.iter = iter;
2365 p->v.For.body = body;
2366 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002367 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002368 p->lineno = lineno;
2369 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002370 p->end_lineno = end_lineno;
2371 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002372 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002373}
2374
2375stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002376AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2377 string type_comment, int lineno, int col_offset, int end_lineno, int
2378 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002379{
2380 stmt_ty p;
2381 if (!target) {
2382 PyErr_SetString(PyExc_ValueError,
2383 "field target is required for AsyncFor");
2384 return NULL;
2385 }
2386 if (!iter) {
2387 PyErr_SetString(PyExc_ValueError,
2388 "field iter is required for AsyncFor");
2389 return NULL;
2390 }
2391 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2392 if (!p)
2393 return NULL;
2394 p->kind = AsyncFor_kind;
2395 p->v.AsyncFor.target = target;
2396 p->v.AsyncFor.iter = iter;
2397 p->v.AsyncFor.body = body;
2398 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002399 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002400 p->lineno = lineno;
2401 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002402 p->end_lineno = end_lineno;
2403 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002404 return p;
2405}
2406
2407stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002408While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002409 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002410{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002411 stmt_ty p;
2412 if (!test) {
2413 PyErr_SetString(PyExc_ValueError,
2414 "field test is required for While");
2415 return NULL;
2416 }
2417 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2418 if (!p)
2419 return NULL;
2420 p->kind = While_kind;
2421 p->v.While.test = test;
2422 p->v.While.body = body;
2423 p->v.While.orelse = orelse;
2424 p->lineno = lineno;
2425 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002426 p->end_lineno = end_lineno;
2427 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002428 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002429}
2430
2431stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002432If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002433 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002434{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002435 stmt_ty p;
2436 if (!test) {
2437 PyErr_SetString(PyExc_ValueError,
2438 "field test is required for If");
2439 return NULL;
2440 }
2441 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2442 if (!p)
2443 return NULL;
2444 p->kind = If_kind;
2445 p->v.If.test = test;
2446 p->v.If.body = body;
2447 p->v.If.orelse = orelse;
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
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002456With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2457 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +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 = With_kind;
2464 p->v.With.items = items;
2465 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002466 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002467 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;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002472}
2473
2474stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002475AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2476 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002477{
2478 stmt_ty p;
2479 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2480 if (!p)
2481 return NULL;
2482 p->kind = AsyncWith_kind;
2483 p->v.AsyncWith.items = items;
2484 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002485 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002486 p->lineno = lineno;
2487 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002488 p->end_lineno = end_lineno;
2489 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002490 return p;
2491}
2492
2493stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002494Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2495 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002497 stmt_ty p;
2498 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2499 if (!p)
2500 return NULL;
2501 p->kind = Raise_kind;
2502 p->v.Raise.exc = exc;
2503 p->v.Raise.cause = cause;
2504 p->lineno = lineno;
2505 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002506 p->end_lineno = end_lineno;
2507 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002508 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002509}
2510
2511stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002512Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002513 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2514 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002515{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002516 stmt_ty p;
2517 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2518 if (!p)
2519 return NULL;
2520 p->kind = Try_kind;
2521 p->v.Try.body = body;
2522 p->v.Try.handlers = handlers;
2523 p->v.Try.orelse = orelse;
2524 p->v.Try.finalbody = finalbody;
2525 p->lineno = lineno;
2526 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002527 p->end_lineno = end_lineno;
2528 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002529 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002530}
2531
2532stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002533Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2534 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002535{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002536 stmt_ty p;
2537 if (!test) {
2538 PyErr_SetString(PyExc_ValueError,
2539 "field test is required for Assert");
2540 return NULL;
2541 }
2542 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2543 if (!p)
2544 return NULL;
2545 p->kind = Assert_kind;
2546 p->v.Assert.test = test;
2547 p->v.Assert.msg = msg;
2548 p->lineno = lineno;
2549 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002550 p->end_lineno = end_lineno;
2551 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002552 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002553}
2554
2555stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002556Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2557 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002558{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002559 stmt_ty p;
2560 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2561 if (!p)
2562 return NULL;
2563 p->kind = Import_kind;
2564 p->v.Import.names = names;
2565 p->lineno = lineno;
2566 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002567 p->end_lineno = end_lineno;
2568 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002569 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002570}
2571
2572stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002573ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002574 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002575{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002576 stmt_ty p;
2577 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2578 if (!p)
2579 return NULL;
2580 p->kind = ImportFrom_kind;
2581 p->v.ImportFrom.module = module;
2582 p->v.ImportFrom.names = names;
2583 p->v.ImportFrom.level = level;
2584 p->lineno = lineno;
2585 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002586 p->end_lineno = end_lineno;
2587 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002588 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002589}
2590
2591stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002592Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2593 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002594{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002595 stmt_ty p;
2596 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2597 if (!p)
2598 return NULL;
2599 p->kind = Global_kind;
2600 p->v.Global.names = names;
2601 p->lineno = lineno;
2602 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002603 p->end_lineno = end_lineno;
2604 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002605 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002606}
2607
2608stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002609Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2610 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002611{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002612 stmt_ty p;
2613 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2614 if (!p)
2615 return NULL;
2616 p->kind = Nonlocal_kind;
2617 p->v.Nonlocal.names = names;
2618 p->lineno = lineno;
2619 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002620 p->end_lineno = end_lineno;
2621 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002622 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002623}
2624
2625stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002626Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2627 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002628{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002629 stmt_ty p;
2630 if (!value) {
2631 PyErr_SetString(PyExc_ValueError,
2632 "field value is required for Expr");
2633 return NULL;
2634 }
2635 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2636 if (!p)
2637 return NULL;
2638 p->kind = Expr_kind;
2639 p->v.Expr.value = value;
2640 p->lineno = lineno;
2641 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002642 p->end_lineno = end_lineno;
2643 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002644 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002645}
2646
2647stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002648Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2649 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002650{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002651 stmt_ty p;
2652 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2653 if (!p)
2654 return NULL;
2655 p->kind = Pass_kind;
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
2663stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002664Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2665 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002666{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002667 stmt_ty p;
2668 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2669 if (!p)
2670 return NULL;
2671 p->kind = Break_kind;
2672 p->lineno = lineno;
2673 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002674 p->end_lineno = end_lineno;
2675 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002676 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002677}
2678
2679stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002680Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2681 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002682{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002683 stmt_ty p;
2684 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2685 if (!p)
2686 return NULL;
2687 p->kind = Continue_kind;
2688 p->lineno = lineno;
2689 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002690 p->end_lineno = end_lineno;
2691 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002692 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002693}
2694
2695expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002696BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2697 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002698{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002699 expr_ty p;
2700 if (!op) {
2701 PyErr_SetString(PyExc_ValueError,
2702 "field op is required for BoolOp");
2703 return NULL;
2704 }
2705 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2706 if (!p)
2707 return NULL;
2708 p->kind = BoolOp_kind;
2709 p->v.BoolOp.op = op;
2710 p->v.BoolOp.values = values;
2711 p->lineno = lineno;
2712 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002713 p->end_lineno = end_lineno;
2714 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002715 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002716}
2717
2718expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002719NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2720 end_lineno, int end_col_offset, PyArena *arena)
2721{
2722 expr_ty p;
2723 if (!target) {
2724 PyErr_SetString(PyExc_ValueError,
2725 "field target is required for NamedExpr");
2726 return NULL;
2727 }
2728 if (!value) {
2729 PyErr_SetString(PyExc_ValueError,
2730 "field value is required for NamedExpr");
2731 return NULL;
2732 }
2733 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2734 if (!p)
2735 return NULL;
2736 p->kind = NamedExpr_kind;
2737 p->v.NamedExpr.target = target;
2738 p->v.NamedExpr.value = value;
2739 p->lineno = lineno;
2740 p->col_offset = col_offset;
2741 p->end_lineno = end_lineno;
2742 p->end_col_offset = end_col_offset;
2743 return p;
2744}
2745
2746expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002747BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002748 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002749{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002750 expr_ty p;
2751 if (!left) {
2752 PyErr_SetString(PyExc_ValueError,
2753 "field left is required for BinOp");
2754 return NULL;
2755 }
2756 if (!op) {
2757 PyErr_SetString(PyExc_ValueError,
2758 "field op is required for BinOp");
2759 return NULL;
2760 }
2761 if (!right) {
2762 PyErr_SetString(PyExc_ValueError,
2763 "field right is required for BinOp");
2764 return NULL;
2765 }
2766 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2767 if (!p)
2768 return NULL;
2769 p->kind = BinOp_kind;
2770 p->v.BinOp.left = left;
2771 p->v.BinOp.op = op;
2772 p->v.BinOp.right = right;
2773 p->lineno = lineno;
2774 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002775 p->end_lineno = end_lineno;
2776 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002777 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002778}
2779
2780expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002781UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2782 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002783{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002784 expr_ty p;
2785 if (!op) {
2786 PyErr_SetString(PyExc_ValueError,
2787 "field op is required for UnaryOp");
2788 return NULL;
2789 }
2790 if (!operand) {
2791 PyErr_SetString(PyExc_ValueError,
2792 "field operand is required for UnaryOp");
2793 return NULL;
2794 }
2795 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2796 if (!p)
2797 return NULL;
2798 p->kind = UnaryOp_kind;
2799 p->v.UnaryOp.op = op;
2800 p->v.UnaryOp.operand = operand;
2801 p->lineno = lineno;
2802 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002803 p->end_lineno = end_lineno;
2804 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002805 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002806}
2807
2808expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002809Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2810 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002811{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002812 expr_ty p;
2813 if (!args) {
2814 PyErr_SetString(PyExc_ValueError,
2815 "field args is required for Lambda");
2816 return NULL;
2817 }
2818 if (!body) {
2819 PyErr_SetString(PyExc_ValueError,
2820 "field body is required for Lambda");
2821 return NULL;
2822 }
2823 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2824 if (!p)
2825 return NULL;
2826 p->kind = Lambda_kind;
2827 p->v.Lambda.args = args;
2828 p->v.Lambda.body = body;
2829 p->lineno = lineno;
2830 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002831 p->end_lineno = end_lineno;
2832 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002833 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002834}
2835
2836expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002837IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002838 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002839{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002840 expr_ty p;
2841 if (!test) {
2842 PyErr_SetString(PyExc_ValueError,
2843 "field test is required for IfExp");
2844 return NULL;
2845 }
2846 if (!body) {
2847 PyErr_SetString(PyExc_ValueError,
2848 "field body is required for IfExp");
2849 return NULL;
2850 }
2851 if (!orelse) {
2852 PyErr_SetString(PyExc_ValueError,
2853 "field orelse is required for IfExp");
2854 return NULL;
2855 }
2856 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2857 if (!p)
2858 return NULL;
2859 p->kind = IfExp_kind;
2860 p->v.IfExp.test = test;
2861 p->v.IfExp.body = body;
2862 p->v.IfExp.orelse = orelse;
2863 p->lineno = lineno;
2864 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002865 p->end_lineno = end_lineno;
2866 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002867 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002868}
2869
2870expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002871Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2872 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002873{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002874 expr_ty p;
2875 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2876 if (!p)
2877 return NULL;
2878 p->kind = Dict_kind;
2879 p->v.Dict.keys = keys;
2880 p->v.Dict.values = values;
2881 p->lineno = lineno;
2882 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002883 p->end_lineno = end_lineno;
2884 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002885 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002886}
2887
2888expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002889Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2890 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002891{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002892 expr_ty p;
2893 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2894 if (!p)
2895 return NULL;
2896 p->kind = Set_kind;
2897 p->v.Set.elts = elts;
2898 p->lineno = lineno;
2899 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002900 p->end_lineno = end_lineno;
2901 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002902 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002903}
2904
2905expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002906ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2907 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002908{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002909 expr_ty p;
2910 if (!elt) {
2911 PyErr_SetString(PyExc_ValueError,
2912 "field elt is required for ListComp");
2913 return NULL;
2914 }
2915 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2916 if (!p)
2917 return NULL;
2918 p->kind = ListComp_kind;
2919 p->v.ListComp.elt = elt;
2920 p->v.ListComp.generators = generators;
2921 p->lineno = lineno;
2922 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002923 p->end_lineno = end_lineno;
2924 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002925 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002926}
2927
2928expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002929SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2930 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002931{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002932 expr_ty p;
2933 if (!elt) {
2934 PyErr_SetString(PyExc_ValueError,
2935 "field elt is required for SetComp");
2936 return NULL;
2937 }
2938 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2939 if (!p)
2940 return NULL;
2941 p->kind = SetComp_kind;
2942 p->v.SetComp.elt = elt;
2943 p->v.SetComp.generators = generators;
2944 p->lineno = lineno;
2945 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002946 p->end_lineno = end_lineno;
2947 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002948 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002949}
2950
2951expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002952DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002953 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002954{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002955 expr_ty p;
2956 if (!key) {
2957 PyErr_SetString(PyExc_ValueError,
2958 "field key is required for DictComp");
2959 return NULL;
2960 }
2961 if (!value) {
2962 PyErr_SetString(PyExc_ValueError,
2963 "field value is required for DictComp");
2964 return NULL;
2965 }
2966 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2967 if (!p)
2968 return NULL;
2969 p->kind = DictComp_kind;
2970 p->v.DictComp.key = key;
2971 p->v.DictComp.value = value;
2972 p->v.DictComp.generators = generators;
2973 p->lineno = lineno;
2974 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002975 p->end_lineno = end_lineno;
2976 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002977 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002978}
2979
2980expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002981GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002982 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002983{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002984 expr_ty p;
2985 if (!elt) {
2986 PyErr_SetString(PyExc_ValueError,
2987 "field elt is required for GeneratorExp");
2988 return NULL;
2989 }
2990 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2991 if (!p)
2992 return NULL;
2993 p->kind = GeneratorExp_kind;
2994 p->v.GeneratorExp.elt = elt;
2995 p->v.GeneratorExp.generators = generators;
2996 p->lineno = lineno;
2997 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002998 p->end_lineno = end_lineno;
2999 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003000 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003001}
3002
3003expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003004Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
3005 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04003006{
3007 expr_ty p;
3008 if (!value) {
3009 PyErr_SetString(PyExc_ValueError,
3010 "field value is required for Await");
3011 return NULL;
3012 }
3013 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3014 if (!p)
3015 return NULL;
3016 p->kind = Await_kind;
3017 p->v.Await.value = value;
3018 p->lineno = lineno;
3019 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003020 p->end_lineno = end_lineno;
3021 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04003022 return p;
3023}
3024
3025expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003026Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
3027 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003028{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003029 expr_ty p;
3030 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3031 if (!p)
3032 return NULL;
3033 p->kind = Yield_kind;
3034 p->v.Yield.value = value;
3035 p->lineno = lineno;
3036 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003037 p->end_lineno = end_lineno;
3038 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003039 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003040}
3041
3042expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003043YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3044 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05003045{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003046 expr_ty p;
3047 if (!value) {
3048 PyErr_SetString(PyExc_ValueError,
3049 "field value is required for YieldFrom");
3050 return NULL;
3051 }
3052 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3053 if (!p)
3054 return NULL;
3055 p->kind = YieldFrom_kind;
3056 p->v.YieldFrom.value = value;
3057 p->lineno = lineno;
3058 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003059 p->end_lineno = end_lineno;
3060 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003061 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05003062}
3063
3064expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003065Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003066 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003067{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003068 expr_ty p;
3069 if (!left) {
3070 PyErr_SetString(PyExc_ValueError,
3071 "field left is required for Compare");
3072 return NULL;
3073 }
3074 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3075 if (!p)
3076 return NULL;
3077 p->kind = Compare_kind;
3078 p->v.Compare.left = left;
3079 p->v.Compare.ops = ops;
3080 p->v.Compare.comparators = comparators;
3081 p->lineno = lineno;
3082 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003083 p->end_lineno = end_lineno;
3084 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003085 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003086}
3087
3088expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04003089Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003090 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003091{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003092 expr_ty p;
3093 if (!func) {
3094 PyErr_SetString(PyExc_ValueError,
3095 "field func is required for Call");
3096 return NULL;
3097 }
3098 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3099 if (!p)
3100 return NULL;
3101 p->kind = Call_kind;
3102 p->v.Call.func = func;
3103 p->v.Call.args = args;
3104 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003105 p->lineno = lineno;
3106 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003107 p->end_lineno = end_lineno;
3108 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003109 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003110}
3111
3112expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04003113FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
3114 int col_offset, int end_lineno, int end_col_offset, PyArena
3115 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003116{
3117 expr_ty p;
3118 if (!value) {
3119 PyErr_SetString(PyExc_ValueError,
3120 "field value is required for FormattedValue");
3121 return NULL;
3122 }
3123 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3124 if (!p)
3125 return NULL;
3126 p->kind = FormattedValue_kind;
3127 p->v.FormattedValue.value = value;
3128 p->v.FormattedValue.conversion = conversion;
3129 p->v.FormattedValue.format_spec = format_spec;
3130 p->lineno = lineno;
3131 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003132 p->end_lineno = end_lineno;
3133 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003134 return p;
3135}
3136
3137expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003138JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3139 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003140{
3141 expr_ty p;
3142 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3143 if (!p)
3144 return NULL;
3145 p->kind = JoinedStr_kind;
3146 p->v.JoinedStr.values = values;
3147 p->lineno = lineno;
3148 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003149 p->end_lineno = end_lineno;
3150 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003151 return p;
3152}
3153
3154expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003155Constant(constant value, string kind, int lineno, int col_offset, int
3156 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003157{
3158 expr_ty p;
3159 if (!value) {
3160 PyErr_SetString(PyExc_ValueError,
3161 "field value is required for Constant");
3162 return NULL;
3163 }
3164 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3165 if (!p)
3166 return NULL;
3167 p->kind = Constant_kind;
3168 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003169 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003170 p->lineno = lineno;
3171 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003172 p->end_lineno = end_lineno;
3173 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003174 return p;
3175}
3176
3177expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003178Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003179 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003180{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003181 expr_ty p;
3182 if (!value) {
3183 PyErr_SetString(PyExc_ValueError,
3184 "field value is required for Attribute");
3185 return NULL;
3186 }
3187 if (!attr) {
3188 PyErr_SetString(PyExc_ValueError,
3189 "field attr is required for Attribute");
3190 return NULL;
3191 }
3192 if (!ctx) {
3193 PyErr_SetString(PyExc_ValueError,
3194 "field ctx is required for Attribute");
3195 return NULL;
3196 }
3197 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3198 if (!p)
3199 return NULL;
3200 p->kind = Attribute_kind;
3201 p->v.Attribute.value = value;
3202 p->v.Attribute.attr = attr;
3203 p->v.Attribute.ctx = ctx;
3204 p->lineno = lineno;
3205 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003206 p->end_lineno = end_lineno;
3207 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003208 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003209}
3210
3211expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003212Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003213 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003214{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003215 expr_ty p;
3216 if (!value) {
3217 PyErr_SetString(PyExc_ValueError,
3218 "field value is required for Subscript");
3219 return NULL;
3220 }
3221 if (!slice) {
3222 PyErr_SetString(PyExc_ValueError,
3223 "field slice is required for Subscript");
3224 return NULL;
3225 }
3226 if (!ctx) {
3227 PyErr_SetString(PyExc_ValueError,
3228 "field ctx is required for Subscript");
3229 return NULL;
3230 }
3231 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3232 if (!p)
3233 return NULL;
3234 p->kind = Subscript_kind;
3235 p->v.Subscript.value = value;
3236 p->v.Subscript.slice = slice;
3237 p->v.Subscript.ctx = ctx;
3238 p->lineno = lineno;
3239 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003240 p->end_lineno = end_lineno;
3241 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003242 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003243}
3244
3245expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003246Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3247 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003248{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003249 expr_ty p;
3250 if (!value) {
3251 PyErr_SetString(PyExc_ValueError,
3252 "field value is required for Starred");
3253 return NULL;
3254 }
3255 if (!ctx) {
3256 PyErr_SetString(PyExc_ValueError,
3257 "field ctx is required for Starred");
3258 return NULL;
3259 }
3260 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3261 if (!p)
3262 return NULL;
3263 p->kind = Starred_kind;
3264 p->v.Starred.value = value;
3265 p->v.Starred.ctx = ctx;
3266 p->lineno = lineno;
3267 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003268 p->end_lineno = end_lineno;
3269 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003270 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003271}
3272
3273expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003274Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3275 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003276{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003277 expr_ty p;
3278 if (!id) {
3279 PyErr_SetString(PyExc_ValueError,
3280 "field id is required for Name");
3281 return NULL;
3282 }
3283 if (!ctx) {
3284 PyErr_SetString(PyExc_ValueError,
3285 "field ctx is required for Name");
3286 return NULL;
3287 }
3288 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3289 if (!p)
3290 return NULL;
3291 p->kind = Name_kind;
3292 p->v.Name.id = id;
3293 p->v.Name.ctx = ctx;
3294 p->lineno = lineno;
3295 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003296 p->end_lineno = end_lineno;
3297 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003298 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003299}
3300
3301expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003302List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3303 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003304{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003305 expr_ty p;
3306 if (!ctx) {
3307 PyErr_SetString(PyExc_ValueError,
3308 "field ctx is required for List");
3309 return NULL;
3310 }
3311 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3312 if (!p)
3313 return NULL;
3314 p->kind = List_kind;
3315 p->v.List.elts = elts;
3316 p->v.List.ctx = ctx;
3317 p->lineno = lineno;
3318 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003319 p->end_lineno = end_lineno;
3320 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003321 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003322}
3323
3324expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003325Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3326 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003327{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003328 expr_ty p;
3329 if (!ctx) {
3330 PyErr_SetString(PyExc_ValueError,
3331 "field ctx is required for Tuple");
3332 return NULL;
3333 }
3334 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3335 if (!p)
3336 return NULL;
3337 p->kind = Tuple_kind;
3338 p->v.Tuple.elts = elts;
3339 p->v.Tuple.ctx = ctx;
3340 p->lineno = lineno;
3341 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003342 p->end_lineno = end_lineno;
3343 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003344 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003345}
3346
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003347expr_ty
3348Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3349 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003350{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003351 expr_ty p;
3352 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003353 if (!p)
3354 return NULL;
3355 p->kind = Slice_kind;
3356 p->v.Slice.lower = lower;
3357 p->v.Slice.upper = upper;
3358 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003359 p->lineno = lineno;
3360 p->col_offset = col_offset;
3361 p->end_lineno = end_lineno;
3362 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003363 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003364}
3365
3366comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003367comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3368 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003369{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003370 comprehension_ty p;
3371 if (!target) {
3372 PyErr_SetString(PyExc_ValueError,
3373 "field target is required for comprehension");
3374 return NULL;
3375 }
3376 if (!iter) {
3377 PyErr_SetString(PyExc_ValueError,
3378 "field iter is required for comprehension");
3379 return NULL;
3380 }
3381 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3382 if (!p)
3383 return NULL;
3384 p->target = target;
3385 p->iter = iter;
3386 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003387 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003388 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003389}
3390
3391excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003392ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003393 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003394{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003395 excepthandler_ty p;
3396 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3397 if (!p)
3398 return NULL;
3399 p->kind = ExceptHandler_kind;
3400 p->v.ExceptHandler.type = type;
3401 p->v.ExceptHandler.name = name;
3402 p->v.ExceptHandler.body = body;
3403 p->lineno = lineno;
3404 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003405 p->end_lineno = end_lineno;
3406 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003407 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003408}
3409
3410arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003411arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003412 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3413 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003414{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003415 arguments_ty p;
3416 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3417 if (!p)
3418 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003419 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003420 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003421 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003422 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003423 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003424 p->kwarg = kwarg;
3425 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003426 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003427}
3428
Neal Norwitzc1505362006-12-28 06:47:50 +00003429arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003430arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3431 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003432{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003433 arg_ty p;
3434 if (!arg) {
3435 PyErr_SetString(PyExc_ValueError,
3436 "field arg is required for arg");
3437 return NULL;
3438 }
3439 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3440 if (!p)
3441 return NULL;
3442 p->arg = arg;
3443 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003444 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003445 p->lineno = lineno;
3446 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003447 p->end_lineno = end_lineno;
3448 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003449 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003450}
3451
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003452keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003453keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003454{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003455 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003456 if (!value) {
3457 PyErr_SetString(PyExc_ValueError,
3458 "field value is required for keyword");
3459 return NULL;
3460 }
3461 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3462 if (!p)
3463 return NULL;
3464 p->arg = arg;
3465 p->value = value;
3466 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003467}
3468
3469alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003470alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003471{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003472 alias_ty p;
3473 if (!name) {
3474 PyErr_SetString(PyExc_ValueError,
3475 "field name is required for alias");
3476 return NULL;
3477 }
3478 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3479 if (!p)
3480 return NULL;
3481 p->name = name;
3482 p->asname = asname;
3483 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003484}
3485
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003486withitem_ty
3487withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3488{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003489 withitem_ty p;
3490 if (!context_expr) {
3491 PyErr_SetString(PyExc_ValueError,
3492 "field context_expr is required for withitem");
3493 return NULL;
3494 }
3495 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3496 if (!p)
3497 return NULL;
3498 p->context_expr = context_expr;
3499 p->optional_vars = optional_vars;
3500 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003501}
3502
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003503type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003504TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003505{
3506 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003507 if (!tag) {
3508 PyErr_SetString(PyExc_ValueError,
3509 "field tag is required for TypeIgnore");
3510 return NULL;
3511 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003512 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3513 if (!p)
3514 return NULL;
3515 p->kind = TypeIgnore_kind;
3516 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003517 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003518 return p;
3519}
3520
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003521
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003522PyObject*
3523ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003524{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003525 mod_ty o = (mod_ty)_o;
3526 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003527 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003528 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003529 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003530 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003531
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003532 switch (o->kind) {
3533 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003534 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3535 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003536 if (!result) goto failed;
3537 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3538 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003539 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003540 goto failed;
3541 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003542 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3543 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003544 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3545 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003546 goto failed;
3547 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003548 break;
3549 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003550 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3551 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003552 if (!result) goto failed;
3553 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3554 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003555 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003556 goto failed;
3557 Py_DECREF(value);
3558 break;
3559 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003560 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3561 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003562 if (!result) goto failed;
3563 value = ast2obj_expr(o->v.Expression.body);
3564 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003565 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003566 goto failed;
3567 Py_DECREF(value);
3568 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003569 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003570 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3571 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003572 if (!result) goto failed;
3573 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3574 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003575 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3576 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003577 goto failed;
3578 Py_DECREF(value);
3579 value = ast2obj_expr(o->v.FunctionType.returns);
3580 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003581 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3582 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003583 goto failed;
3584 Py_DECREF(value);
3585 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003586 }
3587 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003588failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003589 Py_XDECREF(value);
3590 Py_XDECREF(result);
3591 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003592}
3593
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003594PyObject*
3595ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003596{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003597 stmt_ty o = (stmt_ty)_o;
3598 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003599 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003600 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003601 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003602 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003603
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003604 switch (o->kind) {
3605 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003606 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3607 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003608 if (!result) goto failed;
3609 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003610 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003611 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003612 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003613 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003615 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003616 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003617 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003618 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003619 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3620 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003621 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003622 goto failed;
3623 Py_DECREF(value);
3624 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3625 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003626 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3627 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003628 goto failed;
3629 Py_DECREF(value);
3630 value = ast2obj_expr(o->v.FunctionDef.returns);
3631 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003632 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3633 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003634 goto failed;
3635 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003636 value = ast2obj_string(o->v.FunctionDef.type_comment);
3637 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003638 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3639 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003640 goto failed;
3641 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003642 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003643 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003644 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3645 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003646 if (!result) goto failed;
3647 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3648 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003649 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003650 goto failed;
3651 Py_DECREF(value);
3652 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3653 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003654 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003655 goto failed;
3656 Py_DECREF(value);
3657 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3658 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003659 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003660 goto failed;
3661 Py_DECREF(value);
3662 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3663 ast2obj_expr);
3664 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003665 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3666 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003667 goto failed;
3668 Py_DECREF(value);
3669 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3670 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003671 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3672 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003673 goto failed;
3674 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003675 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3676 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003677 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3678 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003679 goto failed;
3680 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003681 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003682 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003683 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3684 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003685 if (!result) goto failed;
3686 value = ast2obj_identifier(o->v.ClassDef.name);
3687 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003688 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003689 goto failed;
3690 Py_DECREF(value);
3691 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3692 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003693 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003694 goto failed;
3695 Py_DECREF(value);
3696 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3697 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003698 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3699 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003700 goto failed;
3701 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003702 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3703 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003704 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003705 goto failed;
3706 Py_DECREF(value);
3707 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3708 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003709 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3710 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003711 goto failed;
3712 Py_DECREF(value);
3713 break;
3714 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003715 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3716 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003717 if (!result) goto failed;
3718 value = ast2obj_expr(o->v.Return.value);
3719 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003720 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003721 goto failed;
3722 Py_DECREF(value);
3723 break;
3724 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003725 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3726 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003727 if (!result) goto failed;
3728 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3729 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003730 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3731 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003732 goto failed;
3733 Py_DECREF(value);
3734 break;
3735 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003736 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3737 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003738 if (!result) goto failed;
3739 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3740 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003741 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3742 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003743 goto failed;
3744 Py_DECREF(value);
3745 value = ast2obj_expr(o->v.Assign.value);
3746 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003747 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003748 goto failed;
3749 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003750 value = ast2obj_string(o->v.Assign.type_comment);
3751 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003752 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3753 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003754 goto failed;
3755 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003756 break;
3757 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003758 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3759 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003760 if (!result) goto failed;
3761 value = ast2obj_expr(o->v.AugAssign.target);
3762 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003763 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3764 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003765 goto failed;
3766 Py_DECREF(value);
3767 value = ast2obj_operator(o->v.AugAssign.op);
3768 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003769 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003770 goto failed;
3771 Py_DECREF(value);
3772 value = ast2obj_expr(o->v.AugAssign.value);
3773 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003774 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003775 goto failed;
3776 Py_DECREF(value);
3777 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003778 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003779 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3780 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003781 if (!result) goto failed;
3782 value = ast2obj_expr(o->v.AnnAssign.target);
3783 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003784 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3785 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003786 goto failed;
3787 Py_DECREF(value);
3788 value = ast2obj_expr(o->v.AnnAssign.annotation);
3789 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003790 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3791 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003792 goto failed;
3793 Py_DECREF(value);
3794 value = ast2obj_expr(o->v.AnnAssign.value);
3795 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003796 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003797 goto failed;
3798 Py_DECREF(value);
3799 value = ast2obj_int(o->v.AnnAssign.simple);
3800 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003801 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3802 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003803 goto failed;
3804 Py_DECREF(value);
3805 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003806 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003807 tp = (PyTypeObject *)astmodulestate_global->For_type;
3808 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003809 if (!result) goto failed;
3810 value = ast2obj_expr(o->v.For.target);
3811 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003812 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3813 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003814 goto failed;
3815 Py_DECREF(value);
3816 value = ast2obj_expr(o->v.For.iter);
3817 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003818 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003819 goto failed;
3820 Py_DECREF(value);
3821 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003823 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003824 goto failed;
3825 Py_DECREF(value);
3826 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3827 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003828 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3829 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003830 goto failed;
3831 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003832 value = ast2obj_string(o->v.For.type_comment);
3833 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003834 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3835 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003836 goto failed;
3837 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003838 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003839 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003840 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3841 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003842 if (!result) goto failed;
3843 value = ast2obj_expr(o->v.AsyncFor.target);
3844 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003845 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3846 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003847 goto failed;
3848 Py_DECREF(value);
3849 value = ast2obj_expr(o->v.AsyncFor.iter);
3850 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003851 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003852 goto failed;
3853 Py_DECREF(value);
3854 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3855 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003856 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003857 goto failed;
3858 Py_DECREF(value);
3859 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3860 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003861 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3862 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003863 goto failed;
3864 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003865 value = ast2obj_string(o->v.AsyncFor.type_comment);
3866 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003867 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3868 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003869 goto failed;
3870 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003871 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003872 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003873 tp = (PyTypeObject *)astmodulestate_global->While_type;
3874 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003875 if (!result) goto failed;
3876 value = ast2obj_expr(o->v.While.test);
3877 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003878 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003879 goto failed;
3880 Py_DECREF(value);
3881 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3882 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003883 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003884 goto failed;
3885 Py_DECREF(value);
3886 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3887 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003888 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3889 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003890 goto failed;
3891 Py_DECREF(value);
3892 break;
3893 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003894 tp = (PyTypeObject *)astmodulestate_global->If_type;
3895 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003896 if (!result) goto failed;
3897 value = ast2obj_expr(o->v.If.test);
3898 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003899 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003900 goto failed;
3901 Py_DECREF(value);
3902 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3903 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003904 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003905 goto failed;
3906 Py_DECREF(value);
3907 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3908 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003909 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3910 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003911 goto failed;
3912 Py_DECREF(value);
3913 break;
3914 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003915 tp = (PyTypeObject *)astmodulestate_global->With_type;
3916 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003917 if (!result) goto failed;
3918 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3919 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003920 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003921 goto failed;
3922 Py_DECREF(value);
3923 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3924 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003925 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003926 goto failed;
3927 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003928 value = ast2obj_string(o->v.With.type_comment);
3929 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003930 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3931 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003932 goto failed;
3933 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003934 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003935 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003936 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3937 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003938 if (!result) goto failed;
3939 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3940 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003941 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003942 goto failed;
3943 Py_DECREF(value);
3944 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3945 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003946 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003947 goto failed;
3948 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003949 value = ast2obj_string(o->v.AsyncWith.type_comment);
3950 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003951 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3952 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003953 goto failed;
3954 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003955 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003956 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003957 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3958 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003959 if (!result) goto failed;
3960 value = ast2obj_expr(o->v.Raise.exc);
3961 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003962 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003963 goto failed;
3964 Py_DECREF(value);
3965 value = ast2obj_expr(o->v.Raise.cause);
3966 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003967 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 goto failed;
3969 Py_DECREF(value);
3970 break;
3971 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003972 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3973 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003974 if (!result) goto failed;
3975 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3976 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003977 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003978 goto failed;
3979 Py_DECREF(value);
3980 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3981 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003982 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3983 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003984 goto failed;
3985 Py_DECREF(value);
3986 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3987 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003988 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3989 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003990 goto failed;
3991 Py_DECREF(value);
3992 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3993 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003994 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3995 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003996 goto failed;
3997 Py_DECREF(value);
3998 break;
3999 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004000 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
4001 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004002 if (!result) goto failed;
4003 value = ast2obj_expr(o->v.Assert.test);
4004 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004005 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004006 goto failed;
4007 Py_DECREF(value);
4008 value = ast2obj_expr(o->v.Assert.msg);
4009 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004010 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004011 goto failed;
4012 Py_DECREF(value);
4013 break;
4014 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004015 tp = (PyTypeObject *)astmodulestate_global->Import_type;
4016 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004017 if (!result) goto failed;
4018 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
4019 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004020 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004021 goto failed;
4022 Py_DECREF(value);
4023 break;
4024 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004025 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
4026 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004027 if (!result) goto failed;
4028 value = ast2obj_identifier(o->v.ImportFrom.module);
4029 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004030 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
4031 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004032 goto failed;
4033 Py_DECREF(value);
4034 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
4035 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004036 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004037 goto failed;
4038 Py_DECREF(value);
4039 value = ast2obj_int(o->v.ImportFrom.level);
4040 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004041 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004042 goto failed;
4043 Py_DECREF(value);
4044 break;
4045 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004046 tp = (PyTypeObject *)astmodulestate_global->Global_type;
4047 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004048 if (!result) goto failed;
4049 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
4050 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004051 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004052 goto failed;
4053 Py_DECREF(value);
4054 break;
4055 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004056 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
4057 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004058 if (!result) goto failed;
4059 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
4060 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004061 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004062 goto failed;
4063 Py_DECREF(value);
4064 break;
4065 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004066 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
4067 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004068 if (!result) goto failed;
4069 value = ast2obj_expr(o->v.Expr.value);
4070 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004071 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004072 goto failed;
4073 Py_DECREF(value);
4074 break;
4075 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004076 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
4077 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004078 if (!result) goto failed;
4079 break;
4080 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004081 tp = (PyTypeObject *)astmodulestate_global->Break_type;
4082 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004083 if (!result) goto failed;
4084 break;
4085 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004086 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
4087 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004088 if (!result) goto failed;
4089 break;
4090 }
4091 value = ast2obj_int(o->lineno);
4092 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004093 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004094 goto failed;
4095 Py_DECREF(value);
4096 value = ast2obj_int(o->col_offset);
4097 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004098 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004099 goto failed;
4100 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004101 value = ast2obj_int(o->end_lineno);
4102 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004103 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004104 goto failed;
4105 Py_DECREF(value);
4106 value = ast2obj_int(o->end_col_offset);
4107 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004108 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4109 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004110 goto failed;
4111 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004112 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004113failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004114 Py_XDECREF(value);
4115 Py_XDECREF(result);
4116 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004117}
4118
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004119PyObject*
4120ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004121{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004122 expr_ty o = (expr_ty)_o;
4123 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004124 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004125 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004126 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004127 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004128
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004129 switch (o->kind) {
4130 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004131 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4132 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004133 if (!result) goto failed;
4134 value = ast2obj_boolop(o->v.BoolOp.op);
4135 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004136 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004137 goto failed;
4138 Py_DECREF(value);
4139 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4140 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004141 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4142 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004143 goto failed;
4144 Py_DECREF(value);
4145 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004146 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004147 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4148 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004149 if (!result) goto failed;
4150 value = ast2obj_expr(o->v.NamedExpr.target);
4151 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004152 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4153 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004154 goto failed;
4155 Py_DECREF(value);
4156 value = ast2obj_expr(o->v.NamedExpr.value);
4157 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004158 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004159 goto failed;
4160 Py_DECREF(value);
4161 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004162 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004163 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4164 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004165 if (!result) goto failed;
4166 value = ast2obj_expr(o->v.BinOp.left);
4167 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004168 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004169 goto failed;
4170 Py_DECREF(value);
4171 value = ast2obj_operator(o->v.BinOp.op);
4172 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004173 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004174 goto failed;
4175 Py_DECREF(value);
4176 value = ast2obj_expr(o->v.BinOp.right);
4177 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004178 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004179 goto failed;
4180 Py_DECREF(value);
4181 break;
4182 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004183 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4184 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004185 if (!result) goto failed;
4186 value = ast2obj_unaryop(o->v.UnaryOp.op);
4187 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004188 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004189 goto failed;
4190 Py_DECREF(value);
4191 value = ast2obj_expr(o->v.UnaryOp.operand);
4192 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004193 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4194 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004195 goto failed;
4196 Py_DECREF(value);
4197 break;
4198 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004199 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4200 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004201 if (!result) goto failed;
4202 value = ast2obj_arguments(o->v.Lambda.args);
4203 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004204 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004205 goto failed;
4206 Py_DECREF(value);
4207 value = ast2obj_expr(o->v.Lambda.body);
4208 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004209 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004210 goto failed;
4211 Py_DECREF(value);
4212 break;
4213 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004214 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4215 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004216 if (!result) goto failed;
4217 value = ast2obj_expr(o->v.IfExp.test);
4218 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004219 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004220 goto failed;
4221 Py_DECREF(value);
4222 value = ast2obj_expr(o->v.IfExp.body);
4223 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004224 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004225 goto failed;
4226 Py_DECREF(value);
4227 value = ast2obj_expr(o->v.IfExp.orelse);
4228 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004229 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4230 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004231 goto failed;
4232 Py_DECREF(value);
4233 break;
4234 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004235 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4236 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004237 if (!result) goto failed;
4238 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4239 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004240 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004241 goto failed;
4242 Py_DECREF(value);
4243 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4244 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004245 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4246 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004247 goto failed;
4248 Py_DECREF(value);
4249 break;
4250 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004251 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4252 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004253 if (!result) goto failed;
4254 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4255 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004256 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004257 goto failed;
4258 Py_DECREF(value);
4259 break;
4260 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004261 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4262 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004263 if (!result) goto failed;
4264 value = ast2obj_expr(o->v.ListComp.elt);
4265 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004266 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004267 goto failed;
4268 Py_DECREF(value);
4269 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4270 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004271 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4272 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004273 goto failed;
4274 Py_DECREF(value);
4275 break;
4276 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004277 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4278 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004279 if (!result) goto failed;
4280 value = ast2obj_expr(o->v.SetComp.elt);
4281 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004282 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004283 goto failed;
4284 Py_DECREF(value);
4285 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4286 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004287 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4288 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004289 goto failed;
4290 Py_DECREF(value);
4291 break;
4292 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004293 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4294 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004295 if (!result) goto failed;
4296 value = ast2obj_expr(o->v.DictComp.key);
4297 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004298 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004299 goto failed;
4300 Py_DECREF(value);
4301 value = ast2obj_expr(o->v.DictComp.value);
4302 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004303 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004304 goto failed;
4305 Py_DECREF(value);
4306 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4307 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004308 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4309 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004310 goto failed;
4311 Py_DECREF(value);
4312 break;
4313 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004314 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4315 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004316 if (!result) goto failed;
4317 value = ast2obj_expr(o->v.GeneratorExp.elt);
4318 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004319 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004320 goto failed;
4321 Py_DECREF(value);
4322 value = ast2obj_list(o->v.GeneratorExp.generators,
4323 ast2obj_comprehension);
4324 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004325 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4326 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004327 goto failed;
4328 Py_DECREF(value);
4329 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004330 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004331 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4332 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004333 if (!result) goto failed;
4334 value = ast2obj_expr(o->v.Await.value);
4335 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004336 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004337 goto failed;
4338 Py_DECREF(value);
4339 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004340 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004341 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4342 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004343 if (!result) goto failed;
4344 value = ast2obj_expr(o->v.Yield.value);
4345 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004346 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004347 goto failed;
4348 Py_DECREF(value);
4349 break;
4350 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004351 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4352 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004353 if (!result) goto failed;
4354 value = ast2obj_expr(o->v.YieldFrom.value);
4355 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004356 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004357 goto failed;
4358 Py_DECREF(value);
4359 break;
4360 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004361 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4362 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004363 if (!result) goto failed;
4364 value = ast2obj_expr(o->v.Compare.left);
4365 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004366 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004367 goto failed;
4368 Py_DECREF(value);
4369 {
4370 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4371 value = PyList_New(n);
4372 if (!value) goto failed;
4373 for(i = 0; i < n; i++)
4374 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004375 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004376 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004377 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004378 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004379 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004380 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004381 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004382 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4383 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004384 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004385 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004386 break;
4387 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004388 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4389 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004390 if (!result) goto failed;
4391 value = ast2obj_expr(o->v.Call.func);
4392 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004393 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004394 goto failed;
4395 Py_DECREF(value);
4396 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4397 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004398 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004399 goto failed;
4400 Py_DECREF(value);
4401 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4402 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004403 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4404 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004405 goto failed;
4406 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004407 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004408 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004409 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4410 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004411 if (!result) goto failed;
4412 value = ast2obj_expr(o->v.FormattedValue.value);
4413 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004414 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004415 goto failed;
4416 Py_DECREF(value);
4417 value = ast2obj_int(o->v.FormattedValue.conversion);
4418 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004419 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4420 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004421 goto failed;
4422 Py_DECREF(value);
4423 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4424 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004425 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4426 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004427 goto failed;
4428 Py_DECREF(value);
4429 break;
4430 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004431 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4432 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004433 if (!result) goto failed;
4434 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4435 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004436 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4437 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004438 goto failed;
4439 Py_DECREF(value);
4440 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004441 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004442 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4443 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004444 if (!result) goto failed;
4445 value = ast2obj_constant(o->v.Constant.value);
4446 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004447 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004448 goto failed;
4449 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004450 value = ast2obj_string(o->v.Constant.kind);
4451 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004452 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004453 goto failed;
4454 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004455 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004456 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004457 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4458 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004459 if (!result) goto failed;
4460 value = ast2obj_expr(o->v.Attribute.value);
4461 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004462 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004463 goto failed;
4464 Py_DECREF(value);
4465 value = ast2obj_identifier(o->v.Attribute.attr);
4466 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004467 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004468 goto failed;
4469 Py_DECREF(value);
4470 value = ast2obj_expr_context(o->v.Attribute.ctx);
4471 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004472 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004473 goto failed;
4474 Py_DECREF(value);
4475 break;
4476 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004477 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4478 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004479 if (!result) goto failed;
4480 value = ast2obj_expr(o->v.Subscript.value);
4481 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004482 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004483 goto failed;
4484 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004485 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004486 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004487 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004488 goto failed;
4489 Py_DECREF(value);
4490 value = ast2obj_expr_context(o->v.Subscript.ctx);
4491 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004492 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004493 goto failed;
4494 Py_DECREF(value);
4495 break;
4496 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004497 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4498 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004499 if (!result) goto failed;
4500 value = ast2obj_expr(o->v.Starred.value);
4501 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004502 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004503 goto failed;
4504 Py_DECREF(value);
4505 value = ast2obj_expr_context(o->v.Starred.ctx);
4506 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004507 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004508 goto failed;
4509 Py_DECREF(value);
4510 break;
4511 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004512 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4513 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004514 if (!result) goto failed;
4515 value = ast2obj_identifier(o->v.Name.id);
4516 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004517 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004518 goto failed;
4519 Py_DECREF(value);
4520 value = ast2obj_expr_context(o->v.Name.ctx);
4521 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004522 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004523 goto failed;
4524 Py_DECREF(value);
4525 break;
4526 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004527 tp = (PyTypeObject *)astmodulestate_global->List_type;
4528 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004529 if (!result) goto failed;
4530 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4531 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004532 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004533 goto failed;
4534 Py_DECREF(value);
4535 value = ast2obj_expr_context(o->v.List.ctx);
4536 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004537 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004538 goto failed;
4539 Py_DECREF(value);
4540 break;
4541 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004542 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4543 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004544 if (!result) goto failed;
4545 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4546 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004547 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004548 goto failed;
4549 Py_DECREF(value);
4550 value = ast2obj_expr_context(o->v.Tuple.ctx);
4551 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004552 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004553 goto failed;
4554 Py_DECREF(value);
4555 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004556 case Slice_kind:
4557 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4558 result = PyType_GenericNew(tp, NULL, NULL);
4559 if (!result) goto failed;
4560 value = ast2obj_expr(o->v.Slice.lower);
4561 if (!value) goto failed;
4562 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4563 goto failed;
4564 Py_DECREF(value);
4565 value = ast2obj_expr(o->v.Slice.upper);
4566 if (!value) goto failed;
4567 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4568 goto failed;
4569 Py_DECREF(value);
4570 value = ast2obj_expr(o->v.Slice.step);
4571 if (!value) goto failed;
4572 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4573 goto failed;
4574 Py_DECREF(value);
4575 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004576 }
4577 value = ast2obj_int(o->lineno);
4578 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004579 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004580 goto failed;
4581 Py_DECREF(value);
4582 value = ast2obj_int(o->col_offset);
4583 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004584 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004585 goto failed;
4586 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004587 value = ast2obj_int(o->end_lineno);
4588 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004589 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004590 goto failed;
4591 Py_DECREF(value);
4592 value = ast2obj_int(o->end_col_offset);
4593 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004594 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4595 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004596 goto failed;
4597 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004598 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004599failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004600 Py_XDECREF(value);
4601 Py_XDECREF(result);
4602 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004603}
4604
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004605PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004606{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004607 switch(o) {
4608 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004609 Py_INCREF(astmodulestate_global->Load_singleton);
4610 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004611 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004612 Py_INCREF(astmodulestate_global->Store_singleton);
4613 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004614 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004615 Py_INCREF(astmodulestate_global->Del_singleton);
4616 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004617 case AugLoad:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004618 Py_INCREF(astmodulestate_global->AugLoad_singleton);
4619 return astmodulestate_global->AugLoad_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 case AugStore:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004621 Py_INCREF(astmodulestate_global->AugStore_singleton);
4622 return astmodulestate_global->AugStore_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004623 default:
4624 /* should never happen, but just in case ... */
4625 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4626 return NULL;
4627 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004628}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004629PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004630{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004631 switch(o) {
4632 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004633 Py_INCREF(astmodulestate_global->And_singleton);
4634 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004635 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004636 Py_INCREF(astmodulestate_global->Or_singleton);
4637 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004638 default:
4639 /* should never happen, but just in case ... */
4640 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4641 return NULL;
4642 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004643}
4644PyObject* ast2obj_operator(operator_ty o)
4645{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004646 switch(o) {
4647 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004648 Py_INCREF(astmodulestate_global->Add_singleton);
4649 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004650 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004651 Py_INCREF(astmodulestate_global->Sub_singleton);
4652 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004653 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004654 Py_INCREF(astmodulestate_global->Mult_singleton);
4655 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004656 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004657 Py_INCREF(astmodulestate_global->MatMult_singleton);
4658 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004659 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004660 Py_INCREF(astmodulestate_global->Div_singleton);
4661 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004662 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004663 Py_INCREF(astmodulestate_global->Mod_singleton);
4664 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004665 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004666 Py_INCREF(astmodulestate_global->Pow_singleton);
4667 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004668 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004669 Py_INCREF(astmodulestate_global->LShift_singleton);
4670 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004671 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004672 Py_INCREF(astmodulestate_global->RShift_singleton);
4673 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004674 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004675 Py_INCREF(astmodulestate_global->BitOr_singleton);
4676 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004677 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004678 Py_INCREF(astmodulestate_global->BitXor_singleton);
4679 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004680 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004681 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4682 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004684 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4685 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004686 default:
4687 /* should never happen, but just in case ... */
4688 PyErr_Format(PyExc_SystemError, "unknown operator found");
4689 return NULL;
4690 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004691}
4692PyObject* ast2obj_unaryop(unaryop_ty o)
4693{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004694 switch(o) {
4695 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004696 Py_INCREF(astmodulestate_global->Invert_singleton);
4697 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004698 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004699 Py_INCREF(astmodulestate_global->Not_singleton);
4700 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004701 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004702 Py_INCREF(astmodulestate_global->UAdd_singleton);
4703 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004704 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004705 Py_INCREF(astmodulestate_global->USub_singleton);
4706 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004707 default:
4708 /* should never happen, but just in case ... */
4709 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4710 return NULL;
4711 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004712}
4713PyObject* ast2obj_cmpop(cmpop_ty o)
4714{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004715 switch(o) {
4716 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004717 Py_INCREF(astmodulestate_global->Eq_singleton);
4718 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004719 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004720 Py_INCREF(astmodulestate_global->NotEq_singleton);
4721 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004722 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004723 Py_INCREF(astmodulestate_global->Lt_singleton);
4724 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004725 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004726 Py_INCREF(astmodulestate_global->LtE_singleton);
4727 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004728 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004729 Py_INCREF(astmodulestate_global->Gt_singleton);
4730 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004731 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004732 Py_INCREF(astmodulestate_global->GtE_singleton);
4733 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004734 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004735 Py_INCREF(astmodulestate_global->Is_singleton);
4736 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004737 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004738 Py_INCREF(astmodulestate_global->IsNot_singleton);
4739 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004740 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004741 Py_INCREF(astmodulestate_global->In_singleton);
4742 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004743 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004744 Py_INCREF(astmodulestate_global->NotIn_singleton);
4745 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004746 default:
4747 /* should never happen, but just in case ... */
4748 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4749 return NULL;
4750 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004751}
4752PyObject*
4753ast2obj_comprehension(void* _o)
4754{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004755 comprehension_ty o = (comprehension_ty)_o;
4756 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004757 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004758 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004759 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004761
Dino Viehlandac46eb42019-09-11 10:16:34 -07004762 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4763 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004764 if (!result) return NULL;
4765 value = ast2obj_expr(o->target);
4766 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004767 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004768 goto failed;
4769 Py_DECREF(value);
4770 value = ast2obj_expr(o->iter);
4771 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004772 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004773 goto failed;
4774 Py_DECREF(value);
4775 value = ast2obj_list(o->ifs, ast2obj_expr);
4776 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004777 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004778 goto failed;
4779 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004780 value = ast2obj_int(o->is_async);
4781 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004782 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004783 goto failed;
4784 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004785 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004786failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004787 Py_XDECREF(value);
4788 Py_XDECREF(result);
4789 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004790}
4791
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004792PyObject*
4793ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004794{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004795 excepthandler_ty o = (excepthandler_ty)_o;
4796 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004797 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004798 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004799 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004800 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004801
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004802 switch (o->kind) {
4803 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004804 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4805 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004806 if (!result) goto failed;
4807 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004808 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004809 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004810 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004811 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004812 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004813 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004814 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004815 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004816 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004817 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4818 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004819 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004820 goto failed;
4821 Py_DECREF(value);
4822 break;
4823 }
4824 value = ast2obj_int(o->lineno);
4825 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004826 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004827 goto failed;
4828 Py_DECREF(value);
4829 value = ast2obj_int(o->col_offset);
4830 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004831 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004832 goto failed;
4833 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004834 value = ast2obj_int(o->end_lineno);
4835 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004836 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004837 goto failed;
4838 Py_DECREF(value);
4839 value = ast2obj_int(o->end_col_offset);
4840 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004841 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4842 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004843 goto failed;
4844 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004845 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004846failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004847 Py_XDECREF(value);
4848 Py_XDECREF(result);
4849 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004850}
4851
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004852PyObject*
4853ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004854{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004855 arguments_ty o = (arguments_ty)_o;
4856 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004857 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004858 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004859 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004860 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004861
Dino Viehlandac46eb42019-09-11 10:16:34 -07004862 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4863 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004864 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004865 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4866 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004867 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4868 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004869 goto failed;
4870 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004871 value = ast2obj_list(o->args, ast2obj_arg);
4872 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004873 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004874 goto failed;
4875 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004876 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004877 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004878 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004879 goto failed;
4880 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004881 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4882 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004883 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4884 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004885 goto failed;
4886 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004887 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004888 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004889 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4890 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 goto failed;
4892 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004893 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004895 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004896 goto failed;
4897 Py_DECREF(value);
4898 value = ast2obj_list(o->defaults, ast2obj_expr);
4899 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004900 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004901 goto failed;
4902 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004903 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004904failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004905 Py_XDECREF(value);
4906 Py_XDECREF(result);
4907 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004908}
4909
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004910PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004911ast2obj_arg(void* _o)
4912{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004913 arg_ty o = (arg_ty)_o;
4914 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004915 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004916 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004917 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004918 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004919
Dino Viehlandac46eb42019-09-11 10:16:34 -07004920 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4921 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004922 if (!result) return NULL;
4923 value = ast2obj_identifier(o->arg);
4924 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004925 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004926 goto failed;
4927 Py_DECREF(value);
4928 value = ast2obj_expr(o->annotation);
4929 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004930 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4931 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004932 goto failed;
4933 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004934 value = ast2obj_string(o->type_comment);
4935 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004936 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4937 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004938 goto failed;
4939 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004940 value = ast2obj_int(o->lineno);
4941 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004942 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004943 goto failed;
4944 Py_DECREF(value);
4945 value = ast2obj_int(o->col_offset);
4946 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004947 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004948 goto failed;
4949 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004950 value = ast2obj_int(o->end_lineno);
4951 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004952 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004953 goto failed;
4954 Py_DECREF(value);
4955 value = ast2obj_int(o->end_col_offset);
4956 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004957 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4958 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004959 goto failed;
4960 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004961 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004962failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004963 Py_XDECREF(value);
4964 Py_XDECREF(result);
4965 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004966}
4967
4968PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004969ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004970{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004971 keyword_ty o = (keyword_ty)_o;
4972 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004973 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004974 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004975 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004976 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004977
Dino Viehlandac46eb42019-09-11 10:16:34 -07004978 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4979 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004980 if (!result) return NULL;
4981 value = ast2obj_identifier(o->arg);
4982 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004983 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004984 goto failed;
4985 Py_DECREF(value);
4986 value = ast2obj_expr(o->value);
4987 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004988 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 goto failed;
4990 Py_DECREF(value);
4991 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004992failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004993 Py_XDECREF(value);
4994 Py_XDECREF(result);
4995 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004996}
4997
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004998PyObject*
4999ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005000{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005001 alias_ty o = (alias_ty)_o;
5002 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005003 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005004 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005005 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005006 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005007
Dino Viehlandac46eb42019-09-11 10:16:34 -07005008 tp = (PyTypeObject *)astmodulestate_global->alias_type;
5009 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005010 if (!result) return NULL;
5011 value = ast2obj_identifier(o->name);
5012 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005013 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005014 goto failed;
5015 Py_DECREF(value);
5016 value = ast2obj_identifier(o->asname);
5017 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005018 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005019 goto failed;
5020 Py_DECREF(value);
5021 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005022failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005023 Py_XDECREF(value);
5024 Py_XDECREF(result);
5025 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005026}
5027
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005028PyObject*
5029ast2obj_withitem(void* _o)
5030{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005031 withitem_ty o = (withitem_ty)_o;
5032 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005033 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005034 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005035 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005036 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005037
Dino Viehlandac46eb42019-09-11 10:16:34 -07005038 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
5039 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005040 if (!result) return NULL;
5041 value = ast2obj_expr(o->context_expr);
5042 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005043 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
5044 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005045 goto failed;
5046 Py_DECREF(value);
5047 value = ast2obj_expr(o->optional_vars);
5048 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005049 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
5050 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005051 goto failed;
5052 Py_DECREF(value);
5053 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005054failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005055 Py_XDECREF(value);
5056 Py_XDECREF(result);
5057 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005058}
5059
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005060PyObject*
5061ast2obj_type_ignore(void* _o)
5062{
5063 type_ignore_ty o = (type_ignore_ty)_o;
5064 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005065 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005066 if (!o) {
5067 Py_RETURN_NONE;
5068 }
5069
5070 switch (o->kind) {
5071 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005072 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5073 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005074 if (!result) goto failed;
5075 value = ast2obj_int(o->v.TypeIgnore.lineno);
5076 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005077 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5078 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005079 goto failed;
5080 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005081 value = ast2obj_string(o->v.TypeIgnore.tag);
5082 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005083 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005084 goto failed;
5085 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005086 break;
5087 }
5088 return result;
5089failed:
5090 Py_XDECREF(value);
5091 Py_XDECREF(result);
5092 return NULL;
5093}
5094
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005095
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005096int
5097obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5098{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005099 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005100
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005101 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005102 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005103
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005104 if (obj == Py_None) {
5105 *out = NULL;
5106 return 0;
5107 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005108 tp = astmodulestate_global->Module_type;
5109 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005110 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005111 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005112 }
5113 if (isinstance) {
5114 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005115 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005116
Dino Viehlandac46eb42019-09-11 10:16:34 -07005117 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005118 return 1;
5119 }
5120 if (tmp == NULL) {
5121 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5122 return 1;
5123 }
5124 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005125 int res;
5126 Py_ssize_t len;
5127 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005128 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005129 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 +02005130 goto failed;
5131 }
5132 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005133 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005134 if (body == NULL) goto failed;
5135 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005136 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005137 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5138 Py_INCREF(tmp2);
5139 res = obj2ast_stmt(tmp2, &val, arena);
5140 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005141 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005142 if (len != PyList_GET_SIZE(tmp)) {
5143 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5144 goto failed;
5145 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005146 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005147 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005148 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005149 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005150 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5151 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005152 return 1;
5153 }
5154 if (tmp == NULL) {
5155 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5156 return 1;
5157 }
5158 else {
5159 int res;
5160 Py_ssize_t len;
5161 Py_ssize_t i;
5162 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005163 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 -08005164 goto failed;
5165 }
5166 len = PyList_GET_SIZE(tmp);
5167 type_ignores = _Py_asdl_seq_new(len, arena);
5168 if (type_ignores == NULL) goto failed;
5169 for (i = 0; i < len; i++) {
5170 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005171 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5172 Py_INCREF(tmp2);
5173 res = obj2ast_type_ignore(tmp2, &val, arena);
5174 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005175 if (res != 0) goto failed;
5176 if (len != PyList_GET_SIZE(tmp)) {
5177 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5178 goto failed;
5179 }
5180 asdl_seq_SET(type_ignores, i, val);
5181 }
5182 Py_CLEAR(tmp);
5183 }
5184 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005185 if (*out == NULL) goto failed;
5186 return 0;
5187 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005188 tp = astmodulestate_global->Interactive_type;
5189 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005190 if (isinstance == -1) {
5191 return 1;
5192 }
5193 if (isinstance) {
5194 asdl_seq* body;
5195
Dino Viehlandac46eb42019-09-11 10:16:34 -07005196 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005197 return 1;
5198 }
5199 if (tmp == NULL) {
5200 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5201 return 1;
5202 }
5203 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005204 int res;
5205 Py_ssize_t len;
5206 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005207 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005208 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 +02005209 goto failed;
5210 }
5211 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005212 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005213 if (body == NULL) goto failed;
5214 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005215 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005216 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5217 Py_INCREF(tmp2);
5218 res = obj2ast_stmt(tmp2, &val, arena);
5219 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005220 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005221 if (len != PyList_GET_SIZE(tmp)) {
5222 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5223 goto failed;
5224 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005225 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005226 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005227 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005228 }
5229 *out = Interactive(body, arena);
5230 if (*out == NULL) goto failed;
5231 return 0;
5232 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005233 tp = astmodulestate_global->Expression_type;
5234 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005235 if (isinstance == -1) {
5236 return 1;
5237 }
5238 if (isinstance) {
5239 expr_ty body;
5240
Dino Viehlandac46eb42019-09-11 10:16:34 -07005241 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005242 return 1;
5243 }
5244 if (tmp == NULL) {
5245 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5246 return 1;
5247 }
5248 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005249 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005250 res = obj2ast_expr(tmp, &body, arena);
5251 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005252 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005253 }
5254 *out = Expression(body, arena);
5255 if (*out == NULL) goto failed;
5256 return 0;
5257 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005258 tp = astmodulestate_global->FunctionType_type;
5259 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005260 if (isinstance == -1) {
5261 return 1;
5262 }
5263 if (isinstance) {
5264 asdl_seq* argtypes;
5265 expr_ty returns;
5266
Dino Viehlandac46eb42019-09-11 10:16:34 -07005267 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5268 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005269 return 1;
5270 }
5271 if (tmp == NULL) {
5272 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5273 return 1;
5274 }
5275 else {
5276 int res;
5277 Py_ssize_t len;
5278 Py_ssize_t i;
5279 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005280 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 -08005281 goto failed;
5282 }
5283 len = PyList_GET_SIZE(tmp);
5284 argtypes = _Py_asdl_seq_new(len, arena);
5285 if (argtypes == NULL) goto failed;
5286 for (i = 0; i < len; i++) {
5287 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005288 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5289 Py_INCREF(tmp2);
5290 res = obj2ast_expr(tmp2, &val, arena);
5291 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005292 if (res != 0) goto failed;
5293 if (len != PyList_GET_SIZE(tmp)) {
5294 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5295 goto failed;
5296 }
5297 asdl_seq_SET(argtypes, i, val);
5298 }
5299 Py_CLEAR(tmp);
5300 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005301 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5302 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005303 return 1;
5304 }
5305 if (tmp == NULL) {
5306 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5307 return 1;
5308 }
5309 else {
5310 int res;
5311 res = obj2ast_expr(tmp, &returns, arena);
5312 if (res != 0) goto failed;
5313 Py_CLEAR(tmp);
5314 }
5315 *out = FunctionType(argtypes, returns, arena);
5316 if (*out == NULL) goto failed;
5317 return 0;
5318 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005319
5320 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5321 failed:
5322 Py_XDECREF(tmp);
5323 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005324}
5325
5326int
5327obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5328{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005329 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005330
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005331 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005332 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005333 int lineno;
5334 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005335 int end_lineno;
5336 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005337
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005338 if (obj == Py_None) {
5339 *out = NULL;
5340 return 0;
5341 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005342 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005343 return 1;
5344 }
5345 if (tmp == NULL) {
5346 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5347 return 1;
5348 }
5349 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005350 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005351 res = obj2ast_int(tmp, &lineno, arena);
5352 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005353 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005355 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5356 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005357 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005358 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005359 if (tmp == NULL) {
5360 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5361 return 1;
5362 }
5363 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005364 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005365 res = obj2ast_int(tmp, &col_offset, arena);
5366 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005367 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005368 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005369 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5370 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005371 return 1;
5372 }
5373 if (tmp == NULL || tmp == Py_None) {
5374 Py_CLEAR(tmp);
5375 end_lineno = 0;
5376 }
5377 else {
5378 int res;
5379 res = obj2ast_int(tmp, &end_lineno, arena);
5380 if (res != 0) goto failed;
5381 Py_CLEAR(tmp);
5382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005383 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5384 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005385 return 1;
5386 }
5387 if (tmp == NULL || tmp == Py_None) {
5388 Py_CLEAR(tmp);
5389 end_col_offset = 0;
5390 }
5391 else {
5392 int res;
5393 res = obj2ast_int(tmp, &end_col_offset, arena);
5394 if (res != 0) goto failed;
5395 Py_CLEAR(tmp);
5396 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005397 tp = astmodulestate_global->FunctionDef_type;
5398 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005399 if (isinstance == -1) {
5400 return 1;
5401 }
5402 if (isinstance) {
5403 identifier name;
5404 arguments_ty args;
5405 asdl_seq* body;
5406 asdl_seq* decorator_list;
5407 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005408 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005409
Dino Viehlandac46eb42019-09-11 10:16:34 -07005410 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005411 return 1;
5412 }
5413 if (tmp == NULL) {
5414 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5415 return 1;
5416 }
5417 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005418 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005419 res = obj2ast_identifier(tmp, &name, arena);
5420 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005421 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005422 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005423 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005424 return 1;
5425 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005426 if (tmp == NULL) {
5427 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5428 return 1;
5429 }
5430 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005431 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005432 res = obj2ast_arguments(tmp, &args, arena);
5433 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005434 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005435 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005436 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005437 return 1;
5438 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005439 if (tmp == NULL) {
5440 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5441 return 1;
5442 }
5443 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005444 int res;
5445 Py_ssize_t len;
5446 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005447 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005448 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 +02005449 goto failed;
5450 }
5451 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005452 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005453 if (body == NULL) goto failed;
5454 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005455 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005456 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5457 Py_INCREF(tmp2);
5458 res = obj2ast_stmt(tmp2, &val, arena);
5459 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005460 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005461 if (len != PyList_GET_SIZE(tmp)) {
5462 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5463 goto failed;
5464 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005465 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005466 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005467 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005468 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005469 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5470 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005471 return 1;
5472 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005473 if (tmp == NULL) {
5474 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5475 return 1;
5476 }
5477 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005478 int res;
5479 Py_ssize_t len;
5480 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005481 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005482 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 +02005483 goto failed;
5484 }
5485 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005486 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005487 if (decorator_list == NULL) goto failed;
5488 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005489 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005490 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5491 Py_INCREF(tmp2);
5492 res = obj2ast_expr(tmp2, &val, arena);
5493 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005494 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005495 if (len != PyList_GET_SIZE(tmp)) {
5496 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5497 goto failed;
5498 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005499 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005500 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005501 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005502 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005503 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5504 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005505 return 1;
5506 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005507 if (tmp == NULL || tmp == Py_None) {
5508 Py_CLEAR(tmp);
5509 returns = NULL;
5510 }
5511 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005512 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005513 res = obj2ast_expr(tmp, &returns, arena);
5514 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005515 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005516 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005517 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5518 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005519 return 1;
5520 }
5521 if (tmp == NULL || tmp == Py_None) {
5522 Py_CLEAR(tmp);
5523 type_comment = NULL;
5524 }
5525 else {
5526 int res;
5527 res = obj2ast_string(tmp, &type_comment, arena);
5528 if (res != 0) goto failed;
5529 Py_CLEAR(tmp);
5530 }
5531 *out = FunctionDef(name, args, body, decorator_list, returns,
5532 type_comment, lineno, col_offset, end_lineno,
5533 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005534 if (*out == NULL) goto failed;
5535 return 0;
5536 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005537 tp = astmodulestate_global->AsyncFunctionDef_type;
5538 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005539 if (isinstance == -1) {
5540 return 1;
5541 }
5542 if (isinstance) {
5543 identifier name;
5544 arguments_ty args;
5545 asdl_seq* body;
5546 asdl_seq* decorator_list;
5547 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005548 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005549
Dino Viehlandac46eb42019-09-11 10:16:34 -07005550 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005551 return 1;
5552 }
5553 if (tmp == NULL) {
5554 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5555 return 1;
5556 }
5557 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005558 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005559 res = obj2ast_identifier(tmp, &name, arena);
5560 if (res != 0) goto failed;
5561 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005562 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005563 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005564 return 1;
5565 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005566 if (tmp == NULL) {
5567 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5568 return 1;
5569 }
5570 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005571 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005572 res = obj2ast_arguments(tmp, &args, arena);
5573 if (res != 0) goto failed;
5574 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005575 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005576 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005577 return 1;
5578 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005579 if (tmp == NULL) {
5580 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5581 return 1;
5582 }
5583 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005584 int res;
5585 Py_ssize_t len;
5586 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005587 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005588 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 -04005589 goto failed;
5590 }
5591 len = PyList_GET_SIZE(tmp);
5592 body = _Py_asdl_seq_new(len, arena);
5593 if (body == NULL) goto failed;
5594 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005595 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005596 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5597 Py_INCREF(tmp2);
5598 res = obj2ast_stmt(tmp2, &val, arena);
5599 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005600 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005601 if (len != PyList_GET_SIZE(tmp)) {
5602 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5603 goto failed;
5604 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005605 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005606 }
5607 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005608 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005609 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5610 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005611 return 1;
5612 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005613 if (tmp == NULL) {
5614 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5615 return 1;
5616 }
5617 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005618 int res;
5619 Py_ssize_t len;
5620 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005621 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005622 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 -04005623 goto failed;
5624 }
5625 len = PyList_GET_SIZE(tmp);
5626 decorator_list = _Py_asdl_seq_new(len, arena);
5627 if (decorator_list == NULL) goto failed;
5628 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005629 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005630 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5631 Py_INCREF(tmp2);
5632 res = obj2ast_expr(tmp2, &val, arena);
5633 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005634 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005635 if (len != PyList_GET_SIZE(tmp)) {
5636 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5637 goto failed;
5638 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005639 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005640 }
5641 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005643 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5644 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005645 return 1;
5646 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005647 if (tmp == NULL || tmp == Py_None) {
5648 Py_CLEAR(tmp);
5649 returns = NULL;
5650 }
5651 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005652 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005653 res = obj2ast_expr(tmp, &returns, arena);
5654 if (res != 0) goto failed;
5655 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005656 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005657 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5658 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005659 return 1;
5660 }
5661 if (tmp == NULL || tmp == Py_None) {
5662 Py_CLEAR(tmp);
5663 type_comment = NULL;
5664 }
5665 else {
5666 int res;
5667 res = obj2ast_string(tmp, &type_comment, arena);
5668 if (res != 0) goto failed;
5669 Py_CLEAR(tmp);
5670 }
Yury Selivanov75445082015-05-11 22:57:16 -04005671 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005672 type_comment, lineno, col_offset, end_lineno,
5673 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005674 if (*out == NULL) goto failed;
5675 return 0;
5676 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005677 tp = astmodulestate_global->ClassDef_type;
5678 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005679 if (isinstance == -1) {
5680 return 1;
5681 }
5682 if (isinstance) {
5683 identifier name;
5684 asdl_seq* bases;
5685 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005686 asdl_seq* body;
5687 asdl_seq* decorator_list;
5688
Dino Viehlandac46eb42019-09-11 10:16:34 -07005689 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005690 return 1;
5691 }
5692 if (tmp == NULL) {
5693 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5694 return 1;
5695 }
5696 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005697 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005698 res = obj2ast_identifier(tmp, &name, arena);
5699 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005700 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005701 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005702 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005703 return 1;
5704 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005705 if (tmp == NULL) {
5706 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5707 return 1;
5708 }
5709 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005710 int res;
5711 Py_ssize_t len;
5712 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005713 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005714 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 +02005715 goto failed;
5716 }
5717 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005718 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005719 if (bases == NULL) goto failed;
5720 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005721 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005722 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5723 Py_INCREF(tmp2);
5724 res = obj2ast_expr(tmp2, &val, arena);
5725 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005726 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005727 if (len != PyList_GET_SIZE(tmp)) {
5728 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5729 goto failed;
5730 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005731 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005732 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005733 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005734 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005735 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5736 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005737 return 1;
5738 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005739 if (tmp == NULL) {
5740 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5741 return 1;
5742 }
5743 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005744 int res;
5745 Py_ssize_t len;
5746 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005747 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005748 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 +02005749 goto failed;
5750 }
5751 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005752 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005753 if (keywords == NULL) goto failed;
5754 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005755 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005756 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5757 Py_INCREF(tmp2);
5758 res = obj2ast_keyword(tmp2, &val, arena);
5759 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005760 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005761 if (len != PyList_GET_SIZE(tmp)) {
5762 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5763 goto failed;
5764 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005765 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005766 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005767 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005768 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005769 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005770 return 1;
5771 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005772 if (tmp == NULL) {
5773 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5774 return 1;
5775 }
5776 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005777 int res;
5778 Py_ssize_t len;
5779 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005780 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005781 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 +02005782 goto failed;
5783 }
5784 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005785 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005786 if (body == NULL) goto failed;
5787 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005788 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005789 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5790 Py_INCREF(tmp2);
5791 res = obj2ast_stmt(tmp2, &val, arena);
5792 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005793 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005794 if (len != PyList_GET_SIZE(tmp)) {
5795 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5796 goto failed;
5797 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005798 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005799 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005800 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005801 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005802 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5803 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005804 return 1;
5805 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005806 if (tmp == NULL) {
5807 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5808 return 1;
5809 }
5810 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005811 int res;
5812 Py_ssize_t len;
5813 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005814 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005815 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 +02005816 goto failed;
5817 }
5818 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005819 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005820 if (decorator_list == NULL) goto failed;
5821 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005822 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005823 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5824 Py_INCREF(tmp2);
5825 res = obj2ast_expr(tmp2, &val, arena);
5826 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005827 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005828 if (len != PyList_GET_SIZE(tmp)) {
5829 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5830 goto failed;
5831 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005832 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005833 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005834 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005835 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005836 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005837 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005838 if (*out == NULL) goto failed;
5839 return 0;
5840 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005841 tp = astmodulestate_global->Return_type;
5842 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005843 if (isinstance == -1) {
5844 return 1;
5845 }
5846 if (isinstance) {
5847 expr_ty value;
5848
Dino Viehlandac46eb42019-09-11 10:16:34 -07005849 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005850 return 1;
5851 }
5852 if (tmp == NULL || tmp == Py_None) {
5853 Py_CLEAR(tmp);
5854 value = NULL;
5855 }
5856 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005857 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005858 res = obj2ast_expr(tmp, &value, arena);
5859 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005860 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005861 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005862 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5863 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005864 if (*out == NULL) goto failed;
5865 return 0;
5866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005867 tp = astmodulestate_global->Delete_type;
5868 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005869 if (isinstance == -1) {
5870 return 1;
5871 }
5872 if (isinstance) {
5873 asdl_seq* targets;
5874
Dino Viehlandac46eb42019-09-11 10:16:34 -07005875 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5876 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005877 return 1;
5878 }
5879 if (tmp == NULL) {
5880 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5881 return 1;
5882 }
5883 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005884 int res;
5885 Py_ssize_t len;
5886 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005887 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005888 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 +02005889 goto failed;
5890 }
5891 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005892 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005893 if (targets == NULL) goto failed;
5894 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005895 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005896 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5897 Py_INCREF(tmp2);
5898 res = obj2ast_expr(tmp2, &val, arena);
5899 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005900 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005901 if (len != PyList_GET_SIZE(tmp)) {
5902 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5903 goto failed;
5904 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005905 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005906 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005907 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005908 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005909 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5910 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005911 if (*out == NULL) goto failed;
5912 return 0;
5913 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005914 tp = astmodulestate_global->Assign_type;
5915 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005916 if (isinstance == -1) {
5917 return 1;
5918 }
5919 if (isinstance) {
5920 asdl_seq* targets;
5921 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005922 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005923
Dino Viehlandac46eb42019-09-11 10:16:34 -07005924 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5925 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005926 return 1;
5927 }
5928 if (tmp == NULL) {
5929 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5930 return 1;
5931 }
5932 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005933 int res;
5934 Py_ssize_t len;
5935 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005936 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005937 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 +02005938 goto failed;
5939 }
5940 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005941 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005942 if (targets == NULL) goto failed;
5943 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005944 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005945 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5946 Py_INCREF(tmp2);
5947 res = obj2ast_expr(tmp2, &val, arena);
5948 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005949 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005950 if (len != PyList_GET_SIZE(tmp)) {
5951 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5952 goto failed;
5953 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005954 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005955 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005956 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005957 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005958 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005959 return 1;
5960 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005961 if (tmp == NULL) {
5962 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5963 return 1;
5964 }
5965 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005966 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005967 res = obj2ast_expr(tmp, &value, arena);
5968 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005969 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005971 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5972 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005973 return 1;
5974 }
5975 if (tmp == NULL || tmp == Py_None) {
5976 Py_CLEAR(tmp);
5977 type_comment = NULL;
5978 }
5979 else {
5980 int res;
5981 res = obj2ast_string(tmp, &type_comment, arena);
5982 if (res != 0) goto failed;
5983 Py_CLEAR(tmp);
5984 }
5985 *out = Assign(targets, value, type_comment, lineno, col_offset,
5986 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005987 if (*out == NULL) goto failed;
5988 return 0;
5989 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005990 tp = astmodulestate_global->AugAssign_type;
5991 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005992 if (isinstance == -1) {
5993 return 1;
5994 }
5995 if (isinstance) {
5996 expr_ty target;
5997 operator_ty op;
5998 expr_ty value;
5999
Dino Viehlandac46eb42019-09-11 10:16:34 -07006000 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6001 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006002 return 1;
6003 }
6004 if (tmp == NULL) {
6005 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6006 return 1;
6007 }
6008 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006009 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006010 res = obj2ast_expr(tmp, &target, arena);
6011 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006012 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006013 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006014 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006015 return 1;
6016 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006017 if (tmp == NULL) {
6018 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6019 return 1;
6020 }
6021 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006022 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006023 res = obj2ast_operator(tmp, &op, arena);
6024 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006025 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006026 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006027 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006028 return 1;
6029 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006030 if (tmp == NULL) {
6031 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6032 return 1;
6033 }
6034 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006035 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006036 res = obj2ast_expr(tmp, &value, arena);
6037 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006038 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006039 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006040 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
6041 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006042 if (*out == NULL) goto failed;
6043 return 0;
6044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006045 tp = astmodulestate_global->AnnAssign_type;
6046 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006047 if (isinstance == -1) {
6048 return 1;
6049 }
6050 if (isinstance) {
6051 expr_ty target;
6052 expr_ty annotation;
6053 expr_ty value;
6054 int simple;
6055
Dino Viehlandac46eb42019-09-11 10:16:34 -07006056 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6057 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006058 return 1;
6059 }
6060 if (tmp == NULL) {
6061 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6062 return 1;
6063 }
6064 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006065 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006066 res = obj2ast_expr(tmp, &target, arena);
6067 if (res != 0) goto failed;
6068 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006070 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6071 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006072 return 1;
6073 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006074 if (tmp == NULL) {
6075 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6076 return 1;
6077 }
6078 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006079 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006080 res = obj2ast_expr(tmp, &annotation, arena);
6081 if (res != 0) goto failed;
6082 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006084 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006085 return 1;
6086 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006087 if (tmp == NULL || tmp == Py_None) {
6088 Py_CLEAR(tmp);
6089 value = NULL;
6090 }
6091 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006092 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006093 res = obj2ast_expr(tmp, &value, arena);
6094 if (res != 0) goto failed;
6095 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006096 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006097 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6098 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006099 return 1;
6100 }
6101 if (tmp == NULL) {
6102 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6103 return 1;
6104 }
6105 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006106 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006107 res = obj2ast_int(tmp, &simple, arena);
6108 if (res != 0) goto failed;
6109 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006110 }
6111 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006112 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006113 if (*out == NULL) goto failed;
6114 return 0;
6115 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006116 tp = astmodulestate_global->For_type;
6117 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006118 if (isinstance == -1) {
6119 return 1;
6120 }
6121 if (isinstance) {
6122 expr_ty target;
6123 expr_ty iter;
6124 asdl_seq* body;
6125 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006126 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006127
Dino Viehlandac46eb42019-09-11 10:16:34 -07006128 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6129 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006130 return 1;
6131 }
6132 if (tmp == NULL) {
6133 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6134 return 1;
6135 }
6136 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006137 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006138 res = obj2ast_expr(tmp, &target, arena);
6139 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006140 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006142 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006143 return 1;
6144 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006145 if (tmp == NULL) {
6146 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6147 return 1;
6148 }
6149 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006150 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006151 res = obj2ast_expr(tmp, &iter, arena);
6152 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006153 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006154 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006155 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006156 return 1;
6157 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006158 if (tmp == NULL) {
6159 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6160 return 1;
6161 }
6162 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006163 int res;
6164 Py_ssize_t len;
6165 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006166 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006167 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 +02006168 goto failed;
6169 }
6170 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006171 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006172 if (body == NULL) goto failed;
6173 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006174 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006175 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6176 Py_INCREF(tmp2);
6177 res = obj2ast_stmt(tmp2, &val, arena);
6178 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006179 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006180 if (len != PyList_GET_SIZE(tmp)) {
6181 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6182 goto failed;
6183 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006184 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006185 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006186 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006187 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006188 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6189 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006190 return 1;
6191 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006192 if (tmp == NULL) {
6193 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6194 return 1;
6195 }
6196 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006197 int res;
6198 Py_ssize_t len;
6199 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006200 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006201 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 +02006202 goto failed;
6203 }
6204 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006205 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006206 if (orelse == NULL) goto failed;
6207 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006208 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006209 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6210 Py_INCREF(tmp2);
6211 res = obj2ast_stmt(tmp2, &val, arena);
6212 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006213 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006214 if (len != PyList_GET_SIZE(tmp)) {
6215 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6216 goto failed;
6217 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006218 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006219 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006220 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006221 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006222 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6223 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006224 return 1;
6225 }
6226 if (tmp == NULL || tmp == Py_None) {
6227 Py_CLEAR(tmp);
6228 type_comment = NULL;
6229 }
6230 else {
6231 int res;
6232 res = obj2ast_string(tmp, &type_comment, arena);
6233 if (res != 0) goto failed;
6234 Py_CLEAR(tmp);
6235 }
6236 *out = For(target, iter, body, orelse, type_comment, lineno,
6237 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006238 if (*out == NULL) goto failed;
6239 return 0;
6240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006241 tp = astmodulestate_global->AsyncFor_type;
6242 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006243 if (isinstance == -1) {
6244 return 1;
6245 }
6246 if (isinstance) {
6247 expr_ty target;
6248 expr_ty iter;
6249 asdl_seq* body;
6250 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006251 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006252
Dino Viehlandac46eb42019-09-11 10:16:34 -07006253 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6254 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006255 return 1;
6256 }
6257 if (tmp == NULL) {
6258 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6259 return 1;
6260 }
6261 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006262 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006263 res = obj2ast_expr(tmp, &target, arena);
6264 if (res != 0) goto failed;
6265 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006266 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006267 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006268 return 1;
6269 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006270 if (tmp == NULL) {
6271 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6272 return 1;
6273 }
6274 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006275 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006276 res = obj2ast_expr(tmp, &iter, arena);
6277 if (res != 0) goto failed;
6278 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006279 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006280 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006281 return 1;
6282 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006283 if (tmp == NULL) {
6284 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6285 return 1;
6286 }
6287 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006288 int res;
6289 Py_ssize_t len;
6290 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006291 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006292 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 -04006293 goto failed;
6294 }
6295 len = PyList_GET_SIZE(tmp);
6296 body = _Py_asdl_seq_new(len, arena);
6297 if (body == NULL) goto failed;
6298 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006299 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006300 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6301 Py_INCREF(tmp2);
6302 res = obj2ast_stmt(tmp2, &val, arena);
6303 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006304 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006305 if (len != PyList_GET_SIZE(tmp)) {
6306 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6307 goto failed;
6308 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006309 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006310 }
6311 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006313 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6314 {
Yury Selivanov75445082015-05-11 22:57:16 -04006315 return 1;
6316 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006317 if (tmp == NULL) {
6318 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6319 return 1;
6320 }
6321 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006322 int res;
6323 Py_ssize_t len;
6324 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006325 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006326 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 -04006327 goto failed;
6328 }
6329 len = PyList_GET_SIZE(tmp);
6330 orelse = _Py_asdl_seq_new(len, arena);
6331 if (orelse == NULL) goto failed;
6332 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006333 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006334 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6335 Py_INCREF(tmp2);
6336 res = obj2ast_stmt(tmp2, &val, arena);
6337 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006338 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006339 if (len != PyList_GET_SIZE(tmp)) {
6340 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6341 goto failed;
6342 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006343 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006344 }
6345 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006346 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006347 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6348 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006349 return 1;
6350 }
6351 if (tmp == NULL || tmp == Py_None) {
6352 Py_CLEAR(tmp);
6353 type_comment = NULL;
6354 }
6355 else {
6356 int res;
6357 res = obj2ast_string(tmp, &type_comment, arena);
6358 if (res != 0) goto failed;
6359 Py_CLEAR(tmp);
6360 }
6361 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6362 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006363 if (*out == NULL) goto failed;
6364 return 0;
6365 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006366 tp = astmodulestate_global->While_type;
6367 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006368 if (isinstance == -1) {
6369 return 1;
6370 }
6371 if (isinstance) {
6372 expr_ty test;
6373 asdl_seq* body;
6374 asdl_seq* orelse;
6375
Dino Viehlandac46eb42019-09-11 10:16:34 -07006376 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006377 return 1;
6378 }
6379 if (tmp == NULL) {
6380 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6381 return 1;
6382 }
6383 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006384 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006385 res = obj2ast_expr(tmp, &test, arena);
6386 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006387 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006388 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006389 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006390 return 1;
6391 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006392 if (tmp == NULL) {
6393 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6394 return 1;
6395 }
6396 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006397 int res;
6398 Py_ssize_t len;
6399 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006400 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006401 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 +02006402 goto failed;
6403 }
6404 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006405 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006406 if (body == NULL) goto failed;
6407 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006408 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006409 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6410 Py_INCREF(tmp2);
6411 res = obj2ast_stmt(tmp2, &val, arena);
6412 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006413 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006414 if (len != PyList_GET_SIZE(tmp)) {
6415 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6416 goto failed;
6417 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006418 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006419 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006420 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006421 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006422 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6423 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006424 return 1;
6425 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006426 if (tmp == NULL) {
6427 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6428 return 1;
6429 }
6430 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006431 int res;
6432 Py_ssize_t len;
6433 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006434 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006435 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 +02006436 goto failed;
6437 }
6438 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006439 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006440 if (orelse == NULL) goto failed;
6441 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006442 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006443 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6444 Py_INCREF(tmp2);
6445 res = obj2ast_stmt(tmp2, &val, arena);
6446 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006447 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006448 if (len != PyList_GET_SIZE(tmp)) {
6449 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6450 goto failed;
6451 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006452 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006453 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006454 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006455 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006456 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6457 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006458 if (*out == NULL) goto failed;
6459 return 0;
6460 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006461 tp = astmodulestate_global->If_type;
6462 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006463 if (isinstance == -1) {
6464 return 1;
6465 }
6466 if (isinstance) {
6467 expr_ty test;
6468 asdl_seq* body;
6469 asdl_seq* orelse;
6470
Dino Viehlandac46eb42019-09-11 10:16:34 -07006471 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006472 return 1;
6473 }
6474 if (tmp == NULL) {
6475 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6476 return 1;
6477 }
6478 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006479 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006480 res = obj2ast_expr(tmp, &test, arena);
6481 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006482 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006483 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006484 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006485 return 1;
6486 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006487 if (tmp == NULL) {
6488 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6489 return 1;
6490 }
6491 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006492 int res;
6493 Py_ssize_t len;
6494 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006495 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006496 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 +02006497 goto failed;
6498 }
6499 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006500 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006501 if (body == NULL) goto failed;
6502 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006503 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006504 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6505 Py_INCREF(tmp2);
6506 res = obj2ast_stmt(tmp2, &val, arena);
6507 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006508 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006509 if (len != PyList_GET_SIZE(tmp)) {
6510 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6511 goto failed;
6512 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006513 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006514 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006515 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006516 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006517 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6518 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006519 return 1;
6520 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006521 if (tmp == NULL) {
6522 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6523 return 1;
6524 }
6525 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006526 int res;
6527 Py_ssize_t len;
6528 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006529 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006530 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 +02006531 goto failed;
6532 }
6533 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006534 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006535 if (orelse == NULL) goto failed;
6536 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006537 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006538 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6539 Py_INCREF(tmp2);
6540 res = obj2ast_stmt(tmp2, &val, arena);
6541 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006542 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006543 if (len != PyList_GET_SIZE(tmp)) {
6544 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6545 goto failed;
6546 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006547 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006548 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006549 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006550 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006551 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6552 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006553 if (*out == NULL) goto failed;
6554 return 0;
6555 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006556 tp = astmodulestate_global->With_type;
6557 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006558 if (isinstance == -1) {
6559 return 1;
6560 }
6561 if (isinstance) {
6562 asdl_seq* items;
6563 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006564 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006565
Dino Viehlandac46eb42019-09-11 10:16:34 -07006566 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006567 return 1;
6568 }
6569 if (tmp == NULL) {
6570 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6571 return 1;
6572 }
6573 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006574 int res;
6575 Py_ssize_t len;
6576 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006577 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006578 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 +02006579 goto failed;
6580 }
6581 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006582 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006583 if (items == NULL) goto failed;
6584 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006585 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006586 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6587 Py_INCREF(tmp2);
6588 res = obj2ast_withitem(tmp2, &val, arena);
6589 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006590 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006591 if (len != PyList_GET_SIZE(tmp)) {
6592 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6593 goto failed;
6594 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006595 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006596 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006597 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006598 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006599 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006600 return 1;
6601 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006602 if (tmp == NULL) {
6603 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6604 return 1;
6605 }
6606 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006607 int res;
6608 Py_ssize_t len;
6609 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006610 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006611 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 +02006612 goto failed;
6613 }
6614 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006615 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006616 if (body == NULL) goto failed;
6617 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006618 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006619 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6620 Py_INCREF(tmp2);
6621 res = obj2ast_stmt(tmp2, &val, arena);
6622 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006623 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006624 if (len != PyList_GET_SIZE(tmp)) {
6625 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6626 goto failed;
6627 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006628 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006629 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006630 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006631 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006632 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6633 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006634 return 1;
6635 }
6636 if (tmp == NULL || tmp == Py_None) {
6637 Py_CLEAR(tmp);
6638 type_comment = NULL;
6639 }
6640 else {
6641 int res;
6642 res = obj2ast_string(tmp, &type_comment, arena);
6643 if (res != 0) goto failed;
6644 Py_CLEAR(tmp);
6645 }
6646 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006647 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006648 if (*out == NULL) goto failed;
6649 return 0;
6650 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006651 tp = astmodulestate_global->AsyncWith_type;
6652 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006653 if (isinstance == -1) {
6654 return 1;
6655 }
6656 if (isinstance) {
6657 asdl_seq* items;
6658 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006659 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006660
Dino Viehlandac46eb42019-09-11 10:16:34 -07006661 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006662 return 1;
6663 }
6664 if (tmp == NULL) {
6665 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6666 return 1;
6667 }
6668 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006669 int res;
6670 Py_ssize_t len;
6671 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006672 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006673 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 -04006674 goto failed;
6675 }
6676 len = PyList_GET_SIZE(tmp);
6677 items = _Py_asdl_seq_new(len, arena);
6678 if (items == NULL) goto failed;
6679 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006680 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006681 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6682 Py_INCREF(tmp2);
6683 res = obj2ast_withitem(tmp2, &val, arena);
6684 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006685 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006686 if (len != PyList_GET_SIZE(tmp)) {
6687 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6688 goto failed;
6689 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006690 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006691 }
6692 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006693 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006694 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006695 return 1;
6696 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006697 if (tmp == NULL) {
6698 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6699 return 1;
6700 }
6701 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006702 int res;
6703 Py_ssize_t len;
6704 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006705 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006706 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 -04006707 goto failed;
6708 }
6709 len = PyList_GET_SIZE(tmp);
6710 body = _Py_asdl_seq_new(len, arena);
6711 if (body == NULL) goto failed;
6712 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006713 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006714 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6715 Py_INCREF(tmp2);
6716 res = obj2ast_stmt(tmp2, &val, arena);
6717 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006718 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006719 if (len != PyList_GET_SIZE(tmp)) {
6720 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6721 goto failed;
6722 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006723 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006724 }
6725 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006726 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006727 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6728 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006729 return 1;
6730 }
6731 if (tmp == NULL || tmp == Py_None) {
6732 Py_CLEAR(tmp);
6733 type_comment = NULL;
6734 }
6735 else {
6736 int res;
6737 res = obj2ast_string(tmp, &type_comment, arena);
6738 if (res != 0) goto failed;
6739 Py_CLEAR(tmp);
6740 }
6741 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6742 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006743 if (*out == NULL) goto failed;
6744 return 0;
6745 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006746 tp = astmodulestate_global->Raise_type;
6747 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006748 if (isinstance == -1) {
6749 return 1;
6750 }
6751 if (isinstance) {
6752 expr_ty exc;
6753 expr_ty cause;
6754
Dino Viehlandac46eb42019-09-11 10:16:34 -07006755 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006756 return 1;
6757 }
6758 if (tmp == NULL || tmp == Py_None) {
6759 Py_CLEAR(tmp);
6760 exc = NULL;
6761 }
6762 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006763 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006764 res = obj2ast_expr(tmp, &exc, arena);
6765 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006766 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006767 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006768 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006769 return 1;
6770 }
6771 if (tmp == NULL || tmp == Py_None) {
6772 Py_CLEAR(tmp);
6773 cause = NULL;
6774 }
6775 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006776 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006777 res = obj2ast_expr(tmp, &cause, arena);
6778 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006779 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006780 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006781 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6782 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006783 if (*out == NULL) goto failed;
6784 return 0;
6785 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006786 tp = astmodulestate_global->Try_type;
6787 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006788 if (isinstance == -1) {
6789 return 1;
6790 }
6791 if (isinstance) {
6792 asdl_seq* body;
6793 asdl_seq* handlers;
6794 asdl_seq* orelse;
6795 asdl_seq* finalbody;
6796
Dino Viehlandac46eb42019-09-11 10:16:34 -07006797 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006798 return 1;
6799 }
6800 if (tmp == NULL) {
6801 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6802 return 1;
6803 }
6804 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006805 int res;
6806 Py_ssize_t len;
6807 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006808 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006809 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 +02006810 goto failed;
6811 }
6812 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006813 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006814 if (body == NULL) goto failed;
6815 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006816 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006817 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6818 Py_INCREF(tmp2);
6819 res = obj2ast_stmt(tmp2, &val, arena);
6820 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006821 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006822 if (len != PyList_GET_SIZE(tmp)) {
6823 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6824 goto failed;
6825 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006826 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006827 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006828 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006829 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006830 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6831 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006832 return 1;
6833 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006834 if (tmp == NULL) {
6835 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6836 return 1;
6837 }
6838 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006839 int res;
6840 Py_ssize_t len;
6841 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006842 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006843 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 +02006844 goto failed;
6845 }
6846 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006847 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006848 if (handlers == NULL) goto failed;
6849 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006850 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006851 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6852 Py_INCREF(tmp2);
6853 res = obj2ast_excepthandler(tmp2, &val, arena);
6854 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006855 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006856 if (len != PyList_GET_SIZE(tmp)) {
6857 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6858 goto failed;
6859 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006860 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006861 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006862 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006863 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006864 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6865 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006866 return 1;
6867 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006868 if (tmp == NULL) {
6869 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6870 return 1;
6871 }
6872 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006873 int res;
6874 Py_ssize_t len;
6875 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006876 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006877 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 +02006878 goto failed;
6879 }
6880 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006881 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006882 if (orelse == NULL) goto failed;
6883 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006884 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006885 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6886 Py_INCREF(tmp2);
6887 res = obj2ast_stmt(tmp2, &val, arena);
6888 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006889 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006890 if (len != PyList_GET_SIZE(tmp)) {
6891 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6892 goto failed;
6893 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006894 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006895 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006896 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006897 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006898 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6899 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006900 return 1;
6901 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006902 if (tmp == NULL) {
6903 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6904 return 1;
6905 }
6906 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006907 int res;
6908 Py_ssize_t len;
6909 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006910 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006911 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 +02006912 goto failed;
6913 }
6914 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006915 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006916 if (finalbody == NULL) goto failed;
6917 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006918 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006919 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6920 Py_INCREF(tmp2);
6921 res = obj2ast_stmt(tmp2, &val, arena);
6922 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006923 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006924 if (len != PyList_GET_SIZE(tmp)) {
6925 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6926 goto failed;
6927 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006928 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006929 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006930 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006931 }
6932 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006933 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006934 if (*out == NULL) goto failed;
6935 return 0;
6936 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006937 tp = astmodulestate_global->Assert_type;
6938 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006939 if (isinstance == -1) {
6940 return 1;
6941 }
6942 if (isinstance) {
6943 expr_ty test;
6944 expr_ty msg;
6945
Dino Viehlandac46eb42019-09-11 10:16:34 -07006946 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006947 return 1;
6948 }
6949 if (tmp == NULL) {
6950 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6951 return 1;
6952 }
6953 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006954 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006955 res = obj2ast_expr(tmp, &test, arena);
6956 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006957 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006958 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006959 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006960 return 1;
6961 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006962 if (tmp == NULL || tmp == Py_None) {
6963 Py_CLEAR(tmp);
6964 msg = NULL;
6965 }
6966 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006967 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006968 res = obj2ast_expr(tmp, &msg, arena);
6969 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006970 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006971 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006972 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6973 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006974 if (*out == NULL) goto failed;
6975 return 0;
6976 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006977 tp = astmodulestate_global->Import_type;
6978 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006979 if (isinstance == -1) {
6980 return 1;
6981 }
6982 if (isinstance) {
6983 asdl_seq* names;
6984
Dino Viehlandac46eb42019-09-11 10:16:34 -07006985 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006986 return 1;
6987 }
6988 if (tmp == NULL) {
6989 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6990 return 1;
6991 }
6992 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006993 int res;
6994 Py_ssize_t len;
6995 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006996 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006997 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 +02006998 goto failed;
6999 }
7000 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007001 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007002 if (names == NULL) goto failed;
7003 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007004 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007005 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7006 Py_INCREF(tmp2);
7007 res = obj2ast_alias(tmp2, &val, arena);
7008 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007009 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007010 if (len != PyList_GET_SIZE(tmp)) {
7011 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7012 goto failed;
7013 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007014 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007015 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007016 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007017 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007018 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
7019 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007020 if (*out == NULL) goto failed;
7021 return 0;
7022 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007023 tp = astmodulestate_global->ImportFrom_type;
7024 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007025 if (isinstance == -1) {
7026 return 1;
7027 }
7028 if (isinstance) {
7029 identifier module;
7030 asdl_seq* names;
7031 int level;
7032
Dino Viehlandac46eb42019-09-11 10:16:34 -07007033 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
7034 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007035 return 1;
7036 }
7037 if (tmp == NULL || tmp == Py_None) {
7038 Py_CLEAR(tmp);
7039 module = NULL;
7040 }
7041 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007042 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007043 res = obj2ast_identifier(tmp, &module, arena);
7044 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007045 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007047 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007048 return 1;
7049 }
7050 if (tmp == NULL) {
7051 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7052 return 1;
7053 }
7054 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007055 int res;
7056 Py_ssize_t len;
7057 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007058 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007059 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 +02007060 goto failed;
7061 }
7062 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007063 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007064 if (names == NULL) goto failed;
7065 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007066 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007067 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7068 Py_INCREF(tmp2);
7069 res = obj2ast_alias(tmp2, &val, arena);
7070 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007071 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007072 if (len != PyList_GET_SIZE(tmp)) {
7073 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7074 goto failed;
7075 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007076 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007077 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007078 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007079 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007080 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007081 return 1;
7082 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007083 if (tmp == NULL || tmp == Py_None) {
7084 Py_CLEAR(tmp);
7085 level = 0;
7086 }
7087 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007088 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007089 res = obj2ast_int(tmp, &level, arena);
7090 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007091 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007092 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007093 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7094 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007095 if (*out == NULL) goto failed;
7096 return 0;
7097 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007098 tp = astmodulestate_global->Global_type;
7099 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007100 if (isinstance == -1) {
7101 return 1;
7102 }
7103 if (isinstance) {
7104 asdl_seq* names;
7105
Dino Viehlandac46eb42019-09-11 10:16:34 -07007106 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007107 return 1;
7108 }
7109 if (tmp == NULL) {
7110 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7111 return 1;
7112 }
7113 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007114 int res;
7115 Py_ssize_t len;
7116 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007117 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007118 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 +02007119 goto failed;
7120 }
7121 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007122 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007123 if (names == NULL) goto failed;
7124 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007125 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007126 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7127 Py_INCREF(tmp2);
7128 res = obj2ast_identifier(tmp2, &val, arena);
7129 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007130 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007131 if (len != PyList_GET_SIZE(tmp)) {
7132 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7133 goto failed;
7134 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007135 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007136 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007137 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007138 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007139 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7140 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007141 if (*out == NULL) goto failed;
7142 return 0;
7143 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007144 tp = astmodulestate_global->Nonlocal_type;
7145 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007146 if (isinstance == -1) {
7147 return 1;
7148 }
7149 if (isinstance) {
7150 asdl_seq* names;
7151
Dino Viehlandac46eb42019-09-11 10:16:34 -07007152 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007153 return 1;
7154 }
7155 if (tmp == NULL) {
7156 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7157 return 1;
7158 }
7159 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007160 int res;
7161 Py_ssize_t len;
7162 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007163 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007164 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 +02007165 goto failed;
7166 }
7167 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007168 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007169 if (names == NULL) goto failed;
7170 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007171 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007172 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7173 Py_INCREF(tmp2);
7174 res = obj2ast_identifier(tmp2, &val, arena);
7175 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007176 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007177 if (len != PyList_GET_SIZE(tmp)) {
7178 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7179 goto failed;
7180 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007181 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007182 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007183 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007184 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007185 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7186 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007187 if (*out == NULL) goto failed;
7188 return 0;
7189 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007190 tp = astmodulestate_global->Expr_type;
7191 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007192 if (isinstance == -1) {
7193 return 1;
7194 }
7195 if (isinstance) {
7196 expr_ty value;
7197
Dino Viehlandac46eb42019-09-11 10:16:34 -07007198 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007199 return 1;
7200 }
7201 if (tmp == NULL) {
7202 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7203 return 1;
7204 }
7205 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007206 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007207 res = obj2ast_expr(tmp, &value, arena);
7208 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007209 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007210 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007211 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7212 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007213 if (*out == NULL) goto failed;
7214 return 0;
7215 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007216 tp = astmodulestate_global->Pass_type;
7217 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007218 if (isinstance == -1) {
7219 return 1;
7220 }
7221 if (isinstance) {
7222
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007223 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007224 if (*out == NULL) goto failed;
7225 return 0;
7226 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007227 tp = astmodulestate_global->Break_type;
7228 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007229 if (isinstance == -1) {
7230 return 1;
7231 }
7232 if (isinstance) {
7233
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007234 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007235 if (*out == NULL) goto failed;
7236 return 0;
7237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007238 tp = astmodulestate_global->Continue_type;
7239 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007240 if (isinstance == -1) {
7241 return 1;
7242 }
7243 if (isinstance) {
7244
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007245 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007246 if (*out == NULL) goto failed;
7247 return 0;
7248 }
7249
7250 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7251 failed:
7252 Py_XDECREF(tmp);
7253 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007254}
7255
7256int
7257obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7258{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007259 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007260
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007261 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007262 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007263 int lineno;
7264 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007265 int end_lineno;
7266 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007267
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007268 if (obj == Py_None) {
7269 *out = NULL;
7270 return 0;
7271 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007272 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007273 return 1;
7274 }
7275 if (tmp == NULL) {
7276 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7277 return 1;
7278 }
7279 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007280 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007281 res = obj2ast_int(tmp, &lineno, arena);
7282 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007283 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007284 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007285 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7286 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007287 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007288 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007289 if (tmp == NULL) {
7290 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7291 return 1;
7292 }
7293 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007294 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007295 res = obj2ast_int(tmp, &col_offset, arena);
7296 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007297 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007298 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007299 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7300 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007301 return 1;
7302 }
7303 if (tmp == NULL || tmp == Py_None) {
7304 Py_CLEAR(tmp);
7305 end_lineno = 0;
7306 }
7307 else {
7308 int res;
7309 res = obj2ast_int(tmp, &end_lineno, arena);
7310 if (res != 0) goto failed;
7311 Py_CLEAR(tmp);
7312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007313 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7314 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007315 return 1;
7316 }
7317 if (tmp == NULL || tmp == Py_None) {
7318 Py_CLEAR(tmp);
7319 end_col_offset = 0;
7320 }
7321 else {
7322 int res;
7323 res = obj2ast_int(tmp, &end_col_offset, arena);
7324 if (res != 0) goto failed;
7325 Py_CLEAR(tmp);
7326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007327 tp = astmodulestate_global->BoolOp_type;
7328 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007329 if (isinstance == -1) {
7330 return 1;
7331 }
7332 if (isinstance) {
7333 boolop_ty op;
7334 asdl_seq* values;
7335
Dino Viehlandac46eb42019-09-11 10:16:34 -07007336 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007337 return 1;
7338 }
7339 if (tmp == NULL) {
7340 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7341 return 1;
7342 }
7343 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007344 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007345 res = obj2ast_boolop(tmp, &op, arena);
7346 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007347 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007348 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007349 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7350 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007351 return 1;
7352 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007353 if (tmp == NULL) {
7354 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7355 return 1;
7356 }
7357 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007358 int res;
7359 Py_ssize_t len;
7360 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007361 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007362 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 +02007363 goto failed;
7364 }
7365 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007366 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007367 if (values == NULL) goto failed;
7368 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007369 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007370 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7371 Py_INCREF(tmp2);
7372 res = obj2ast_expr(tmp2, &val, arena);
7373 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007374 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007375 if (len != PyList_GET_SIZE(tmp)) {
7376 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7377 goto failed;
7378 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007379 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007380 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007381 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007382 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007383 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7384 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007385 if (*out == NULL) goto failed;
7386 return 0;
7387 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007388 tp = astmodulestate_global->NamedExpr_type;
7389 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007390 if (isinstance == -1) {
7391 return 1;
7392 }
7393 if (isinstance) {
7394 expr_ty target;
7395 expr_ty value;
7396
Dino Viehlandac46eb42019-09-11 10:16:34 -07007397 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7398 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007399 return 1;
7400 }
7401 if (tmp == NULL) {
7402 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7403 return 1;
7404 }
7405 else {
7406 int res;
7407 res = obj2ast_expr(tmp, &target, arena);
7408 if (res != 0) goto failed;
7409 Py_CLEAR(tmp);
7410 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007411 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007412 return 1;
7413 }
7414 if (tmp == NULL) {
7415 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7416 return 1;
7417 }
7418 else {
7419 int res;
7420 res = obj2ast_expr(tmp, &value, arena);
7421 if (res != 0) goto failed;
7422 Py_CLEAR(tmp);
7423 }
7424 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7425 end_col_offset, arena);
7426 if (*out == NULL) goto failed;
7427 return 0;
7428 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007429 tp = astmodulestate_global->BinOp_type;
7430 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007431 if (isinstance == -1) {
7432 return 1;
7433 }
7434 if (isinstance) {
7435 expr_ty left;
7436 operator_ty op;
7437 expr_ty right;
7438
Dino Viehlandac46eb42019-09-11 10:16:34 -07007439 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007440 return 1;
7441 }
7442 if (tmp == NULL) {
7443 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7444 return 1;
7445 }
7446 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007447 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007448 res = obj2ast_expr(tmp, &left, arena);
7449 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007450 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007451 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007452 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007453 return 1;
7454 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007455 if (tmp == NULL) {
7456 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7457 return 1;
7458 }
7459 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007460 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007461 res = obj2ast_operator(tmp, &op, arena);
7462 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007463 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007464 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007465 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007466 return 1;
7467 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007468 if (tmp == NULL) {
7469 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7470 return 1;
7471 }
7472 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007473 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007474 res = obj2ast_expr(tmp, &right, arena);
7475 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007476 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007477 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007478 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7479 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007480 if (*out == NULL) goto failed;
7481 return 0;
7482 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007483 tp = astmodulestate_global->UnaryOp_type;
7484 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007485 if (isinstance == -1) {
7486 return 1;
7487 }
7488 if (isinstance) {
7489 unaryop_ty op;
7490 expr_ty operand;
7491
Dino Viehlandac46eb42019-09-11 10:16:34 -07007492 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007493 return 1;
7494 }
7495 if (tmp == NULL) {
7496 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7497 return 1;
7498 }
7499 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007500 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007501 res = obj2ast_unaryop(tmp, &op, arena);
7502 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007503 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007504 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007505 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7506 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 return 1;
7508 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007509 if (tmp == NULL) {
7510 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7511 return 1;
7512 }
7513 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007514 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007515 res = obj2ast_expr(tmp, &operand, arena);
7516 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007517 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007518 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007519 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7520 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007521 if (*out == NULL) goto failed;
7522 return 0;
7523 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007524 tp = astmodulestate_global->Lambda_type;
7525 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007526 if (isinstance == -1) {
7527 return 1;
7528 }
7529 if (isinstance) {
7530 arguments_ty args;
7531 expr_ty body;
7532
Dino Viehlandac46eb42019-09-11 10:16:34 -07007533 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007534 return 1;
7535 }
7536 if (tmp == NULL) {
7537 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7538 return 1;
7539 }
7540 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007541 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007542 res = obj2ast_arguments(tmp, &args, arena);
7543 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007544 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007545 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007546 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007547 return 1;
7548 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007549 if (tmp == NULL) {
7550 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7551 return 1;
7552 }
7553 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007554 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007555 res = obj2ast_expr(tmp, &body, arena);
7556 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007557 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007558 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007559 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7560 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007561 if (*out == NULL) goto failed;
7562 return 0;
7563 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007564 tp = astmodulestate_global->IfExp_type;
7565 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007566 if (isinstance == -1) {
7567 return 1;
7568 }
7569 if (isinstance) {
7570 expr_ty test;
7571 expr_ty body;
7572 expr_ty orelse;
7573
Dino Viehlandac46eb42019-09-11 10:16:34 -07007574 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007575 return 1;
7576 }
7577 if (tmp == NULL) {
7578 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7579 return 1;
7580 }
7581 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007582 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007583 res = obj2ast_expr(tmp, &test, arena);
7584 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007585 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007586 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007587 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007588 return 1;
7589 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007590 if (tmp == NULL) {
7591 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7592 return 1;
7593 }
7594 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007595 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007596 res = obj2ast_expr(tmp, &body, arena);
7597 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007598 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007599 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007600 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7601 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 return 1;
7603 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007604 if (tmp == NULL) {
7605 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7606 return 1;
7607 }
7608 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007609 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007610 res = obj2ast_expr(tmp, &orelse, arena);
7611 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007612 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007613 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007614 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7615 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007616 if (*out == NULL) goto failed;
7617 return 0;
7618 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007619 tp = astmodulestate_global->Dict_type;
7620 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007621 if (isinstance == -1) {
7622 return 1;
7623 }
7624 if (isinstance) {
7625 asdl_seq* keys;
7626 asdl_seq* values;
7627
Dino Viehlandac46eb42019-09-11 10:16:34 -07007628 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007629 return 1;
7630 }
7631 if (tmp == NULL) {
7632 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7633 return 1;
7634 }
7635 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007636 int res;
7637 Py_ssize_t len;
7638 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007639 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007640 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 +02007641 goto failed;
7642 }
7643 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007644 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007645 if (keys == NULL) goto failed;
7646 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007647 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007648 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7649 Py_INCREF(tmp2);
7650 res = obj2ast_expr(tmp2, &val, arena);
7651 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007652 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007653 if (len != PyList_GET_SIZE(tmp)) {
7654 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7655 goto failed;
7656 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007657 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007658 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007659 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007660 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007661 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7662 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007663 return 1;
7664 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007665 if (tmp == NULL) {
7666 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7667 return 1;
7668 }
7669 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007670 int res;
7671 Py_ssize_t len;
7672 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007673 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007674 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 +02007675 goto failed;
7676 }
7677 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007678 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007679 if (values == NULL) goto failed;
7680 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007681 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007682 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7683 Py_INCREF(tmp2);
7684 res = obj2ast_expr(tmp2, &val, arena);
7685 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007686 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007687 if (len != PyList_GET_SIZE(tmp)) {
7688 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7689 goto failed;
7690 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007691 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007692 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007693 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007694 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007695 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7696 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007697 if (*out == NULL) goto failed;
7698 return 0;
7699 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007700 tp = astmodulestate_global->Set_type;
7701 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007702 if (isinstance == -1) {
7703 return 1;
7704 }
7705 if (isinstance) {
7706 asdl_seq* elts;
7707
Dino Viehlandac46eb42019-09-11 10:16:34 -07007708 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007709 return 1;
7710 }
7711 if (tmp == NULL) {
7712 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7713 return 1;
7714 }
7715 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007716 int res;
7717 Py_ssize_t len;
7718 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007719 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007720 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 +02007721 goto failed;
7722 }
7723 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007724 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007725 if (elts == NULL) goto failed;
7726 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007727 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007728 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7729 Py_INCREF(tmp2);
7730 res = obj2ast_expr(tmp2, &val, arena);
7731 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007732 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007733 if (len != PyList_GET_SIZE(tmp)) {
7734 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7735 goto failed;
7736 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007737 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007738 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007739 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007740 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007741 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007742 if (*out == NULL) goto failed;
7743 return 0;
7744 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007745 tp = astmodulestate_global->ListComp_type;
7746 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007747 if (isinstance == -1) {
7748 return 1;
7749 }
7750 if (isinstance) {
7751 expr_ty elt;
7752 asdl_seq* generators;
7753
Dino Viehlandac46eb42019-09-11 10:16:34 -07007754 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007755 return 1;
7756 }
7757 if (tmp == NULL) {
7758 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7759 return 1;
7760 }
7761 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007762 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007763 res = obj2ast_expr(tmp, &elt, arena);
7764 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007765 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007766 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007767 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7768 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007769 return 1;
7770 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007771 if (tmp == NULL) {
7772 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7773 return 1;
7774 }
7775 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007776 int res;
7777 Py_ssize_t len;
7778 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007779 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007780 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 +02007781 goto failed;
7782 }
7783 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007784 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007785 if (generators == NULL) goto failed;
7786 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007787 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007788 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7789 Py_INCREF(tmp2);
7790 res = obj2ast_comprehension(tmp2, &val, arena);
7791 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007792 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007793 if (len != PyList_GET_SIZE(tmp)) {
7794 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7795 goto failed;
7796 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007797 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007798 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007799 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007800 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007801 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7802 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007803 if (*out == NULL) goto failed;
7804 return 0;
7805 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007806 tp = astmodulestate_global->SetComp_type;
7807 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007808 if (isinstance == -1) {
7809 return 1;
7810 }
7811 if (isinstance) {
7812 expr_ty elt;
7813 asdl_seq* generators;
7814
Dino Viehlandac46eb42019-09-11 10:16:34 -07007815 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007816 return 1;
7817 }
7818 if (tmp == NULL) {
7819 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7820 return 1;
7821 }
7822 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007823 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007824 res = obj2ast_expr(tmp, &elt, arena);
7825 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007826 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007827 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007828 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7829 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007830 return 1;
7831 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007832 if (tmp == NULL) {
7833 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7834 return 1;
7835 }
7836 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007837 int res;
7838 Py_ssize_t len;
7839 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007840 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007841 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 +02007842 goto failed;
7843 }
7844 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007845 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007846 if (generators == NULL) goto failed;
7847 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007848 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007849 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7850 Py_INCREF(tmp2);
7851 res = obj2ast_comprehension(tmp2, &val, arena);
7852 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007853 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007854 if (len != PyList_GET_SIZE(tmp)) {
7855 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7856 goto failed;
7857 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007858 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007859 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007860 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007861 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007862 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7863 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007864 if (*out == NULL) goto failed;
7865 return 0;
7866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007867 tp = astmodulestate_global->DictComp_type;
7868 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007869 if (isinstance == -1) {
7870 return 1;
7871 }
7872 if (isinstance) {
7873 expr_ty key;
7874 expr_ty value;
7875 asdl_seq* generators;
7876
Dino Viehlandac46eb42019-09-11 10:16:34 -07007877 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007878 return 1;
7879 }
7880 if (tmp == NULL) {
7881 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7882 return 1;
7883 }
7884 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007885 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007886 res = obj2ast_expr(tmp, &key, arena);
7887 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007888 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007890 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007891 return 1;
7892 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007893 if (tmp == NULL) {
7894 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7895 return 1;
7896 }
7897 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007898 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007899 res = obj2ast_expr(tmp, &value, arena);
7900 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007901 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007903 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7904 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007905 return 1;
7906 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007907 if (tmp == NULL) {
7908 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7909 return 1;
7910 }
7911 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007912 int res;
7913 Py_ssize_t len;
7914 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007915 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007916 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 +02007917 goto failed;
7918 }
7919 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007920 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007921 if (generators == NULL) goto failed;
7922 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007923 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007924 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7925 Py_INCREF(tmp2);
7926 res = obj2ast_comprehension(tmp2, &val, arena);
7927 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007928 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007929 if (len != PyList_GET_SIZE(tmp)) {
7930 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7931 goto failed;
7932 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007933 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007934 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007935 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007936 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007937 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7938 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007939 if (*out == NULL) goto failed;
7940 return 0;
7941 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007942 tp = astmodulestate_global->GeneratorExp_type;
7943 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007944 if (isinstance == -1) {
7945 return 1;
7946 }
7947 if (isinstance) {
7948 expr_ty elt;
7949 asdl_seq* generators;
7950
Dino Viehlandac46eb42019-09-11 10:16:34 -07007951 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007952 return 1;
7953 }
7954 if (tmp == NULL) {
7955 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7956 return 1;
7957 }
7958 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007959 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007960 res = obj2ast_expr(tmp, &elt, arena);
7961 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007962 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007963 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007964 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7965 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007966 return 1;
7967 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007968 if (tmp == NULL) {
7969 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7970 return 1;
7971 }
7972 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007973 int res;
7974 Py_ssize_t len;
7975 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007976 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007977 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 +02007978 goto failed;
7979 }
7980 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007981 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007982 if (generators == NULL) goto failed;
7983 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007984 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007985 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7986 Py_INCREF(tmp2);
7987 res = obj2ast_comprehension(tmp2, &val, arena);
7988 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007989 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007990 if (len != PyList_GET_SIZE(tmp)) {
7991 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7992 goto failed;
7993 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007994 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007995 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007996 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007997 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007998 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7999 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008000 if (*out == NULL) goto failed;
8001 return 0;
8002 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008003 tp = astmodulestate_global->Await_type;
8004 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04008005 if (isinstance == -1) {
8006 return 1;
8007 }
8008 if (isinstance) {
8009 expr_ty value;
8010
Dino Viehlandac46eb42019-09-11 10:16:34 -07008011 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008012 return 1;
8013 }
8014 if (tmp == NULL) {
8015 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8016 return 1;
8017 }
8018 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008019 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04008020 res = obj2ast_expr(tmp, &value, arena);
8021 if (res != 0) goto failed;
8022 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008023 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008024 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
8025 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008026 if (*out == NULL) goto failed;
8027 return 0;
8028 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008029 tp = astmodulestate_global->Yield_type;
8030 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008031 if (isinstance == -1) {
8032 return 1;
8033 }
8034 if (isinstance) {
8035 expr_ty value;
8036
Dino Viehlandac46eb42019-09-11 10:16:34 -07008037 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008038 return 1;
8039 }
8040 if (tmp == NULL || tmp == Py_None) {
8041 Py_CLEAR(tmp);
8042 value = NULL;
8043 }
8044 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008045 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008046 res = obj2ast_expr(tmp, &value, arena);
8047 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008048 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008049 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008050 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8051 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008052 if (*out == NULL) goto failed;
8053 return 0;
8054 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008055 tp = astmodulestate_global->YieldFrom_type;
8056 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008057 if (isinstance == -1) {
8058 return 1;
8059 }
8060 if (isinstance) {
8061 expr_ty value;
8062
Dino Viehlandac46eb42019-09-11 10:16:34 -07008063 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008064 return 1;
8065 }
8066 if (tmp == NULL) {
8067 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8068 return 1;
8069 }
8070 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008071 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008072 res = obj2ast_expr(tmp, &value, arena);
8073 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008074 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008075 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008076 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8077 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008078 if (*out == NULL) goto failed;
8079 return 0;
8080 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008081 tp = astmodulestate_global->Compare_type;
8082 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008083 if (isinstance == -1) {
8084 return 1;
8085 }
8086 if (isinstance) {
8087 expr_ty left;
8088 asdl_int_seq* ops;
8089 asdl_seq* comparators;
8090
Dino Viehlandac46eb42019-09-11 10:16:34 -07008091 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008092 return 1;
8093 }
8094 if (tmp == NULL) {
8095 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8096 return 1;
8097 }
8098 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008099 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008100 res = obj2ast_expr(tmp, &left, arena);
8101 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008102 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008103 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008104 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008105 return 1;
8106 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008107 if (tmp == NULL) {
8108 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8109 return 1;
8110 }
8111 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008112 int res;
8113 Py_ssize_t len;
8114 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008115 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008116 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 +02008117 goto failed;
8118 }
8119 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008120 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008121 if (ops == NULL) goto failed;
8122 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008123 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008124 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8125 Py_INCREF(tmp2);
8126 res = obj2ast_cmpop(tmp2, &val, arena);
8127 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008128 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008129 if (len != PyList_GET_SIZE(tmp)) {
8130 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8131 goto failed;
8132 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008133 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008134 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008135 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008137 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8138 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008139 return 1;
8140 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008141 if (tmp == NULL) {
8142 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8143 return 1;
8144 }
8145 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008146 int res;
8147 Py_ssize_t len;
8148 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008149 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008150 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 +02008151 goto failed;
8152 }
8153 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008154 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008155 if (comparators == NULL) goto failed;
8156 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008157 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008158 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8159 Py_INCREF(tmp2);
8160 res = obj2ast_expr(tmp2, &val, arena);
8161 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008162 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008163 if (len != PyList_GET_SIZE(tmp)) {
8164 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8165 goto failed;
8166 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008167 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008168 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008169 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008170 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008171 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8172 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008173 if (*out == NULL) goto failed;
8174 return 0;
8175 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008176 tp = astmodulestate_global->Call_type;
8177 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008178 if (isinstance == -1) {
8179 return 1;
8180 }
8181 if (isinstance) {
8182 expr_ty func;
8183 asdl_seq* args;
8184 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008185
Dino Viehlandac46eb42019-09-11 10:16:34 -07008186 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008187 return 1;
8188 }
8189 if (tmp == NULL) {
8190 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8191 return 1;
8192 }
8193 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008194 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008195 res = obj2ast_expr(tmp, &func, arena);
8196 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008197 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008198 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008199 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008200 return 1;
8201 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008202 if (tmp == NULL) {
8203 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8204 return 1;
8205 }
8206 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008207 int res;
8208 Py_ssize_t len;
8209 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008210 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008211 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 +02008212 goto failed;
8213 }
8214 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008215 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008216 if (args == NULL) goto failed;
8217 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008218 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008219 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8220 Py_INCREF(tmp2);
8221 res = obj2ast_expr(tmp2, &val, arena);
8222 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008223 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008224 if (len != PyList_GET_SIZE(tmp)) {
8225 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8226 goto failed;
8227 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008228 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008229 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008230 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008231 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008232 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8233 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008234 return 1;
8235 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008236 if (tmp == NULL) {
8237 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8238 return 1;
8239 }
8240 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008241 int res;
8242 Py_ssize_t len;
8243 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008244 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008245 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 +02008246 goto failed;
8247 }
8248 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008249 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008250 if (keywords == NULL) goto failed;
8251 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008252 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008253 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8254 Py_INCREF(tmp2);
8255 res = obj2ast_keyword(tmp2, &val, arena);
8256 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008257 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008258 if (len != PyList_GET_SIZE(tmp)) {
8259 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8260 goto failed;
8261 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008262 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008263 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008264 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008265 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008266 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8267 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008268 if (*out == NULL) goto failed;
8269 return 0;
8270 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008271 tp = astmodulestate_global->FormattedValue_type;
8272 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008273 if (isinstance == -1) {
8274 return 1;
8275 }
8276 if (isinstance) {
8277 expr_ty value;
8278 int conversion;
8279 expr_ty format_spec;
8280
Dino Viehlandac46eb42019-09-11 10:16:34 -07008281 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008282 return 1;
8283 }
8284 if (tmp == NULL) {
8285 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8286 return 1;
8287 }
8288 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008289 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008290 res = obj2ast_expr(tmp, &value, arena);
8291 if (res != 0) goto failed;
8292 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008293 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008294 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8295 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008296 return 1;
8297 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008298 if (tmp == NULL || tmp == Py_None) {
8299 Py_CLEAR(tmp);
8300 conversion = 0;
8301 }
8302 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008303 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008304 res = obj2ast_int(tmp, &conversion, arena);
8305 if (res != 0) goto failed;
8306 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008307 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008308 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8309 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008310 return 1;
8311 }
8312 if (tmp == NULL || tmp == Py_None) {
8313 Py_CLEAR(tmp);
8314 format_spec = NULL;
8315 }
8316 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008317 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008318 res = obj2ast_expr(tmp, &format_spec, arena);
8319 if (res != 0) goto failed;
8320 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008321 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008322 *out = FormattedValue(value, conversion, format_spec, lineno,
8323 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008324 if (*out == NULL) goto failed;
8325 return 0;
8326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008327 tp = astmodulestate_global->JoinedStr_type;
8328 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008329 if (isinstance == -1) {
8330 return 1;
8331 }
8332 if (isinstance) {
8333 asdl_seq* values;
8334
Dino Viehlandac46eb42019-09-11 10:16:34 -07008335 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8336 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008337 return 1;
8338 }
8339 if (tmp == NULL) {
8340 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8341 return 1;
8342 }
8343 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008344 int res;
8345 Py_ssize_t len;
8346 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008347 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008348 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 -04008349 goto failed;
8350 }
8351 len = PyList_GET_SIZE(tmp);
8352 values = _Py_asdl_seq_new(len, arena);
8353 if (values == NULL) goto failed;
8354 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008355 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008356 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8357 Py_INCREF(tmp2);
8358 res = obj2ast_expr(tmp2, &val, arena);
8359 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008360 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008361 if (len != PyList_GET_SIZE(tmp)) {
8362 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8363 goto failed;
8364 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008365 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008366 }
8367 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008368 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008369 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8370 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008371 if (*out == NULL) goto failed;
8372 return 0;
8373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008374 tp = astmodulestate_global->Constant_type;
8375 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008376 if (isinstance == -1) {
8377 return 1;
8378 }
8379 if (isinstance) {
8380 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008381 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008382
Dino Viehlandac46eb42019-09-11 10:16:34 -07008383 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008384 return 1;
8385 }
8386 if (tmp == NULL) {
8387 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8388 return 1;
8389 }
8390 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008391 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008392 res = obj2ast_constant(tmp, &value, arena);
8393 if (res != 0) goto failed;
8394 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008395 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008396 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008397 return 1;
8398 }
8399 if (tmp == NULL || tmp == Py_None) {
8400 Py_CLEAR(tmp);
8401 kind = NULL;
8402 }
8403 else {
8404 int res;
8405 res = obj2ast_string(tmp, &kind, arena);
8406 if (res != 0) goto failed;
8407 Py_CLEAR(tmp);
8408 }
8409 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8410 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008411 if (*out == NULL) goto failed;
8412 return 0;
8413 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008414 tp = astmodulestate_global->Attribute_type;
8415 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008416 if (isinstance == -1) {
8417 return 1;
8418 }
8419 if (isinstance) {
8420 expr_ty value;
8421 identifier attr;
8422 expr_context_ty ctx;
8423
Dino Viehlandac46eb42019-09-11 10:16:34 -07008424 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008425 return 1;
8426 }
8427 if (tmp == NULL) {
8428 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8429 return 1;
8430 }
8431 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008432 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008433 res = obj2ast_expr(tmp, &value, arena);
8434 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008435 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008436 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008437 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008438 return 1;
8439 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008440 if (tmp == NULL) {
8441 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8442 return 1;
8443 }
8444 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008445 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008446 res = obj2ast_identifier(tmp, &attr, arena);
8447 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008448 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008449 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008450 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008451 return 1;
8452 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008453 if (tmp == NULL) {
8454 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8455 return 1;
8456 }
8457 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008458 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008459 res = obj2ast_expr_context(tmp, &ctx, arena);
8460 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008461 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008462 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008463 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8464 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008465 if (*out == NULL) goto failed;
8466 return 0;
8467 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008468 tp = astmodulestate_global->Subscript_type;
8469 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008470 if (isinstance == -1) {
8471 return 1;
8472 }
8473 if (isinstance) {
8474 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008475 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008476 expr_context_ty ctx;
8477
Dino Viehlandac46eb42019-09-11 10:16:34 -07008478 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008479 return 1;
8480 }
8481 if (tmp == NULL) {
8482 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8483 return 1;
8484 }
8485 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008486 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008487 res = obj2ast_expr(tmp, &value, arena);
8488 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008489 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008490 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008491 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008492 return 1;
8493 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008494 if (tmp == NULL) {
8495 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8496 return 1;
8497 }
8498 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008499 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008500 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008501 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008502 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008503 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008504 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008505 return 1;
8506 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008507 if (tmp == NULL) {
8508 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8509 return 1;
8510 }
8511 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008512 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008513 res = obj2ast_expr_context(tmp, &ctx, arena);
8514 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008515 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008516 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008517 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8518 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008519 if (*out == NULL) goto failed;
8520 return 0;
8521 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008522 tp = astmodulestate_global->Starred_type;
8523 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008524 if (isinstance == -1) {
8525 return 1;
8526 }
8527 if (isinstance) {
8528 expr_ty value;
8529 expr_context_ty ctx;
8530
Dino Viehlandac46eb42019-09-11 10:16:34 -07008531 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008532 return 1;
8533 }
8534 if (tmp == NULL) {
8535 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8536 return 1;
8537 }
8538 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008539 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008540 res = obj2ast_expr(tmp, &value, arena);
8541 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008542 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008543 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008544 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008545 return 1;
8546 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008547 if (tmp == NULL) {
8548 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8549 return 1;
8550 }
8551 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008552 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008553 res = obj2ast_expr_context(tmp, &ctx, arena);
8554 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008555 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008556 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008557 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8558 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008559 if (*out == NULL) goto failed;
8560 return 0;
8561 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008562 tp = astmodulestate_global->Name_type;
8563 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008564 if (isinstance == -1) {
8565 return 1;
8566 }
8567 if (isinstance) {
8568 identifier id;
8569 expr_context_ty ctx;
8570
Dino Viehlandac46eb42019-09-11 10:16:34 -07008571 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008572 return 1;
8573 }
8574 if (tmp == NULL) {
8575 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8576 return 1;
8577 }
8578 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008579 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008580 res = obj2ast_identifier(tmp, &id, arena);
8581 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008582 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008583 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008584 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008585 return 1;
8586 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008587 if (tmp == NULL) {
8588 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8589 return 1;
8590 }
8591 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008592 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008593 res = obj2ast_expr_context(tmp, &ctx, arena);
8594 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008595 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008596 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008597 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8598 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008599 if (*out == NULL) goto failed;
8600 return 0;
8601 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008602 tp = astmodulestate_global->List_type;
8603 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008604 if (isinstance == -1) {
8605 return 1;
8606 }
8607 if (isinstance) {
8608 asdl_seq* elts;
8609 expr_context_ty ctx;
8610
Dino Viehlandac46eb42019-09-11 10:16:34 -07008611 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008612 return 1;
8613 }
8614 if (tmp == NULL) {
8615 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8616 return 1;
8617 }
8618 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008619 int res;
8620 Py_ssize_t len;
8621 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008622 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008623 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 +02008624 goto failed;
8625 }
8626 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008627 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008628 if (elts == NULL) goto failed;
8629 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008630 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008631 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8632 Py_INCREF(tmp2);
8633 res = obj2ast_expr(tmp2, &val, arena);
8634 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008635 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008636 if (len != PyList_GET_SIZE(tmp)) {
8637 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8638 goto failed;
8639 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008640 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008641 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008642 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008643 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008644 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008645 return 1;
8646 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008647 if (tmp == NULL) {
8648 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8649 return 1;
8650 }
8651 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008652 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008653 res = obj2ast_expr_context(tmp, &ctx, arena);
8654 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008655 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008656 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008657 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8658 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008659 if (*out == NULL) goto failed;
8660 return 0;
8661 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008662 tp = astmodulestate_global->Tuple_type;
8663 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008664 if (isinstance == -1) {
8665 return 1;
8666 }
8667 if (isinstance) {
8668 asdl_seq* elts;
8669 expr_context_ty ctx;
8670
Dino Viehlandac46eb42019-09-11 10:16:34 -07008671 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008672 return 1;
8673 }
8674 if (tmp == NULL) {
8675 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8676 return 1;
8677 }
8678 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008679 int res;
8680 Py_ssize_t len;
8681 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008682 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008683 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 +02008684 goto failed;
8685 }
8686 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008687 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008688 if (elts == NULL) goto failed;
8689 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008690 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008691 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8692 Py_INCREF(tmp2);
8693 res = obj2ast_expr(tmp2, &val, arena);
8694 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008695 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008696 if (len != PyList_GET_SIZE(tmp)) {
8697 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8698 goto failed;
8699 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008700 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008701 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008702 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008703 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008704 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008705 return 1;
8706 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008707 if (tmp == NULL) {
8708 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8709 return 1;
8710 }
8711 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008712 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008713 res = obj2ast_expr_context(tmp, &ctx, arena);
8714 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008715 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008716 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008717 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8718 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008719 if (*out == NULL) goto failed;
8720 return 0;
8721 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008722 tp = astmodulestate_global->Slice_type;
8723 isinstance = PyObject_IsInstance(obj, tp);
8724 if (isinstance == -1) {
8725 return 1;
8726 }
8727 if (isinstance) {
8728 expr_ty lower;
8729 expr_ty upper;
8730 expr_ty step;
8731
8732 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8733 return 1;
8734 }
8735 if (tmp == NULL || tmp == Py_None) {
8736 Py_CLEAR(tmp);
8737 lower = NULL;
8738 }
8739 else {
8740 int res;
8741 res = obj2ast_expr(tmp, &lower, arena);
8742 if (res != 0) goto failed;
8743 Py_CLEAR(tmp);
8744 }
8745 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8746 return 1;
8747 }
8748 if (tmp == NULL || tmp == Py_None) {
8749 Py_CLEAR(tmp);
8750 upper = NULL;
8751 }
8752 else {
8753 int res;
8754 res = obj2ast_expr(tmp, &upper, arena);
8755 if (res != 0) goto failed;
8756 Py_CLEAR(tmp);
8757 }
8758 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8759 return 1;
8760 }
8761 if (tmp == NULL || tmp == Py_None) {
8762 Py_CLEAR(tmp);
8763 step = NULL;
8764 }
8765 else {
8766 int res;
8767 res = obj2ast_expr(tmp, &step, arena);
8768 if (res != 0) goto failed;
8769 Py_CLEAR(tmp);
8770 }
8771 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8772 end_col_offset, arena);
8773 if (*out == NULL) goto failed;
8774 return 0;
8775 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008776
8777 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8778 failed:
8779 Py_XDECREF(tmp);
8780 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008781}
8782
8783int
8784obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8785{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008786 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008787
Dino Viehlandac46eb42019-09-11 10:16:34 -07008788 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008789 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008790 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008791 }
8792 if (isinstance) {
8793 *out = Load;
8794 return 0;
8795 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008796 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008797 if (isinstance == -1) {
8798 return 1;
8799 }
8800 if (isinstance) {
8801 *out = Store;
8802 return 0;
8803 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008804 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008805 if (isinstance == -1) {
8806 return 1;
8807 }
8808 if (isinstance) {
8809 *out = Del;
8810 return 0;
8811 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008812 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugLoad_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008813 if (isinstance == -1) {
8814 return 1;
8815 }
8816 if (isinstance) {
8817 *out = AugLoad;
8818 return 0;
8819 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008820 isinstance = PyObject_IsInstance(obj, astmodulestate_global->AugStore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008821 if (isinstance == -1) {
8822 return 1;
8823 }
8824 if (isinstance) {
8825 *out = AugStore;
8826 return 0;
8827 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008828
8829 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8830 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008831}
8832
8833int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008834obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8835{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008836 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008837
Dino Viehlandac46eb42019-09-11 10:16:34 -07008838 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008839 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008840 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008841 }
8842 if (isinstance) {
8843 *out = And;
8844 return 0;
8845 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008846 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008847 if (isinstance == -1) {
8848 return 1;
8849 }
8850 if (isinstance) {
8851 *out = Or;
8852 return 0;
8853 }
8854
8855 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8856 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008857}
8858
8859int
8860obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8861{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008862 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008863
Dino Viehlandac46eb42019-09-11 10:16:34 -07008864 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008865 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008866 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008867 }
8868 if (isinstance) {
8869 *out = Add;
8870 return 0;
8871 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008872 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008873 if (isinstance == -1) {
8874 return 1;
8875 }
8876 if (isinstance) {
8877 *out = Sub;
8878 return 0;
8879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008880 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008881 if (isinstance == -1) {
8882 return 1;
8883 }
8884 if (isinstance) {
8885 *out = Mult;
8886 return 0;
8887 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008888 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008889 if (isinstance == -1) {
8890 return 1;
8891 }
8892 if (isinstance) {
8893 *out = MatMult;
8894 return 0;
8895 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008896 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008897 if (isinstance == -1) {
8898 return 1;
8899 }
8900 if (isinstance) {
8901 *out = Div;
8902 return 0;
8903 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008904 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008905 if (isinstance == -1) {
8906 return 1;
8907 }
8908 if (isinstance) {
8909 *out = Mod;
8910 return 0;
8911 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008912 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008913 if (isinstance == -1) {
8914 return 1;
8915 }
8916 if (isinstance) {
8917 *out = Pow;
8918 return 0;
8919 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008920 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008921 if (isinstance == -1) {
8922 return 1;
8923 }
8924 if (isinstance) {
8925 *out = LShift;
8926 return 0;
8927 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008928 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008929 if (isinstance == -1) {
8930 return 1;
8931 }
8932 if (isinstance) {
8933 *out = RShift;
8934 return 0;
8935 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008936 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008937 if (isinstance == -1) {
8938 return 1;
8939 }
8940 if (isinstance) {
8941 *out = BitOr;
8942 return 0;
8943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008944 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008945 if (isinstance == -1) {
8946 return 1;
8947 }
8948 if (isinstance) {
8949 *out = BitXor;
8950 return 0;
8951 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008952 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008953 if (isinstance == -1) {
8954 return 1;
8955 }
8956 if (isinstance) {
8957 *out = BitAnd;
8958 return 0;
8959 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008960 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008961 if (isinstance == -1) {
8962 return 1;
8963 }
8964 if (isinstance) {
8965 *out = FloorDiv;
8966 return 0;
8967 }
8968
8969 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8970 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008971}
8972
8973int
8974obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8975{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008976 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008977
Dino Viehlandac46eb42019-09-11 10:16:34 -07008978 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008979 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008980 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008981 }
8982 if (isinstance) {
8983 *out = Invert;
8984 return 0;
8985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008986 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008987 if (isinstance == -1) {
8988 return 1;
8989 }
8990 if (isinstance) {
8991 *out = Not;
8992 return 0;
8993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008994 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008995 if (isinstance == -1) {
8996 return 1;
8997 }
8998 if (isinstance) {
8999 *out = UAdd;
9000 return 0;
9001 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009002 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009003 if (isinstance == -1) {
9004 return 1;
9005 }
9006 if (isinstance) {
9007 *out = USub;
9008 return 0;
9009 }
9010
9011 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9012 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009013}
9014
9015int
9016obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9017{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009018 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009019
Dino Viehlandac46eb42019-09-11 10:16:34 -07009020 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009021 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009022 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009023 }
9024 if (isinstance) {
9025 *out = Eq;
9026 return 0;
9027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009028 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009029 if (isinstance == -1) {
9030 return 1;
9031 }
9032 if (isinstance) {
9033 *out = NotEq;
9034 return 0;
9035 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009036 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009037 if (isinstance == -1) {
9038 return 1;
9039 }
9040 if (isinstance) {
9041 *out = Lt;
9042 return 0;
9043 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009044 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009045 if (isinstance == -1) {
9046 return 1;
9047 }
9048 if (isinstance) {
9049 *out = LtE;
9050 return 0;
9051 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009052 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009053 if (isinstance == -1) {
9054 return 1;
9055 }
9056 if (isinstance) {
9057 *out = Gt;
9058 return 0;
9059 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009060 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009061 if (isinstance == -1) {
9062 return 1;
9063 }
9064 if (isinstance) {
9065 *out = GtE;
9066 return 0;
9067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009068 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009069 if (isinstance == -1) {
9070 return 1;
9071 }
9072 if (isinstance) {
9073 *out = Is;
9074 return 0;
9075 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009076 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009077 if (isinstance == -1) {
9078 return 1;
9079 }
9080 if (isinstance) {
9081 *out = IsNot;
9082 return 0;
9083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009084 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009085 if (isinstance == -1) {
9086 return 1;
9087 }
9088 if (isinstance) {
9089 *out = In;
9090 return 0;
9091 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009092 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009093 if (isinstance == -1) {
9094 return 1;
9095 }
9096 if (isinstance) {
9097 *out = NotIn;
9098 return 0;
9099 }
9100
9101 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9102 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009103}
9104
9105int
9106obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9107{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009108 PyObject* tmp = NULL;
9109 expr_ty target;
9110 expr_ty iter;
9111 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009112 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009113
Dino Viehlandac46eb42019-09-11 10:16:34 -07009114 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009115 return 1;
9116 }
9117 if (tmp == NULL) {
9118 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9119 return 1;
9120 }
9121 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009122 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009123 res = obj2ast_expr(tmp, &target, arena);
9124 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009125 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009126 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009127 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009128 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009129 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009130 if (tmp == NULL) {
9131 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9132 return 1;
9133 }
9134 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009135 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009136 res = obj2ast_expr(tmp, &iter, arena);
9137 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009138 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009139 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009140 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009141 return 1;
9142 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009143 if (tmp == NULL) {
9144 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9145 return 1;
9146 }
9147 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009148 int res;
9149 Py_ssize_t len;
9150 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009151 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009152 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 +02009153 goto failed;
9154 }
9155 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009156 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009157 if (ifs == NULL) goto failed;
9158 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009159 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009160 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9161 Py_INCREF(tmp2);
9162 res = obj2ast_expr(tmp2, &val, arena);
9163 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009164 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009165 if (len != PyList_GET_SIZE(tmp)) {
9166 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9167 goto failed;
9168 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009169 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009170 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009171 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009172 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009173 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009174 return 1;
9175 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009176 if (tmp == NULL) {
9177 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9178 return 1;
9179 }
9180 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009181 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009182 res = obj2ast_int(tmp, &is_async, arena);
9183 if (res != 0) goto failed;
9184 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009185 }
9186 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009187 return 0;
9188failed:
9189 Py_XDECREF(tmp);
9190 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009191}
9192
9193int
9194obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9195{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009196 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009197
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009198 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009199 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009200 int lineno;
9201 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009202 int end_lineno;
9203 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009204
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009205 if (obj == Py_None) {
9206 *out = NULL;
9207 return 0;
9208 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009209 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009210 return 1;
9211 }
9212 if (tmp == NULL) {
9213 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9214 return 1;
9215 }
9216 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009217 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009218 res = obj2ast_int(tmp, &lineno, arena);
9219 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009220 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009221 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009222 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9223 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009224 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009225 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009226 if (tmp == NULL) {
9227 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9228 return 1;
9229 }
9230 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009231 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009232 res = obj2ast_int(tmp, &col_offset, arena);
9233 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009234 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009235 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009236 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9237 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009238 return 1;
9239 }
9240 if (tmp == NULL || tmp == Py_None) {
9241 Py_CLEAR(tmp);
9242 end_lineno = 0;
9243 }
9244 else {
9245 int res;
9246 res = obj2ast_int(tmp, &end_lineno, arena);
9247 if (res != 0) goto failed;
9248 Py_CLEAR(tmp);
9249 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009250 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9251 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009252 return 1;
9253 }
9254 if (tmp == NULL || tmp == Py_None) {
9255 Py_CLEAR(tmp);
9256 end_col_offset = 0;
9257 }
9258 else {
9259 int res;
9260 res = obj2ast_int(tmp, &end_col_offset, arena);
9261 if (res != 0) goto failed;
9262 Py_CLEAR(tmp);
9263 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009264 tp = astmodulestate_global->ExceptHandler_type;
9265 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009266 if (isinstance == -1) {
9267 return 1;
9268 }
9269 if (isinstance) {
9270 expr_ty type;
9271 identifier name;
9272 asdl_seq* body;
9273
Dino Viehlandac46eb42019-09-11 10:16:34 -07009274 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009275 return 1;
9276 }
9277 if (tmp == NULL || tmp == Py_None) {
9278 Py_CLEAR(tmp);
9279 type = NULL;
9280 }
9281 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009282 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009283 res = obj2ast_expr(tmp, &type, arena);
9284 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009285 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009286 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009287 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009288 return 1;
9289 }
9290 if (tmp == NULL || tmp == Py_None) {
9291 Py_CLEAR(tmp);
9292 name = NULL;
9293 }
9294 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009295 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009296 res = obj2ast_identifier(tmp, &name, arena);
9297 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009298 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009299 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009300 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009301 return 1;
9302 }
9303 if (tmp == NULL) {
9304 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9305 return 1;
9306 }
9307 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009308 int res;
9309 Py_ssize_t len;
9310 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009311 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009312 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 +02009313 goto failed;
9314 }
9315 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009316 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009317 if (body == NULL) goto failed;
9318 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009319 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009320 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9321 Py_INCREF(tmp2);
9322 res = obj2ast_stmt(tmp2, &val, arena);
9323 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009324 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009325 if (len != PyList_GET_SIZE(tmp)) {
9326 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9327 goto failed;
9328 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009329 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009330 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009331 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009332 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009333 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9334 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009335 if (*out == NULL) goto failed;
9336 return 0;
9337 }
9338
9339 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9340 failed:
9341 Py_XDECREF(tmp);
9342 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009343}
9344
9345int
9346obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9347{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009348 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009349 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009350 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009351 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009352 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009353 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009354 arg_ty kwarg;
9355 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009356
Dino Viehlandac46eb42019-09-11 10:16:34 -07009357 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9358 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009359 return 1;
9360 }
9361 if (tmp == NULL) {
9362 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9363 return 1;
9364 }
9365 else {
9366 int res;
9367 Py_ssize_t len;
9368 Py_ssize_t i;
9369 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009370 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 +01009371 goto failed;
9372 }
9373 len = PyList_GET_SIZE(tmp);
9374 posonlyargs = _Py_asdl_seq_new(len, arena);
9375 if (posonlyargs == NULL) goto failed;
9376 for (i = 0; i < len; i++) {
9377 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009378 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9379 Py_INCREF(tmp2);
9380 res = obj2ast_arg(tmp2, &val, arena);
9381 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009382 if (res != 0) goto failed;
9383 if (len != PyList_GET_SIZE(tmp)) {
9384 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9385 goto failed;
9386 }
9387 asdl_seq_SET(posonlyargs, i, val);
9388 }
9389 Py_CLEAR(tmp);
9390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009391 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009392 return 1;
9393 }
9394 if (tmp == NULL) {
9395 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9396 return 1;
9397 }
9398 else {
9399 int res;
9400 Py_ssize_t len;
9401 Py_ssize_t i;
9402 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009403 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 +02009404 goto failed;
9405 }
9406 len = PyList_GET_SIZE(tmp);
9407 args = _Py_asdl_seq_new(len, arena);
9408 if (args == NULL) goto failed;
9409 for (i = 0; i < len; i++) {
9410 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009411 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9412 Py_INCREF(tmp2);
9413 res = obj2ast_arg(tmp2, &val, arena);
9414 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009415 if (res != 0) goto failed;
9416 if (len != PyList_GET_SIZE(tmp)) {
9417 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9418 goto failed;
9419 }
9420 asdl_seq_SET(args, i, val);
9421 }
9422 Py_CLEAR(tmp);
9423 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009424 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009425 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009426 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009427 if (tmp == NULL || tmp == Py_None) {
9428 Py_CLEAR(tmp);
9429 vararg = NULL;
9430 }
9431 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009432 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009433 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009434 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009435 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009436 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009437 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9438 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009439 return 1;
9440 }
9441 if (tmp == NULL) {
9442 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9443 return 1;
9444 }
9445 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009446 int res;
9447 Py_ssize_t len;
9448 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009449 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009450 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 +02009451 goto failed;
9452 }
9453 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009454 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009455 if (kwonlyargs == NULL) goto failed;
9456 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009457 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009458 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9459 Py_INCREF(tmp2);
9460 res = obj2ast_arg(tmp2, &val, arena);
9461 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009462 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009463 if (len != PyList_GET_SIZE(tmp)) {
9464 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9465 goto failed;
9466 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009467 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009468 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009469 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009470 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009471 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9472 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009473 return 1;
9474 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009475 if (tmp == NULL) {
9476 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9477 return 1;
9478 }
9479 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009480 int res;
9481 Py_ssize_t len;
9482 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009483 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009484 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 +02009485 goto failed;
9486 }
9487 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009488 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009489 if (kw_defaults == NULL) goto failed;
9490 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009491 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009492 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9493 Py_INCREF(tmp2);
9494 res = obj2ast_expr(tmp2, &val, arena);
9495 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009496 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009497 if (len != PyList_GET_SIZE(tmp)) {
9498 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9499 goto failed;
9500 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009501 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009502 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009503 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009504 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009505 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009506 return 1;
9507 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009508 if (tmp == NULL || tmp == Py_None) {
9509 Py_CLEAR(tmp);
9510 kwarg = NULL;
9511 }
9512 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009513 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009514 res = obj2ast_arg(tmp, &kwarg, arena);
9515 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009516 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009517 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009518 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009519 return 1;
9520 }
9521 if (tmp == NULL) {
9522 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9523 return 1;
9524 }
9525 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009526 int res;
9527 Py_ssize_t len;
9528 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009529 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009530 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 +02009531 goto failed;
9532 }
9533 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009534 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009535 if (defaults == NULL) goto failed;
9536 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009537 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009538 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9539 Py_INCREF(tmp2);
9540 res = obj2ast_expr(tmp2, &val, arena);
9541 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009542 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009543 if (len != PyList_GET_SIZE(tmp)) {
9544 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9545 goto failed;
9546 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009547 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009548 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009549 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009550 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009551 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009552 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009553 return 0;
9554failed:
9555 Py_XDECREF(tmp);
9556 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009557}
9558
9559int
9560obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9561{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009562 PyObject* tmp = NULL;
9563 identifier arg;
9564 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009565 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009566 int lineno;
9567 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009568 int end_lineno;
9569 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009570
Dino Viehlandac46eb42019-09-11 10:16:34 -07009571 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009572 return 1;
9573 }
9574 if (tmp == NULL) {
9575 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9576 return 1;
9577 }
9578 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009579 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009580 res = obj2ast_identifier(tmp, &arg, arena);
9581 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009582 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009583 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009584 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9585 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009586 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009587 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009588 if (tmp == NULL || tmp == Py_None) {
9589 Py_CLEAR(tmp);
9590 annotation = NULL;
9591 }
9592 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009593 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009594 res = obj2ast_expr(tmp, &annotation, arena);
9595 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009596 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009597 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009598 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9599 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009600 return 1;
9601 }
9602 if (tmp == NULL || tmp == Py_None) {
9603 Py_CLEAR(tmp);
9604 type_comment = NULL;
9605 }
9606 else {
9607 int res;
9608 res = obj2ast_string(tmp, &type_comment, arena);
9609 if (res != 0) goto failed;
9610 Py_CLEAR(tmp);
9611 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009612 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009613 return 1;
9614 }
9615 if (tmp == NULL) {
9616 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9617 return 1;
9618 }
9619 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009620 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009621 res = obj2ast_int(tmp, &lineno, arena);
9622 if (res != 0) goto failed;
9623 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009624 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009625 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9626 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009627 return 1;
9628 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009629 if (tmp == NULL) {
9630 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9631 return 1;
9632 }
9633 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009634 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009635 res = obj2ast_int(tmp, &col_offset, arena);
9636 if (res != 0) goto failed;
9637 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009638 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009639 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9640 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009641 return 1;
9642 }
9643 if (tmp == NULL || tmp == Py_None) {
9644 Py_CLEAR(tmp);
9645 end_lineno = 0;
9646 }
9647 else {
9648 int res;
9649 res = obj2ast_int(tmp, &end_lineno, arena);
9650 if (res != 0) goto failed;
9651 Py_CLEAR(tmp);
9652 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009653 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9654 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009655 return 1;
9656 }
9657 if (tmp == NULL || tmp == Py_None) {
9658 Py_CLEAR(tmp);
9659 end_col_offset = 0;
9660 }
9661 else {
9662 int res;
9663 res = obj2ast_int(tmp, &end_col_offset, arena);
9664 if (res != 0) goto failed;
9665 Py_CLEAR(tmp);
9666 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009667 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9668 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009669 return 0;
9670failed:
9671 Py_XDECREF(tmp);
9672 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009673}
9674
9675int
9676obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9677{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009678 PyObject* tmp = NULL;
9679 identifier arg;
9680 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009681
Dino Viehlandac46eb42019-09-11 10:16:34 -07009682 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009683 return 1;
9684 }
9685 if (tmp == NULL || tmp == Py_None) {
9686 Py_CLEAR(tmp);
9687 arg = NULL;
9688 }
9689 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009690 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009691 res = obj2ast_identifier(tmp, &arg, arena);
9692 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009693 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009694 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009695 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009696 return 1;
9697 }
9698 if (tmp == NULL) {
9699 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9700 return 1;
9701 }
9702 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009703 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009704 res = obj2ast_expr(tmp, &value, arena);
9705 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009706 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009707 }
9708 *out = keyword(arg, value, arena);
9709 return 0;
9710failed:
9711 Py_XDECREF(tmp);
9712 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009713}
9714
9715int
9716obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9717{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009718 PyObject* tmp = NULL;
9719 identifier name;
9720 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009721
Dino Viehlandac46eb42019-09-11 10:16:34 -07009722 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009723 return 1;
9724 }
9725 if (tmp == NULL) {
9726 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9727 return 1;
9728 }
9729 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009730 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009731 res = obj2ast_identifier(tmp, &name, arena);
9732 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009733 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009734 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009735 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009736 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009737 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009738 if (tmp == NULL || tmp == Py_None) {
9739 Py_CLEAR(tmp);
9740 asname = NULL;
9741 }
9742 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009743 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009744 res = obj2ast_identifier(tmp, &asname, arena);
9745 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009746 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009747 }
9748 *out = alias(name, asname, arena);
9749 return 0;
9750failed:
9751 Py_XDECREF(tmp);
9752 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009753}
9754
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009755int
9756obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9757{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009758 PyObject* tmp = NULL;
9759 expr_ty context_expr;
9760 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009761
Dino Viehlandac46eb42019-09-11 10:16:34 -07009762 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9763 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009764 return 1;
9765 }
9766 if (tmp == NULL) {
9767 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9768 return 1;
9769 }
9770 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009771 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009772 res = obj2ast_expr(tmp, &context_expr, arena);
9773 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009774 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009775 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009776 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9777 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009778 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009779 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009780 if (tmp == NULL || tmp == Py_None) {
9781 Py_CLEAR(tmp);
9782 optional_vars = NULL;
9783 }
9784 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009785 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009786 res = obj2ast_expr(tmp, &optional_vars, arena);
9787 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009788 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009789 }
9790 *out = withitem(context_expr, optional_vars, arena);
9791 return 0;
9792failed:
9793 Py_XDECREF(tmp);
9794 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009795}
9796
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009797int
9798obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9799{
9800 int isinstance;
9801
9802 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009803 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009804
9805 if (obj == Py_None) {
9806 *out = NULL;
9807 return 0;
9808 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009809 tp = astmodulestate_global->TypeIgnore_type;
9810 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009811 if (isinstance == -1) {
9812 return 1;
9813 }
9814 if (isinstance) {
9815 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009816 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009817
Dino Viehlandac46eb42019-09-11 10:16:34 -07009818 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9819 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009820 return 1;
9821 }
9822 if (tmp == NULL) {
9823 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9824 return 1;
9825 }
9826 else {
9827 int res;
9828 res = obj2ast_int(tmp, &lineno, arena);
9829 if (res != 0) goto failed;
9830 Py_CLEAR(tmp);
9831 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009832 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009833 return 1;
9834 }
9835 if (tmp == NULL) {
9836 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9837 return 1;
9838 }
9839 else {
9840 int res;
9841 res = obj2ast_string(tmp, &tag, arena);
9842 if (res != 0) goto failed;
9843 Py_CLEAR(tmp);
9844 }
9845 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009846 if (*out == NULL) goto failed;
9847 return 0;
9848 }
9849
9850 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9851 failed:
9852 Py_XDECREF(tmp);
9853 return 1;
9854}
9855
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009856
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009857PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009858PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009859{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009860 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009861 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009862 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009863 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009864 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9865 goto error;
9866 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009867 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009868 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9869 goto error;
9870 }
9871 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9872 goto error;
9873 }
9874 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9875 goto error;
9876 }
9877 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9878 goto error;
9879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009880 Py_INCREF(astmodulestate(m)->mod_type);
9881 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009882 0) {
9883 goto error;
9884 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009885 Py_INCREF(astmodulestate(m)->Module_type);
9886 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009887 astmodulestate_global->Interactive_type) < 0) {
9888 goto error;
9889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009890 Py_INCREF(astmodulestate(m)->Interactive_type);
9891 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009892 astmodulestate_global->Expression_type) < 0) {
9893 goto error;
9894 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009895 Py_INCREF(astmodulestate(m)->Expression_type);
9896 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009897 astmodulestate_global->FunctionType_type) < 0) {
9898 goto error;
9899 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009900 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009901 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9902 goto error;
9903 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009904 Py_INCREF(astmodulestate(m)->stmt_type);
9905 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009906 astmodulestate_global->FunctionDef_type) < 0) {
9907 goto error;
9908 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009909 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9910 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009911 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9912 goto error;
9913 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009914 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9915 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009916 < 0) {
9917 goto error;
9918 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009919 Py_INCREF(astmodulestate(m)->ClassDef_type);
9920 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009921 0) {
9922 goto error;
9923 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009924 Py_INCREF(astmodulestate(m)->Return_type);
9925 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009926 0) {
9927 goto error;
9928 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009929 Py_INCREF(astmodulestate(m)->Delete_type);
9930 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009931 0) {
9932 goto error;
9933 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009934 Py_INCREF(astmodulestate(m)->Assign_type);
9935 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009936 astmodulestate_global->AugAssign_type) < 0) {
9937 goto error;
9938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009939 Py_INCREF(astmodulestate(m)->AugAssign_type);
9940 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009941 astmodulestate_global->AnnAssign_type) < 0) {
9942 goto error;
9943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009944 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009945 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9946 goto error;
9947 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009948 Py_INCREF(astmodulestate(m)->For_type);
9949 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009950 < 0) {
9951 goto error;
9952 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009953 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009954 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
9955 goto error;
9956 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009957 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009958 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
9959 goto error;
9960 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009961 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009962 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
9963 goto error;
9964 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009965 Py_INCREF(astmodulestate(m)->With_type);
9966 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009967 astmodulestate_global->AsyncWith_type) < 0) {
9968 goto error;
9969 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009970 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009971 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
9972 goto error;
9973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009974 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009975 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
9976 goto error;
9977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009978 Py_INCREF(astmodulestate(m)->Try_type);
9979 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009980 0) {
9981 goto error;
9982 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009983 Py_INCREF(astmodulestate(m)->Assert_type);
9984 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009985 0) {
9986 goto error;
9987 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009988 Py_INCREF(astmodulestate(m)->Import_type);
9989 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009990 astmodulestate_global->ImportFrom_type) < 0) {
9991 goto error;
9992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009993 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9994 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_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)->Global_type);
9999 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010000 < 0) {
10001 goto error;
10002 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010003 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010004 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10005 goto error;
10006 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010007 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010008 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10009 goto error;
10010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010011 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010012 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10013 goto error;
10014 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010015 Py_INCREF(astmodulestate(m)->Break_type);
10016 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010017 < 0) {
10018 goto error;
10019 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010020 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010021 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10022 goto error;
10023 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010024 Py_INCREF(astmodulestate(m)->expr_type);
10025 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010026 0) {
10027 goto error;
10028 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010029 Py_INCREF(astmodulestate(m)->BoolOp_type);
10030 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010031 astmodulestate_global->NamedExpr_type) < 0) {
10032 goto error;
10033 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010034 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010035 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10036 goto error;
10037 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010038 Py_INCREF(astmodulestate(m)->BinOp_type);
10039 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_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)->UnaryOp_type);
10044 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_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)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010049 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10050 goto error;
10051 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010052 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010053 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10054 goto error;
10055 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010056 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010057 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10058 goto error;
10059 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010060 Py_INCREF(astmodulestate(m)->Set_type);
10061 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_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)->ListComp_type);
10066 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010067 0) {
10068 goto error;
10069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010070 Py_INCREF(astmodulestate(m)->SetComp_type);
10071 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010072 < 0) {
10073 goto error;
10074 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010075 Py_INCREF(astmodulestate(m)->DictComp_type);
10076 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010077 astmodulestate_global->GeneratorExp_type) < 0) {
10078 goto error;
10079 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010080 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010081 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10082 goto error;
10083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010084 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010085 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10086 goto error;
10087 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010088 Py_INCREF(astmodulestate(m)->Yield_type);
10089 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010090 astmodulestate_global->YieldFrom_type) < 0) {
10091 goto error;
10092 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010093 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10094 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010095 0) {
10096 goto error;
10097 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010098 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010099 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10100 goto error;
10101 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010102 Py_INCREF(astmodulestate(m)->Call_type);
10103 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010104 astmodulestate_global->FormattedValue_type) < 0) {
10105 goto error;
10106 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010107 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10108 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010109 astmodulestate_global->JoinedStr_type) < 0) {
10110 goto error;
10111 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010112 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10113 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010114 < 0) {
10115 goto error;
10116 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010117 Py_INCREF(astmodulestate(m)->Constant_type);
10118 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010119 astmodulestate_global->Attribute_type) < 0) {
10120 goto error;
10121 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010122 Py_INCREF(astmodulestate(m)->Attribute_type);
10123 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010124 astmodulestate_global->Subscript_type) < 0) {
10125 goto error;
10126 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010127 Py_INCREF(astmodulestate(m)->Subscript_type);
10128 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010129 0) {
10130 goto error;
10131 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010132 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010133 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10134 goto error;
10135 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010136 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010137 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10138 goto error;
10139 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010140 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010141 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10142 goto error;
10143 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010144 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010145 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10146 goto error;
10147 }
10148 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010149 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010150 astmodulestate_global->expr_context_type) < 0) {
10151 goto error;
10152 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010153 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010154 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10155 goto error;
10156 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010157 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010158 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10159 goto error;
10160 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010161 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010162 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10163 goto error;
10164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010165 Py_INCREF(astmodulestate(m)->Del_type);
10166 if (PyModule_AddObject(m, "AugLoad", astmodulestate_global->AugLoad_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010167 0) {
10168 goto error;
10169 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010170 Py_INCREF(astmodulestate(m)->AugLoad_type);
10171 if (PyModule_AddObject(m, "AugStore", astmodulestate_global->AugStore_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010172 < 0) {
10173 goto error;
10174 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010175 Py_INCREF(astmodulestate(m)->AugStore_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010176 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010177 0) {
10178 goto error;
10179 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010180 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010181 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10182 goto error;
10183 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010184 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010185 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10186 goto error;
10187 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010188 Py_INCREF(astmodulestate(m)->Or_type);
10189 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010190 < 0) {
10191 goto error;
10192 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010193 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010194 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10195 goto error;
10196 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010197 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010198 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10199 goto error;
10200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010201 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010202 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10203 goto error;
10204 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010205 Py_INCREF(astmodulestate(m)->Mult_type);
10206 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010207 0) {
10208 goto error;
10209 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010210 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010211 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10212 goto error;
10213 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010214 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010215 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10216 goto error;
10217 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010218 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010219 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10220 goto error;
10221 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010222 Py_INCREF(astmodulestate(m)->Pow_type);
10223 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010224 0) {
10225 goto error;
10226 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010227 Py_INCREF(astmodulestate(m)->LShift_type);
10228 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010229 0) {
10230 goto error;
10231 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010232 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010233 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10234 goto error;
10235 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010236 Py_INCREF(astmodulestate(m)->BitOr_type);
10237 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010238 0) {
10239 goto error;
10240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010241 Py_INCREF(astmodulestate(m)->BitXor_type);
10242 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010243 0) {
10244 goto error;
10245 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010246 Py_INCREF(astmodulestate(m)->BitAnd_type);
10247 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010248 < 0) {
10249 goto error;
10250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010251 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10252 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010253 0) {
10254 goto error;
10255 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010256 Py_INCREF(astmodulestate(m)->unaryop_type);
10257 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010258 0) {
10259 goto error;
10260 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010261 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010262 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10263 goto error;
10264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010265 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010266 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10267 goto error;
10268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010269 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010270 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10271 goto error;
10272 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010273 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010274 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10275 goto error;
10276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010277 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010278 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10279 goto error;
10280 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010281 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010282 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10283 goto error;
10284 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010285 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010286 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10287 goto error;
10288 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010289 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010290 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10291 goto error;
10292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010293 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010294 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10295 goto error;
10296 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010297 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010298 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10299 goto error;
10300 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010301 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010302 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10303 goto error;
10304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010305 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010306 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10307 goto error;
10308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010309 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010310 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10311 goto error;
10312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010313 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010314 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10315 goto error;
10316 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010317 Py_INCREF(astmodulestate(m)->NotIn_type);
10318 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010319 astmodulestate_global->comprehension_type) < 0) {
10320 goto error;
10321 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010322 Py_INCREF(astmodulestate(m)->comprehension_type);
10323 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010324 astmodulestate_global->excepthandler_type) < 0) {
10325 goto error;
10326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010327 Py_INCREF(astmodulestate(m)->excepthandler_type);
10328 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010329 astmodulestate_global->ExceptHandler_type) < 0) {
10330 goto error;
10331 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010332 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10333 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010334 astmodulestate_global->arguments_type) < 0) {
10335 goto error;
10336 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010337 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010338 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10339 goto error;
10340 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010341 Py_INCREF(astmodulestate(m)->arg_type);
10342 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010343 0) {
10344 goto error;
10345 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010346 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010347 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10348 goto error;
10349 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010350 Py_INCREF(astmodulestate(m)->alias_type);
10351 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010352 < 0) {
10353 goto error;
10354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010355 Py_INCREF(astmodulestate(m)->withitem_type);
10356 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010357 astmodulestate_global->type_ignore_type) < 0) {
10358 goto error;
10359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010360 Py_INCREF(astmodulestate(m)->type_ignore_type);
10361 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010362 astmodulestate_global->TypeIgnore_type) < 0) {
10363 goto error;
10364 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010365 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010366 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010367error:
10368 Py_DECREF(m);
10369 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010370}
10371
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010372
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010373PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010374{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010375 if (!init_types())
10376 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010377 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010378}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010379
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010380/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10381mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010382{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010383 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010384 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010385 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010386
Steve Dowerb82e17e2019-05-23 08:45:22 -070010387 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10388 return NULL;
10389 }
10390
Dino Viehlandac46eb42019-09-11 10:16:34 -070010391 req_type[0] = astmodulestate_global->Module_type;
10392 req_type[1] = astmodulestate_global->Expression_type;
10393 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010394
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010395 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010396
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010397 if (!init_types())
10398 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010399
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010400 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10401 if (isinstance == -1)
10402 return NULL;
10403 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010404 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010405 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010406 return NULL;
10407 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010408
10409 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010410 if (obj2ast_mod(ast, &res, arena) != 0)
10411 return NULL;
10412 else
10413 return res;
10414}
10415
10416int PyAST_Check(PyObject* obj)
10417{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010418 if (!init_types())
10419 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010420 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010421}
10422
Martin v. Löwis5b222132007-06-10 09:51:05 +000010423