blob: c7c7fda45d8519f0132bfa2d105591c3ccd84b64 [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;
Dino Viehlandac46eb42019-09-11 10:16:34 -070024 PyObject *Await_type;
25 PyObject *BinOp_type;
26 PyObject *BitAnd_singleton;
27 PyObject *BitAnd_type;
28 PyObject *BitOr_singleton;
29 PyObject *BitOr_type;
30 PyObject *BitXor_singleton;
31 PyObject *BitXor_type;
32 PyObject *BoolOp_type;
33 PyObject *Break_type;
34 PyObject *Call_type;
35 PyObject *ClassDef_type;
36 PyObject *Compare_type;
37 PyObject *Constant_type;
38 PyObject *Continue_type;
39 PyObject *Del_singleton;
40 PyObject *Del_type;
41 PyObject *Delete_type;
42 PyObject *DictComp_type;
43 PyObject *Dict_type;
44 PyObject *Div_singleton;
45 PyObject *Div_type;
46 PyObject *Eq_singleton;
47 PyObject *Eq_type;
48 PyObject *ExceptHandler_type;
49 PyObject *Expr_type;
50 PyObject *Expression_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070051 PyObject *FloorDiv_singleton;
52 PyObject *FloorDiv_type;
53 PyObject *For_type;
54 PyObject *FormattedValue_type;
55 PyObject *FunctionDef_type;
56 PyObject *FunctionType_type;
57 PyObject *GeneratorExp_type;
58 PyObject *Global_type;
59 PyObject *GtE_singleton;
60 PyObject *GtE_type;
61 PyObject *Gt_singleton;
62 PyObject *Gt_type;
63 PyObject *IfExp_type;
64 PyObject *If_type;
65 PyObject *ImportFrom_type;
66 PyObject *Import_type;
67 PyObject *In_singleton;
68 PyObject *In_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -070069 PyObject *Interactive_type;
70 PyObject *Invert_singleton;
71 PyObject *Invert_type;
72 PyObject *IsNot_singleton;
73 PyObject *IsNot_type;
74 PyObject *Is_singleton;
75 PyObject *Is_type;
76 PyObject *JoinedStr_type;
77 PyObject *LShift_singleton;
78 PyObject *LShift_type;
79 PyObject *Lambda_type;
80 PyObject *ListComp_type;
81 PyObject *List_type;
82 PyObject *Load_singleton;
83 PyObject *Load_type;
84 PyObject *LtE_singleton;
85 PyObject *LtE_type;
86 PyObject *Lt_singleton;
87 PyObject *Lt_type;
88 PyObject *MatMult_singleton;
89 PyObject *MatMult_type;
90 PyObject *Mod_singleton;
91 PyObject *Mod_type;
92 PyObject *Module_type;
93 PyObject *Mult_singleton;
94 PyObject *Mult_type;
95 PyObject *Name_type;
96 PyObject *NamedExpr_type;
97 PyObject *Nonlocal_type;
98 PyObject *NotEq_singleton;
99 PyObject *NotEq_type;
100 PyObject *NotIn_singleton;
101 PyObject *NotIn_type;
102 PyObject *Not_singleton;
103 PyObject *Not_type;
104 PyObject *Or_singleton;
105 PyObject *Or_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700106 PyObject *Pass_type;
107 PyObject *Pow_singleton;
108 PyObject *Pow_type;
109 PyObject *RShift_singleton;
110 PyObject *RShift_type;
111 PyObject *Raise_type;
112 PyObject *Return_type;
113 PyObject *SetComp_type;
114 PyObject *Set_type;
115 PyObject *Slice_type;
116 PyObject *Starred_type;
117 PyObject *Store_singleton;
118 PyObject *Store_type;
119 PyObject *Sub_singleton;
120 PyObject *Sub_type;
121 PyObject *Subscript_type;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700122 PyObject *Try_type;
123 PyObject *Tuple_type;
124 PyObject *TypeIgnore_type;
125 PyObject *UAdd_singleton;
126 PyObject *UAdd_type;
127 PyObject *USub_singleton;
128 PyObject *USub_type;
129 PyObject *UnaryOp_type;
130 PyObject *While_type;
131 PyObject *With_type;
132 PyObject *YieldFrom_type;
133 PyObject *Yield_type;
134 PyObject *__dict__;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300135 PyObject *__doc__;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700136 PyObject *__module__;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700137 PyObject *_attributes;
138 PyObject *_fields;
139 PyObject *alias_type;
140 PyObject *annotation;
141 PyObject *arg;
142 PyObject *arg_type;
143 PyObject *args;
144 PyObject *argtypes;
145 PyObject *arguments_type;
146 PyObject *asname;
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200147 PyObject *ast;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700148 PyObject *attr;
149 PyObject *bases;
150 PyObject *body;
151 PyObject *boolop_type;
152 PyObject *cause;
153 PyObject *cmpop_type;
154 PyObject *col_offset;
155 PyObject *comparators;
156 PyObject *comprehension_type;
157 PyObject *context_expr;
158 PyObject *conversion;
159 PyObject *ctx;
160 PyObject *decorator_list;
161 PyObject *defaults;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700162 PyObject *elt;
163 PyObject *elts;
164 PyObject *end_col_offset;
165 PyObject *end_lineno;
166 PyObject *exc;
167 PyObject *excepthandler_type;
168 PyObject *expr_context_type;
169 PyObject *expr_type;
170 PyObject *finalbody;
171 PyObject *format_spec;
172 PyObject *func;
173 PyObject *generators;
174 PyObject *handlers;
175 PyObject *id;
176 PyObject *ifs;
177 PyObject *is_async;
178 PyObject *items;
179 PyObject *iter;
180 PyObject *key;
181 PyObject *keys;
182 PyObject *keyword_type;
183 PyObject *keywords;
184 PyObject *kind;
185 PyObject *kw_defaults;
186 PyObject *kwarg;
187 PyObject *kwonlyargs;
188 PyObject *left;
189 PyObject *level;
190 PyObject *lineno;
191 PyObject *lower;
192 PyObject *mod_type;
193 PyObject *module;
194 PyObject *msg;
195 PyObject *name;
196 PyObject *names;
197 PyObject *op;
198 PyObject *operand;
199 PyObject *operator_type;
200 PyObject *ops;
201 PyObject *optional_vars;
202 PyObject *orelse;
203 PyObject *posonlyargs;
204 PyObject *returns;
205 PyObject *right;
206 PyObject *simple;
207 PyObject *slice;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700208 PyObject *step;
209 PyObject *stmt_type;
210 PyObject *tag;
211 PyObject *target;
212 PyObject *targets;
213 PyObject *test;
214 PyObject *type;
215 PyObject *type_comment;
216 PyObject *type_ignore_type;
217 PyObject *type_ignores;
218 PyObject *unaryop_type;
219 PyObject *upper;
220 PyObject *value;
221 PyObject *values;
222 PyObject *vararg;
223 PyObject *withitem_type;
224} astmodulestate;
225
226
227#define astmodulestate(o) ((astmodulestate *)PyModule_GetState(o))
228
229static int astmodule_clear(PyObject *module)
230{
231 Py_CLEAR(astmodulestate(module)->AST_type);
232 Py_CLEAR(astmodulestate(module)->Add_singleton);
233 Py_CLEAR(astmodulestate(module)->Add_type);
234 Py_CLEAR(astmodulestate(module)->And_singleton);
235 Py_CLEAR(astmodulestate(module)->And_type);
236 Py_CLEAR(astmodulestate(module)->AnnAssign_type);
237 Py_CLEAR(astmodulestate(module)->Assert_type);
238 Py_CLEAR(astmodulestate(module)->Assign_type);
239 Py_CLEAR(astmodulestate(module)->AsyncFor_type);
240 Py_CLEAR(astmodulestate(module)->AsyncFunctionDef_type);
241 Py_CLEAR(astmodulestate(module)->AsyncWith_type);
242 Py_CLEAR(astmodulestate(module)->Attribute_type);
243 Py_CLEAR(astmodulestate(module)->AugAssign_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700244 Py_CLEAR(astmodulestate(module)->Await_type);
245 Py_CLEAR(astmodulestate(module)->BinOp_type);
246 Py_CLEAR(astmodulestate(module)->BitAnd_singleton);
247 Py_CLEAR(astmodulestate(module)->BitAnd_type);
248 Py_CLEAR(astmodulestate(module)->BitOr_singleton);
249 Py_CLEAR(astmodulestate(module)->BitOr_type);
250 Py_CLEAR(astmodulestate(module)->BitXor_singleton);
251 Py_CLEAR(astmodulestate(module)->BitXor_type);
252 Py_CLEAR(astmodulestate(module)->BoolOp_type);
253 Py_CLEAR(astmodulestate(module)->Break_type);
254 Py_CLEAR(astmodulestate(module)->Call_type);
255 Py_CLEAR(astmodulestate(module)->ClassDef_type);
256 Py_CLEAR(astmodulestate(module)->Compare_type);
257 Py_CLEAR(astmodulestate(module)->Constant_type);
258 Py_CLEAR(astmodulestate(module)->Continue_type);
259 Py_CLEAR(astmodulestate(module)->Del_singleton);
260 Py_CLEAR(astmodulestate(module)->Del_type);
261 Py_CLEAR(astmodulestate(module)->Delete_type);
262 Py_CLEAR(astmodulestate(module)->DictComp_type);
263 Py_CLEAR(astmodulestate(module)->Dict_type);
264 Py_CLEAR(astmodulestate(module)->Div_singleton);
265 Py_CLEAR(astmodulestate(module)->Div_type);
266 Py_CLEAR(astmodulestate(module)->Eq_singleton);
267 Py_CLEAR(astmodulestate(module)->Eq_type);
268 Py_CLEAR(astmodulestate(module)->ExceptHandler_type);
269 Py_CLEAR(astmodulestate(module)->Expr_type);
270 Py_CLEAR(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700271 Py_CLEAR(astmodulestate(module)->FloorDiv_singleton);
272 Py_CLEAR(astmodulestate(module)->FloorDiv_type);
273 Py_CLEAR(astmodulestate(module)->For_type);
274 Py_CLEAR(astmodulestate(module)->FormattedValue_type);
275 Py_CLEAR(astmodulestate(module)->FunctionDef_type);
276 Py_CLEAR(astmodulestate(module)->FunctionType_type);
277 Py_CLEAR(astmodulestate(module)->GeneratorExp_type);
278 Py_CLEAR(astmodulestate(module)->Global_type);
279 Py_CLEAR(astmodulestate(module)->GtE_singleton);
280 Py_CLEAR(astmodulestate(module)->GtE_type);
281 Py_CLEAR(astmodulestate(module)->Gt_singleton);
282 Py_CLEAR(astmodulestate(module)->Gt_type);
283 Py_CLEAR(astmodulestate(module)->IfExp_type);
284 Py_CLEAR(astmodulestate(module)->If_type);
285 Py_CLEAR(astmodulestate(module)->ImportFrom_type);
286 Py_CLEAR(astmodulestate(module)->Import_type);
287 Py_CLEAR(astmodulestate(module)->In_singleton);
288 Py_CLEAR(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700289 Py_CLEAR(astmodulestate(module)->Interactive_type);
290 Py_CLEAR(astmodulestate(module)->Invert_singleton);
291 Py_CLEAR(astmodulestate(module)->Invert_type);
292 Py_CLEAR(astmodulestate(module)->IsNot_singleton);
293 Py_CLEAR(astmodulestate(module)->IsNot_type);
294 Py_CLEAR(astmodulestate(module)->Is_singleton);
295 Py_CLEAR(astmodulestate(module)->Is_type);
296 Py_CLEAR(astmodulestate(module)->JoinedStr_type);
297 Py_CLEAR(astmodulestate(module)->LShift_singleton);
298 Py_CLEAR(astmodulestate(module)->LShift_type);
299 Py_CLEAR(astmodulestate(module)->Lambda_type);
300 Py_CLEAR(astmodulestate(module)->ListComp_type);
301 Py_CLEAR(astmodulestate(module)->List_type);
302 Py_CLEAR(astmodulestate(module)->Load_singleton);
303 Py_CLEAR(astmodulestate(module)->Load_type);
304 Py_CLEAR(astmodulestate(module)->LtE_singleton);
305 Py_CLEAR(astmodulestate(module)->LtE_type);
306 Py_CLEAR(astmodulestate(module)->Lt_singleton);
307 Py_CLEAR(astmodulestate(module)->Lt_type);
308 Py_CLEAR(astmodulestate(module)->MatMult_singleton);
309 Py_CLEAR(astmodulestate(module)->MatMult_type);
310 Py_CLEAR(astmodulestate(module)->Mod_singleton);
311 Py_CLEAR(astmodulestate(module)->Mod_type);
312 Py_CLEAR(astmodulestate(module)->Module_type);
313 Py_CLEAR(astmodulestate(module)->Mult_singleton);
314 Py_CLEAR(astmodulestate(module)->Mult_type);
315 Py_CLEAR(astmodulestate(module)->Name_type);
316 Py_CLEAR(astmodulestate(module)->NamedExpr_type);
317 Py_CLEAR(astmodulestate(module)->Nonlocal_type);
318 Py_CLEAR(astmodulestate(module)->NotEq_singleton);
319 Py_CLEAR(astmodulestate(module)->NotEq_type);
320 Py_CLEAR(astmodulestate(module)->NotIn_singleton);
321 Py_CLEAR(astmodulestate(module)->NotIn_type);
322 Py_CLEAR(astmodulestate(module)->Not_singleton);
323 Py_CLEAR(astmodulestate(module)->Not_type);
324 Py_CLEAR(astmodulestate(module)->Or_singleton);
325 Py_CLEAR(astmodulestate(module)->Or_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700326 Py_CLEAR(astmodulestate(module)->Pass_type);
327 Py_CLEAR(astmodulestate(module)->Pow_singleton);
328 Py_CLEAR(astmodulestate(module)->Pow_type);
329 Py_CLEAR(astmodulestate(module)->RShift_singleton);
330 Py_CLEAR(astmodulestate(module)->RShift_type);
331 Py_CLEAR(astmodulestate(module)->Raise_type);
332 Py_CLEAR(astmodulestate(module)->Return_type);
333 Py_CLEAR(astmodulestate(module)->SetComp_type);
334 Py_CLEAR(astmodulestate(module)->Set_type);
335 Py_CLEAR(astmodulestate(module)->Slice_type);
336 Py_CLEAR(astmodulestate(module)->Starred_type);
337 Py_CLEAR(astmodulestate(module)->Store_singleton);
338 Py_CLEAR(astmodulestate(module)->Store_type);
339 Py_CLEAR(astmodulestate(module)->Sub_singleton);
340 Py_CLEAR(astmodulestate(module)->Sub_type);
341 Py_CLEAR(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700342 Py_CLEAR(astmodulestate(module)->Try_type);
343 Py_CLEAR(astmodulestate(module)->Tuple_type);
344 Py_CLEAR(astmodulestate(module)->TypeIgnore_type);
345 Py_CLEAR(astmodulestate(module)->UAdd_singleton);
346 Py_CLEAR(astmodulestate(module)->UAdd_type);
347 Py_CLEAR(astmodulestate(module)->USub_singleton);
348 Py_CLEAR(astmodulestate(module)->USub_type);
349 Py_CLEAR(astmodulestate(module)->UnaryOp_type);
350 Py_CLEAR(astmodulestate(module)->While_type);
351 Py_CLEAR(astmodulestate(module)->With_type);
352 Py_CLEAR(astmodulestate(module)->YieldFrom_type);
353 Py_CLEAR(astmodulestate(module)->Yield_type);
354 Py_CLEAR(astmodulestate(module)->__dict__);
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300355 Py_CLEAR(astmodulestate(module)->__doc__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700356 Py_CLEAR(astmodulestate(module)->__module__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700357 Py_CLEAR(astmodulestate(module)->_attributes);
358 Py_CLEAR(astmodulestate(module)->_fields);
359 Py_CLEAR(astmodulestate(module)->alias_type);
360 Py_CLEAR(astmodulestate(module)->annotation);
361 Py_CLEAR(astmodulestate(module)->arg);
362 Py_CLEAR(astmodulestate(module)->arg_type);
363 Py_CLEAR(astmodulestate(module)->args);
364 Py_CLEAR(astmodulestate(module)->argtypes);
365 Py_CLEAR(astmodulestate(module)->arguments_type);
366 Py_CLEAR(astmodulestate(module)->asname);
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200367 Py_CLEAR(astmodulestate(module)->ast);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700368 Py_CLEAR(astmodulestate(module)->attr);
369 Py_CLEAR(astmodulestate(module)->bases);
370 Py_CLEAR(astmodulestate(module)->body);
371 Py_CLEAR(astmodulestate(module)->boolop_type);
372 Py_CLEAR(astmodulestate(module)->cause);
373 Py_CLEAR(astmodulestate(module)->cmpop_type);
374 Py_CLEAR(astmodulestate(module)->col_offset);
375 Py_CLEAR(astmodulestate(module)->comparators);
376 Py_CLEAR(astmodulestate(module)->comprehension_type);
377 Py_CLEAR(astmodulestate(module)->context_expr);
378 Py_CLEAR(astmodulestate(module)->conversion);
379 Py_CLEAR(astmodulestate(module)->ctx);
380 Py_CLEAR(astmodulestate(module)->decorator_list);
381 Py_CLEAR(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700382 Py_CLEAR(astmodulestate(module)->elt);
383 Py_CLEAR(astmodulestate(module)->elts);
384 Py_CLEAR(astmodulestate(module)->end_col_offset);
385 Py_CLEAR(astmodulestate(module)->end_lineno);
386 Py_CLEAR(astmodulestate(module)->exc);
387 Py_CLEAR(astmodulestate(module)->excepthandler_type);
388 Py_CLEAR(astmodulestate(module)->expr_context_type);
389 Py_CLEAR(astmodulestate(module)->expr_type);
390 Py_CLEAR(astmodulestate(module)->finalbody);
391 Py_CLEAR(astmodulestate(module)->format_spec);
392 Py_CLEAR(astmodulestate(module)->func);
393 Py_CLEAR(astmodulestate(module)->generators);
394 Py_CLEAR(astmodulestate(module)->handlers);
395 Py_CLEAR(astmodulestate(module)->id);
396 Py_CLEAR(astmodulestate(module)->ifs);
397 Py_CLEAR(astmodulestate(module)->is_async);
398 Py_CLEAR(astmodulestate(module)->items);
399 Py_CLEAR(astmodulestate(module)->iter);
400 Py_CLEAR(astmodulestate(module)->key);
401 Py_CLEAR(astmodulestate(module)->keys);
402 Py_CLEAR(astmodulestate(module)->keyword_type);
403 Py_CLEAR(astmodulestate(module)->keywords);
404 Py_CLEAR(astmodulestate(module)->kind);
405 Py_CLEAR(astmodulestate(module)->kw_defaults);
406 Py_CLEAR(astmodulestate(module)->kwarg);
407 Py_CLEAR(astmodulestate(module)->kwonlyargs);
408 Py_CLEAR(astmodulestate(module)->left);
409 Py_CLEAR(astmodulestate(module)->level);
410 Py_CLEAR(astmodulestate(module)->lineno);
411 Py_CLEAR(astmodulestate(module)->lower);
412 Py_CLEAR(astmodulestate(module)->mod_type);
413 Py_CLEAR(astmodulestate(module)->module);
414 Py_CLEAR(astmodulestate(module)->msg);
415 Py_CLEAR(astmodulestate(module)->name);
416 Py_CLEAR(astmodulestate(module)->names);
417 Py_CLEAR(astmodulestate(module)->op);
418 Py_CLEAR(astmodulestate(module)->operand);
419 Py_CLEAR(astmodulestate(module)->operator_type);
420 Py_CLEAR(astmodulestate(module)->ops);
421 Py_CLEAR(astmodulestate(module)->optional_vars);
422 Py_CLEAR(astmodulestate(module)->orelse);
423 Py_CLEAR(astmodulestate(module)->posonlyargs);
424 Py_CLEAR(astmodulestate(module)->returns);
425 Py_CLEAR(astmodulestate(module)->right);
426 Py_CLEAR(astmodulestate(module)->simple);
427 Py_CLEAR(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700428 Py_CLEAR(astmodulestate(module)->step);
429 Py_CLEAR(astmodulestate(module)->stmt_type);
430 Py_CLEAR(astmodulestate(module)->tag);
431 Py_CLEAR(astmodulestate(module)->target);
432 Py_CLEAR(astmodulestate(module)->targets);
433 Py_CLEAR(astmodulestate(module)->test);
434 Py_CLEAR(astmodulestate(module)->type);
435 Py_CLEAR(astmodulestate(module)->type_comment);
436 Py_CLEAR(astmodulestate(module)->type_ignore_type);
437 Py_CLEAR(astmodulestate(module)->type_ignores);
438 Py_CLEAR(astmodulestate(module)->unaryop_type);
439 Py_CLEAR(astmodulestate(module)->upper);
440 Py_CLEAR(astmodulestate(module)->value);
441 Py_CLEAR(astmodulestate(module)->values);
442 Py_CLEAR(astmodulestate(module)->vararg);
443 Py_CLEAR(astmodulestate(module)->withitem_type);
444
445 return 0;
446}
447
448static int astmodule_traverse(PyObject *module, visitproc visit, void* arg)
449{
450 Py_VISIT(astmodulestate(module)->AST_type);
451 Py_VISIT(astmodulestate(module)->Add_singleton);
452 Py_VISIT(astmodulestate(module)->Add_type);
453 Py_VISIT(astmodulestate(module)->And_singleton);
454 Py_VISIT(astmodulestate(module)->And_type);
455 Py_VISIT(astmodulestate(module)->AnnAssign_type);
456 Py_VISIT(astmodulestate(module)->Assert_type);
457 Py_VISIT(astmodulestate(module)->Assign_type);
458 Py_VISIT(astmodulestate(module)->AsyncFor_type);
459 Py_VISIT(astmodulestate(module)->AsyncFunctionDef_type);
460 Py_VISIT(astmodulestate(module)->AsyncWith_type);
461 Py_VISIT(astmodulestate(module)->Attribute_type);
462 Py_VISIT(astmodulestate(module)->AugAssign_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700463 Py_VISIT(astmodulestate(module)->Await_type);
464 Py_VISIT(astmodulestate(module)->BinOp_type);
465 Py_VISIT(astmodulestate(module)->BitAnd_singleton);
466 Py_VISIT(astmodulestate(module)->BitAnd_type);
467 Py_VISIT(astmodulestate(module)->BitOr_singleton);
468 Py_VISIT(astmodulestate(module)->BitOr_type);
469 Py_VISIT(astmodulestate(module)->BitXor_singleton);
470 Py_VISIT(astmodulestate(module)->BitXor_type);
471 Py_VISIT(astmodulestate(module)->BoolOp_type);
472 Py_VISIT(astmodulestate(module)->Break_type);
473 Py_VISIT(astmodulestate(module)->Call_type);
474 Py_VISIT(astmodulestate(module)->ClassDef_type);
475 Py_VISIT(astmodulestate(module)->Compare_type);
476 Py_VISIT(astmodulestate(module)->Constant_type);
477 Py_VISIT(astmodulestate(module)->Continue_type);
478 Py_VISIT(astmodulestate(module)->Del_singleton);
479 Py_VISIT(astmodulestate(module)->Del_type);
480 Py_VISIT(astmodulestate(module)->Delete_type);
481 Py_VISIT(astmodulestate(module)->DictComp_type);
482 Py_VISIT(astmodulestate(module)->Dict_type);
483 Py_VISIT(astmodulestate(module)->Div_singleton);
484 Py_VISIT(astmodulestate(module)->Div_type);
485 Py_VISIT(astmodulestate(module)->Eq_singleton);
486 Py_VISIT(astmodulestate(module)->Eq_type);
487 Py_VISIT(astmodulestate(module)->ExceptHandler_type);
488 Py_VISIT(astmodulestate(module)->Expr_type);
489 Py_VISIT(astmodulestate(module)->Expression_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700490 Py_VISIT(astmodulestate(module)->FloorDiv_singleton);
491 Py_VISIT(astmodulestate(module)->FloorDiv_type);
492 Py_VISIT(astmodulestate(module)->For_type);
493 Py_VISIT(astmodulestate(module)->FormattedValue_type);
494 Py_VISIT(astmodulestate(module)->FunctionDef_type);
495 Py_VISIT(astmodulestate(module)->FunctionType_type);
496 Py_VISIT(astmodulestate(module)->GeneratorExp_type);
497 Py_VISIT(astmodulestate(module)->Global_type);
498 Py_VISIT(astmodulestate(module)->GtE_singleton);
499 Py_VISIT(astmodulestate(module)->GtE_type);
500 Py_VISIT(astmodulestate(module)->Gt_singleton);
501 Py_VISIT(astmodulestate(module)->Gt_type);
502 Py_VISIT(astmodulestate(module)->IfExp_type);
503 Py_VISIT(astmodulestate(module)->If_type);
504 Py_VISIT(astmodulestate(module)->ImportFrom_type);
505 Py_VISIT(astmodulestate(module)->Import_type);
506 Py_VISIT(astmodulestate(module)->In_singleton);
507 Py_VISIT(astmodulestate(module)->In_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700508 Py_VISIT(astmodulestate(module)->Interactive_type);
509 Py_VISIT(astmodulestate(module)->Invert_singleton);
510 Py_VISIT(astmodulestate(module)->Invert_type);
511 Py_VISIT(astmodulestate(module)->IsNot_singleton);
512 Py_VISIT(astmodulestate(module)->IsNot_type);
513 Py_VISIT(astmodulestate(module)->Is_singleton);
514 Py_VISIT(astmodulestate(module)->Is_type);
515 Py_VISIT(astmodulestate(module)->JoinedStr_type);
516 Py_VISIT(astmodulestate(module)->LShift_singleton);
517 Py_VISIT(astmodulestate(module)->LShift_type);
518 Py_VISIT(astmodulestate(module)->Lambda_type);
519 Py_VISIT(astmodulestate(module)->ListComp_type);
520 Py_VISIT(astmodulestate(module)->List_type);
521 Py_VISIT(astmodulestate(module)->Load_singleton);
522 Py_VISIT(astmodulestate(module)->Load_type);
523 Py_VISIT(astmodulestate(module)->LtE_singleton);
524 Py_VISIT(astmodulestate(module)->LtE_type);
525 Py_VISIT(astmodulestate(module)->Lt_singleton);
526 Py_VISIT(astmodulestate(module)->Lt_type);
527 Py_VISIT(astmodulestate(module)->MatMult_singleton);
528 Py_VISIT(astmodulestate(module)->MatMult_type);
529 Py_VISIT(astmodulestate(module)->Mod_singleton);
530 Py_VISIT(astmodulestate(module)->Mod_type);
531 Py_VISIT(astmodulestate(module)->Module_type);
532 Py_VISIT(astmodulestate(module)->Mult_singleton);
533 Py_VISIT(astmodulestate(module)->Mult_type);
534 Py_VISIT(astmodulestate(module)->Name_type);
535 Py_VISIT(astmodulestate(module)->NamedExpr_type);
536 Py_VISIT(astmodulestate(module)->Nonlocal_type);
537 Py_VISIT(astmodulestate(module)->NotEq_singleton);
538 Py_VISIT(astmodulestate(module)->NotEq_type);
539 Py_VISIT(astmodulestate(module)->NotIn_singleton);
540 Py_VISIT(astmodulestate(module)->NotIn_type);
541 Py_VISIT(astmodulestate(module)->Not_singleton);
542 Py_VISIT(astmodulestate(module)->Not_type);
543 Py_VISIT(astmodulestate(module)->Or_singleton);
544 Py_VISIT(astmodulestate(module)->Or_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700545 Py_VISIT(astmodulestate(module)->Pass_type);
546 Py_VISIT(astmodulestate(module)->Pow_singleton);
547 Py_VISIT(astmodulestate(module)->Pow_type);
548 Py_VISIT(astmodulestate(module)->RShift_singleton);
549 Py_VISIT(astmodulestate(module)->RShift_type);
550 Py_VISIT(astmodulestate(module)->Raise_type);
551 Py_VISIT(astmodulestate(module)->Return_type);
552 Py_VISIT(astmodulestate(module)->SetComp_type);
553 Py_VISIT(astmodulestate(module)->Set_type);
554 Py_VISIT(astmodulestate(module)->Slice_type);
555 Py_VISIT(astmodulestate(module)->Starred_type);
556 Py_VISIT(astmodulestate(module)->Store_singleton);
557 Py_VISIT(astmodulestate(module)->Store_type);
558 Py_VISIT(astmodulestate(module)->Sub_singleton);
559 Py_VISIT(astmodulestate(module)->Sub_type);
560 Py_VISIT(astmodulestate(module)->Subscript_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700561 Py_VISIT(astmodulestate(module)->Try_type);
562 Py_VISIT(astmodulestate(module)->Tuple_type);
563 Py_VISIT(astmodulestate(module)->TypeIgnore_type);
564 Py_VISIT(astmodulestate(module)->UAdd_singleton);
565 Py_VISIT(astmodulestate(module)->UAdd_type);
566 Py_VISIT(astmodulestate(module)->USub_singleton);
567 Py_VISIT(astmodulestate(module)->USub_type);
568 Py_VISIT(astmodulestate(module)->UnaryOp_type);
569 Py_VISIT(astmodulestate(module)->While_type);
570 Py_VISIT(astmodulestate(module)->With_type);
571 Py_VISIT(astmodulestate(module)->YieldFrom_type);
572 Py_VISIT(astmodulestate(module)->Yield_type);
573 Py_VISIT(astmodulestate(module)->__dict__);
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300574 Py_VISIT(astmodulestate(module)->__doc__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700575 Py_VISIT(astmodulestate(module)->__module__);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700576 Py_VISIT(astmodulestate(module)->_attributes);
577 Py_VISIT(astmodulestate(module)->_fields);
578 Py_VISIT(astmodulestate(module)->alias_type);
579 Py_VISIT(astmodulestate(module)->annotation);
580 Py_VISIT(astmodulestate(module)->arg);
581 Py_VISIT(astmodulestate(module)->arg_type);
582 Py_VISIT(astmodulestate(module)->args);
583 Py_VISIT(astmodulestate(module)->argtypes);
584 Py_VISIT(astmodulestate(module)->arguments_type);
585 Py_VISIT(astmodulestate(module)->asname);
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200586 Py_VISIT(astmodulestate(module)->ast);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700587 Py_VISIT(astmodulestate(module)->attr);
588 Py_VISIT(astmodulestate(module)->bases);
589 Py_VISIT(astmodulestate(module)->body);
590 Py_VISIT(astmodulestate(module)->boolop_type);
591 Py_VISIT(astmodulestate(module)->cause);
592 Py_VISIT(astmodulestate(module)->cmpop_type);
593 Py_VISIT(astmodulestate(module)->col_offset);
594 Py_VISIT(astmodulestate(module)->comparators);
595 Py_VISIT(astmodulestate(module)->comprehension_type);
596 Py_VISIT(astmodulestate(module)->context_expr);
597 Py_VISIT(astmodulestate(module)->conversion);
598 Py_VISIT(astmodulestate(module)->ctx);
599 Py_VISIT(astmodulestate(module)->decorator_list);
600 Py_VISIT(astmodulestate(module)->defaults);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700601 Py_VISIT(astmodulestate(module)->elt);
602 Py_VISIT(astmodulestate(module)->elts);
603 Py_VISIT(astmodulestate(module)->end_col_offset);
604 Py_VISIT(astmodulestate(module)->end_lineno);
605 Py_VISIT(astmodulestate(module)->exc);
606 Py_VISIT(astmodulestate(module)->excepthandler_type);
607 Py_VISIT(astmodulestate(module)->expr_context_type);
608 Py_VISIT(astmodulestate(module)->expr_type);
609 Py_VISIT(astmodulestate(module)->finalbody);
610 Py_VISIT(astmodulestate(module)->format_spec);
611 Py_VISIT(astmodulestate(module)->func);
612 Py_VISIT(astmodulestate(module)->generators);
613 Py_VISIT(astmodulestate(module)->handlers);
614 Py_VISIT(astmodulestate(module)->id);
615 Py_VISIT(astmodulestate(module)->ifs);
616 Py_VISIT(astmodulestate(module)->is_async);
617 Py_VISIT(astmodulestate(module)->items);
618 Py_VISIT(astmodulestate(module)->iter);
619 Py_VISIT(astmodulestate(module)->key);
620 Py_VISIT(astmodulestate(module)->keys);
621 Py_VISIT(astmodulestate(module)->keyword_type);
622 Py_VISIT(astmodulestate(module)->keywords);
623 Py_VISIT(astmodulestate(module)->kind);
624 Py_VISIT(astmodulestate(module)->kw_defaults);
625 Py_VISIT(astmodulestate(module)->kwarg);
626 Py_VISIT(astmodulestate(module)->kwonlyargs);
627 Py_VISIT(astmodulestate(module)->left);
628 Py_VISIT(astmodulestate(module)->level);
629 Py_VISIT(astmodulestate(module)->lineno);
630 Py_VISIT(astmodulestate(module)->lower);
631 Py_VISIT(astmodulestate(module)->mod_type);
632 Py_VISIT(astmodulestate(module)->module);
633 Py_VISIT(astmodulestate(module)->msg);
634 Py_VISIT(astmodulestate(module)->name);
635 Py_VISIT(astmodulestate(module)->names);
636 Py_VISIT(astmodulestate(module)->op);
637 Py_VISIT(astmodulestate(module)->operand);
638 Py_VISIT(astmodulestate(module)->operator_type);
639 Py_VISIT(astmodulestate(module)->ops);
640 Py_VISIT(astmodulestate(module)->optional_vars);
641 Py_VISIT(astmodulestate(module)->orelse);
642 Py_VISIT(astmodulestate(module)->posonlyargs);
643 Py_VISIT(astmodulestate(module)->returns);
644 Py_VISIT(astmodulestate(module)->right);
645 Py_VISIT(astmodulestate(module)->simple);
646 Py_VISIT(astmodulestate(module)->slice);
Dino Viehlandac46eb42019-09-11 10:16:34 -0700647 Py_VISIT(astmodulestate(module)->step);
648 Py_VISIT(astmodulestate(module)->stmt_type);
649 Py_VISIT(astmodulestate(module)->tag);
650 Py_VISIT(astmodulestate(module)->target);
651 Py_VISIT(astmodulestate(module)->targets);
652 Py_VISIT(astmodulestate(module)->test);
653 Py_VISIT(astmodulestate(module)->type);
654 Py_VISIT(astmodulestate(module)->type_comment);
655 Py_VISIT(astmodulestate(module)->type_ignore_type);
656 Py_VISIT(astmodulestate(module)->type_ignores);
657 Py_VISIT(astmodulestate(module)->unaryop_type);
658 Py_VISIT(astmodulestate(module)->upper);
659 Py_VISIT(astmodulestate(module)->value);
660 Py_VISIT(astmodulestate(module)->values);
661 Py_VISIT(astmodulestate(module)->vararg);
662 Py_VISIT(astmodulestate(module)->withitem_type);
663
664 return 0;
665}
666
667static void astmodule_free(void* module) {
668 astmodule_clear((PyObject*)module);
669}
670
671static struct PyModuleDef _astmodule = {
672 PyModuleDef_HEAD_INIT,
673 "_ast",
674 NULL,
675 sizeof(astmodulestate),
676 NULL,
677 NULL,
678 astmodule_traverse,
679 astmodule_clear,
680 astmodule_free,
681};
682
683#define astmodulestate_global ((astmodulestate *)PyModule_GetState(PyState_FindModule(&_astmodule)))
684
685static int init_identifiers(void)
686{
687 astmodulestate *state = astmodulestate_global;
688 if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +0300689 if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700690 if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700691 if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
692 if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
693 if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
694 if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
695 if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
696 if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
697 if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
Serhiy Storchakabace59d2020-03-22 20:33:34 +0200698 if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700699 if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
700 if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
701 if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
702 if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
703 if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
704 if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
705 if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
706 if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
707 if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
708 if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
709 if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -0700710 if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
711 if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
712 if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
713 if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
714 if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
715 if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
716 if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
717 if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
718 if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
719 if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
720 if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
721 if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
722 if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
723 if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
724 if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
725 if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
726 if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
727 if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
728 if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
729 if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
730 if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
731 if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
732 if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
733 if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
734 if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
735 if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
736 if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
737 if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
738 if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
739 if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
740 if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
741 if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
742 if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
743 if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
744 if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
745 if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
746 if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
747 if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
748 if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
749 if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
750 if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
751 if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
752 if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
753 if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
754 if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
755 if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
756 if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
757 if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
758 if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
759 if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
760 if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
761 if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
762 return 1;
763};
764
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000765static PyObject* ast2obj_mod(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300766static const char * const Module_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200767 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800768 "type_ignores",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000769};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300770static const char * const Interactive_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200771 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000772};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300773static const char * const Expression_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200774 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000775};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300776static const char * const FunctionType_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800777 "argtypes",
778 "returns",
779};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300780static const char * const stmt_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200781 "lineno",
782 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000783 "end_lineno",
784 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000785};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000786static PyObject* ast2obj_stmt(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300787static const char * const FunctionDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200788 "name",
789 "args",
790 "body",
791 "decorator_list",
792 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800793 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000794};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300795static const char * const AsyncFunctionDef_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400796 "name",
797 "args",
798 "body",
799 "decorator_list",
800 "returns",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800801 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400802};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300803static const char * const ClassDef_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200804 "name",
805 "bases",
806 "keywords",
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200807 "body",
808 "decorator_list",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000809};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300810static const char * const Return_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200811 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000812};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300813static const char * const Delete_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200814 "targets",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000815};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300816static const char * const Assign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200817 "targets",
818 "value",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800819 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000820};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300821static const char * const AugAssign_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200822 "target",
823 "op",
824 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000825};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300826static const char * const AnnAssign_fields[]={
Yury Selivanovf8cb8a12016-09-08 20:50:03 -0700827 "target",
828 "annotation",
829 "value",
830 "simple",
831};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300832static const char * const For_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200833 "target",
834 "iter",
835 "body",
836 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800837 "type_comment",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000838};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300839static const char * const AsyncFor_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400840 "target",
841 "iter",
842 "body",
843 "orelse",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800844 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400845};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300846static const char * const While_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200847 "test",
848 "body",
849 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000850};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300851static const char * const If_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200852 "test",
853 "body",
854 "orelse",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000855};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300856static const char * const With_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200857 "items",
858 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800859 "type_comment",
Guido van Rossumc2e20742006-02-27 22:32:47 +0000860};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300861static const char * const AsyncWith_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400862 "items",
863 "body",
Guido van Rossumdcfcd142019-01-31 03:40:27 -0800864 "type_comment",
Yury Selivanov75445082015-05-11 22:57:16 -0400865};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300866static const char * const Raise_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200867 "exc",
868 "cause",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000869};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300870static const char * const Try_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200871 "body",
872 "handlers",
873 "orelse",
874 "finalbody",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000875};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300876static const char * const Assert_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200877 "test",
878 "msg",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000879};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300880static const char * const Import_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200881 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000882};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300883static const char * const ImportFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200884 "module",
885 "names",
886 "level",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000887};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300888static const char * const Global_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200889 "names",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000890};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300891static const char * const Nonlocal_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200892 "names",
Jeremy Hylton81e95022007-02-27 06:50:52 +0000893};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300894static const char * const Expr_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200895 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000896};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300897static const char * const expr_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200898 "lineno",
899 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +0000900 "end_lineno",
901 "end_col_offset",
Martin v. Löwis577b5b92006-02-27 15:23:19 +0000902};
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000903static PyObject* ast2obj_expr(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300904static const char * const BoolOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200905 "op",
906 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000907};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300908static const char * const NamedExpr_fields[]={
Emily Morehouse8f59ee02019-01-24 16:49:56 -0700909 "target",
910 "value",
911};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300912static const char * const BinOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200913 "left",
914 "op",
915 "right",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000916};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300917static const char * const UnaryOp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200918 "op",
919 "operand",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000920};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300921static const char * const Lambda_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200922 "args",
923 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000924};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300925static const char * const IfExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200926 "test",
927 "body",
928 "orelse",
Thomas Woutersdca3b9c2006-02-27 00:24:13 +0000929};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300930static const char * const Dict_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200931 "keys",
932 "values",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000933};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300934static const char * const Set_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200935 "elts",
Guido van Rossum86e58e22006-08-28 15:27:34 +0000936};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300937static const char * const ListComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200938 "elt",
939 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000940};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300941static const char * const SetComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200942 "elt",
943 "generators",
Nick Coghlan650f0d02007-04-15 12:05:43 +0000944};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300945static const char * const DictComp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200946 "key",
947 "value",
948 "generators",
Guido van Rossum992d4a32007-07-11 13:09:30 +0000949};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300950static const char * const GeneratorExp_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200951 "elt",
952 "generators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000953};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300954static const char * const Await_fields[]={
Yury Selivanov75445082015-05-11 22:57:16 -0400955 "value",
956};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300957static const char * const Yield_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200958 "value",
Benjamin Peterson527c6222012-01-14 08:58:23 -0500959};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300960static const char * const YieldFrom_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200961 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000962};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300963static const char * const Compare_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200964 "left",
965 "ops",
966 "comparators",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000967};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300968static const char * const Call_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200969 "func",
970 "args",
971 "keywords",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000972};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300973static const char * const FormattedValue_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400974 "value",
975 "conversion",
976 "format_spec",
977};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300978static const char * const JoinedStr_fields[]={
Eric V. Smith235a6f02015-09-19 14:51:32 -0400979 "values",
980};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300981static const char * const Constant_fields[]={
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100982 "value",
Guido van Rossum10f8ce62019-03-13 13:00:46 -0700983 "kind",
Victor Stinnerf2c1aa12016-01-26 00:40:57 +0100984};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300985static const char * const Attribute_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200986 "value",
987 "attr",
988 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000989};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300990static const char * const Subscript_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200991 "value",
992 "slice",
993 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +0000994};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300995static const char * const Starred_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +0200996 "value",
997 "ctx",
Guido van Rossum0368b722007-05-11 16:50:42 +0000998};
Serhiy Storchaka43c97312019-09-10 13:02:30 +0300999static const char * const Name_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001000 "id",
1001 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001002};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001003static const char * const List_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001004 "elts",
1005 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001006};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001007static const char * const Tuple_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001008 "elts",
1009 "ctx",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001010};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001011static const char * const Slice_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001012 "lower",
1013 "upper",
1014 "step",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001015};
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001016static PyObject* ast2obj_expr_context(expr_context_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001017static PyObject* ast2obj_boolop(boolop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001018static PyObject* ast2obj_operator(operator_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001019static PyObject* ast2obj_unaryop(unaryop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001020static PyObject* ast2obj_cmpop(cmpop_ty);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001021static PyObject* ast2obj_comprehension(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001022static const char * const comprehension_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001023 "target",
1024 "iter",
1025 "ifs",
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07001026 "is_async",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001027};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001028static const char * const excepthandler_attributes[] = {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001029 "lineno",
1030 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001031 "end_lineno",
1032 "end_col_offset",
Neal Norwitzad74aa82008-03-31 05:14:30 +00001033};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001034static PyObject* ast2obj_excepthandler(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001035static const char * const ExceptHandler_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001036 "type",
1037 "name",
1038 "body",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001039};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001040static PyObject* ast2obj_arguments(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001041static const char * const arguments_fields[]={
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01001042 "posonlyargs",
Pablo Galindocd6e83b2019-07-15 01:32:18 +02001043 "args",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001044 "vararg",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001045 "kwonlyargs",
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001046 "kw_defaults",
Victor Stinneree4b59c2013-07-27 00:01:35 +02001047 "kwarg",
1048 "defaults",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001049};
Neal Norwitzc1505362006-12-28 06:47:50 +00001050static PyObject* ast2obj_arg(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001051static const char * const arg_attributes[] = {
Victor Stinneree4b59c2013-07-27 00:01:35 +02001052 "lineno",
1053 "col_offset",
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00001054 "end_lineno",
1055 "end_col_offset",
Benjamin Petersoncda75be2013-03-18 10:48:58 -07001056};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001057static const char * const arg_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001058 "arg",
1059 "annotation",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001060 "type_comment",
Neal Norwitzc1505362006-12-28 06:47:50 +00001061};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001062static PyObject* ast2obj_keyword(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001063static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001064 "arg",
1065 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001066};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001067static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001068static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001069 "name",
1070 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001071};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001072static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001073static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001074 "context_expr",
1075 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001076};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001077static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001078static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001079 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001080 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001081};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001082
1083
INADA Naokifc489082017-01-25 22:33:43 +09001084
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001085typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001086 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001087 PyObject *dict;
1088} AST_object;
1089
Benjamin Peterson1767e022012-03-14 21:50:29 -05001090static void
1091ast_dealloc(AST_object *self)
1092{
INADA Naokia6296d32017-08-24 14:55:17 +09001093 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001094 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001095 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001096 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001097 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1098 assert(free_func != NULL);
1099 free_func(self);
1100 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001101}
1102
Neal Norwitz207c9f32008-03-31 04:42:11 +00001103static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001104ast_traverse(AST_object *self, visitproc visit, void *arg)
1105{
1106 Py_VISIT(self->dict);
1107 return 0;
1108}
1109
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001110static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001111ast_clear(AST_object *self)
1112{
1113 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001114 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001115}
1116
1117static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001118ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1119{
1120 Py_ssize_t i, numfields = 0;
1121 int res = -1;
1122 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001123 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001124 goto cleanup;
1125 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001126 if (fields) {
1127 numfields = PySequence_Size(fields);
1128 if (numfields == -1)
1129 goto cleanup;
1130 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001131
Neal Norwitz207c9f32008-03-31 04:42:11 +00001132 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001133 if (numfields < PyTuple_GET_SIZE(args)) {
1134 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1135 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001136 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001137 numfields, numfields == 1 ? "" : "s");
1138 res = -1;
1139 goto cleanup;
1140 }
1141 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1142 /* cannot be reached when fields is NULL */
1143 PyObject *name = PySequence_GetItem(fields, i);
1144 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001145 res = -1;
1146 goto cleanup;
1147 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001148 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1149 Py_DECREF(name);
1150 if (res < 0)
1151 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001152 }
1153 if (kw) {
1154 i = 0; /* needed by PyDict_Next */
1155 while (PyDict_Next(kw, &i, &key, &value)) {
1156 res = PyObject_SetAttr(self, key, value);
1157 if (res < 0)
1158 goto cleanup;
1159 }
1160 }
1161 cleanup:
1162 Py_XDECREF(fields);
1163 return res;
1164}
1165
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001166/* Pickling support */
1167static PyObject *
1168ast_type_reduce(PyObject *self, PyObject *unused)
1169{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001170 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001171 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001172 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001173 }
1174 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001175 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001176 }
1177 return Py_BuildValue("O()", Py_TYPE(self));
1178}
1179
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001180static PyMemberDef ast_type_members[] = {
1181 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1182 {NULL} /* Sentinel */
1183};
1184
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001185static PyMethodDef ast_type_methods[] = {
1186 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1187 {NULL}
1188};
1189
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001190static PyGetSetDef ast_type_getsets[] = {
1191 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1192 {NULL}
1193};
1194
Dino Viehlandac46eb42019-09-11 10:16:34 -07001195static PyType_Slot AST_type_slots[] = {
1196 {Py_tp_dealloc, ast_dealloc},
1197 {Py_tp_getattro, PyObject_GenericGetAttr},
1198 {Py_tp_setattro, PyObject_GenericSetAttr},
1199 {Py_tp_traverse, ast_traverse},
1200 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001201 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001202 {Py_tp_methods, ast_type_methods},
1203 {Py_tp_getset, ast_type_getsets},
1204 {Py_tp_init, ast_type_init},
1205 {Py_tp_alloc, PyType_GenericAlloc},
1206 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001207 {Py_tp_free, PyObject_GC_Del},
1208 {0, 0},
1209};
1210
1211static PyType_Spec AST_type_spec = {
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001212 "ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001213 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001214 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001215 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1216 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001217};
1218
Dino Viehlandac46eb42019-09-11 10:16:34 -07001219static PyObject *
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001220make_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 +00001221{
1222 PyObject *fnames, *result;
1223 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001224 fnames = PyTuple_New(num_fields);
1225 if (!fnames) return NULL;
1226 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001227 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001228 if (!field) {
1229 Py_DECREF(fnames);
1230 return NULL;
1231 }
1232 PyTuple_SET_ITEM(fnames, i, field);
1233 }
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001234 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +09001235 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001236 astmodulestate_global->_fields, fnames,
1237 astmodulestate_global->__module__,
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001238 astmodulestate_global->ast,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001239 astmodulestate_global->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001240 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001241 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001242}
1243
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001244static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001245add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001246{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001247 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001248 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001249 if (!l)
1250 return 0;
1251 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001252 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001253 if (!s) {
1254 Py_DECREF(l);
1255 return 0;
1256 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001257 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001258 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001259 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001260 Py_DECREF(l);
1261 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001262}
1263
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001264/* Conversion AST -> Python */
1265
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001266static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1267{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001268 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001269 PyObject *result = PyList_New(n);
1270 PyObject *value;
1271 if (!result)
1272 return NULL;
1273 for (i = 0; i < n; i++) {
1274 value = func(asdl_seq_GET(seq, i));
1275 if (!value) {
1276 Py_DECREF(result);
1277 return NULL;
1278 }
1279 PyList_SET_ITEM(result, i, value);
1280 }
1281 return result;
1282}
1283
1284static PyObject* ast2obj_object(void *o)
1285{
1286 if (!o)
1287 o = Py_None;
1288 Py_INCREF((PyObject*)o);
1289 return (PyObject*)o;
1290}
Benjamin Peterson442f2092012-12-06 17:41:04 -05001291#define ast2obj_singleton ast2obj_object
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001292#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001293#define ast2obj_identifier ast2obj_object
1294#define ast2obj_string ast2obj_object
Benjamin Petersone2498412011-08-09 16:08:39 -05001295#define ast2obj_bytes ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001296
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001297static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001298{
Christian Heimes217cfd12007-12-02 14:31:20 +00001299 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001300}
1301
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001302/* Conversion Python -> AST */
1303
1304static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1305{
1306 if (obj == Py_None)
1307 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001308 if (obj) {
1309 if (PyArena_AddPyObject(arena, obj) < 0) {
1310 *out = NULL;
1311 return -1;
1312 }
1313 Py_INCREF(obj);
1314 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001315 *out = obj;
1316 return 0;
1317}
1318
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001319static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1320{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001321 if (PyArena_AddPyObject(arena, obj) < 0) {
1322 *out = NULL;
1323 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001324 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001325 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001326 *out = obj;
1327 return 0;
1328}
1329
Benjamin Peterson180e6352011-07-22 11:09:07 -05001330static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001331{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001332 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1333 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001334 return 1;
1335 }
1336 return obj2ast_object(obj, out, arena);
1337}
1338
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001339static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1340{
1341 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1342 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1343 return 1;
1344 }
1345 return obj2ast_object(obj, out, arena);
1346}
1347
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001348static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1349{
1350 int i;
1351 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001352 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001353 return 1;
1354 }
1355
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001356 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001357 if (i == -1 && PyErr_Occurred())
1358 return 1;
1359 *out = i;
1360 return 0;
1361}
1362
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001363static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001364{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001365 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001366 empty_tuple = PyTuple_New(0);
1367 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001368 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1369 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001370 Py_XDECREF(empty_tuple);
1371 return -1;
1372 }
1373 Py_DECREF(empty_tuple);
1374 return 0;
1375}
1376
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001377
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001378static int init_types(void)
1379{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001380 PyObject *m;
1381 if (PyState_FindModule(&_astmodule) == NULL) {
1382 m = PyModule_Create(&_astmodule);
1383 if (!m) return 0;
1384 PyState_AddModule(m, &_astmodule);
1385 }
1386 astmodulestate *state = astmodulestate_global;
1387 if (state->initialized) return 1;
1388 if (init_identifiers() < 0) return 0;
1389 state->AST_type = PyType_FromSpec(&AST_type_spec);
1390 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001391 if (add_ast_fields() < 0) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001392 state->mod_type = make_type("mod", state->AST_type, NULL, 0,
1393 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1394 " | Interactive(stmt* body)\n"
1395 " | Expression(expr body)\n"
1396 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001397 if (!state->mod_type) return 0;
1398 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001399 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2,
1400 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001401 if (!state->Module_type) return 0;
1402 state->Interactive_type = make_type("Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001403 Interactive_fields, 1,
1404 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001405 if (!state->Interactive_type) return 0;
1406 state->Expression_type = make_type("Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001407 Expression_fields, 1,
1408 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001409 if (!state->Expression_type) return 0;
1410 state->FunctionType_type = make_type("FunctionType", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001411 FunctionType_fields, 2,
1412 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001413 if (!state->FunctionType_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001414 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0,
1415 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1416 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1417 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1418 " | Return(expr? value)\n"
1419 " | Delete(expr* targets)\n"
1420 " | Assign(expr* targets, expr value, string? type_comment)\n"
1421 " | AugAssign(expr target, operator op, expr value)\n"
1422 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1423 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1424 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1425 " | While(expr test, stmt* body, stmt* orelse)\n"
1426 " | If(expr test, stmt* body, stmt* orelse)\n"
1427 " | With(withitem* items, stmt* body, string? type_comment)\n"
1428 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1429 " | Raise(expr? exc, expr? cause)\n"
1430 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1431 " | Assert(expr test, expr? msg)\n"
1432 " | Import(alias* names)\n"
1433 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1434 " | Global(identifier* names)\n"
1435 " | Nonlocal(identifier* names)\n"
1436 " | Expr(expr value)\n"
1437 " | Pass\n"
1438 " | Break\n"
1439 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001440 if (!state->stmt_type) return 0;
1441 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001442 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1443 return 0;
1444 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1445 -1)
1446 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001447 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001448 FunctionDef_fields, 6,
1449 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001450 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001451 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1452 -1)
1453 return 0;
1454 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1455 == -1)
1456 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001457 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1458 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001459 AsyncFunctionDef_fields, 6,
1460 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001461 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001462 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1463 == -1)
1464 return 0;
1465 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1466 Py_None) == -1)
1467 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001468 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001469 ClassDef_fields, 5,
1470 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001471 if (!state->ClassDef_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001472 state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1,
1473 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001474 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001475 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1476 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001477 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1,
1478 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001479 if (!state->Delete_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001480 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3,
1481 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001482 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001483 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1484 -1)
1485 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001486 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001487 AugAssign_fields, 3,
1488 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001489 if (!state->AugAssign_type) return 0;
1490 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001491 AnnAssign_fields, 4,
1492 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001493 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001494 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1495 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001496 state->For_type = make_type("For", state->stmt_type, For_fields, 5,
1497 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001498 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001499 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1500 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001501 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001502 AsyncFor_fields, 5,
1503 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001504 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001505 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1506 -1)
1507 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001508 state->While_type = make_type("While", state->stmt_type, While_fields, 3,
1509 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001510 if (!state->While_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001511 state->If_type = make_type("If", state->stmt_type, If_fields, 3,
1512 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001513 if (!state->If_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001514 state->With_type = make_type("With", state->stmt_type, With_fields, 3,
1515 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001516 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001517 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1518 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001519 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001520 AsyncWith_fields, 3,
1521 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001522 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001523 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1524 == -1)
1525 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001526 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2,
1527 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001528 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001529 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1530 return 0;
1531 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1532 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001533 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4,
1534 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001535 if (!state->Try_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001536 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2,
1537 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001538 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001539 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1540 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001541 state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1,
1542 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001543 if (!state->Import_type) return 0;
1544 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001545 ImportFrom_fields, 3,
1546 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001547 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001548 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1549 return 0;
1550 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1551 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001552 state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1,
1553 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001554 if (!state->Global_type) return 0;
1555 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001556 Nonlocal_fields, 1,
1557 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001558 if (!state->Nonlocal_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001559 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1,
1560 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001561 if (!state->Expr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001562 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0,
1563 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001564 if (!state->Pass_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001565 state->Break_type = make_type("Break", state->stmt_type, NULL, 0,
1566 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001567 if (!state->Break_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001568 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0,
1569 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001570 if (!state->Continue_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001571 state->expr_type = make_type("expr", state->AST_type, NULL, 0,
1572 "expr = BoolOp(boolop op, expr* values)\n"
1573 " | NamedExpr(expr target, expr value)\n"
1574 " | BinOp(expr left, operator op, expr right)\n"
1575 " | UnaryOp(unaryop op, expr operand)\n"
1576 " | Lambda(arguments args, expr body)\n"
1577 " | IfExp(expr test, expr body, expr orelse)\n"
1578 " | Dict(expr* keys, expr* values)\n"
1579 " | Set(expr* elts)\n"
1580 " | ListComp(expr elt, comprehension* generators)\n"
1581 " | SetComp(expr elt, comprehension* generators)\n"
1582 " | DictComp(expr key, expr value, comprehension* generators)\n"
1583 " | GeneratorExp(expr elt, comprehension* generators)\n"
1584 " | Await(expr value)\n"
1585 " | Yield(expr? value)\n"
1586 " | YieldFrom(expr value)\n"
1587 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1588 " | Call(expr func, expr* args, keyword* keywords)\n"
1589 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1590 " | JoinedStr(expr* values)\n"
1591 " | Constant(constant value, string? kind)\n"
1592 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1593 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1594 " | Starred(expr value, expr_context ctx)\n"
1595 " | Name(identifier id, expr_context ctx)\n"
1596 " | List(expr* elts, expr_context ctx)\n"
1597 " | Tuple(expr* elts, expr_context ctx)\n"
1598 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001599 if (!state->expr_type) return 0;
1600 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001601 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1602 return 0;
1603 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1604 -1)
1605 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001606 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2,
1607 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001608 if (!state->BoolOp_type) return 0;
1609 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001610 NamedExpr_fields, 2,
1611 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001612 if (!state->NamedExpr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001613 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3,
1614 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001615 if (!state->BinOp_type) return 0;
1616 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001617 UnaryOp_fields, 2,
1618 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001619 if (!state->UnaryOp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001620 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2,
1621 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001622 if (!state->Lambda_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001623 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3,
1624 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001625 if (!state->IfExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001626 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2,
1627 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001628 if (!state->Dict_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001629 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1,
1630 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001631 if (!state->Set_type) return 0;
1632 state->ListComp_type = make_type("ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001633 ListComp_fields, 2,
1634 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001635 if (!state->ListComp_type) return 0;
1636 state->SetComp_type = make_type("SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001637 SetComp_fields, 2,
1638 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001639 if (!state->SetComp_type) return 0;
1640 state->DictComp_type = make_type("DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001641 DictComp_fields, 3,
1642 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001643 if (!state->DictComp_type) return 0;
1644 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001645 GeneratorExp_fields, 2,
1646 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001647 if (!state->GeneratorExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001648 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1,
1649 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001650 if (!state->Await_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001651 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1,
1652 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001653 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001654 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1655 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001656 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001657 YieldFrom_fields, 1,
1658 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001659 if (!state->YieldFrom_type) return 0;
1660 state->Compare_type = make_type("Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001661 Compare_fields, 3,
1662 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001663 if (!state->Compare_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001664 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3,
1665 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001666 if (!state->Call_type) return 0;
1667 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001668 FormattedValue_fields, 3,
1669 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001670 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001671 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1672 Py_None) == -1)
1673 return 0;
1674 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1675 Py_None) == -1)
1676 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001677 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001678 JoinedStr_fields, 1,
1679 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001680 if (!state->JoinedStr_type) return 0;
1681 state->Constant_type = make_type("Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001682 Constant_fields, 2,
1683 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001684 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001685 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1686 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001687 state->Attribute_type = make_type("Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001688 Attribute_fields, 3,
1689 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001690 if (!state->Attribute_type) return 0;
1691 state->Subscript_type = make_type("Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001692 Subscript_fields, 3,
1693 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001694 if (!state->Subscript_type) return 0;
1695 state->Starred_type = make_type("Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001696 Starred_fields, 2,
1697 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001698 if (!state->Starred_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001699 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2,
1700 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001701 if (!state->Name_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001702 state->List_type = make_type("List", state->expr_type, List_fields, 2,
1703 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001704 if (!state->List_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001705 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2,
1706 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001707 if (!state->Tuple_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001708 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3,
1709 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001710 if (!state->Slice_type) return 0;
1711 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1712 return 0;
1713 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1714 return 0;
1715 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1716 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001717 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001718 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001719 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001720 if (!state->expr_context_type) return 0;
1721 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001722 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0,
1723 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001724 if (!state->Load_type) return 0;
1725 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1726 NULL, NULL);
1727 if (!state->Load_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001728 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0,
1729 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001730 if (!state->Store_type) return 0;
1731 state->Store_singleton = PyType_GenericNew((PyTypeObject
1732 *)state->Store_type, NULL, NULL);
1733 if (!state->Store_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001734 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0,
1735 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001736 if (!state->Del_type) return 0;
1737 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1738 NULL, NULL);
1739 if (!state->Del_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001740 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0,
1741 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001742 if (!state->boolop_type) return 0;
1743 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001744 state->And_type = make_type("And", state->boolop_type, NULL, 0,
1745 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001746 if (!state->And_type) return 0;
1747 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1748 NULL, NULL);
1749 if (!state->And_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001750 state->Or_type = make_type("Or", state->boolop_type, NULL, 0,
1751 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001752 if (!state->Or_type) return 0;
1753 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1754 NULL, NULL);
1755 if (!state->Or_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001756 state->operator_type = make_type("operator", state->AST_type, NULL, 0,
1757 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001758 if (!state->operator_type) return 0;
1759 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001760 state->Add_type = make_type("Add", state->operator_type, NULL, 0,
1761 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001762 if (!state->Add_type) return 0;
1763 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1764 NULL, NULL);
1765 if (!state->Add_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001766 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0,
1767 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001768 if (!state->Sub_type) return 0;
1769 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1770 NULL, NULL);
1771 if (!state->Sub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001772 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0,
1773 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001774 if (!state->Mult_type) return 0;
1775 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1776 NULL, NULL);
1777 if (!state->Mult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001778 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0,
1779 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001780 if (!state->MatMult_type) return 0;
1781 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1782 *)state->MatMult_type, NULL,
1783 NULL);
1784 if (!state->MatMult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001785 state->Div_type = make_type("Div", state->operator_type, NULL, 0,
1786 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001787 if (!state->Div_type) return 0;
1788 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1789 NULL, NULL);
1790 if (!state->Div_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001791 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0,
1792 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001793 if (!state->Mod_type) return 0;
1794 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1795 NULL, NULL);
1796 if (!state->Mod_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001797 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0,
1798 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001799 if (!state->Pow_type) return 0;
1800 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1801 NULL, NULL);
1802 if (!state->Pow_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001803 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0,
1804 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001805 if (!state->LShift_type) return 0;
1806 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1807 *)state->LShift_type, NULL,
1808 NULL);
1809 if (!state->LShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001810 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0,
1811 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001812 if (!state->RShift_type) return 0;
1813 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1814 *)state->RShift_type, NULL,
1815 NULL);
1816 if (!state->RShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001817 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0,
1818 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001819 if (!state->BitOr_type) return 0;
1820 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1821 *)state->BitOr_type, NULL, NULL);
1822 if (!state->BitOr_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001823 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0,
1824 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001825 if (!state->BitXor_type) return 0;
1826 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1827 *)state->BitXor_type, NULL,
1828 NULL);
1829 if (!state->BitXor_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001830 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0,
1831 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001832 if (!state->BitAnd_type) return 0;
1833 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1834 *)state->BitAnd_type, NULL,
1835 NULL);
1836 if (!state->BitAnd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001837 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0,
1838 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001839 if (!state->FloorDiv_type) return 0;
1840 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1841 *)state->FloorDiv_type, NULL,
1842 NULL);
1843 if (!state->FloorDiv_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001844 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0,
1845 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001846 if (!state->unaryop_type) return 0;
1847 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001848 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0,
1849 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001850 if (!state->Invert_type) return 0;
1851 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1852 *)state->Invert_type, NULL,
1853 NULL);
1854 if (!state->Invert_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001855 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0,
1856 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001857 if (!state->Not_type) return 0;
1858 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1859 NULL, NULL);
1860 if (!state->Not_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001861 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0,
1862 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001863 if (!state->UAdd_type) return 0;
1864 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1865 NULL, NULL);
1866 if (!state->UAdd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001867 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0,
1868 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001869 if (!state->USub_type) return 0;
1870 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1871 NULL, NULL);
1872 if (!state->USub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001873 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0,
1874 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001875 if (!state->cmpop_type) return 0;
1876 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001877 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0,
1878 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001879 if (!state->Eq_type) return 0;
1880 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1881 NULL, NULL);
1882 if (!state->Eq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001883 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0,
1884 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001885 if (!state->NotEq_type) return 0;
1886 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1887 *)state->NotEq_type, NULL, NULL);
1888 if (!state->NotEq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001889 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0,
1890 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001891 if (!state->Lt_type) return 0;
1892 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1893 NULL, NULL);
1894 if (!state->Lt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001895 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0,
1896 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001897 if (!state->LtE_type) return 0;
1898 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1899 NULL, NULL);
1900 if (!state->LtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001901 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0,
1902 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001903 if (!state->Gt_type) return 0;
1904 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1905 NULL, NULL);
1906 if (!state->Gt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001907 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0,
1908 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001909 if (!state->GtE_type) return 0;
1910 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1911 NULL, NULL);
1912 if (!state->GtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001913 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0,
1914 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001915 if (!state->Is_type) return 0;
1916 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1917 NULL, NULL);
1918 if (!state->Is_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001919 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0,
1920 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001921 if (!state->IsNot_type) return 0;
1922 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1923 *)state->IsNot_type, NULL, NULL);
1924 if (!state->IsNot_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001925 state->In_type = make_type("In", state->cmpop_type, NULL, 0,
1926 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001927 if (!state->In_type) return 0;
1928 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1929 NULL, NULL);
1930 if (!state->In_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001931 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0,
1932 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001933 if (!state->NotIn_type) return 0;
1934 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1935 *)state->NotIn_type, NULL, NULL);
1936 if (!state->NotIn_singleton) return 0;
1937 state->comprehension_type = make_type("comprehension", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001938 comprehension_fields, 4,
1939 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001940 if (!state->comprehension_type) return 0;
1941 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1942 state->excepthandler_type = make_type("excepthandler", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001943 NULL, 0,
1944 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001945 if (!state->excepthandler_type) return 0;
1946 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1947 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001948 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1949 == -1)
1950 return 0;
1951 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1952 Py_None) == -1)
1953 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001954 state->ExceptHandler_type = make_type("ExceptHandler",
1955 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001956 ExceptHandler_fields, 3,
1957 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001958 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001959 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1960 return 0;
1961 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1962 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001963 state->arguments_type = make_type("arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001964 arguments_fields, 7,
1965 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001966 if (!state->arguments_type) return 0;
1967 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001968 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1969 return 0;
1970 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1971 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001972 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3,
1973 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001974 if (!state->arg_type) return 0;
1975 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001976 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1977 return 0;
1978 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1979 return 0;
1980 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1981 return 0;
1982 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1983 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001984 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001985 2,
1986 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001987 if (!state->keyword_type) return 0;
1988 if (!add_attributes(state->keyword_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001989 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1990 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001991 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2,
1992 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001993 if (!state->alias_type) return 0;
1994 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001995 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
1996 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001997 state->withitem_type = make_type("withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001998 withitem_fields, 2,
1999 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002000 if (!state->withitem_type) return 0;
2001 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002002 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
2003 == -1)
2004 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002005 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0,
2006 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002007 if (!state->type_ignore_type) return 0;
2008 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
2009 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002010 TypeIgnore_fields, 2,
2011 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002012 if (!state->TypeIgnore_type) return 0;
2013 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002014 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002015}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002016
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002017static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2018static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
2019static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
2020static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
2021 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002022static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
2023static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
2024static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
2025static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
2026static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
2027 arena);
2028static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
2029 arena);
2030static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
2031static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
2032static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
2033static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002034static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002035static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
2036 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002037
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002038mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002039Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002040{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002041 mod_ty p;
2042 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2043 if (!p)
2044 return NULL;
2045 p->kind = Module_kind;
2046 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002047 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002048 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002049}
2050
2051mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002052Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002053{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002054 mod_ty p;
2055 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2056 if (!p)
2057 return NULL;
2058 p->kind = Interactive_kind;
2059 p->v.Interactive.body = body;
2060 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002061}
2062
2063mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002064Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002065{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002066 mod_ty p;
2067 if (!body) {
2068 PyErr_SetString(PyExc_ValueError,
2069 "field body is required for Expression");
2070 return NULL;
2071 }
2072 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2073 if (!p)
2074 return NULL;
2075 p->kind = Expression_kind;
2076 p->v.Expression.body = body;
2077 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002078}
2079
2080mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002081FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
2082{
2083 mod_ty p;
2084 if (!returns) {
2085 PyErr_SetString(PyExc_ValueError,
2086 "field returns is required for FunctionType");
2087 return NULL;
2088 }
2089 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2090 if (!p)
2091 return NULL;
2092 p->kind = FunctionType_kind;
2093 p->v.FunctionType.argtypes = argtypes;
2094 p->v.FunctionType.returns = returns;
2095 return p;
2096}
2097
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002098stmt_ty
2099FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002100 decorator_list, expr_ty returns, string type_comment, int lineno,
2101 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002102{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002103 stmt_ty p;
2104 if (!name) {
2105 PyErr_SetString(PyExc_ValueError,
2106 "field name is required for FunctionDef");
2107 return NULL;
2108 }
2109 if (!args) {
2110 PyErr_SetString(PyExc_ValueError,
2111 "field args is required for FunctionDef");
2112 return NULL;
2113 }
2114 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2115 if (!p)
2116 return NULL;
2117 p->kind = FunctionDef_kind;
2118 p->v.FunctionDef.name = name;
2119 p->v.FunctionDef.args = args;
2120 p->v.FunctionDef.body = body;
2121 p->v.FunctionDef.decorator_list = decorator_list;
2122 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002123 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002124 p->lineno = lineno;
2125 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002126 p->end_lineno = end_lineno;
2127 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002128 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002129}
2130
2131stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002132AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002133 * decorator_list, expr_ty returns, string type_comment, int
2134 lineno, int col_offset, int end_lineno, int end_col_offset,
2135 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002136{
2137 stmt_ty p;
2138 if (!name) {
2139 PyErr_SetString(PyExc_ValueError,
2140 "field name is required for AsyncFunctionDef");
2141 return NULL;
2142 }
2143 if (!args) {
2144 PyErr_SetString(PyExc_ValueError,
2145 "field args is required for AsyncFunctionDef");
2146 return NULL;
2147 }
2148 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2149 if (!p)
2150 return NULL;
2151 p->kind = AsyncFunctionDef_kind;
2152 p->v.AsyncFunctionDef.name = name;
2153 p->v.AsyncFunctionDef.args = args;
2154 p->v.AsyncFunctionDef.body = body;
2155 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2156 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002157 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002158 p->lineno = lineno;
2159 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002160 p->end_lineno = end_lineno;
2161 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002162 return p;
2163}
2164
2165stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002166ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002167 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2168 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002169{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002170 stmt_ty p;
2171 if (!name) {
2172 PyErr_SetString(PyExc_ValueError,
2173 "field name is required for ClassDef");
2174 return NULL;
2175 }
2176 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2177 if (!p)
2178 return NULL;
2179 p->kind = ClassDef_kind;
2180 p->v.ClassDef.name = name;
2181 p->v.ClassDef.bases = bases;
2182 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002183 p->v.ClassDef.body = body;
2184 p->v.ClassDef.decorator_list = decorator_list;
2185 p->lineno = lineno;
2186 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002187 p->end_lineno = end_lineno;
2188 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002189 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002190}
2191
2192stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002193Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2194 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002195{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002196 stmt_ty p;
2197 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2198 if (!p)
2199 return NULL;
2200 p->kind = Return_kind;
2201 p->v.Return.value = value;
2202 p->lineno = lineno;
2203 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002204 p->end_lineno = end_lineno;
2205 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002206 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002207}
2208
2209stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002210Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2211 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002212{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002213 stmt_ty p;
2214 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2215 if (!p)
2216 return NULL;
2217 p->kind = Delete_kind;
2218 p->v.Delete.targets = targets;
2219 p->lineno = lineno;
2220 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002221 p->end_lineno = end_lineno;
2222 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002223 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002224}
2225
2226stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002227Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2228 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002229{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002230 stmt_ty p;
2231 if (!value) {
2232 PyErr_SetString(PyExc_ValueError,
2233 "field value is required for Assign");
2234 return NULL;
2235 }
2236 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2237 if (!p)
2238 return NULL;
2239 p->kind = Assign_kind;
2240 p->v.Assign.targets = targets;
2241 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002242 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002243 p->lineno = lineno;
2244 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002245 p->end_lineno = end_lineno;
2246 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002247 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002248}
2249
2250stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002251AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002252 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002253{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002254 stmt_ty p;
2255 if (!target) {
2256 PyErr_SetString(PyExc_ValueError,
2257 "field target is required for AugAssign");
2258 return NULL;
2259 }
2260 if (!op) {
2261 PyErr_SetString(PyExc_ValueError,
2262 "field op is required for AugAssign");
2263 return NULL;
2264 }
2265 if (!value) {
2266 PyErr_SetString(PyExc_ValueError,
2267 "field value is required for AugAssign");
2268 return NULL;
2269 }
2270 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2271 if (!p)
2272 return NULL;
2273 p->kind = AugAssign_kind;
2274 p->v.AugAssign.target = target;
2275 p->v.AugAssign.op = op;
2276 p->v.AugAssign.value = value;
2277 p->lineno = lineno;
2278 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002279 p->end_lineno = end_lineno;
2280 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002281 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002282}
2283
2284stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002285AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002286 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2287 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002288{
2289 stmt_ty p;
2290 if (!target) {
2291 PyErr_SetString(PyExc_ValueError,
2292 "field target is required for AnnAssign");
2293 return NULL;
2294 }
2295 if (!annotation) {
2296 PyErr_SetString(PyExc_ValueError,
2297 "field annotation is required for AnnAssign");
2298 return NULL;
2299 }
2300 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2301 if (!p)
2302 return NULL;
2303 p->kind = AnnAssign_kind;
2304 p->v.AnnAssign.target = target;
2305 p->v.AnnAssign.annotation = annotation;
2306 p->v.AnnAssign.value = value;
2307 p->v.AnnAssign.simple = simple;
2308 p->lineno = lineno;
2309 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002310 p->end_lineno = end_lineno;
2311 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002312 return p;
2313}
2314
2315stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002316For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2317 type_comment, int lineno, int col_offset, int end_lineno, int
2318 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002319{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002320 stmt_ty p;
2321 if (!target) {
2322 PyErr_SetString(PyExc_ValueError,
2323 "field target is required for For");
2324 return NULL;
2325 }
2326 if (!iter) {
2327 PyErr_SetString(PyExc_ValueError,
2328 "field iter is required for For");
2329 return NULL;
2330 }
2331 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2332 if (!p)
2333 return NULL;
2334 p->kind = For_kind;
2335 p->v.For.target = target;
2336 p->v.For.iter = iter;
2337 p->v.For.body = body;
2338 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002339 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002340 p->lineno = lineno;
2341 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002342 p->end_lineno = end_lineno;
2343 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002344 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002345}
2346
2347stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002348AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2349 string type_comment, int lineno, int col_offset, int end_lineno, int
2350 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002351{
2352 stmt_ty p;
2353 if (!target) {
2354 PyErr_SetString(PyExc_ValueError,
2355 "field target is required for AsyncFor");
2356 return NULL;
2357 }
2358 if (!iter) {
2359 PyErr_SetString(PyExc_ValueError,
2360 "field iter is required for AsyncFor");
2361 return NULL;
2362 }
2363 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2364 if (!p)
2365 return NULL;
2366 p->kind = AsyncFor_kind;
2367 p->v.AsyncFor.target = target;
2368 p->v.AsyncFor.iter = iter;
2369 p->v.AsyncFor.body = body;
2370 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002371 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002372 p->lineno = lineno;
2373 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002374 p->end_lineno = end_lineno;
2375 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002376 return p;
2377}
2378
2379stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002380While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002381 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002382{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002383 stmt_ty p;
2384 if (!test) {
2385 PyErr_SetString(PyExc_ValueError,
2386 "field test is required for While");
2387 return NULL;
2388 }
2389 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2390 if (!p)
2391 return NULL;
2392 p->kind = While_kind;
2393 p->v.While.test = test;
2394 p->v.While.body = body;
2395 p->v.While.orelse = orelse;
2396 p->lineno = lineno;
2397 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002398 p->end_lineno = end_lineno;
2399 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002400 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002401}
2402
2403stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002404If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002405 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002406{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002407 stmt_ty p;
2408 if (!test) {
2409 PyErr_SetString(PyExc_ValueError,
2410 "field test is required for If");
2411 return NULL;
2412 }
2413 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2414 if (!p)
2415 return NULL;
2416 p->kind = If_kind;
2417 p->v.If.test = test;
2418 p->v.If.body = body;
2419 p->v.If.orelse = orelse;
2420 p->lineno = lineno;
2421 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002422 p->end_lineno = end_lineno;
2423 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002424 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002425}
2426
2427stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002428With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2429 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002430{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002431 stmt_ty p;
2432 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2433 if (!p)
2434 return NULL;
2435 p->kind = With_kind;
2436 p->v.With.items = items;
2437 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002438 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002439 p->lineno = lineno;
2440 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002441 p->end_lineno = end_lineno;
2442 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002443 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002444}
2445
2446stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002447AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2448 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002449{
2450 stmt_ty p;
2451 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2452 if (!p)
2453 return NULL;
2454 p->kind = AsyncWith_kind;
2455 p->v.AsyncWith.items = items;
2456 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002457 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002458 p->lineno = lineno;
2459 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002460 p->end_lineno = end_lineno;
2461 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002462 return p;
2463}
2464
2465stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002466Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2467 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002468{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002469 stmt_ty p;
2470 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2471 if (!p)
2472 return NULL;
2473 p->kind = Raise_kind;
2474 p->v.Raise.exc = exc;
2475 p->v.Raise.cause = cause;
2476 p->lineno = lineno;
2477 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002478 p->end_lineno = end_lineno;
2479 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002480 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002481}
2482
2483stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002484Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002485 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2486 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002487{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002488 stmt_ty p;
2489 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2490 if (!p)
2491 return NULL;
2492 p->kind = Try_kind;
2493 p->v.Try.body = body;
2494 p->v.Try.handlers = handlers;
2495 p->v.Try.orelse = orelse;
2496 p->v.Try.finalbody = finalbody;
2497 p->lineno = lineno;
2498 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002499 p->end_lineno = end_lineno;
2500 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002501 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002502}
2503
2504stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002505Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2506 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002507{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002508 stmt_ty p;
2509 if (!test) {
2510 PyErr_SetString(PyExc_ValueError,
2511 "field test is required for Assert");
2512 return NULL;
2513 }
2514 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2515 if (!p)
2516 return NULL;
2517 p->kind = Assert_kind;
2518 p->v.Assert.test = test;
2519 p->v.Assert.msg = msg;
2520 p->lineno = lineno;
2521 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002522 p->end_lineno = end_lineno;
2523 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002524 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002525}
2526
2527stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002528Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2529 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002530{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002531 stmt_ty p;
2532 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2533 if (!p)
2534 return NULL;
2535 p->kind = Import_kind;
2536 p->v.Import.names = names;
2537 p->lineno = lineno;
2538 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002539 p->end_lineno = end_lineno;
2540 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002541 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002542}
2543
2544stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002545ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002546 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002547{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002548 stmt_ty p;
2549 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2550 if (!p)
2551 return NULL;
2552 p->kind = ImportFrom_kind;
2553 p->v.ImportFrom.module = module;
2554 p->v.ImportFrom.names = names;
2555 p->v.ImportFrom.level = level;
2556 p->lineno = lineno;
2557 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002558 p->end_lineno = end_lineno;
2559 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002560 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002561}
2562
2563stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002564Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2565 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002566{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002567 stmt_ty p;
2568 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2569 if (!p)
2570 return NULL;
2571 p->kind = Global_kind;
2572 p->v.Global.names = names;
2573 p->lineno = lineno;
2574 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002575 p->end_lineno = end_lineno;
2576 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002577 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002578}
2579
2580stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002581Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2582 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002583{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002584 stmt_ty p;
2585 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2586 if (!p)
2587 return NULL;
2588 p->kind = Nonlocal_kind;
2589 p->v.Nonlocal.names = names;
2590 p->lineno = lineno;
2591 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002592 p->end_lineno = end_lineno;
2593 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002594 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002595}
2596
2597stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002598Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2599 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002600{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002601 stmt_ty p;
2602 if (!value) {
2603 PyErr_SetString(PyExc_ValueError,
2604 "field value is required for Expr");
2605 return NULL;
2606 }
2607 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2608 if (!p)
2609 return NULL;
2610 p->kind = Expr_kind;
2611 p->v.Expr.value = value;
2612 p->lineno = lineno;
2613 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002614 p->end_lineno = end_lineno;
2615 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002616 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002617}
2618
2619stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002620Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2621 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002622{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002623 stmt_ty p;
2624 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2625 if (!p)
2626 return NULL;
2627 p->kind = Pass_kind;
2628 p->lineno = lineno;
2629 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002630 p->end_lineno = end_lineno;
2631 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002632 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002633}
2634
2635stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002636Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2637 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002638{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002639 stmt_ty p;
2640 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2641 if (!p)
2642 return NULL;
2643 p->kind = Break_kind;
2644 p->lineno = lineno;
2645 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002646 p->end_lineno = end_lineno;
2647 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002648 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002649}
2650
2651stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002652Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2653 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002654{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002655 stmt_ty p;
2656 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2657 if (!p)
2658 return NULL;
2659 p->kind = Continue_kind;
2660 p->lineno = lineno;
2661 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002662 p->end_lineno = end_lineno;
2663 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002664 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002665}
2666
2667expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002668BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2669 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002670{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002671 expr_ty p;
2672 if (!op) {
2673 PyErr_SetString(PyExc_ValueError,
2674 "field op is required for BoolOp");
2675 return NULL;
2676 }
2677 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2678 if (!p)
2679 return NULL;
2680 p->kind = BoolOp_kind;
2681 p->v.BoolOp.op = op;
2682 p->v.BoolOp.values = values;
2683 p->lineno = lineno;
2684 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002685 p->end_lineno = end_lineno;
2686 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002687 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002688}
2689
2690expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002691NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2692 end_lineno, int end_col_offset, PyArena *arena)
2693{
2694 expr_ty p;
2695 if (!target) {
2696 PyErr_SetString(PyExc_ValueError,
2697 "field target is required for NamedExpr");
2698 return NULL;
2699 }
2700 if (!value) {
2701 PyErr_SetString(PyExc_ValueError,
2702 "field value is required for NamedExpr");
2703 return NULL;
2704 }
2705 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2706 if (!p)
2707 return NULL;
2708 p->kind = NamedExpr_kind;
2709 p->v.NamedExpr.target = target;
2710 p->v.NamedExpr.value = value;
2711 p->lineno = lineno;
2712 p->col_offset = col_offset;
2713 p->end_lineno = end_lineno;
2714 p->end_col_offset = end_col_offset;
2715 return p;
2716}
2717
2718expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002719BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002720 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002721{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002722 expr_ty p;
2723 if (!left) {
2724 PyErr_SetString(PyExc_ValueError,
2725 "field left is required for BinOp");
2726 return NULL;
2727 }
2728 if (!op) {
2729 PyErr_SetString(PyExc_ValueError,
2730 "field op is required for BinOp");
2731 return NULL;
2732 }
2733 if (!right) {
2734 PyErr_SetString(PyExc_ValueError,
2735 "field right is required for BinOp");
2736 return NULL;
2737 }
2738 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2739 if (!p)
2740 return NULL;
2741 p->kind = BinOp_kind;
2742 p->v.BinOp.left = left;
2743 p->v.BinOp.op = op;
2744 p->v.BinOp.right = right;
2745 p->lineno = lineno;
2746 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002747 p->end_lineno = end_lineno;
2748 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002749 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002750}
2751
2752expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002753UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2754 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002755{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002756 expr_ty p;
2757 if (!op) {
2758 PyErr_SetString(PyExc_ValueError,
2759 "field op is required for UnaryOp");
2760 return NULL;
2761 }
2762 if (!operand) {
2763 PyErr_SetString(PyExc_ValueError,
2764 "field operand is required for UnaryOp");
2765 return NULL;
2766 }
2767 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2768 if (!p)
2769 return NULL;
2770 p->kind = UnaryOp_kind;
2771 p->v.UnaryOp.op = op;
2772 p->v.UnaryOp.operand = operand;
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 +00002781Lambda(arguments_ty args, expr_ty body, 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 (!args) {
2786 PyErr_SetString(PyExc_ValueError,
2787 "field args is required for Lambda");
2788 return NULL;
2789 }
2790 if (!body) {
2791 PyErr_SetString(PyExc_ValueError,
2792 "field body is required for Lambda");
2793 return NULL;
2794 }
2795 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2796 if (!p)
2797 return NULL;
2798 p->kind = Lambda_kind;
2799 p->v.Lambda.args = args;
2800 p->v.Lambda.body = body;
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
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002809IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002810 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002811{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002812 expr_ty p;
2813 if (!test) {
2814 PyErr_SetString(PyExc_ValueError,
2815 "field test is required for IfExp");
2816 return NULL;
2817 }
2818 if (!body) {
2819 PyErr_SetString(PyExc_ValueError,
2820 "field body is required for IfExp");
2821 return NULL;
2822 }
2823 if (!orelse) {
2824 PyErr_SetString(PyExc_ValueError,
2825 "field orelse is required for IfExp");
2826 return NULL;
2827 }
2828 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2829 if (!p)
2830 return NULL;
2831 p->kind = IfExp_kind;
2832 p->v.IfExp.test = test;
2833 p->v.IfExp.body = body;
2834 p->v.IfExp.orelse = orelse;
2835 p->lineno = lineno;
2836 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002837 p->end_lineno = end_lineno;
2838 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002839 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002840}
2841
2842expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002843Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2844 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002845{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002846 expr_ty p;
2847 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2848 if (!p)
2849 return NULL;
2850 p->kind = Dict_kind;
2851 p->v.Dict.keys = keys;
2852 p->v.Dict.values = values;
2853 p->lineno = lineno;
2854 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002855 p->end_lineno = end_lineno;
2856 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002857 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002858}
2859
2860expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002861Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2862 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002863{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002864 expr_ty p;
2865 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2866 if (!p)
2867 return NULL;
2868 p->kind = Set_kind;
2869 p->v.Set.elts = elts;
2870 p->lineno = lineno;
2871 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002872 p->end_lineno = end_lineno;
2873 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002874 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002875}
2876
2877expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002878ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2879 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002880{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002881 expr_ty p;
2882 if (!elt) {
2883 PyErr_SetString(PyExc_ValueError,
2884 "field elt is required for ListComp");
2885 return NULL;
2886 }
2887 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2888 if (!p)
2889 return NULL;
2890 p->kind = ListComp_kind;
2891 p->v.ListComp.elt = elt;
2892 p->v.ListComp.generators = generators;
2893 p->lineno = lineno;
2894 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002895 p->end_lineno = end_lineno;
2896 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002897 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002898}
2899
2900expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002901SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2902 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002903{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002904 expr_ty p;
2905 if (!elt) {
2906 PyErr_SetString(PyExc_ValueError,
2907 "field elt is required for SetComp");
2908 return NULL;
2909 }
2910 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2911 if (!p)
2912 return NULL;
2913 p->kind = SetComp_kind;
2914 p->v.SetComp.elt = elt;
2915 p->v.SetComp.generators = generators;
2916 p->lineno = lineno;
2917 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002918 p->end_lineno = end_lineno;
2919 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002920 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002921}
2922
2923expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002924DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002925 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002926{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002927 expr_ty p;
2928 if (!key) {
2929 PyErr_SetString(PyExc_ValueError,
2930 "field key is required for DictComp");
2931 return NULL;
2932 }
2933 if (!value) {
2934 PyErr_SetString(PyExc_ValueError,
2935 "field value is required for DictComp");
2936 return NULL;
2937 }
2938 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2939 if (!p)
2940 return NULL;
2941 p->kind = DictComp_kind;
2942 p->v.DictComp.key = key;
2943 p->v.DictComp.value = value;
2944 p->v.DictComp.generators = generators;
2945 p->lineno = lineno;
2946 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002947 p->end_lineno = end_lineno;
2948 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002949 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002950}
2951
2952expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002953GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002954 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002955{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002956 expr_ty p;
2957 if (!elt) {
2958 PyErr_SetString(PyExc_ValueError,
2959 "field elt is required for GeneratorExp");
2960 return NULL;
2961 }
2962 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2963 if (!p)
2964 return NULL;
2965 p->kind = GeneratorExp_kind;
2966 p->v.GeneratorExp.elt = elt;
2967 p->v.GeneratorExp.generators = generators;
2968 p->lineno = lineno;
2969 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002970 p->end_lineno = end_lineno;
2971 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002972 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002973}
2974
2975expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002976Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2977 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002978{
2979 expr_ty p;
2980 if (!value) {
2981 PyErr_SetString(PyExc_ValueError,
2982 "field value is required for Await");
2983 return NULL;
2984 }
2985 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2986 if (!p)
2987 return NULL;
2988 p->kind = Await_kind;
2989 p->v.Await.value = value;
2990 p->lineno = lineno;
2991 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002992 p->end_lineno = end_lineno;
2993 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002994 return p;
2995}
2996
2997expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002998Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
2999 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003000{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003001 expr_ty p;
3002 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3003 if (!p)
3004 return NULL;
3005 p->kind = Yield_kind;
3006 p->v.Yield.value = value;
3007 p->lineno = lineno;
3008 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003009 p->end_lineno = end_lineno;
3010 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003011 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003012}
3013
3014expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003015YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3016 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05003017{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003018 expr_ty p;
3019 if (!value) {
3020 PyErr_SetString(PyExc_ValueError,
3021 "field value is required for YieldFrom");
3022 return NULL;
3023 }
3024 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3025 if (!p)
3026 return NULL;
3027 p->kind = YieldFrom_kind;
3028 p->v.YieldFrom.value = value;
3029 p->lineno = lineno;
3030 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003031 p->end_lineno = end_lineno;
3032 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003033 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05003034}
3035
3036expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003037Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003038 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003039{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003040 expr_ty p;
3041 if (!left) {
3042 PyErr_SetString(PyExc_ValueError,
3043 "field left is required for Compare");
3044 return NULL;
3045 }
3046 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3047 if (!p)
3048 return NULL;
3049 p->kind = Compare_kind;
3050 p->v.Compare.left = left;
3051 p->v.Compare.ops = ops;
3052 p->v.Compare.comparators = comparators;
3053 p->lineno = lineno;
3054 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003055 p->end_lineno = end_lineno;
3056 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003057 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003058}
3059
3060expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04003061Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003062 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003063{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003064 expr_ty p;
3065 if (!func) {
3066 PyErr_SetString(PyExc_ValueError,
3067 "field func is required for Call");
3068 return NULL;
3069 }
3070 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3071 if (!p)
3072 return NULL;
3073 p->kind = Call_kind;
3074 p->v.Call.func = func;
3075 p->v.Call.args = args;
3076 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003077 p->lineno = lineno;
3078 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003079 p->end_lineno = end_lineno;
3080 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003081 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003082}
3083
3084expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04003085FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
3086 int col_offset, int end_lineno, int end_col_offset, PyArena
3087 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003088{
3089 expr_ty p;
3090 if (!value) {
3091 PyErr_SetString(PyExc_ValueError,
3092 "field value is required for FormattedValue");
3093 return NULL;
3094 }
3095 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3096 if (!p)
3097 return NULL;
3098 p->kind = FormattedValue_kind;
3099 p->v.FormattedValue.value = value;
3100 p->v.FormattedValue.conversion = conversion;
3101 p->v.FormattedValue.format_spec = format_spec;
3102 p->lineno = lineno;
3103 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003104 p->end_lineno = end_lineno;
3105 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003106 return p;
3107}
3108
3109expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003110JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3111 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003112{
3113 expr_ty p;
3114 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3115 if (!p)
3116 return NULL;
3117 p->kind = JoinedStr_kind;
3118 p->v.JoinedStr.values = values;
3119 p->lineno = lineno;
3120 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003121 p->end_lineno = end_lineno;
3122 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003123 return p;
3124}
3125
3126expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003127Constant(constant value, string kind, int lineno, int col_offset, int
3128 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003129{
3130 expr_ty p;
3131 if (!value) {
3132 PyErr_SetString(PyExc_ValueError,
3133 "field value is required for Constant");
3134 return NULL;
3135 }
3136 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3137 if (!p)
3138 return NULL;
3139 p->kind = Constant_kind;
3140 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003141 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003142 p->lineno = lineno;
3143 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003144 p->end_lineno = end_lineno;
3145 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003146 return p;
3147}
3148
3149expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003150Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003151 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003152{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003153 expr_ty p;
3154 if (!value) {
3155 PyErr_SetString(PyExc_ValueError,
3156 "field value is required for Attribute");
3157 return NULL;
3158 }
3159 if (!attr) {
3160 PyErr_SetString(PyExc_ValueError,
3161 "field attr is required for Attribute");
3162 return NULL;
3163 }
3164 if (!ctx) {
3165 PyErr_SetString(PyExc_ValueError,
3166 "field ctx is required for Attribute");
3167 return NULL;
3168 }
3169 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3170 if (!p)
3171 return NULL;
3172 p->kind = Attribute_kind;
3173 p->v.Attribute.value = value;
3174 p->v.Attribute.attr = attr;
3175 p->v.Attribute.ctx = ctx;
3176 p->lineno = lineno;
3177 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003178 p->end_lineno = end_lineno;
3179 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003180 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003181}
3182
3183expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003184Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003185 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003186{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003187 expr_ty p;
3188 if (!value) {
3189 PyErr_SetString(PyExc_ValueError,
3190 "field value is required for Subscript");
3191 return NULL;
3192 }
3193 if (!slice) {
3194 PyErr_SetString(PyExc_ValueError,
3195 "field slice is required for Subscript");
3196 return NULL;
3197 }
3198 if (!ctx) {
3199 PyErr_SetString(PyExc_ValueError,
3200 "field ctx is required for Subscript");
3201 return NULL;
3202 }
3203 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3204 if (!p)
3205 return NULL;
3206 p->kind = Subscript_kind;
3207 p->v.Subscript.value = value;
3208 p->v.Subscript.slice = slice;
3209 p->v.Subscript.ctx = ctx;
3210 p->lineno = lineno;
3211 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003212 p->end_lineno = end_lineno;
3213 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003214 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003215}
3216
3217expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003218Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3219 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003220{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003221 expr_ty p;
3222 if (!value) {
3223 PyErr_SetString(PyExc_ValueError,
3224 "field value is required for Starred");
3225 return NULL;
3226 }
3227 if (!ctx) {
3228 PyErr_SetString(PyExc_ValueError,
3229 "field ctx is required for Starred");
3230 return NULL;
3231 }
3232 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3233 if (!p)
3234 return NULL;
3235 p->kind = Starred_kind;
3236 p->v.Starred.value = value;
3237 p->v.Starred.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;
Guido van Rossum0368b722007-05-11 16:50:42 +00003243}
3244
3245expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003246Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3247 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003248{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003249 expr_ty p;
3250 if (!id) {
3251 PyErr_SetString(PyExc_ValueError,
3252 "field id is required for Name");
3253 return NULL;
3254 }
3255 if (!ctx) {
3256 PyErr_SetString(PyExc_ValueError,
3257 "field ctx is required for Name");
3258 return NULL;
3259 }
3260 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3261 if (!p)
3262 return NULL;
3263 p->kind = Name_kind;
3264 p->v.Name.id = id;
3265 p->v.Name.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;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003271}
3272
3273expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003274List(asdl_seq * elts, 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 (!ctx) {
3279 PyErr_SetString(PyExc_ValueError,
3280 "field ctx is required for List");
3281 return NULL;
3282 }
3283 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3284 if (!p)
3285 return NULL;
3286 p->kind = List_kind;
3287 p->v.List.elts = elts;
3288 p->v.List.ctx = ctx;
3289 p->lineno = lineno;
3290 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003291 p->end_lineno = end_lineno;
3292 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003293 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003294}
3295
3296expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003297Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3298 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003299{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003300 expr_ty p;
3301 if (!ctx) {
3302 PyErr_SetString(PyExc_ValueError,
3303 "field ctx is required for Tuple");
3304 return NULL;
3305 }
3306 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3307 if (!p)
3308 return NULL;
3309 p->kind = Tuple_kind;
3310 p->v.Tuple.elts = elts;
3311 p->v.Tuple.ctx = ctx;
3312 p->lineno = lineno;
3313 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003314 p->end_lineno = end_lineno;
3315 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003316 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003317}
3318
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003319expr_ty
3320Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3321 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003322{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003323 expr_ty p;
3324 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003325 if (!p)
3326 return NULL;
3327 p->kind = Slice_kind;
3328 p->v.Slice.lower = lower;
3329 p->v.Slice.upper = upper;
3330 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003331 p->lineno = lineno;
3332 p->col_offset = col_offset;
3333 p->end_lineno = end_lineno;
3334 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003335 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003336}
3337
3338comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003339comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3340 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003341{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003342 comprehension_ty p;
3343 if (!target) {
3344 PyErr_SetString(PyExc_ValueError,
3345 "field target is required for comprehension");
3346 return NULL;
3347 }
3348 if (!iter) {
3349 PyErr_SetString(PyExc_ValueError,
3350 "field iter is required for comprehension");
3351 return NULL;
3352 }
3353 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3354 if (!p)
3355 return NULL;
3356 p->target = target;
3357 p->iter = iter;
3358 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003359 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003360 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003361}
3362
3363excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003364ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003365 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003366{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003367 excepthandler_ty p;
3368 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3369 if (!p)
3370 return NULL;
3371 p->kind = ExceptHandler_kind;
3372 p->v.ExceptHandler.type = type;
3373 p->v.ExceptHandler.name = name;
3374 p->v.ExceptHandler.body = body;
3375 p->lineno = lineno;
3376 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003377 p->end_lineno = end_lineno;
3378 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003379 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003380}
3381
3382arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003383arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003384 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3385 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003386{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003387 arguments_ty p;
3388 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3389 if (!p)
3390 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003391 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003392 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003393 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003394 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003395 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003396 p->kwarg = kwarg;
3397 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003398 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003399}
3400
Neal Norwitzc1505362006-12-28 06:47:50 +00003401arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003402arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3403 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003404{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003405 arg_ty p;
3406 if (!arg) {
3407 PyErr_SetString(PyExc_ValueError,
3408 "field arg is required for arg");
3409 return NULL;
3410 }
3411 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3412 if (!p)
3413 return NULL;
3414 p->arg = arg;
3415 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003416 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003417 p->lineno = lineno;
3418 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003419 p->end_lineno = end_lineno;
3420 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003421 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003422}
3423
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003424keyword_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003425keyword(identifier arg, expr_ty value, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003426{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003427 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003428 if (!value) {
3429 PyErr_SetString(PyExc_ValueError,
3430 "field value is required for keyword");
3431 return NULL;
3432 }
3433 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3434 if (!p)
3435 return NULL;
3436 p->arg = arg;
3437 p->value = value;
3438 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003439}
3440
3441alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003442alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003443{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003444 alias_ty p;
3445 if (!name) {
3446 PyErr_SetString(PyExc_ValueError,
3447 "field name is required for alias");
3448 return NULL;
3449 }
3450 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3451 if (!p)
3452 return NULL;
3453 p->name = name;
3454 p->asname = asname;
3455 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003456}
3457
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003458withitem_ty
3459withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3460{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003461 withitem_ty p;
3462 if (!context_expr) {
3463 PyErr_SetString(PyExc_ValueError,
3464 "field context_expr is required for withitem");
3465 return NULL;
3466 }
3467 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3468 if (!p)
3469 return NULL;
3470 p->context_expr = context_expr;
3471 p->optional_vars = optional_vars;
3472 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003473}
3474
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003475type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003476TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003477{
3478 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003479 if (!tag) {
3480 PyErr_SetString(PyExc_ValueError,
3481 "field tag is required for TypeIgnore");
3482 return NULL;
3483 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003484 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3485 if (!p)
3486 return NULL;
3487 p->kind = TypeIgnore_kind;
3488 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003489 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003490 return p;
3491}
3492
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003493
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003494PyObject*
3495ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003496{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003497 mod_ty o = (mod_ty)_o;
3498 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003499 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003500 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003501 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003502 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003503
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003504 switch (o->kind) {
3505 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003506 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3507 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003508 if (!result) goto failed;
3509 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3510 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003511 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003512 goto failed;
3513 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003514 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3515 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003516 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3517 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003518 goto failed;
3519 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003520 break;
3521 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003522 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3523 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003524 if (!result) goto failed;
3525 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3526 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003527 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003528 goto failed;
3529 Py_DECREF(value);
3530 break;
3531 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003532 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3533 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003534 if (!result) goto failed;
3535 value = ast2obj_expr(o->v.Expression.body);
3536 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003537 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003538 goto failed;
3539 Py_DECREF(value);
3540 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003541 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003542 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3543 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003544 if (!result) goto failed;
3545 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3546 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003547 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3548 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003549 goto failed;
3550 Py_DECREF(value);
3551 value = ast2obj_expr(o->v.FunctionType.returns);
3552 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003553 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3554 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003555 goto failed;
3556 Py_DECREF(value);
3557 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003558 }
3559 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003560failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003561 Py_XDECREF(value);
3562 Py_XDECREF(result);
3563 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003564}
3565
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003566PyObject*
3567ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003568{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003569 stmt_ty o = (stmt_ty)_o;
3570 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003571 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003572 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003573 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003574 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003575
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003576 switch (o->kind) {
3577 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003578 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3579 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003580 if (!result) goto failed;
3581 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003582 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003583 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003584 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003585 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003586 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003587 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003588 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003589 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003590 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003591 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3592 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003593 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003594 goto failed;
3595 Py_DECREF(value);
3596 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3597 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003598 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3599 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003600 goto failed;
3601 Py_DECREF(value);
3602 value = ast2obj_expr(o->v.FunctionDef.returns);
3603 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003604 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3605 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003606 goto failed;
3607 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003608 value = ast2obj_string(o->v.FunctionDef.type_comment);
3609 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003610 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3611 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003612 goto failed;
3613 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003615 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003616 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3617 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003618 if (!result) goto failed;
3619 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3620 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003621 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003622 goto failed;
3623 Py_DECREF(value);
3624 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3625 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003626 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003627 goto failed;
3628 Py_DECREF(value);
3629 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3630 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003631 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003632 goto failed;
3633 Py_DECREF(value);
3634 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3635 ast2obj_expr);
3636 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003637 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3638 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003639 goto failed;
3640 Py_DECREF(value);
3641 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3642 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003643 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3644 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003645 goto failed;
3646 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003647 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3648 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003649 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3650 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003651 goto failed;
3652 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003653 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003654 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003655 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3656 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003657 if (!result) goto failed;
3658 value = ast2obj_identifier(o->v.ClassDef.name);
3659 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003660 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003661 goto failed;
3662 Py_DECREF(value);
3663 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3664 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003665 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003666 goto failed;
3667 Py_DECREF(value);
3668 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3669 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003670 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3671 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003672 goto failed;
3673 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003674 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3675 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003676 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003677 goto failed;
3678 Py_DECREF(value);
3679 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3680 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003681 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3682 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003683 goto failed;
3684 Py_DECREF(value);
3685 break;
3686 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003687 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3688 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003689 if (!result) goto failed;
3690 value = ast2obj_expr(o->v.Return.value);
3691 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003692 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003693 goto failed;
3694 Py_DECREF(value);
3695 break;
3696 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003697 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3698 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003699 if (!result) goto failed;
3700 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3701 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003702 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3703 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003704 goto failed;
3705 Py_DECREF(value);
3706 break;
3707 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003708 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3709 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003710 if (!result) goto failed;
3711 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3712 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003713 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3714 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003715 goto failed;
3716 Py_DECREF(value);
3717 value = ast2obj_expr(o->v.Assign.value);
3718 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003719 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003720 goto failed;
3721 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003722 value = ast2obj_string(o->v.Assign.type_comment);
3723 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003724 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3725 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003726 goto failed;
3727 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003728 break;
3729 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003730 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3731 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003732 if (!result) goto failed;
3733 value = ast2obj_expr(o->v.AugAssign.target);
3734 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003735 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3736 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003737 goto failed;
3738 Py_DECREF(value);
3739 value = ast2obj_operator(o->v.AugAssign.op);
3740 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003741 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003742 goto failed;
3743 Py_DECREF(value);
3744 value = ast2obj_expr(o->v.AugAssign.value);
3745 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003746 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003747 goto failed;
3748 Py_DECREF(value);
3749 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003750 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003751 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3752 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003753 if (!result) goto failed;
3754 value = ast2obj_expr(o->v.AnnAssign.target);
3755 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003756 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3757 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003758 goto failed;
3759 Py_DECREF(value);
3760 value = ast2obj_expr(o->v.AnnAssign.annotation);
3761 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003762 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3763 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003764 goto failed;
3765 Py_DECREF(value);
3766 value = ast2obj_expr(o->v.AnnAssign.value);
3767 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003768 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003769 goto failed;
3770 Py_DECREF(value);
3771 value = ast2obj_int(o->v.AnnAssign.simple);
3772 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003773 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3774 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003775 goto failed;
3776 Py_DECREF(value);
3777 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003778 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003779 tp = (PyTypeObject *)astmodulestate_global->For_type;
3780 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003781 if (!result) goto failed;
3782 value = ast2obj_expr(o->v.For.target);
3783 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003784 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3785 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003786 goto failed;
3787 Py_DECREF(value);
3788 value = ast2obj_expr(o->v.For.iter);
3789 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003790 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003791 goto failed;
3792 Py_DECREF(value);
3793 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3794 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003795 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003796 goto failed;
3797 Py_DECREF(value);
3798 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3799 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003800 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3801 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003802 goto failed;
3803 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003804 value = ast2obj_string(o->v.For.type_comment);
3805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003806 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3807 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003808 goto failed;
3809 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003810 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003811 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003812 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3813 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003814 if (!result) goto failed;
3815 value = ast2obj_expr(o->v.AsyncFor.target);
3816 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003817 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3818 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003819 goto failed;
3820 Py_DECREF(value);
3821 value = ast2obj_expr(o->v.AsyncFor.iter);
3822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003823 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003824 goto failed;
3825 Py_DECREF(value);
3826 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3827 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003828 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003829 goto failed;
3830 Py_DECREF(value);
3831 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003833 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3834 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003835 goto failed;
3836 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003837 value = ast2obj_string(o->v.AsyncFor.type_comment);
3838 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003839 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3840 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003841 goto failed;
3842 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003843 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003844 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003845 tp = (PyTypeObject *)astmodulestate_global->While_type;
3846 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003847 if (!result) goto failed;
3848 value = ast2obj_expr(o->v.While.test);
3849 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003850 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003851 goto failed;
3852 Py_DECREF(value);
3853 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3854 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003855 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003856 goto failed;
3857 Py_DECREF(value);
3858 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3859 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003860 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3861 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003862 goto failed;
3863 Py_DECREF(value);
3864 break;
3865 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003866 tp = (PyTypeObject *)astmodulestate_global->If_type;
3867 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003868 if (!result) goto failed;
3869 value = ast2obj_expr(o->v.If.test);
3870 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003871 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003872 goto failed;
3873 Py_DECREF(value);
3874 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3875 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003876 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003877 goto failed;
3878 Py_DECREF(value);
3879 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3880 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003881 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3882 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003883 goto failed;
3884 Py_DECREF(value);
3885 break;
3886 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003887 tp = (PyTypeObject *)astmodulestate_global->With_type;
3888 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003889 if (!result) goto failed;
3890 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3891 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003892 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003893 goto failed;
3894 Py_DECREF(value);
3895 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3896 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003897 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003898 goto failed;
3899 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003900 value = ast2obj_string(o->v.With.type_comment);
3901 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003902 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3903 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003904 goto failed;
3905 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003906 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003907 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003908 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3909 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003910 if (!result) goto failed;
3911 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3912 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003913 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003914 goto failed;
3915 Py_DECREF(value);
3916 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3917 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003918 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003919 goto failed;
3920 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003921 value = ast2obj_string(o->v.AsyncWith.type_comment);
3922 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003923 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3924 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003925 goto failed;
3926 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003927 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003928 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003929 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3930 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003931 if (!result) goto failed;
3932 value = ast2obj_expr(o->v.Raise.exc);
3933 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003934 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003935 goto failed;
3936 Py_DECREF(value);
3937 value = ast2obj_expr(o->v.Raise.cause);
3938 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003939 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003940 goto failed;
3941 Py_DECREF(value);
3942 break;
3943 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003944 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3945 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003946 if (!result) goto failed;
3947 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3948 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003949 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003950 goto failed;
3951 Py_DECREF(value);
3952 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3953 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003954 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3955 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003956 goto failed;
3957 Py_DECREF(value);
3958 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3959 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003960 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3961 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003962 goto failed;
3963 Py_DECREF(value);
3964 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3965 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003966 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3967 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003968 goto failed;
3969 Py_DECREF(value);
3970 break;
3971 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003972 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3973 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003974 if (!result) goto failed;
3975 value = ast2obj_expr(o->v.Assert.test);
3976 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003977 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003978 goto failed;
3979 Py_DECREF(value);
3980 value = ast2obj_expr(o->v.Assert.msg);
3981 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003982 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003983 goto failed;
3984 Py_DECREF(value);
3985 break;
3986 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003987 tp = (PyTypeObject *)astmodulestate_global->Import_type;
3988 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003989 if (!result) goto failed;
3990 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
3991 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003992 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003993 goto failed;
3994 Py_DECREF(value);
3995 break;
3996 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003997 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
3998 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003999 if (!result) goto failed;
4000 value = ast2obj_identifier(o->v.ImportFrom.module);
4001 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004002 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
4003 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004004 goto failed;
4005 Py_DECREF(value);
4006 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
4007 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004008 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004009 goto failed;
4010 Py_DECREF(value);
4011 value = ast2obj_int(o->v.ImportFrom.level);
4012 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004013 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004014 goto failed;
4015 Py_DECREF(value);
4016 break;
4017 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004018 tp = (PyTypeObject *)astmodulestate_global->Global_type;
4019 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004020 if (!result) goto failed;
4021 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
4022 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004023 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004024 goto failed;
4025 Py_DECREF(value);
4026 break;
4027 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004028 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
4029 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004030 if (!result) goto failed;
4031 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
4032 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004033 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004034 goto failed;
4035 Py_DECREF(value);
4036 break;
4037 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004038 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
4039 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 if (!result) goto failed;
4041 value = ast2obj_expr(o->v.Expr.value);
4042 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004043 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 goto failed;
4045 Py_DECREF(value);
4046 break;
4047 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004048 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
4049 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004050 if (!result) goto failed;
4051 break;
4052 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004053 tp = (PyTypeObject *)astmodulestate_global->Break_type;
4054 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004055 if (!result) goto failed;
4056 break;
4057 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004058 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
4059 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004060 if (!result) goto failed;
4061 break;
4062 }
4063 value = ast2obj_int(o->lineno);
4064 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004065 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004066 goto failed;
4067 Py_DECREF(value);
4068 value = ast2obj_int(o->col_offset);
4069 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004070 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004071 goto failed;
4072 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004073 value = ast2obj_int(o->end_lineno);
4074 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004075 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004076 goto failed;
4077 Py_DECREF(value);
4078 value = ast2obj_int(o->end_col_offset);
4079 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004080 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4081 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004082 goto failed;
4083 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004084 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004085failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004086 Py_XDECREF(value);
4087 Py_XDECREF(result);
4088 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004089}
4090
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004091PyObject*
4092ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004093{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004094 expr_ty o = (expr_ty)_o;
4095 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004096 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004097 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004098 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004099 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004100
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004101 switch (o->kind) {
4102 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004103 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4104 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004105 if (!result) goto failed;
4106 value = ast2obj_boolop(o->v.BoolOp.op);
4107 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004108 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004109 goto failed;
4110 Py_DECREF(value);
4111 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4112 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004113 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4114 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004115 goto failed;
4116 Py_DECREF(value);
4117 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004118 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004119 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4120 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004121 if (!result) goto failed;
4122 value = ast2obj_expr(o->v.NamedExpr.target);
4123 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004124 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4125 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004126 goto failed;
4127 Py_DECREF(value);
4128 value = ast2obj_expr(o->v.NamedExpr.value);
4129 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004130 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004131 goto failed;
4132 Py_DECREF(value);
4133 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004134 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004135 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4136 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004137 if (!result) goto failed;
4138 value = ast2obj_expr(o->v.BinOp.left);
4139 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004140 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004141 goto failed;
4142 Py_DECREF(value);
4143 value = ast2obj_operator(o->v.BinOp.op);
4144 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004145 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004146 goto failed;
4147 Py_DECREF(value);
4148 value = ast2obj_expr(o->v.BinOp.right);
4149 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004150 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004151 goto failed;
4152 Py_DECREF(value);
4153 break;
4154 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004155 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4156 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004157 if (!result) goto failed;
4158 value = ast2obj_unaryop(o->v.UnaryOp.op);
4159 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004160 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004161 goto failed;
4162 Py_DECREF(value);
4163 value = ast2obj_expr(o->v.UnaryOp.operand);
4164 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004165 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4166 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004167 goto failed;
4168 Py_DECREF(value);
4169 break;
4170 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004171 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4172 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004173 if (!result) goto failed;
4174 value = ast2obj_arguments(o->v.Lambda.args);
4175 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004176 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004177 goto failed;
4178 Py_DECREF(value);
4179 value = ast2obj_expr(o->v.Lambda.body);
4180 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004181 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004182 goto failed;
4183 Py_DECREF(value);
4184 break;
4185 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004186 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4187 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004188 if (!result) goto failed;
4189 value = ast2obj_expr(o->v.IfExp.test);
4190 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004191 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004192 goto failed;
4193 Py_DECREF(value);
4194 value = ast2obj_expr(o->v.IfExp.body);
4195 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004196 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004197 goto failed;
4198 Py_DECREF(value);
4199 value = ast2obj_expr(o->v.IfExp.orelse);
4200 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004201 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4202 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004203 goto failed;
4204 Py_DECREF(value);
4205 break;
4206 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004207 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4208 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004209 if (!result) goto failed;
4210 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4211 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004212 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004213 goto failed;
4214 Py_DECREF(value);
4215 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4216 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004217 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4218 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004219 goto failed;
4220 Py_DECREF(value);
4221 break;
4222 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004223 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4224 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004225 if (!result) goto failed;
4226 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4227 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004228 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004229 goto failed;
4230 Py_DECREF(value);
4231 break;
4232 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004233 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4234 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004235 if (!result) goto failed;
4236 value = ast2obj_expr(o->v.ListComp.elt);
4237 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004238 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004239 goto failed;
4240 Py_DECREF(value);
4241 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4242 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004243 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4244 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004245 goto failed;
4246 Py_DECREF(value);
4247 break;
4248 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004249 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4250 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004251 if (!result) goto failed;
4252 value = ast2obj_expr(o->v.SetComp.elt);
4253 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004254 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004255 goto failed;
4256 Py_DECREF(value);
4257 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4258 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004259 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4260 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004261 goto failed;
4262 Py_DECREF(value);
4263 break;
4264 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004265 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4266 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004267 if (!result) goto failed;
4268 value = ast2obj_expr(o->v.DictComp.key);
4269 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004270 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004271 goto failed;
4272 Py_DECREF(value);
4273 value = ast2obj_expr(o->v.DictComp.value);
4274 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004275 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004276 goto failed;
4277 Py_DECREF(value);
4278 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4279 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004280 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4281 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004282 goto failed;
4283 Py_DECREF(value);
4284 break;
4285 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004286 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4287 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004288 if (!result) goto failed;
4289 value = ast2obj_expr(o->v.GeneratorExp.elt);
4290 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004291 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004292 goto failed;
4293 Py_DECREF(value);
4294 value = ast2obj_list(o->v.GeneratorExp.generators,
4295 ast2obj_comprehension);
4296 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004297 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4298 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004299 goto failed;
4300 Py_DECREF(value);
4301 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004302 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004303 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4304 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004305 if (!result) goto failed;
4306 value = ast2obj_expr(o->v.Await.value);
4307 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004308 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004309 goto failed;
4310 Py_DECREF(value);
4311 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004313 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4314 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004315 if (!result) goto failed;
4316 value = ast2obj_expr(o->v.Yield.value);
4317 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004318 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004319 goto failed;
4320 Py_DECREF(value);
4321 break;
4322 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004323 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4324 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004325 if (!result) goto failed;
4326 value = ast2obj_expr(o->v.YieldFrom.value);
4327 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004328 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004329 goto failed;
4330 Py_DECREF(value);
4331 break;
4332 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004333 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4334 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004335 if (!result) goto failed;
4336 value = ast2obj_expr(o->v.Compare.left);
4337 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004338 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004339 goto failed;
4340 Py_DECREF(value);
4341 {
4342 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4343 value = PyList_New(n);
4344 if (!value) goto failed;
4345 for(i = 0; i < n; i++)
4346 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004347 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004348 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004349 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004350 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004351 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004352 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004353 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004354 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4355 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004356 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004357 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004358 break;
4359 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004360 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4361 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004362 if (!result) goto failed;
4363 value = ast2obj_expr(o->v.Call.func);
4364 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004365 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 goto failed;
4367 Py_DECREF(value);
4368 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4369 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004370 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004371 goto failed;
4372 Py_DECREF(value);
4373 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4374 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004375 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4376 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004377 goto failed;
4378 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004379 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004380 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004381 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4382 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004383 if (!result) goto failed;
4384 value = ast2obj_expr(o->v.FormattedValue.value);
4385 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004386 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004387 goto failed;
4388 Py_DECREF(value);
4389 value = ast2obj_int(o->v.FormattedValue.conversion);
4390 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004391 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4392 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004393 goto failed;
4394 Py_DECREF(value);
4395 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4396 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004397 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4398 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004399 goto failed;
4400 Py_DECREF(value);
4401 break;
4402 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004403 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4404 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004405 if (!result) goto failed;
4406 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4407 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004408 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4409 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004410 goto failed;
4411 Py_DECREF(value);
4412 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004413 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004414 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4415 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004416 if (!result) goto failed;
4417 value = ast2obj_constant(o->v.Constant.value);
4418 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004419 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004420 goto failed;
4421 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004422 value = ast2obj_string(o->v.Constant.kind);
4423 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004424 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004425 goto failed;
4426 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004427 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004428 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004429 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4430 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004431 if (!result) goto failed;
4432 value = ast2obj_expr(o->v.Attribute.value);
4433 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004434 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004435 goto failed;
4436 Py_DECREF(value);
4437 value = ast2obj_identifier(o->v.Attribute.attr);
4438 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004439 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004440 goto failed;
4441 Py_DECREF(value);
4442 value = ast2obj_expr_context(o->v.Attribute.ctx);
4443 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004444 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004445 goto failed;
4446 Py_DECREF(value);
4447 break;
4448 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004449 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4450 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004451 if (!result) goto failed;
4452 value = ast2obj_expr(o->v.Subscript.value);
4453 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004454 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004455 goto failed;
4456 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004457 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004458 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004459 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004460 goto failed;
4461 Py_DECREF(value);
4462 value = ast2obj_expr_context(o->v.Subscript.ctx);
4463 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004464 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004465 goto failed;
4466 Py_DECREF(value);
4467 break;
4468 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004469 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4470 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004471 if (!result) goto failed;
4472 value = ast2obj_expr(o->v.Starred.value);
4473 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004474 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004475 goto failed;
4476 Py_DECREF(value);
4477 value = ast2obj_expr_context(o->v.Starred.ctx);
4478 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004479 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004480 goto failed;
4481 Py_DECREF(value);
4482 break;
4483 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004484 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4485 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004486 if (!result) goto failed;
4487 value = ast2obj_identifier(o->v.Name.id);
4488 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004489 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004490 goto failed;
4491 Py_DECREF(value);
4492 value = ast2obj_expr_context(o->v.Name.ctx);
4493 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004494 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004495 goto failed;
4496 Py_DECREF(value);
4497 break;
4498 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004499 tp = (PyTypeObject *)astmodulestate_global->List_type;
4500 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004501 if (!result) goto failed;
4502 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4503 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004504 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004505 goto failed;
4506 Py_DECREF(value);
4507 value = ast2obj_expr_context(o->v.List.ctx);
4508 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004509 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004510 goto failed;
4511 Py_DECREF(value);
4512 break;
4513 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004514 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4515 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004516 if (!result) goto failed;
4517 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4518 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004519 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004520 goto failed;
4521 Py_DECREF(value);
4522 value = ast2obj_expr_context(o->v.Tuple.ctx);
4523 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004524 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004525 goto failed;
4526 Py_DECREF(value);
4527 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004528 case Slice_kind:
4529 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4530 result = PyType_GenericNew(tp, NULL, NULL);
4531 if (!result) goto failed;
4532 value = ast2obj_expr(o->v.Slice.lower);
4533 if (!value) goto failed;
4534 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4535 goto failed;
4536 Py_DECREF(value);
4537 value = ast2obj_expr(o->v.Slice.upper);
4538 if (!value) goto failed;
4539 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4540 goto failed;
4541 Py_DECREF(value);
4542 value = ast2obj_expr(o->v.Slice.step);
4543 if (!value) goto failed;
4544 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4545 goto failed;
4546 Py_DECREF(value);
4547 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004548 }
4549 value = ast2obj_int(o->lineno);
4550 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004551 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004552 goto failed;
4553 Py_DECREF(value);
4554 value = ast2obj_int(o->col_offset);
4555 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004556 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004557 goto failed;
4558 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004559 value = ast2obj_int(o->end_lineno);
4560 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004561 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004562 goto failed;
4563 Py_DECREF(value);
4564 value = ast2obj_int(o->end_col_offset);
4565 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004566 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4567 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004568 goto failed;
4569 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004570 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004571failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004572 Py_XDECREF(value);
4573 Py_XDECREF(result);
4574 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004575}
4576
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004577PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004578{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004579 switch(o) {
4580 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004581 Py_INCREF(astmodulestate_global->Load_singleton);
4582 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004583 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004584 Py_INCREF(astmodulestate_global->Store_singleton);
4585 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004586 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004587 Py_INCREF(astmodulestate_global->Del_singleton);
4588 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004589 default:
4590 /* should never happen, but just in case ... */
4591 PyErr_Format(PyExc_SystemError, "unknown expr_context found");
4592 return NULL;
4593 }
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004594}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004595PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004596{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004597 switch(o) {
4598 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004599 Py_INCREF(astmodulestate_global->And_singleton);
4600 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004601 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004602 Py_INCREF(astmodulestate_global->Or_singleton);
4603 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004604 default:
4605 /* should never happen, but just in case ... */
4606 PyErr_Format(PyExc_SystemError, "unknown boolop found");
4607 return NULL;
4608 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004609}
4610PyObject* ast2obj_operator(operator_ty o)
4611{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004612 switch(o) {
4613 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004614 Py_INCREF(astmodulestate_global->Add_singleton);
4615 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004616 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004617 Py_INCREF(astmodulestate_global->Sub_singleton);
4618 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004619 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004620 Py_INCREF(astmodulestate_global->Mult_singleton);
4621 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004622 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004623 Py_INCREF(astmodulestate_global->MatMult_singleton);
4624 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004625 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004626 Py_INCREF(astmodulestate_global->Div_singleton);
4627 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004628 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004629 Py_INCREF(astmodulestate_global->Mod_singleton);
4630 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004631 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004632 Py_INCREF(astmodulestate_global->Pow_singleton);
4633 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004634 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004635 Py_INCREF(astmodulestate_global->LShift_singleton);
4636 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004637 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004638 Py_INCREF(astmodulestate_global->RShift_singleton);
4639 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004640 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004641 Py_INCREF(astmodulestate_global->BitOr_singleton);
4642 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004643 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004644 Py_INCREF(astmodulestate_global->BitXor_singleton);
4645 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004646 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004647 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4648 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004649 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004650 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4651 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004652 default:
4653 /* should never happen, but just in case ... */
4654 PyErr_Format(PyExc_SystemError, "unknown operator found");
4655 return NULL;
4656 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004657}
4658PyObject* ast2obj_unaryop(unaryop_ty o)
4659{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004660 switch(o) {
4661 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004662 Py_INCREF(astmodulestate_global->Invert_singleton);
4663 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004664 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004665 Py_INCREF(astmodulestate_global->Not_singleton);
4666 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004667 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004668 Py_INCREF(astmodulestate_global->UAdd_singleton);
4669 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004670 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004671 Py_INCREF(astmodulestate_global->USub_singleton);
4672 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004673 default:
4674 /* should never happen, but just in case ... */
4675 PyErr_Format(PyExc_SystemError, "unknown unaryop found");
4676 return NULL;
4677 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004678}
4679PyObject* ast2obj_cmpop(cmpop_ty o)
4680{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004681 switch(o) {
4682 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004683 Py_INCREF(astmodulestate_global->Eq_singleton);
4684 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004685 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004686 Py_INCREF(astmodulestate_global->NotEq_singleton);
4687 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004688 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004689 Py_INCREF(astmodulestate_global->Lt_singleton);
4690 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004691 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004692 Py_INCREF(astmodulestate_global->LtE_singleton);
4693 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004694 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004695 Py_INCREF(astmodulestate_global->Gt_singleton);
4696 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004697 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004698 Py_INCREF(astmodulestate_global->GtE_singleton);
4699 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004700 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004701 Py_INCREF(astmodulestate_global->Is_singleton);
4702 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004703 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004704 Py_INCREF(astmodulestate_global->IsNot_singleton);
4705 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004706 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004707 Py_INCREF(astmodulestate_global->In_singleton);
4708 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004709 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004710 Py_INCREF(astmodulestate_global->NotIn_singleton);
4711 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004712 default:
4713 /* should never happen, but just in case ... */
4714 PyErr_Format(PyExc_SystemError, "unknown cmpop found");
4715 return NULL;
4716 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004717}
4718PyObject*
4719ast2obj_comprehension(void* _o)
4720{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004721 comprehension_ty o = (comprehension_ty)_o;
4722 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004723 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004724 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004725 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004726 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004727
Dino Viehlandac46eb42019-09-11 10:16:34 -07004728 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4729 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004730 if (!result) return NULL;
4731 value = ast2obj_expr(o->target);
4732 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004733 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004734 goto failed;
4735 Py_DECREF(value);
4736 value = ast2obj_expr(o->iter);
4737 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004738 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004739 goto failed;
4740 Py_DECREF(value);
4741 value = ast2obj_list(o->ifs, ast2obj_expr);
4742 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004743 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004744 goto failed;
4745 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004746 value = ast2obj_int(o->is_async);
4747 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004748 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004749 goto failed;
4750 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004751 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004752failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004753 Py_XDECREF(value);
4754 Py_XDECREF(result);
4755 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004756}
4757
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004758PyObject*
4759ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004760{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004761 excepthandler_ty o = (excepthandler_ty)_o;
4762 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004763 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004764 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004765 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004766 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004767
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004768 switch (o->kind) {
4769 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004770 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4771 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004772 if (!result) goto failed;
4773 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004774 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004775 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004776 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004777 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004778 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004779 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004780 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004781 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004782 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004783 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4784 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004785 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004786 goto failed;
4787 Py_DECREF(value);
4788 break;
4789 }
4790 value = ast2obj_int(o->lineno);
4791 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004792 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004793 goto failed;
4794 Py_DECREF(value);
4795 value = ast2obj_int(o->col_offset);
4796 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004797 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004798 goto failed;
4799 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004800 value = ast2obj_int(o->end_lineno);
4801 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004802 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004803 goto failed;
4804 Py_DECREF(value);
4805 value = ast2obj_int(o->end_col_offset);
4806 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004807 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4808 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004809 goto failed;
4810 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004811 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004812failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004813 Py_XDECREF(value);
4814 Py_XDECREF(result);
4815 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004816}
4817
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004818PyObject*
4819ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004820{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004821 arguments_ty o = (arguments_ty)_o;
4822 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004823 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004824 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004825 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004826 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004827
Dino Viehlandac46eb42019-09-11 10:16:34 -07004828 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4829 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004830 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004831 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4832 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004833 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4834 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004835 goto failed;
4836 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004837 value = ast2obj_list(o->args, ast2obj_arg);
4838 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004839 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004840 goto failed;
4841 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004842 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004843 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004844 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004845 goto failed;
4846 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004847 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4848 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004849 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4850 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004851 goto failed;
4852 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004853 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004854 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004855 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4856 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004857 goto failed;
4858 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004859 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004860 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004861 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004862 goto failed;
4863 Py_DECREF(value);
4864 value = ast2obj_list(o->defaults, ast2obj_expr);
4865 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004866 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004867 goto failed;
4868 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004869 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004870failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004871 Py_XDECREF(value);
4872 Py_XDECREF(result);
4873 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004874}
4875
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004876PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004877ast2obj_arg(void* _o)
4878{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004879 arg_ty o = (arg_ty)_o;
4880 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004881 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004882 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004883 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004884 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004885
Dino Viehlandac46eb42019-09-11 10:16:34 -07004886 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4887 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004888 if (!result) return NULL;
4889 value = ast2obj_identifier(o->arg);
4890 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004891 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004892 goto failed;
4893 Py_DECREF(value);
4894 value = ast2obj_expr(o->annotation);
4895 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004896 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4897 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004898 goto failed;
4899 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004900 value = ast2obj_string(o->type_comment);
4901 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004902 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4903 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004904 goto failed;
4905 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004906 value = ast2obj_int(o->lineno);
4907 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004908 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004909 goto failed;
4910 Py_DECREF(value);
4911 value = ast2obj_int(o->col_offset);
4912 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004913 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004914 goto failed;
4915 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004916 value = ast2obj_int(o->end_lineno);
4917 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004918 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004919 goto failed;
4920 Py_DECREF(value);
4921 value = ast2obj_int(o->end_col_offset);
4922 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004923 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4924 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004925 goto failed;
4926 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004927 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004928failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004929 Py_XDECREF(value);
4930 Py_XDECREF(result);
4931 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004932}
4933
4934PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004935ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004936{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004937 keyword_ty o = (keyword_ty)_o;
4938 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004939 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004940 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004941 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004942 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004943
Dino Viehlandac46eb42019-09-11 10:16:34 -07004944 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4945 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004946 if (!result) return NULL;
4947 value = ast2obj_identifier(o->arg);
4948 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004949 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004950 goto failed;
4951 Py_DECREF(value);
4952 value = ast2obj_expr(o->value);
4953 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004954 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004955 goto failed;
4956 Py_DECREF(value);
4957 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004958failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004959 Py_XDECREF(value);
4960 Py_XDECREF(result);
4961 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004962}
4963
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004964PyObject*
4965ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004966{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004967 alias_ty o = (alias_ty)_o;
4968 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004969 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004970 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004971 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004972 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004973
Dino Viehlandac46eb42019-09-11 10:16:34 -07004974 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4975 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004976 if (!result) return NULL;
4977 value = ast2obj_identifier(o->name);
4978 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004979 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004980 goto failed;
4981 Py_DECREF(value);
4982 value = ast2obj_identifier(o->asname);
4983 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004984 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004985 goto failed;
4986 Py_DECREF(value);
4987 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004988failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004989 Py_XDECREF(value);
4990 Py_XDECREF(result);
4991 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004992}
4993
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05004994PyObject*
4995ast2obj_withitem(void* _o)
4996{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004997 withitem_ty o = (withitem_ty)_o;
4998 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004999 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005000 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005001 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005002 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005003
Dino Viehlandac46eb42019-09-11 10:16:34 -07005004 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
5005 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005006 if (!result) return NULL;
5007 value = ast2obj_expr(o->context_expr);
5008 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005009 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
5010 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005011 goto failed;
5012 Py_DECREF(value);
5013 value = ast2obj_expr(o->optional_vars);
5014 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005015 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
5016 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005017 goto failed;
5018 Py_DECREF(value);
5019 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005020failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005021 Py_XDECREF(value);
5022 Py_XDECREF(result);
5023 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005024}
5025
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005026PyObject*
5027ast2obj_type_ignore(void* _o)
5028{
5029 type_ignore_ty o = (type_ignore_ty)_o;
5030 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005031 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005032 if (!o) {
5033 Py_RETURN_NONE;
5034 }
5035
5036 switch (o->kind) {
5037 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005038 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5039 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005040 if (!result) goto failed;
5041 value = ast2obj_int(o->v.TypeIgnore.lineno);
5042 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005043 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5044 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005045 goto failed;
5046 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005047 value = ast2obj_string(o->v.TypeIgnore.tag);
5048 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005049 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005050 goto failed;
5051 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005052 break;
5053 }
5054 return result;
5055failed:
5056 Py_XDECREF(value);
5057 Py_XDECREF(result);
5058 return NULL;
5059}
5060
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005061
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005062int
5063obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5064{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005065 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005066
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005067 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005068 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005069
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005070 if (obj == Py_None) {
5071 *out = NULL;
5072 return 0;
5073 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005074 tp = astmodulestate_global->Module_type;
5075 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005076 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005077 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005078 }
5079 if (isinstance) {
5080 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005081 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005082
Dino Viehlandac46eb42019-09-11 10:16:34 -07005083 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005084 return 1;
5085 }
5086 if (tmp == NULL) {
5087 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5088 return 1;
5089 }
5090 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005091 int res;
5092 Py_ssize_t len;
5093 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005094 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005095 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 +02005096 goto failed;
5097 }
5098 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005099 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005100 if (body == NULL) goto failed;
5101 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005102 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005103 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5104 Py_INCREF(tmp2);
5105 res = obj2ast_stmt(tmp2, &val, arena);
5106 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005107 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005108 if (len != PyList_GET_SIZE(tmp)) {
5109 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5110 goto failed;
5111 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005112 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005113 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005114 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005115 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005116 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5117 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005118 return 1;
5119 }
5120 if (tmp == NULL) {
5121 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5122 return 1;
5123 }
5124 else {
5125 int res;
5126 Py_ssize_t len;
5127 Py_ssize_t i;
5128 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005129 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 -08005130 goto failed;
5131 }
5132 len = PyList_GET_SIZE(tmp);
5133 type_ignores = _Py_asdl_seq_new(len, arena);
5134 if (type_ignores == NULL) goto failed;
5135 for (i = 0; i < len; i++) {
5136 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005137 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5138 Py_INCREF(tmp2);
5139 res = obj2ast_type_ignore(tmp2, &val, arena);
5140 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005141 if (res != 0) goto failed;
5142 if (len != PyList_GET_SIZE(tmp)) {
5143 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5144 goto failed;
5145 }
5146 asdl_seq_SET(type_ignores, i, val);
5147 }
5148 Py_CLEAR(tmp);
5149 }
5150 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005151 if (*out == NULL) goto failed;
5152 return 0;
5153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005154 tp = astmodulestate_global->Interactive_type;
5155 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005156 if (isinstance == -1) {
5157 return 1;
5158 }
5159 if (isinstance) {
5160 asdl_seq* body;
5161
Dino Viehlandac46eb42019-09-11 10:16:34 -07005162 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005163 return 1;
5164 }
5165 if (tmp == NULL) {
5166 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5167 return 1;
5168 }
5169 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005170 int res;
5171 Py_ssize_t len;
5172 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005173 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005174 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 +02005175 goto failed;
5176 }
5177 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005178 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005179 if (body == NULL) goto failed;
5180 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005181 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005182 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5183 Py_INCREF(tmp2);
5184 res = obj2ast_stmt(tmp2, &val, arena);
5185 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005186 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005187 if (len != PyList_GET_SIZE(tmp)) {
5188 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5189 goto failed;
5190 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005191 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005192 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005193 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005194 }
5195 *out = Interactive(body, arena);
5196 if (*out == NULL) goto failed;
5197 return 0;
5198 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005199 tp = astmodulestate_global->Expression_type;
5200 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005201 if (isinstance == -1) {
5202 return 1;
5203 }
5204 if (isinstance) {
5205 expr_ty body;
5206
Dino Viehlandac46eb42019-09-11 10:16:34 -07005207 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005208 return 1;
5209 }
5210 if (tmp == NULL) {
5211 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5212 return 1;
5213 }
5214 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005215 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005216 res = obj2ast_expr(tmp, &body, arena);
5217 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005218 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005219 }
5220 *out = Expression(body, arena);
5221 if (*out == NULL) goto failed;
5222 return 0;
5223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005224 tp = astmodulestate_global->FunctionType_type;
5225 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005226 if (isinstance == -1) {
5227 return 1;
5228 }
5229 if (isinstance) {
5230 asdl_seq* argtypes;
5231 expr_ty returns;
5232
Dino Viehlandac46eb42019-09-11 10:16:34 -07005233 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5234 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005235 return 1;
5236 }
5237 if (tmp == NULL) {
5238 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5239 return 1;
5240 }
5241 else {
5242 int res;
5243 Py_ssize_t len;
5244 Py_ssize_t i;
5245 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005246 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 -08005247 goto failed;
5248 }
5249 len = PyList_GET_SIZE(tmp);
5250 argtypes = _Py_asdl_seq_new(len, arena);
5251 if (argtypes == NULL) goto failed;
5252 for (i = 0; i < len; i++) {
5253 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005254 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5255 Py_INCREF(tmp2);
5256 res = obj2ast_expr(tmp2, &val, arena);
5257 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005258 if (res != 0) goto failed;
5259 if (len != PyList_GET_SIZE(tmp)) {
5260 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5261 goto failed;
5262 }
5263 asdl_seq_SET(argtypes, i, val);
5264 }
5265 Py_CLEAR(tmp);
5266 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005267 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &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 \"returns\" missing from FunctionType");
5273 return 1;
5274 }
5275 else {
5276 int res;
5277 res = obj2ast_expr(tmp, &returns, arena);
5278 if (res != 0) goto failed;
5279 Py_CLEAR(tmp);
5280 }
5281 *out = FunctionType(argtypes, returns, arena);
5282 if (*out == NULL) goto failed;
5283 return 0;
5284 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005285
5286 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5287 failed:
5288 Py_XDECREF(tmp);
5289 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005290}
5291
5292int
5293obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5294{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005295 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005296
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005297 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005298 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005299 int lineno;
5300 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005301 int end_lineno;
5302 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005303
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005304 if (obj == Py_None) {
5305 *out = NULL;
5306 return 0;
5307 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005308 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005309 return 1;
5310 }
5311 if (tmp == NULL) {
5312 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5313 return 1;
5314 }
5315 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005316 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005317 res = obj2ast_int(tmp, &lineno, arena);
5318 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005319 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005320 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005321 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5322 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005323 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005324 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005325 if (tmp == NULL) {
5326 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5327 return 1;
5328 }
5329 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005330 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005331 res = obj2ast_int(tmp, &col_offset, arena);
5332 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005333 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005334 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005335 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5336 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005337 return 1;
5338 }
5339 if (tmp == NULL || tmp == Py_None) {
5340 Py_CLEAR(tmp);
5341 end_lineno = 0;
5342 }
5343 else {
5344 int res;
5345 res = obj2ast_int(tmp, &end_lineno, arena);
5346 if (res != 0) goto failed;
5347 Py_CLEAR(tmp);
5348 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005349 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5350 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005351 return 1;
5352 }
5353 if (tmp == NULL || tmp == Py_None) {
5354 Py_CLEAR(tmp);
5355 end_col_offset = 0;
5356 }
5357 else {
5358 int res;
5359 res = obj2ast_int(tmp, &end_col_offset, arena);
5360 if (res != 0) goto failed;
5361 Py_CLEAR(tmp);
5362 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005363 tp = astmodulestate_global->FunctionDef_type;
5364 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005365 if (isinstance == -1) {
5366 return 1;
5367 }
5368 if (isinstance) {
5369 identifier name;
5370 arguments_ty args;
5371 asdl_seq* body;
5372 asdl_seq* decorator_list;
5373 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005374 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005375
Dino Viehlandac46eb42019-09-11 10:16:34 -07005376 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005377 return 1;
5378 }
5379 if (tmp == NULL) {
5380 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5381 return 1;
5382 }
5383 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005384 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005385 res = obj2ast_identifier(tmp, &name, arena);
5386 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005387 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005388 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005389 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005390 return 1;
5391 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005392 if (tmp == NULL) {
5393 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5394 return 1;
5395 }
5396 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005397 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005398 res = obj2ast_arguments(tmp, &args, arena);
5399 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005400 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005401 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005402 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005403 return 1;
5404 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005405 if (tmp == NULL) {
5406 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5407 return 1;
5408 }
5409 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005410 int res;
5411 Py_ssize_t len;
5412 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005413 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005414 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 +02005415 goto failed;
5416 }
5417 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005418 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005419 if (body == NULL) goto failed;
5420 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005421 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005422 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5423 Py_INCREF(tmp2);
5424 res = obj2ast_stmt(tmp2, &val, arena);
5425 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005426 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005427 if (len != PyList_GET_SIZE(tmp)) {
5428 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5429 goto failed;
5430 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005431 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005432 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005433 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005434 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005435 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5436 &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 \"decorator_list\" 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 \"decorator_list\" 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 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005453 if (decorator_list == NULL) goto failed;
5454 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005455 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005456 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5457 Py_INCREF(tmp2);
5458 res = obj2ast_expr(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 \"decorator_list\" changed size during iteration");
5463 goto failed;
5464 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005465 asdl_seq_SET(decorator_list, 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->returns, &tmp) <
5470 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005471 return 1;
5472 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005473 if (tmp == NULL || tmp == Py_None) {
5474 Py_CLEAR(tmp);
5475 returns = NULL;
5476 }
5477 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005478 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005479 res = obj2ast_expr(tmp, &returns, arena);
5480 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005481 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005482 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005483 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5484 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005485 return 1;
5486 }
5487 if (tmp == NULL || tmp == Py_None) {
5488 Py_CLEAR(tmp);
5489 type_comment = NULL;
5490 }
5491 else {
5492 int res;
5493 res = obj2ast_string(tmp, &type_comment, arena);
5494 if (res != 0) goto failed;
5495 Py_CLEAR(tmp);
5496 }
5497 *out = FunctionDef(name, args, body, decorator_list, returns,
5498 type_comment, lineno, col_offset, end_lineno,
5499 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005500 if (*out == NULL) goto failed;
5501 return 0;
5502 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005503 tp = astmodulestate_global->AsyncFunctionDef_type;
5504 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005505 if (isinstance == -1) {
5506 return 1;
5507 }
5508 if (isinstance) {
5509 identifier name;
5510 arguments_ty args;
5511 asdl_seq* body;
5512 asdl_seq* decorator_list;
5513 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005514 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005515
Dino Viehlandac46eb42019-09-11 10:16:34 -07005516 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005517 return 1;
5518 }
5519 if (tmp == NULL) {
5520 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5521 return 1;
5522 }
5523 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005524 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005525 res = obj2ast_identifier(tmp, &name, arena);
5526 if (res != 0) goto failed;
5527 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005528 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005529 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005530 return 1;
5531 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005532 if (tmp == NULL) {
5533 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5534 return 1;
5535 }
5536 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005537 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005538 res = obj2ast_arguments(tmp, &args, arena);
5539 if (res != 0) goto failed;
5540 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005541 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005542 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005543 return 1;
5544 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005545 if (tmp == NULL) {
5546 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5547 return 1;
5548 }
5549 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005550 int res;
5551 Py_ssize_t len;
5552 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005553 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005554 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 -04005555 goto failed;
5556 }
5557 len = PyList_GET_SIZE(tmp);
5558 body = _Py_asdl_seq_new(len, arena);
5559 if (body == NULL) goto failed;
5560 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005561 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005562 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5563 Py_INCREF(tmp2);
5564 res = obj2ast_stmt(tmp2, &val, arena);
5565 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005566 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005567 if (len != PyList_GET_SIZE(tmp)) {
5568 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5569 goto failed;
5570 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005571 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005572 }
5573 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005574 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005575 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5576 &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 \"decorator_list\" 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 \"decorator_list\" 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 decorator_list = _Py_asdl_seq_new(len, arena);
5593 if (decorator_list == NULL) goto failed;
5594 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005595 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005596 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5597 Py_INCREF(tmp2);
5598 res = obj2ast_expr(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 \"decorator_list\" changed size during iteration");
5603 goto failed;
5604 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005605 asdl_seq_SET(decorator_list, 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->returns, &tmp) <
5610 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005611 return 1;
5612 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005613 if (tmp == NULL || tmp == Py_None) {
5614 Py_CLEAR(tmp);
5615 returns = NULL;
5616 }
5617 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005618 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005619 res = obj2ast_expr(tmp, &returns, arena);
5620 if (res != 0) goto failed;
5621 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005622 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005623 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5624 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005625 return 1;
5626 }
5627 if (tmp == NULL || tmp == Py_None) {
5628 Py_CLEAR(tmp);
5629 type_comment = NULL;
5630 }
5631 else {
5632 int res;
5633 res = obj2ast_string(tmp, &type_comment, arena);
5634 if (res != 0) goto failed;
5635 Py_CLEAR(tmp);
5636 }
Yury Selivanov75445082015-05-11 22:57:16 -04005637 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005638 type_comment, lineno, col_offset, end_lineno,
5639 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005640 if (*out == NULL) goto failed;
5641 return 0;
5642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005643 tp = astmodulestate_global->ClassDef_type;
5644 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005645 if (isinstance == -1) {
5646 return 1;
5647 }
5648 if (isinstance) {
5649 identifier name;
5650 asdl_seq* bases;
5651 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005652 asdl_seq* body;
5653 asdl_seq* decorator_list;
5654
Dino Viehlandac46eb42019-09-11 10:16:34 -07005655 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005656 return 1;
5657 }
5658 if (tmp == NULL) {
5659 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5660 return 1;
5661 }
5662 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005663 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005664 res = obj2ast_identifier(tmp, &name, arena);
5665 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005666 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005667 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005668 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005669 return 1;
5670 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005671 if (tmp == NULL) {
5672 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5673 return 1;
5674 }
5675 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005676 int res;
5677 Py_ssize_t len;
5678 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005679 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005680 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 +02005681 goto failed;
5682 }
5683 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005684 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005685 if (bases == NULL) goto failed;
5686 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005687 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005688 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5689 Py_INCREF(tmp2);
5690 res = obj2ast_expr(tmp2, &val, arena);
5691 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005692 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005693 if (len != PyList_GET_SIZE(tmp)) {
5694 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5695 goto failed;
5696 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005697 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005698 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005699 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005700 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005701 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5702 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 \"keywords\" 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 \"keywords\" 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 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005719 if (keywords == NULL) goto failed;
5720 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005721 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005722 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5723 Py_INCREF(tmp2);
5724 res = obj2ast_keyword(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 \"keywords\" changed size during iteration");
5729 goto failed;
5730 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005731 asdl_seq_SET(keywords, 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->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005736 return 1;
5737 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005738 if (tmp == NULL) {
5739 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5740 return 1;
5741 }
5742 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005743 int res;
5744 Py_ssize_t len;
5745 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005746 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005747 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 +02005748 goto failed;
5749 }
5750 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005751 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005752 if (body == NULL) goto failed;
5753 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005754 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005755 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5756 Py_INCREF(tmp2);
5757 res = obj2ast_stmt(tmp2, &val, arena);
5758 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005759 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005760 if (len != PyList_GET_SIZE(tmp)) {
5761 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5762 goto failed;
5763 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005764 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005765 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005766 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005767 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005768 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5769 &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 \"decorator_list\" 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 \"decorator_list\" 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 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005786 if (decorator_list == NULL) goto failed;
5787 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005788 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005789 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5790 Py_INCREF(tmp2);
5791 res = obj2ast_expr(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 \"decorator_list\" changed size during iteration");
5796 goto failed;
5797 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005798 asdl_seq_SET(decorator_list, 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 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005802 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005803 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005804 if (*out == NULL) goto failed;
5805 return 0;
5806 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005807 tp = astmodulestate_global->Return_type;
5808 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005809 if (isinstance == -1) {
5810 return 1;
5811 }
5812 if (isinstance) {
5813 expr_ty value;
5814
Dino Viehlandac46eb42019-09-11 10:16:34 -07005815 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005816 return 1;
5817 }
5818 if (tmp == NULL || tmp == Py_None) {
5819 Py_CLEAR(tmp);
5820 value = NULL;
5821 }
5822 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005823 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005824 res = obj2ast_expr(tmp, &value, arena);
5825 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005826 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005827 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005828 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5829 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005830 if (*out == NULL) goto failed;
5831 return 0;
5832 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005833 tp = astmodulestate_global->Delete_type;
5834 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005835 if (isinstance == -1) {
5836 return 1;
5837 }
5838 if (isinstance) {
5839 asdl_seq* targets;
5840
Dino Viehlandac46eb42019-09-11 10:16:34 -07005841 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5842 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005843 return 1;
5844 }
5845 if (tmp == NULL) {
5846 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5847 return 1;
5848 }
5849 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005850 int res;
5851 Py_ssize_t len;
5852 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005853 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005854 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 +02005855 goto failed;
5856 }
5857 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005858 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005859 if (targets == NULL) goto failed;
5860 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005861 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005862 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5863 Py_INCREF(tmp2);
5864 res = obj2ast_expr(tmp2, &val, arena);
5865 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005866 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005867 if (len != PyList_GET_SIZE(tmp)) {
5868 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5869 goto failed;
5870 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005871 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005872 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005873 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005874 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005875 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5876 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005877 if (*out == NULL) goto failed;
5878 return 0;
5879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005880 tp = astmodulestate_global->Assign_type;
5881 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005882 if (isinstance == -1) {
5883 return 1;
5884 }
5885 if (isinstance) {
5886 asdl_seq* targets;
5887 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005888 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005889
Dino Viehlandac46eb42019-09-11 10:16:34 -07005890 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5891 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005892 return 1;
5893 }
5894 if (tmp == NULL) {
5895 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5896 return 1;
5897 }
5898 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005899 int res;
5900 Py_ssize_t len;
5901 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005902 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005903 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 +02005904 goto failed;
5905 }
5906 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005907 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005908 if (targets == NULL) goto failed;
5909 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005910 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005911 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5912 Py_INCREF(tmp2);
5913 res = obj2ast_expr(tmp2, &val, arena);
5914 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005915 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005916 if (len != PyList_GET_SIZE(tmp)) {
5917 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5918 goto failed;
5919 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005920 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005921 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005922 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005923 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005924 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005925 return 1;
5926 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005927 if (tmp == NULL) {
5928 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5929 return 1;
5930 }
5931 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005932 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005933 res = obj2ast_expr(tmp, &value, arena);
5934 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005935 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005936 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005937 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5938 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005939 return 1;
5940 }
5941 if (tmp == NULL || tmp == Py_None) {
5942 Py_CLEAR(tmp);
5943 type_comment = NULL;
5944 }
5945 else {
5946 int res;
5947 res = obj2ast_string(tmp, &type_comment, arena);
5948 if (res != 0) goto failed;
5949 Py_CLEAR(tmp);
5950 }
5951 *out = Assign(targets, value, type_comment, lineno, col_offset,
5952 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005953 if (*out == NULL) goto failed;
5954 return 0;
5955 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005956 tp = astmodulestate_global->AugAssign_type;
5957 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005958 if (isinstance == -1) {
5959 return 1;
5960 }
5961 if (isinstance) {
5962 expr_ty target;
5963 operator_ty op;
5964 expr_ty value;
5965
Dino Viehlandac46eb42019-09-11 10:16:34 -07005966 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5967 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005968 return 1;
5969 }
5970 if (tmp == NULL) {
5971 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5972 return 1;
5973 }
5974 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005975 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005976 res = obj2ast_expr(tmp, &target, arena);
5977 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005978 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005979 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005980 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005981 return 1;
5982 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005983 if (tmp == NULL) {
5984 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
5985 return 1;
5986 }
5987 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005988 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005989 res = obj2ast_operator(tmp, &op, arena);
5990 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005991 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005993 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005994 return 1;
5995 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005996 if (tmp == NULL) {
5997 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
5998 return 1;
5999 }
6000 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006001 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006002 res = obj2ast_expr(tmp, &value, arena);
6003 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006004 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006005 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006006 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
6007 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006008 if (*out == NULL) goto failed;
6009 return 0;
6010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006011 tp = astmodulestate_global->AnnAssign_type;
6012 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006013 if (isinstance == -1) {
6014 return 1;
6015 }
6016 if (isinstance) {
6017 expr_ty target;
6018 expr_ty annotation;
6019 expr_ty value;
6020 int simple;
6021
Dino Viehlandac46eb42019-09-11 10:16:34 -07006022 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6023 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006024 return 1;
6025 }
6026 if (tmp == NULL) {
6027 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6028 return 1;
6029 }
6030 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006031 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006032 res = obj2ast_expr(tmp, &target, arena);
6033 if (res != 0) goto failed;
6034 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006035 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006036 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6037 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006038 return 1;
6039 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006040 if (tmp == NULL) {
6041 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6042 return 1;
6043 }
6044 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006045 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006046 res = obj2ast_expr(tmp, &annotation, arena);
6047 if (res != 0) goto failed;
6048 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006049 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006050 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006051 return 1;
6052 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006053 if (tmp == NULL || tmp == Py_None) {
6054 Py_CLEAR(tmp);
6055 value = NULL;
6056 }
6057 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006058 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006059 res = obj2ast_expr(tmp, &value, arena);
6060 if (res != 0) goto failed;
6061 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006063 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6064 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006065 return 1;
6066 }
6067 if (tmp == NULL) {
6068 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6069 return 1;
6070 }
6071 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006072 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006073 res = obj2ast_int(tmp, &simple, arena);
6074 if (res != 0) goto failed;
6075 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006076 }
6077 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006078 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006079 if (*out == NULL) goto failed;
6080 return 0;
6081 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006082 tp = astmodulestate_global->For_type;
6083 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006084 if (isinstance == -1) {
6085 return 1;
6086 }
6087 if (isinstance) {
6088 expr_ty target;
6089 expr_ty iter;
6090 asdl_seq* body;
6091 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006092 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006093
Dino Viehlandac46eb42019-09-11 10:16:34 -07006094 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6095 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006096 return 1;
6097 }
6098 if (tmp == NULL) {
6099 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6100 return 1;
6101 }
6102 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006103 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006104 res = obj2ast_expr(tmp, &target, arena);
6105 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006106 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006107 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006108 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006109 return 1;
6110 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006111 if (tmp == NULL) {
6112 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6113 return 1;
6114 }
6115 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006116 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006117 res = obj2ast_expr(tmp, &iter, arena);
6118 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006119 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006120 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006121 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006122 return 1;
6123 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006124 if (tmp == NULL) {
6125 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6126 return 1;
6127 }
6128 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006129 int res;
6130 Py_ssize_t len;
6131 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006132 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006133 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 +02006134 goto failed;
6135 }
6136 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006137 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006138 if (body == NULL) goto failed;
6139 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006140 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006141 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6142 Py_INCREF(tmp2);
6143 res = obj2ast_stmt(tmp2, &val, arena);
6144 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006145 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006146 if (len != PyList_GET_SIZE(tmp)) {
6147 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6148 goto failed;
6149 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006150 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006151 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006152 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006154 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6155 {
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 \"orelse\" 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 \"orelse\" 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 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006172 if (orelse == 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 \"orelse\" changed size during iteration");
6182 goto failed;
6183 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006184 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006185 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006186 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006187 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006188 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6189 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006190 return 1;
6191 }
6192 if (tmp == NULL || tmp == Py_None) {
6193 Py_CLEAR(tmp);
6194 type_comment = NULL;
6195 }
6196 else {
6197 int res;
6198 res = obj2ast_string(tmp, &type_comment, arena);
6199 if (res != 0) goto failed;
6200 Py_CLEAR(tmp);
6201 }
6202 *out = For(target, iter, body, orelse, type_comment, lineno,
6203 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006204 if (*out == NULL) goto failed;
6205 return 0;
6206 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006207 tp = astmodulestate_global->AsyncFor_type;
6208 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006209 if (isinstance == -1) {
6210 return 1;
6211 }
6212 if (isinstance) {
6213 expr_ty target;
6214 expr_ty iter;
6215 asdl_seq* body;
6216 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006217 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006218
Dino Viehlandac46eb42019-09-11 10:16:34 -07006219 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6220 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006221 return 1;
6222 }
6223 if (tmp == NULL) {
6224 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6225 return 1;
6226 }
6227 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006228 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006229 res = obj2ast_expr(tmp, &target, arena);
6230 if (res != 0) goto failed;
6231 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006232 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006233 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006234 return 1;
6235 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006236 if (tmp == NULL) {
6237 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6238 return 1;
6239 }
6240 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006241 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006242 res = obj2ast_expr(tmp, &iter, arena);
6243 if (res != 0) goto failed;
6244 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006245 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006246 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006247 return 1;
6248 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006249 if (tmp == NULL) {
6250 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6251 return 1;
6252 }
6253 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006254 int res;
6255 Py_ssize_t len;
6256 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006257 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006258 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 -04006259 goto failed;
6260 }
6261 len = PyList_GET_SIZE(tmp);
6262 body = _Py_asdl_seq_new(len, arena);
6263 if (body == NULL) goto failed;
6264 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006265 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006266 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6267 Py_INCREF(tmp2);
6268 res = obj2ast_stmt(tmp2, &val, arena);
6269 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006270 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006271 if (len != PyList_GET_SIZE(tmp)) {
6272 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6273 goto failed;
6274 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006275 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006276 }
6277 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006279 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6280 {
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 \"orelse\" 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 \"orelse\" 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 orelse = _Py_asdl_seq_new(len, arena);
6297 if (orelse == 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 \"orelse\" changed size during iteration");
6307 goto failed;
6308 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006309 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006310 }
6311 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006313 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6314 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006315 return 1;
6316 }
6317 if (tmp == NULL || tmp == Py_None) {
6318 Py_CLEAR(tmp);
6319 type_comment = NULL;
6320 }
6321 else {
6322 int res;
6323 res = obj2ast_string(tmp, &type_comment, arena);
6324 if (res != 0) goto failed;
6325 Py_CLEAR(tmp);
6326 }
6327 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6328 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006329 if (*out == NULL) goto failed;
6330 return 0;
6331 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006332 tp = astmodulestate_global->While_type;
6333 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006334 if (isinstance == -1) {
6335 return 1;
6336 }
6337 if (isinstance) {
6338 expr_ty test;
6339 asdl_seq* body;
6340 asdl_seq* orelse;
6341
Dino Viehlandac46eb42019-09-11 10:16:34 -07006342 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006343 return 1;
6344 }
6345 if (tmp == NULL) {
6346 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6347 return 1;
6348 }
6349 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006350 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006351 res = obj2ast_expr(tmp, &test, arena);
6352 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006353 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006355 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006356 return 1;
6357 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006358 if (tmp == NULL) {
6359 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6360 return 1;
6361 }
6362 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006363 int res;
6364 Py_ssize_t len;
6365 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006366 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006367 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 +02006368 goto failed;
6369 }
6370 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006371 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006372 if (body == NULL) goto failed;
6373 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006374 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006375 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6376 Py_INCREF(tmp2);
6377 res = obj2ast_stmt(tmp2, &val, arena);
6378 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006379 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006380 if (len != PyList_GET_SIZE(tmp)) {
6381 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6382 goto failed;
6383 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006384 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006385 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006386 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006387 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006388 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6389 {
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 \"orelse\" 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 \"orelse\" 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 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006406 if (orelse == 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 \"orelse\" changed size during iteration");
6416 goto failed;
6417 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006418 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006419 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006420 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006421 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006422 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6423 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006424 if (*out == NULL) goto failed;
6425 return 0;
6426 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006427 tp = astmodulestate_global->If_type;
6428 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006429 if (isinstance == -1) {
6430 return 1;
6431 }
6432 if (isinstance) {
6433 expr_ty test;
6434 asdl_seq* body;
6435 asdl_seq* orelse;
6436
Dino Viehlandac46eb42019-09-11 10:16:34 -07006437 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006438 return 1;
6439 }
6440 if (tmp == NULL) {
6441 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6442 return 1;
6443 }
6444 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006445 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006446 res = obj2ast_expr(tmp, &test, arena);
6447 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006448 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006449 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006450 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006451 return 1;
6452 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006453 if (tmp == NULL) {
6454 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6455 return 1;
6456 }
6457 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006458 int res;
6459 Py_ssize_t len;
6460 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006461 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006462 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 +02006463 goto failed;
6464 }
6465 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006466 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006467 if (body == NULL) goto failed;
6468 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006469 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006470 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6471 Py_INCREF(tmp2);
6472 res = obj2ast_stmt(tmp2, &val, arena);
6473 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006474 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006475 if (len != PyList_GET_SIZE(tmp)) {
6476 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6477 goto failed;
6478 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006479 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006480 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006481 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006482 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006483 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6484 {
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 \"orelse\" 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 \"orelse\" 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 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006501 if (orelse == 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 \"orelse\" changed size during iteration");
6511 goto failed;
6512 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006513 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006514 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006515 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006516 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006517 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6518 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006519 if (*out == NULL) goto failed;
6520 return 0;
6521 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006522 tp = astmodulestate_global->With_type;
6523 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006524 if (isinstance == -1) {
6525 return 1;
6526 }
6527 if (isinstance) {
6528 asdl_seq* items;
6529 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006530 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006531
Dino Viehlandac46eb42019-09-11 10:16:34 -07006532 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006533 return 1;
6534 }
6535 if (tmp == NULL) {
6536 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6537 return 1;
6538 }
6539 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006540 int res;
6541 Py_ssize_t len;
6542 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006543 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006544 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 +02006545 goto failed;
6546 }
6547 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006548 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006549 if (items == NULL) goto failed;
6550 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006551 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006552 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6553 Py_INCREF(tmp2);
6554 res = obj2ast_withitem(tmp2, &val, arena);
6555 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006556 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006557 if (len != PyList_GET_SIZE(tmp)) {
6558 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6559 goto failed;
6560 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006561 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006562 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006563 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006564 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006565 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006566 return 1;
6567 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006568 if (tmp == NULL) {
6569 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6570 return 1;
6571 }
6572 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006573 int res;
6574 Py_ssize_t len;
6575 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006576 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006577 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 +02006578 goto failed;
6579 }
6580 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006581 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006582 if (body == NULL) goto failed;
6583 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006584 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006585 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6586 Py_INCREF(tmp2);
6587 res = obj2ast_stmt(tmp2, &val, arena);
6588 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006589 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006590 if (len != PyList_GET_SIZE(tmp)) {
6591 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6592 goto failed;
6593 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006594 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006595 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006596 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006597 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006598 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6599 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006600 return 1;
6601 }
6602 if (tmp == NULL || tmp == Py_None) {
6603 Py_CLEAR(tmp);
6604 type_comment = NULL;
6605 }
6606 else {
6607 int res;
6608 res = obj2ast_string(tmp, &type_comment, arena);
6609 if (res != 0) goto failed;
6610 Py_CLEAR(tmp);
6611 }
6612 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006613 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006614 if (*out == NULL) goto failed;
6615 return 0;
6616 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006617 tp = astmodulestate_global->AsyncWith_type;
6618 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006619 if (isinstance == -1) {
6620 return 1;
6621 }
6622 if (isinstance) {
6623 asdl_seq* items;
6624 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006625 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006626
Dino Viehlandac46eb42019-09-11 10:16:34 -07006627 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006628 return 1;
6629 }
6630 if (tmp == NULL) {
6631 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6632 return 1;
6633 }
6634 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006635 int res;
6636 Py_ssize_t len;
6637 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006638 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006639 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 -04006640 goto failed;
6641 }
6642 len = PyList_GET_SIZE(tmp);
6643 items = _Py_asdl_seq_new(len, arena);
6644 if (items == NULL) goto failed;
6645 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006646 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006647 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6648 Py_INCREF(tmp2);
6649 res = obj2ast_withitem(tmp2, &val, arena);
6650 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006651 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006652 if (len != PyList_GET_SIZE(tmp)) {
6653 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6654 goto failed;
6655 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006656 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006657 }
6658 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006659 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006660 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006661 return 1;
6662 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006663 if (tmp == NULL) {
6664 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6665 return 1;
6666 }
6667 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006668 int res;
6669 Py_ssize_t len;
6670 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006671 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006672 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 -04006673 goto failed;
6674 }
6675 len = PyList_GET_SIZE(tmp);
6676 body = _Py_asdl_seq_new(len, arena);
6677 if (body == NULL) goto failed;
6678 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006679 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006680 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6681 Py_INCREF(tmp2);
6682 res = obj2ast_stmt(tmp2, &val, arena);
6683 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006684 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006685 if (len != PyList_GET_SIZE(tmp)) {
6686 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6687 goto failed;
6688 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006689 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006690 }
6691 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006692 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006693 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6694 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006695 return 1;
6696 }
6697 if (tmp == NULL || tmp == Py_None) {
6698 Py_CLEAR(tmp);
6699 type_comment = NULL;
6700 }
6701 else {
6702 int res;
6703 res = obj2ast_string(tmp, &type_comment, arena);
6704 if (res != 0) goto failed;
6705 Py_CLEAR(tmp);
6706 }
6707 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6708 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006709 if (*out == NULL) goto failed;
6710 return 0;
6711 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006712 tp = astmodulestate_global->Raise_type;
6713 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006714 if (isinstance == -1) {
6715 return 1;
6716 }
6717 if (isinstance) {
6718 expr_ty exc;
6719 expr_ty cause;
6720
Dino Viehlandac46eb42019-09-11 10:16:34 -07006721 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006722 return 1;
6723 }
6724 if (tmp == NULL || tmp == Py_None) {
6725 Py_CLEAR(tmp);
6726 exc = NULL;
6727 }
6728 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006729 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006730 res = obj2ast_expr(tmp, &exc, arena);
6731 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006732 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006733 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006734 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006735 return 1;
6736 }
6737 if (tmp == NULL || tmp == Py_None) {
6738 Py_CLEAR(tmp);
6739 cause = NULL;
6740 }
6741 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006742 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006743 res = obj2ast_expr(tmp, &cause, arena);
6744 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006745 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006746 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006747 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6748 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006749 if (*out == NULL) goto failed;
6750 return 0;
6751 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006752 tp = astmodulestate_global->Try_type;
6753 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006754 if (isinstance == -1) {
6755 return 1;
6756 }
6757 if (isinstance) {
6758 asdl_seq* body;
6759 asdl_seq* handlers;
6760 asdl_seq* orelse;
6761 asdl_seq* finalbody;
6762
Dino Viehlandac46eb42019-09-11 10:16:34 -07006763 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006764 return 1;
6765 }
6766 if (tmp == NULL) {
6767 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6768 return 1;
6769 }
6770 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006771 int res;
6772 Py_ssize_t len;
6773 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006774 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006775 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 +02006776 goto failed;
6777 }
6778 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006779 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006780 if (body == NULL) goto failed;
6781 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006782 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006783 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6784 Py_INCREF(tmp2);
6785 res = obj2ast_stmt(tmp2, &val, arena);
6786 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006787 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006788 if (len != PyList_GET_SIZE(tmp)) {
6789 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6790 goto failed;
6791 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006792 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006793 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006794 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006795 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006796 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6797 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006798 return 1;
6799 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006800 if (tmp == NULL) {
6801 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" 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 \"handlers\" 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 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006814 if (handlers == NULL) goto failed;
6815 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006816 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006817 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6818 Py_INCREF(tmp2);
6819 res = obj2ast_excepthandler(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 \"handlers\" changed size during iteration");
6824 goto failed;
6825 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006826 asdl_seq_SET(handlers, 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->orelse, &tmp) < 0)
6831 {
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 \"orelse\" 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 \"orelse\" 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 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006848 if (orelse == NULL) goto failed;
6849 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006850 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006851 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6852 Py_INCREF(tmp2);
6853 res = obj2ast_stmt(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 \"orelse\" changed size during iteration");
6858 goto failed;
6859 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006860 asdl_seq_SET(orelse, 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->finalbody, &tmp) <
6865 0) {
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 \"finalbody\" 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 \"finalbody\" 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 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006882 if (finalbody == 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 \"finalbody\" changed size during iteration");
6892 goto failed;
6893 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006894 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006895 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006896 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006897 }
6898 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006899 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006900 if (*out == NULL) goto failed;
6901 return 0;
6902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006903 tp = astmodulestate_global->Assert_type;
6904 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006905 if (isinstance == -1) {
6906 return 1;
6907 }
6908 if (isinstance) {
6909 expr_ty test;
6910 expr_ty msg;
6911
Dino Viehlandac46eb42019-09-11 10:16:34 -07006912 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006913 return 1;
6914 }
6915 if (tmp == NULL) {
6916 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6917 return 1;
6918 }
6919 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006920 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006921 res = obj2ast_expr(tmp, &test, arena);
6922 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006923 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006925 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006926 return 1;
6927 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006928 if (tmp == NULL || tmp == Py_None) {
6929 Py_CLEAR(tmp);
6930 msg = NULL;
6931 }
6932 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006933 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006934 res = obj2ast_expr(tmp, &msg, arena);
6935 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006936 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006937 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006938 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6939 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006940 if (*out == NULL) goto failed;
6941 return 0;
6942 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006943 tp = astmodulestate_global->Import_type;
6944 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006945 if (isinstance == -1) {
6946 return 1;
6947 }
6948 if (isinstance) {
6949 asdl_seq* names;
6950
Dino Viehlandac46eb42019-09-11 10:16:34 -07006951 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006952 return 1;
6953 }
6954 if (tmp == NULL) {
6955 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6956 return 1;
6957 }
6958 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006959 int res;
6960 Py_ssize_t len;
6961 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006962 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006963 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 +02006964 goto failed;
6965 }
6966 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006967 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006968 if (names == NULL) goto failed;
6969 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006970 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006971 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6972 Py_INCREF(tmp2);
6973 res = obj2ast_alias(tmp2, &val, arena);
6974 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006975 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006976 if (len != PyList_GET_SIZE(tmp)) {
6977 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6978 goto failed;
6979 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006980 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006981 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006982 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006983 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006984 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
6985 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006986 if (*out == NULL) goto failed;
6987 return 0;
6988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006989 tp = astmodulestate_global->ImportFrom_type;
6990 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006991 if (isinstance == -1) {
6992 return 1;
6993 }
6994 if (isinstance) {
6995 identifier module;
6996 asdl_seq* names;
6997 int level;
6998
Dino Viehlandac46eb42019-09-11 10:16:34 -07006999 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
7000 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007001 return 1;
7002 }
7003 if (tmp == NULL || tmp == Py_None) {
7004 Py_CLEAR(tmp);
7005 module = NULL;
7006 }
7007 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007008 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007009 res = obj2ast_identifier(tmp, &module, arena);
7010 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007011 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007012 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007013 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007014 return 1;
7015 }
7016 if (tmp == NULL) {
7017 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7018 return 1;
7019 }
7020 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007021 int res;
7022 Py_ssize_t len;
7023 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007024 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007025 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 +02007026 goto failed;
7027 }
7028 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007029 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007030 if (names == NULL) goto failed;
7031 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007032 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007033 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7034 Py_INCREF(tmp2);
7035 res = obj2ast_alias(tmp2, &val, arena);
7036 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007037 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007038 if (len != PyList_GET_SIZE(tmp)) {
7039 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7040 goto failed;
7041 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007042 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007043 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007044 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007045 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007046 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007047 return 1;
7048 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007049 if (tmp == NULL || tmp == Py_None) {
7050 Py_CLEAR(tmp);
7051 level = 0;
7052 }
7053 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007054 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007055 res = obj2ast_int(tmp, &level, arena);
7056 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007057 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007058 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007059 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7060 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007061 if (*out == NULL) goto failed;
7062 return 0;
7063 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007064 tp = astmodulestate_global->Global_type;
7065 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007066 if (isinstance == -1) {
7067 return 1;
7068 }
7069 if (isinstance) {
7070 asdl_seq* names;
7071
Dino Viehlandac46eb42019-09-11 10:16:34 -07007072 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007073 return 1;
7074 }
7075 if (tmp == NULL) {
7076 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7077 return 1;
7078 }
7079 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007080 int res;
7081 Py_ssize_t len;
7082 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007083 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007084 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 +02007085 goto failed;
7086 }
7087 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007088 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007089 if (names == NULL) goto failed;
7090 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007091 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007092 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7093 Py_INCREF(tmp2);
7094 res = obj2ast_identifier(tmp2, &val, arena);
7095 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007096 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007097 if (len != PyList_GET_SIZE(tmp)) {
7098 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7099 goto failed;
7100 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007101 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007102 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007103 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007104 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007105 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7106 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007107 if (*out == NULL) goto failed;
7108 return 0;
7109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007110 tp = astmodulestate_global->Nonlocal_type;
7111 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007112 if (isinstance == -1) {
7113 return 1;
7114 }
7115 if (isinstance) {
7116 asdl_seq* names;
7117
Dino Viehlandac46eb42019-09-11 10:16:34 -07007118 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007119 return 1;
7120 }
7121 if (tmp == NULL) {
7122 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7123 return 1;
7124 }
7125 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007126 int res;
7127 Py_ssize_t len;
7128 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007129 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007130 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 +02007131 goto failed;
7132 }
7133 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007134 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007135 if (names == NULL) goto failed;
7136 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007137 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007138 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7139 Py_INCREF(tmp2);
7140 res = obj2ast_identifier(tmp2, &val, arena);
7141 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007142 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007143 if (len != PyList_GET_SIZE(tmp)) {
7144 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7145 goto failed;
7146 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007147 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007148 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007149 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007150 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007151 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7152 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007153 if (*out == NULL) goto failed;
7154 return 0;
7155 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007156 tp = astmodulestate_global->Expr_type;
7157 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007158 if (isinstance == -1) {
7159 return 1;
7160 }
7161 if (isinstance) {
7162 expr_ty value;
7163
Dino Viehlandac46eb42019-09-11 10:16:34 -07007164 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007165 return 1;
7166 }
7167 if (tmp == NULL) {
7168 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7169 return 1;
7170 }
7171 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007172 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007173 res = obj2ast_expr(tmp, &value, arena);
7174 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007175 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007176 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007177 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7178 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007179 if (*out == NULL) goto failed;
7180 return 0;
7181 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007182 tp = astmodulestate_global->Pass_type;
7183 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007184 if (isinstance == -1) {
7185 return 1;
7186 }
7187 if (isinstance) {
7188
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007189 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007190 if (*out == NULL) goto failed;
7191 return 0;
7192 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007193 tp = astmodulestate_global->Break_type;
7194 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007195 if (isinstance == -1) {
7196 return 1;
7197 }
7198 if (isinstance) {
7199
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007200 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007201 if (*out == NULL) goto failed;
7202 return 0;
7203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007204 tp = astmodulestate_global->Continue_type;
7205 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007206 if (isinstance == -1) {
7207 return 1;
7208 }
7209 if (isinstance) {
7210
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007211 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007212 if (*out == NULL) goto failed;
7213 return 0;
7214 }
7215
7216 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7217 failed:
7218 Py_XDECREF(tmp);
7219 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007220}
7221
7222int
7223obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7224{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007225 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007226
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007227 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007228 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007229 int lineno;
7230 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007231 int end_lineno;
7232 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007233
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007234 if (obj == Py_None) {
7235 *out = NULL;
7236 return 0;
7237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007238 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007239 return 1;
7240 }
7241 if (tmp == NULL) {
7242 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7243 return 1;
7244 }
7245 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007246 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007247 res = obj2ast_int(tmp, &lineno, arena);
7248 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007249 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007250 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007251 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7252 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007253 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007254 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007255 if (tmp == NULL) {
7256 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7257 return 1;
7258 }
7259 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007260 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007261 res = obj2ast_int(tmp, &col_offset, arena);
7262 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007263 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007265 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7266 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007267 return 1;
7268 }
7269 if (tmp == NULL || tmp == Py_None) {
7270 Py_CLEAR(tmp);
7271 end_lineno = 0;
7272 }
7273 else {
7274 int res;
7275 res = obj2ast_int(tmp, &end_lineno, arena);
7276 if (res != 0) goto failed;
7277 Py_CLEAR(tmp);
7278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007279 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7280 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007281 return 1;
7282 }
7283 if (tmp == NULL || tmp == Py_None) {
7284 Py_CLEAR(tmp);
7285 end_col_offset = 0;
7286 }
7287 else {
7288 int res;
7289 res = obj2ast_int(tmp, &end_col_offset, arena);
7290 if (res != 0) goto failed;
7291 Py_CLEAR(tmp);
7292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007293 tp = astmodulestate_global->BoolOp_type;
7294 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007295 if (isinstance == -1) {
7296 return 1;
7297 }
7298 if (isinstance) {
7299 boolop_ty op;
7300 asdl_seq* values;
7301
Dino Viehlandac46eb42019-09-11 10:16:34 -07007302 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007303 return 1;
7304 }
7305 if (tmp == NULL) {
7306 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7307 return 1;
7308 }
7309 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007310 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007311 res = obj2ast_boolop(tmp, &op, arena);
7312 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007313 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007314 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007315 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7316 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007317 return 1;
7318 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007319 if (tmp == NULL) {
7320 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7321 return 1;
7322 }
7323 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007324 int res;
7325 Py_ssize_t len;
7326 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007327 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007328 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 +02007329 goto failed;
7330 }
7331 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007332 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007333 if (values == NULL) goto failed;
7334 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007335 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007336 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7337 Py_INCREF(tmp2);
7338 res = obj2ast_expr(tmp2, &val, arena);
7339 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007340 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007341 if (len != PyList_GET_SIZE(tmp)) {
7342 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7343 goto failed;
7344 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007345 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007346 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007347 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007348 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007349 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7350 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007351 if (*out == NULL) goto failed;
7352 return 0;
7353 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007354 tp = astmodulestate_global->NamedExpr_type;
7355 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007356 if (isinstance == -1) {
7357 return 1;
7358 }
7359 if (isinstance) {
7360 expr_ty target;
7361 expr_ty value;
7362
Dino Viehlandac46eb42019-09-11 10:16:34 -07007363 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7364 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007365 return 1;
7366 }
7367 if (tmp == NULL) {
7368 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7369 return 1;
7370 }
7371 else {
7372 int res;
7373 res = obj2ast_expr(tmp, &target, arena);
7374 if (res != 0) goto failed;
7375 Py_CLEAR(tmp);
7376 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007377 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007378 return 1;
7379 }
7380 if (tmp == NULL) {
7381 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7382 return 1;
7383 }
7384 else {
7385 int res;
7386 res = obj2ast_expr(tmp, &value, arena);
7387 if (res != 0) goto failed;
7388 Py_CLEAR(tmp);
7389 }
7390 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7391 end_col_offset, arena);
7392 if (*out == NULL) goto failed;
7393 return 0;
7394 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007395 tp = astmodulestate_global->BinOp_type;
7396 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007397 if (isinstance == -1) {
7398 return 1;
7399 }
7400 if (isinstance) {
7401 expr_ty left;
7402 operator_ty op;
7403 expr_ty right;
7404
Dino Viehlandac46eb42019-09-11 10:16:34 -07007405 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007406 return 1;
7407 }
7408 if (tmp == NULL) {
7409 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7410 return 1;
7411 }
7412 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007413 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007414 res = obj2ast_expr(tmp, &left, arena);
7415 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007416 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007417 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007418 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007419 return 1;
7420 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007421 if (tmp == NULL) {
7422 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7423 return 1;
7424 }
7425 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007426 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007427 res = obj2ast_operator(tmp, &op, arena);
7428 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007429 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007430 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007431 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007432 return 1;
7433 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007434 if (tmp == NULL) {
7435 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7436 return 1;
7437 }
7438 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007439 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007440 res = obj2ast_expr(tmp, &right, arena);
7441 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007442 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007443 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007444 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7445 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007446 if (*out == NULL) goto failed;
7447 return 0;
7448 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007449 tp = astmodulestate_global->UnaryOp_type;
7450 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007451 if (isinstance == -1) {
7452 return 1;
7453 }
7454 if (isinstance) {
7455 unaryop_ty op;
7456 expr_ty operand;
7457
Dino Viehlandac46eb42019-09-11 10:16:34 -07007458 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007459 return 1;
7460 }
7461 if (tmp == NULL) {
7462 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7463 return 1;
7464 }
7465 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007466 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007467 res = obj2ast_unaryop(tmp, &op, arena);
7468 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007469 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007470 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007471 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7472 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007473 return 1;
7474 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007475 if (tmp == NULL) {
7476 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7477 return 1;
7478 }
7479 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007480 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007481 res = obj2ast_expr(tmp, &operand, arena);
7482 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007483 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007484 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007485 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7486 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007487 if (*out == NULL) goto failed;
7488 return 0;
7489 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007490 tp = astmodulestate_global->Lambda_type;
7491 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007492 if (isinstance == -1) {
7493 return 1;
7494 }
7495 if (isinstance) {
7496 arguments_ty args;
7497 expr_ty body;
7498
Dino Viehlandac46eb42019-09-11 10:16:34 -07007499 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007500 return 1;
7501 }
7502 if (tmp == NULL) {
7503 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7504 return 1;
7505 }
7506 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007508 res = obj2ast_arguments(tmp, &args, arena);
7509 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007510 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007511 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007512 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007513 return 1;
7514 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007515 if (tmp == NULL) {
7516 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7517 return 1;
7518 }
7519 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007520 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007521 res = obj2ast_expr(tmp, &body, arena);
7522 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007523 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007524 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007525 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7526 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007527 if (*out == NULL) goto failed;
7528 return 0;
7529 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007530 tp = astmodulestate_global->IfExp_type;
7531 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007532 if (isinstance == -1) {
7533 return 1;
7534 }
7535 if (isinstance) {
7536 expr_ty test;
7537 expr_ty body;
7538 expr_ty orelse;
7539
Dino Viehlandac46eb42019-09-11 10:16:34 -07007540 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007541 return 1;
7542 }
7543 if (tmp == NULL) {
7544 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7545 return 1;
7546 }
7547 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007548 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007549 res = obj2ast_expr(tmp, &test, arena);
7550 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007551 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007552 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007553 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007554 return 1;
7555 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007556 if (tmp == NULL) {
7557 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7558 return 1;
7559 }
7560 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007561 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007562 res = obj2ast_expr(tmp, &body, arena);
7563 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007564 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007565 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007566 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7567 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007568 return 1;
7569 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007570 if (tmp == NULL) {
7571 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7572 return 1;
7573 }
7574 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007575 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007576 res = obj2ast_expr(tmp, &orelse, arena);
7577 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007578 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007579 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007580 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7581 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007582 if (*out == NULL) goto failed;
7583 return 0;
7584 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007585 tp = astmodulestate_global->Dict_type;
7586 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007587 if (isinstance == -1) {
7588 return 1;
7589 }
7590 if (isinstance) {
7591 asdl_seq* keys;
7592 asdl_seq* values;
7593
Dino Viehlandac46eb42019-09-11 10:16:34 -07007594 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007595 return 1;
7596 }
7597 if (tmp == NULL) {
7598 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7599 return 1;
7600 }
7601 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 int res;
7603 Py_ssize_t len;
7604 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007605 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007606 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 +02007607 goto failed;
7608 }
7609 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007610 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007611 if (keys == NULL) goto failed;
7612 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007613 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007614 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7615 Py_INCREF(tmp2);
7616 res = obj2ast_expr(tmp2, &val, arena);
7617 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007618 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007619 if (len != PyList_GET_SIZE(tmp)) {
7620 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7621 goto failed;
7622 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007623 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007624 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007625 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007626 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007627 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7628 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007629 return 1;
7630 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007631 if (tmp == NULL) {
7632 PyErr_SetString(PyExc_TypeError, "required field \"values\" 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 \"values\" 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 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007645 if (values == 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 \"values\" changed size during iteration");
7655 goto failed;
7656 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007657 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007658 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007659 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007660 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007661 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7662 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007663 if (*out == NULL) goto failed;
7664 return 0;
7665 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007666 tp = astmodulestate_global->Set_type;
7667 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007668 if (isinstance == -1) {
7669 return 1;
7670 }
7671 if (isinstance) {
7672 asdl_seq* elts;
7673
Dino Viehlandac46eb42019-09-11 10:16:34 -07007674 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007675 return 1;
7676 }
7677 if (tmp == NULL) {
7678 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7679 return 1;
7680 }
7681 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007682 int res;
7683 Py_ssize_t len;
7684 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007685 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007686 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 +02007687 goto failed;
7688 }
7689 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007690 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007691 if (elts == NULL) goto failed;
7692 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007693 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007694 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7695 Py_INCREF(tmp2);
7696 res = obj2ast_expr(tmp2, &val, arena);
7697 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007698 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007699 if (len != PyList_GET_SIZE(tmp)) {
7700 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7701 goto failed;
7702 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007703 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007704 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007705 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007706 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007707 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007708 if (*out == NULL) goto failed;
7709 return 0;
7710 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007711 tp = astmodulestate_global->ListComp_type;
7712 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007713 if (isinstance == -1) {
7714 return 1;
7715 }
7716 if (isinstance) {
7717 expr_ty elt;
7718 asdl_seq* generators;
7719
Dino Viehlandac46eb42019-09-11 10:16:34 -07007720 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007721 return 1;
7722 }
7723 if (tmp == NULL) {
7724 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7725 return 1;
7726 }
7727 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007728 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007729 res = obj2ast_expr(tmp, &elt, arena);
7730 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007731 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007732 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007733 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7734 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007735 return 1;
7736 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007737 if (tmp == NULL) {
7738 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7739 return 1;
7740 }
7741 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007742 int res;
7743 Py_ssize_t len;
7744 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007745 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007746 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 +02007747 goto failed;
7748 }
7749 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007750 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007751 if (generators == NULL) goto failed;
7752 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007753 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007754 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7755 Py_INCREF(tmp2);
7756 res = obj2ast_comprehension(tmp2, &val, arena);
7757 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007758 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007759 if (len != PyList_GET_SIZE(tmp)) {
7760 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7761 goto failed;
7762 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007763 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007764 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007765 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007766 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007767 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7768 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007769 if (*out == NULL) goto failed;
7770 return 0;
7771 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007772 tp = astmodulestate_global->SetComp_type;
7773 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007774 if (isinstance == -1) {
7775 return 1;
7776 }
7777 if (isinstance) {
7778 expr_ty elt;
7779 asdl_seq* generators;
7780
Dino Viehlandac46eb42019-09-11 10:16:34 -07007781 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007782 return 1;
7783 }
7784 if (tmp == NULL) {
7785 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7786 return 1;
7787 }
7788 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007789 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007790 res = obj2ast_expr(tmp, &elt, arena);
7791 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007792 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007793 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007794 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7795 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007796 return 1;
7797 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007798 if (tmp == NULL) {
7799 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7800 return 1;
7801 }
7802 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007803 int res;
7804 Py_ssize_t len;
7805 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007806 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007807 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 +02007808 goto failed;
7809 }
7810 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007811 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007812 if (generators == NULL) goto failed;
7813 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007814 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007815 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7816 Py_INCREF(tmp2);
7817 res = obj2ast_comprehension(tmp2, &val, arena);
7818 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007819 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007820 if (len != PyList_GET_SIZE(tmp)) {
7821 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7822 goto failed;
7823 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007824 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007825 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007826 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007827 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007828 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7829 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007830 if (*out == NULL) goto failed;
7831 return 0;
7832 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007833 tp = astmodulestate_global->DictComp_type;
7834 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007835 if (isinstance == -1) {
7836 return 1;
7837 }
7838 if (isinstance) {
7839 expr_ty key;
7840 expr_ty value;
7841 asdl_seq* generators;
7842
Dino Viehlandac46eb42019-09-11 10:16:34 -07007843 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007844 return 1;
7845 }
7846 if (tmp == NULL) {
7847 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7848 return 1;
7849 }
7850 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007851 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007852 res = obj2ast_expr(tmp, &key, arena);
7853 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007854 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007855 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007856 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007857 return 1;
7858 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007859 if (tmp == NULL) {
7860 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7861 return 1;
7862 }
7863 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007864 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007865 res = obj2ast_expr(tmp, &value, arena);
7866 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007867 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007868 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007869 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7870 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007871 return 1;
7872 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007873 if (tmp == NULL) {
7874 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7875 return 1;
7876 }
7877 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007878 int res;
7879 Py_ssize_t len;
7880 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007881 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007882 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 +02007883 goto failed;
7884 }
7885 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007886 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007887 if (generators == NULL) goto failed;
7888 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007889 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007890 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7891 Py_INCREF(tmp2);
7892 res = obj2ast_comprehension(tmp2, &val, arena);
7893 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007894 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007895 if (len != PyList_GET_SIZE(tmp)) {
7896 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7897 goto failed;
7898 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007899 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007900 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007901 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007902 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007903 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7904 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007905 if (*out == NULL) goto failed;
7906 return 0;
7907 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007908 tp = astmodulestate_global->GeneratorExp_type;
7909 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007910 if (isinstance == -1) {
7911 return 1;
7912 }
7913 if (isinstance) {
7914 expr_ty elt;
7915 asdl_seq* generators;
7916
Dino Viehlandac46eb42019-09-11 10:16:34 -07007917 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007918 return 1;
7919 }
7920 if (tmp == NULL) {
7921 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7922 return 1;
7923 }
7924 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007925 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007926 res = obj2ast_expr(tmp, &elt, arena);
7927 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007928 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007930 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7931 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007932 return 1;
7933 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007934 if (tmp == NULL) {
7935 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7936 return 1;
7937 }
7938 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007939 int res;
7940 Py_ssize_t len;
7941 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007942 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007943 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 +02007944 goto failed;
7945 }
7946 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007947 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007948 if (generators == NULL) goto failed;
7949 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007950 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007951 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7952 Py_INCREF(tmp2);
7953 res = obj2ast_comprehension(tmp2, &val, arena);
7954 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007955 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007956 if (len != PyList_GET_SIZE(tmp)) {
7957 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7958 goto failed;
7959 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007960 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007961 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007962 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007963 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007964 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7965 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007966 if (*out == NULL) goto failed;
7967 return 0;
7968 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007969 tp = astmodulestate_global->Await_type;
7970 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007971 if (isinstance == -1) {
7972 return 1;
7973 }
7974 if (isinstance) {
7975 expr_ty value;
7976
Dino Viehlandac46eb42019-09-11 10:16:34 -07007977 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007978 return 1;
7979 }
7980 if (tmp == NULL) {
7981 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
7982 return 1;
7983 }
7984 else {
Yury Selivanov75445082015-05-11 22:57:16 -04007985 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04007986 res = obj2ast_expr(tmp, &value, arena);
7987 if (res != 0) goto failed;
7988 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04007989 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007990 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
7991 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04007992 if (*out == NULL) goto failed;
7993 return 0;
7994 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007995 tp = astmodulestate_global->Yield_type;
7996 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007997 if (isinstance == -1) {
7998 return 1;
7999 }
8000 if (isinstance) {
8001 expr_ty value;
8002
Dino Viehlandac46eb42019-09-11 10:16:34 -07008003 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008004 return 1;
8005 }
8006 if (tmp == NULL || tmp == Py_None) {
8007 Py_CLEAR(tmp);
8008 value = NULL;
8009 }
8010 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008011 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008012 res = obj2ast_expr(tmp, &value, arena);
8013 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008014 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008015 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008016 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8017 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008018 if (*out == NULL) goto failed;
8019 return 0;
8020 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008021 tp = astmodulestate_global->YieldFrom_type;
8022 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008023 if (isinstance == -1) {
8024 return 1;
8025 }
8026 if (isinstance) {
8027 expr_ty value;
8028
Dino Viehlandac46eb42019-09-11 10:16:34 -07008029 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008030 return 1;
8031 }
8032 if (tmp == NULL) {
8033 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8034 return 1;
8035 }
8036 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008037 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008038 res = obj2ast_expr(tmp, &value, arena);
8039 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008040 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008041 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008042 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8043 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008044 if (*out == NULL) goto failed;
8045 return 0;
8046 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008047 tp = astmodulestate_global->Compare_type;
8048 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008049 if (isinstance == -1) {
8050 return 1;
8051 }
8052 if (isinstance) {
8053 expr_ty left;
8054 asdl_int_seq* ops;
8055 asdl_seq* comparators;
8056
Dino Viehlandac46eb42019-09-11 10:16:34 -07008057 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008058 return 1;
8059 }
8060 if (tmp == NULL) {
8061 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8062 return 1;
8063 }
8064 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008065 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008066 res = obj2ast_expr(tmp, &left, arena);
8067 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008068 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008070 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008071 return 1;
8072 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008073 if (tmp == NULL) {
8074 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8075 return 1;
8076 }
8077 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008078 int res;
8079 Py_ssize_t len;
8080 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008081 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008082 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 +02008083 goto failed;
8084 }
8085 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008086 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008087 if (ops == NULL) goto failed;
8088 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008089 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008090 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8091 Py_INCREF(tmp2);
8092 res = obj2ast_cmpop(tmp2, &val, arena);
8093 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008094 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008095 if (len != PyList_GET_SIZE(tmp)) {
8096 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8097 goto failed;
8098 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008099 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008100 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008101 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008102 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008103 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8104 < 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 \"comparators\" 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 \"comparators\" 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 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008121 if (comparators == NULL) goto failed;
8122 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008123 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008124 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8125 Py_INCREF(tmp2);
8126 res = obj2ast_expr(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 \"comparators\" changed size during iteration");
8131 goto failed;
8132 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008133 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008134 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008135 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008136 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008137 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8138 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008139 if (*out == NULL) goto failed;
8140 return 0;
8141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008142 tp = astmodulestate_global->Call_type;
8143 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008144 if (isinstance == -1) {
8145 return 1;
8146 }
8147 if (isinstance) {
8148 expr_ty func;
8149 asdl_seq* args;
8150 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008151
Dino Viehlandac46eb42019-09-11 10:16:34 -07008152 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008153 return 1;
8154 }
8155 if (tmp == NULL) {
8156 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8157 return 1;
8158 }
8159 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008160 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008161 res = obj2ast_expr(tmp, &func, arena);
8162 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008163 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008165 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008166 return 1;
8167 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008168 if (tmp == NULL) {
8169 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8170 return 1;
8171 }
8172 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008173 int res;
8174 Py_ssize_t len;
8175 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008176 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008177 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 +02008178 goto failed;
8179 }
8180 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008181 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008182 if (args == NULL) goto failed;
8183 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008184 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008185 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8186 Py_INCREF(tmp2);
8187 res = obj2ast_expr(tmp2, &val, arena);
8188 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008189 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008190 if (len != PyList_GET_SIZE(tmp)) {
8191 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8192 goto failed;
8193 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008194 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008195 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008196 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008197 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008198 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8199 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 \"keywords\" 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 \"keywords\" 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 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008216 if (keywords == NULL) goto failed;
8217 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008218 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008219 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8220 Py_INCREF(tmp2);
8221 res = obj2ast_keyword(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 \"keywords\" changed size during iteration");
8226 goto failed;
8227 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008228 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008229 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008230 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008231 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008232 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8233 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008234 if (*out == NULL) goto failed;
8235 return 0;
8236 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008237 tp = astmodulestate_global->FormattedValue_type;
8238 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008239 if (isinstance == -1) {
8240 return 1;
8241 }
8242 if (isinstance) {
8243 expr_ty value;
8244 int conversion;
8245 expr_ty format_spec;
8246
Dino Viehlandac46eb42019-09-11 10:16:34 -07008247 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008248 return 1;
8249 }
8250 if (tmp == NULL) {
8251 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8252 return 1;
8253 }
8254 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008255 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008256 res = obj2ast_expr(tmp, &value, arena);
8257 if (res != 0) goto failed;
8258 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008259 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008260 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8261 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008262 return 1;
8263 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008264 if (tmp == NULL || tmp == Py_None) {
8265 Py_CLEAR(tmp);
8266 conversion = 0;
8267 }
8268 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008269 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008270 res = obj2ast_int(tmp, &conversion, arena);
8271 if (res != 0) goto failed;
8272 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008273 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008274 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8275 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008276 return 1;
8277 }
8278 if (tmp == NULL || tmp == Py_None) {
8279 Py_CLEAR(tmp);
8280 format_spec = NULL;
8281 }
8282 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008283 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008284 res = obj2ast_expr(tmp, &format_spec, arena);
8285 if (res != 0) goto failed;
8286 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008287 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008288 *out = FormattedValue(value, conversion, format_spec, lineno,
8289 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008290 if (*out == NULL) goto failed;
8291 return 0;
8292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008293 tp = astmodulestate_global->JoinedStr_type;
8294 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008295 if (isinstance == -1) {
8296 return 1;
8297 }
8298 if (isinstance) {
8299 asdl_seq* values;
8300
Dino Viehlandac46eb42019-09-11 10:16:34 -07008301 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8302 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008303 return 1;
8304 }
8305 if (tmp == NULL) {
8306 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8307 return 1;
8308 }
8309 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008310 int res;
8311 Py_ssize_t len;
8312 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008313 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008314 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 -04008315 goto failed;
8316 }
8317 len = PyList_GET_SIZE(tmp);
8318 values = _Py_asdl_seq_new(len, arena);
8319 if (values == NULL) goto failed;
8320 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008321 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008322 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8323 Py_INCREF(tmp2);
8324 res = obj2ast_expr(tmp2, &val, arena);
8325 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008326 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008327 if (len != PyList_GET_SIZE(tmp)) {
8328 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8329 goto failed;
8330 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008331 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008332 }
8333 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008334 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008335 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8336 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008337 if (*out == NULL) goto failed;
8338 return 0;
8339 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008340 tp = astmodulestate_global->Constant_type;
8341 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008342 if (isinstance == -1) {
8343 return 1;
8344 }
8345 if (isinstance) {
8346 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008347 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008348
Dino Viehlandac46eb42019-09-11 10:16:34 -07008349 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008350 return 1;
8351 }
8352 if (tmp == NULL) {
8353 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8354 return 1;
8355 }
8356 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008357 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008358 res = obj2ast_constant(tmp, &value, arena);
8359 if (res != 0) goto failed;
8360 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008361 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008362 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008363 return 1;
8364 }
8365 if (tmp == NULL || tmp == Py_None) {
8366 Py_CLEAR(tmp);
8367 kind = NULL;
8368 }
8369 else {
8370 int res;
8371 res = obj2ast_string(tmp, &kind, arena);
8372 if (res != 0) goto failed;
8373 Py_CLEAR(tmp);
8374 }
8375 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8376 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008377 if (*out == NULL) goto failed;
8378 return 0;
8379 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008380 tp = astmodulestate_global->Attribute_type;
8381 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008382 if (isinstance == -1) {
8383 return 1;
8384 }
8385 if (isinstance) {
8386 expr_ty value;
8387 identifier attr;
8388 expr_context_ty ctx;
8389
Dino Viehlandac46eb42019-09-11 10:16:34 -07008390 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008391 return 1;
8392 }
8393 if (tmp == NULL) {
8394 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8395 return 1;
8396 }
8397 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008398 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008399 res = obj2ast_expr(tmp, &value, arena);
8400 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008401 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008402 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008403 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008404 return 1;
8405 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008406 if (tmp == NULL) {
8407 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8408 return 1;
8409 }
8410 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008411 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008412 res = obj2ast_identifier(tmp, &attr, arena);
8413 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008414 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008415 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008416 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008417 return 1;
8418 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008419 if (tmp == NULL) {
8420 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8421 return 1;
8422 }
8423 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008424 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008425 res = obj2ast_expr_context(tmp, &ctx, arena);
8426 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008427 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008428 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008429 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8430 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008431 if (*out == NULL) goto failed;
8432 return 0;
8433 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008434 tp = astmodulestate_global->Subscript_type;
8435 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008436 if (isinstance == -1) {
8437 return 1;
8438 }
8439 if (isinstance) {
8440 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008441 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008442 expr_context_ty ctx;
8443
Dino Viehlandac46eb42019-09-11 10:16:34 -07008444 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008445 return 1;
8446 }
8447 if (tmp == NULL) {
8448 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8449 return 1;
8450 }
8451 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008452 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008453 res = obj2ast_expr(tmp, &value, arena);
8454 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008455 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008456 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008457 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008458 return 1;
8459 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008460 if (tmp == NULL) {
8461 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8462 return 1;
8463 }
8464 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008465 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008466 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008467 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008468 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008469 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008470 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008471 return 1;
8472 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008473 if (tmp == NULL) {
8474 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8475 return 1;
8476 }
8477 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008478 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008479 res = obj2ast_expr_context(tmp, &ctx, arena);
8480 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008481 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008482 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008483 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8484 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008485 if (*out == NULL) goto failed;
8486 return 0;
8487 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008488 tp = astmodulestate_global->Starred_type;
8489 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008490 if (isinstance == -1) {
8491 return 1;
8492 }
8493 if (isinstance) {
8494 expr_ty value;
8495 expr_context_ty ctx;
8496
Dino Viehlandac46eb42019-09-11 10:16:34 -07008497 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008498 return 1;
8499 }
8500 if (tmp == NULL) {
8501 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8502 return 1;
8503 }
8504 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008505 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008506 res = obj2ast_expr(tmp, &value, arena);
8507 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008508 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008509 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008510 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008511 return 1;
8512 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008513 if (tmp == NULL) {
8514 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8515 return 1;
8516 }
8517 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008518 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008519 res = obj2ast_expr_context(tmp, &ctx, arena);
8520 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008521 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008522 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008523 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8524 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008525 if (*out == NULL) goto failed;
8526 return 0;
8527 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008528 tp = astmodulestate_global->Name_type;
8529 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008530 if (isinstance == -1) {
8531 return 1;
8532 }
8533 if (isinstance) {
8534 identifier id;
8535 expr_context_ty ctx;
8536
Dino Viehlandac46eb42019-09-11 10:16:34 -07008537 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008538 return 1;
8539 }
8540 if (tmp == NULL) {
8541 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8542 return 1;
8543 }
8544 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008545 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008546 res = obj2ast_identifier(tmp, &id, arena);
8547 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008548 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008549 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008550 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008551 return 1;
8552 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008553 if (tmp == NULL) {
8554 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8555 return 1;
8556 }
8557 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008558 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008559 res = obj2ast_expr_context(tmp, &ctx, arena);
8560 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008561 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008562 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008563 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8564 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008565 if (*out == NULL) goto failed;
8566 return 0;
8567 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008568 tp = astmodulestate_global->List_type;
8569 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008570 if (isinstance == -1) {
8571 return 1;
8572 }
8573 if (isinstance) {
8574 asdl_seq* elts;
8575 expr_context_ty ctx;
8576
Dino Viehlandac46eb42019-09-11 10:16:34 -07008577 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008578 return 1;
8579 }
8580 if (tmp == NULL) {
8581 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8582 return 1;
8583 }
8584 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008585 int res;
8586 Py_ssize_t len;
8587 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008588 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008589 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 +02008590 goto failed;
8591 }
8592 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008593 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008594 if (elts == NULL) goto failed;
8595 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008596 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008597 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8598 Py_INCREF(tmp2);
8599 res = obj2ast_expr(tmp2, &val, arena);
8600 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008601 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008602 if (len != PyList_GET_SIZE(tmp)) {
8603 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8604 goto failed;
8605 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008606 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008607 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008608 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008609 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008610 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008611 return 1;
8612 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008613 if (tmp == NULL) {
8614 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8615 return 1;
8616 }
8617 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008618 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008619 res = obj2ast_expr_context(tmp, &ctx, arena);
8620 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008621 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008622 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008623 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8624 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008625 if (*out == NULL) goto failed;
8626 return 0;
8627 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008628 tp = astmodulestate_global->Tuple_type;
8629 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008630 if (isinstance == -1) {
8631 return 1;
8632 }
8633 if (isinstance) {
8634 asdl_seq* elts;
8635 expr_context_ty ctx;
8636
Dino Viehlandac46eb42019-09-11 10:16:34 -07008637 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008638 return 1;
8639 }
8640 if (tmp == NULL) {
8641 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8642 return 1;
8643 }
8644 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008645 int res;
8646 Py_ssize_t len;
8647 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008648 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008649 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 +02008650 goto failed;
8651 }
8652 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008653 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008654 if (elts == NULL) goto failed;
8655 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008656 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008657 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8658 Py_INCREF(tmp2);
8659 res = obj2ast_expr(tmp2, &val, arena);
8660 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008661 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008662 if (len != PyList_GET_SIZE(tmp)) {
8663 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8664 goto failed;
8665 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008666 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008667 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008668 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008669 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008670 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008671 return 1;
8672 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008673 if (tmp == NULL) {
8674 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8675 return 1;
8676 }
8677 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008678 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008679 res = obj2ast_expr_context(tmp, &ctx, arena);
8680 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008681 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008682 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008683 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8684 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008685 if (*out == NULL) goto failed;
8686 return 0;
8687 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008688 tp = astmodulestate_global->Slice_type;
8689 isinstance = PyObject_IsInstance(obj, tp);
8690 if (isinstance == -1) {
8691 return 1;
8692 }
8693 if (isinstance) {
8694 expr_ty lower;
8695 expr_ty upper;
8696 expr_ty step;
8697
8698 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8699 return 1;
8700 }
8701 if (tmp == NULL || tmp == Py_None) {
8702 Py_CLEAR(tmp);
8703 lower = NULL;
8704 }
8705 else {
8706 int res;
8707 res = obj2ast_expr(tmp, &lower, arena);
8708 if (res != 0) goto failed;
8709 Py_CLEAR(tmp);
8710 }
8711 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8712 return 1;
8713 }
8714 if (tmp == NULL || tmp == Py_None) {
8715 Py_CLEAR(tmp);
8716 upper = NULL;
8717 }
8718 else {
8719 int res;
8720 res = obj2ast_expr(tmp, &upper, arena);
8721 if (res != 0) goto failed;
8722 Py_CLEAR(tmp);
8723 }
8724 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8725 return 1;
8726 }
8727 if (tmp == NULL || tmp == Py_None) {
8728 Py_CLEAR(tmp);
8729 step = NULL;
8730 }
8731 else {
8732 int res;
8733 res = obj2ast_expr(tmp, &step, arena);
8734 if (res != 0) goto failed;
8735 Py_CLEAR(tmp);
8736 }
8737 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8738 end_col_offset, arena);
8739 if (*out == NULL) goto failed;
8740 return 0;
8741 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008742
8743 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8744 failed:
8745 Py_XDECREF(tmp);
8746 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008747}
8748
8749int
8750obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8751{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008752 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008753
Dino Viehlandac46eb42019-09-11 10:16:34 -07008754 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008755 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008756 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008757 }
8758 if (isinstance) {
8759 *out = Load;
8760 return 0;
8761 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008762 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008763 if (isinstance == -1) {
8764 return 1;
8765 }
8766 if (isinstance) {
8767 *out = Store;
8768 return 0;
8769 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008770 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008771 if (isinstance == -1) {
8772 return 1;
8773 }
8774 if (isinstance) {
8775 *out = Del;
8776 return 0;
8777 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008778
8779 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8780 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008781}
8782
8783int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008784obj2ast_boolop(PyObject* obj, boolop_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->And_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 = And;
8794 return 0;
8795 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008796 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008797 if (isinstance == -1) {
8798 return 1;
8799 }
8800 if (isinstance) {
8801 *out = Or;
8802 return 0;
8803 }
8804
8805 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8806 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008807}
8808
8809int
8810obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8811{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008812 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008813
Dino Viehlandac46eb42019-09-11 10:16:34 -07008814 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008815 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008816 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008817 }
8818 if (isinstance) {
8819 *out = Add;
8820 return 0;
8821 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008822 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008823 if (isinstance == -1) {
8824 return 1;
8825 }
8826 if (isinstance) {
8827 *out = Sub;
8828 return 0;
8829 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008830 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008831 if (isinstance == -1) {
8832 return 1;
8833 }
8834 if (isinstance) {
8835 *out = Mult;
8836 return 0;
8837 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008838 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008839 if (isinstance == -1) {
8840 return 1;
8841 }
8842 if (isinstance) {
8843 *out = MatMult;
8844 return 0;
8845 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008846 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008847 if (isinstance == -1) {
8848 return 1;
8849 }
8850 if (isinstance) {
8851 *out = Div;
8852 return 0;
8853 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008854 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008855 if (isinstance == -1) {
8856 return 1;
8857 }
8858 if (isinstance) {
8859 *out = Mod;
8860 return 0;
8861 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008862 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008863 if (isinstance == -1) {
8864 return 1;
8865 }
8866 if (isinstance) {
8867 *out = Pow;
8868 return 0;
8869 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008870 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008871 if (isinstance == -1) {
8872 return 1;
8873 }
8874 if (isinstance) {
8875 *out = LShift;
8876 return 0;
8877 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008878 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008879 if (isinstance == -1) {
8880 return 1;
8881 }
8882 if (isinstance) {
8883 *out = RShift;
8884 return 0;
8885 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008886 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008887 if (isinstance == -1) {
8888 return 1;
8889 }
8890 if (isinstance) {
8891 *out = BitOr;
8892 return 0;
8893 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008894 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008895 if (isinstance == -1) {
8896 return 1;
8897 }
8898 if (isinstance) {
8899 *out = BitXor;
8900 return 0;
8901 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008902 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008903 if (isinstance == -1) {
8904 return 1;
8905 }
8906 if (isinstance) {
8907 *out = BitAnd;
8908 return 0;
8909 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008910 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008911 if (isinstance == -1) {
8912 return 1;
8913 }
8914 if (isinstance) {
8915 *out = FloorDiv;
8916 return 0;
8917 }
8918
8919 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8920 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008921}
8922
8923int
8924obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8925{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008926 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008927
Dino Viehlandac46eb42019-09-11 10:16:34 -07008928 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008929 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008930 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008931 }
8932 if (isinstance) {
8933 *out = Invert;
8934 return 0;
8935 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008936 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008937 if (isinstance == -1) {
8938 return 1;
8939 }
8940 if (isinstance) {
8941 *out = Not;
8942 return 0;
8943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008944 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008945 if (isinstance == -1) {
8946 return 1;
8947 }
8948 if (isinstance) {
8949 *out = UAdd;
8950 return 0;
8951 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008952 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008953 if (isinstance == -1) {
8954 return 1;
8955 }
8956 if (isinstance) {
8957 *out = USub;
8958 return 0;
8959 }
8960
8961 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
8962 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008963}
8964
8965int
8966obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
8967{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008968 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008969
Dino Viehlandac46eb42019-09-11 10:16:34 -07008970 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008971 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008972 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008973 }
8974 if (isinstance) {
8975 *out = Eq;
8976 return 0;
8977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008978 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008979 if (isinstance == -1) {
8980 return 1;
8981 }
8982 if (isinstance) {
8983 *out = NotEq;
8984 return 0;
8985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008986 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008987 if (isinstance == -1) {
8988 return 1;
8989 }
8990 if (isinstance) {
8991 *out = Lt;
8992 return 0;
8993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008994 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008995 if (isinstance == -1) {
8996 return 1;
8997 }
8998 if (isinstance) {
8999 *out = LtE;
9000 return 0;
9001 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009002 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009003 if (isinstance == -1) {
9004 return 1;
9005 }
9006 if (isinstance) {
9007 *out = Gt;
9008 return 0;
9009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009010 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009011 if (isinstance == -1) {
9012 return 1;
9013 }
9014 if (isinstance) {
9015 *out = GtE;
9016 return 0;
9017 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009018 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009019 if (isinstance == -1) {
9020 return 1;
9021 }
9022 if (isinstance) {
9023 *out = Is;
9024 return 0;
9025 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009026 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009027 if (isinstance == -1) {
9028 return 1;
9029 }
9030 if (isinstance) {
9031 *out = IsNot;
9032 return 0;
9033 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009034 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009035 if (isinstance == -1) {
9036 return 1;
9037 }
9038 if (isinstance) {
9039 *out = In;
9040 return 0;
9041 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009042 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009043 if (isinstance == -1) {
9044 return 1;
9045 }
9046 if (isinstance) {
9047 *out = NotIn;
9048 return 0;
9049 }
9050
9051 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9052 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009053}
9054
9055int
9056obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9057{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009058 PyObject* tmp = NULL;
9059 expr_ty target;
9060 expr_ty iter;
9061 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009062 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009063
Dino Viehlandac46eb42019-09-11 10:16:34 -07009064 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009065 return 1;
9066 }
9067 if (tmp == NULL) {
9068 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9069 return 1;
9070 }
9071 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009072 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009073 res = obj2ast_expr(tmp, &target, arena);
9074 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009075 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009076 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009077 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009078 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009079 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009080 if (tmp == NULL) {
9081 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9082 return 1;
9083 }
9084 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009085 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009086 res = obj2ast_expr(tmp, &iter, arena);
9087 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009088 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009090 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009091 return 1;
9092 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009093 if (tmp == NULL) {
9094 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9095 return 1;
9096 }
9097 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009098 int res;
9099 Py_ssize_t len;
9100 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009101 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009102 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 +02009103 goto failed;
9104 }
9105 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009106 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009107 if (ifs == NULL) goto failed;
9108 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009109 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009110 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9111 Py_INCREF(tmp2);
9112 res = obj2ast_expr(tmp2, &val, arena);
9113 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009114 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009115 if (len != PyList_GET_SIZE(tmp)) {
9116 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9117 goto failed;
9118 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009119 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009120 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009121 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009122 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009123 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009124 return 1;
9125 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009126 if (tmp == NULL) {
9127 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9128 return 1;
9129 }
9130 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009131 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009132 res = obj2ast_int(tmp, &is_async, arena);
9133 if (res != 0) goto failed;
9134 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009135 }
9136 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009137 return 0;
9138failed:
9139 Py_XDECREF(tmp);
9140 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009141}
9142
9143int
9144obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9145{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009146 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009147
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009148 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009149 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009150 int lineno;
9151 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009152 int end_lineno;
9153 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009154
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009155 if (obj == Py_None) {
9156 *out = NULL;
9157 return 0;
9158 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009159 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009160 return 1;
9161 }
9162 if (tmp == NULL) {
9163 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9164 return 1;
9165 }
9166 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009167 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009168 res = obj2ast_int(tmp, &lineno, arena);
9169 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009170 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009171 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009172 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9173 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009174 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009175 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009176 if (tmp == NULL) {
9177 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9178 return 1;
9179 }
9180 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009181 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009182 res = obj2ast_int(tmp, &col_offset, arena);
9183 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009184 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009185 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009186 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9187 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009188 return 1;
9189 }
9190 if (tmp == NULL || tmp == Py_None) {
9191 Py_CLEAR(tmp);
9192 end_lineno = 0;
9193 }
9194 else {
9195 int res;
9196 res = obj2ast_int(tmp, &end_lineno, arena);
9197 if (res != 0) goto failed;
9198 Py_CLEAR(tmp);
9199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009200 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9201 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009202 return 1;
9203 }
9204 if (tmp == NULL || tmp == Py_None) {
9205 Py_CLEAR(tmp);
9206 end_col_offset = 0;
9207 }
9208 else {
9209 int res;
9210 res = obj2ast_int(tmp, &end_col_offset, arena);
9211 if (res != 0) goto failed;
9212 Py_CLEAR(tmp);
9213 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009214 tp = astmodulestate_global->ExceptHandler_type;
9215 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009216 if (isinstance == -1) {
9217 return 1;
9218 }
9219 if (isinstance) {
9220 expr_ty type;
9221 identifier name;
9222 asdl_seq* body;
9223
Dino Viehlandac46eb42019-09-11 10:16:34 -07009224 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009225 return 1;
9226 }
9227 if (tmp == NULL || tmp == Py_None) {
9228 Py_CLEAR(tmp);
9229 type = NULL;
9230 }
9231 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009232 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009233 res = obj2ast_expr(tmp, &type, arena);
9234 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009235 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009236 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009237 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009238 return 1;
9239 }
9240 if (tmp == NULL || tmp == Py_None) {
9241 Py_CLEAR(tmp);
9242 name = NULL;
9243 }
9244 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009245 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009246 res = obj2ast_identifier(tmp, &name, arena);
9247 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009248 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009249 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009250 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009251 return 1;
9252 }
9253 if (tmp == NULL) {
9254 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9255 return 1;
9256 }
9257 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009258 int res;
9259 Py_ssize_t len;
9260 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009261 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009262 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 +02009263 goto failed;
9264 }
9265 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009266 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009267 if (body == NULL) goto failed;
9268 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009269 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009270 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9271 Py_INCREF(tmp2);
9272 res = obj2ast_stmt(tmp2, &val, arena);
9273 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009274 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009275 if (len != PyList_GET_SIZE(tmp)) {
9276 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9277 goto failed;
9278 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009279 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009280 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009281 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009282 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009283 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9284 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009285 if (*out == NULL) goto failed;
9286 return 0;
9287 }
9288
9289 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9290 failed:
9291 Py_XDECREF(tmp);
9292 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009293}
9294
9295int
9296obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9297{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009298 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009299 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009300 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009301 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009302 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009303 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009304 arg_ty kwarg;
9305 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009306
Dino Viehlandac46eb42019-09-11 10:16:34 -07009307 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9308 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009309 return 1;
9310 }
9311 if (tmp == NULL) {
9312 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9313 return 1;
9314 }
9315 else {
9316 int res;
9317 Py_ssize_t len;
9318 Py_ssize_t i;
9319 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009320 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 +01009321 goto failed;
9322 }
9323 len = PyList_GET_SIZE(tmp);
9324 posonlyargs = _Py_asdl_seq_new(len, arena);
9325 if (posonlyargs == NULL) goto failed;
9326 for (i = 0; i < len; i++) {
9327 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009328 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9329 Py_INCREF(tmp2);
9330 res = obj2ast_arg(tmp2, &val, arena);
9331 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009332 if (res != 0) goto failed;
9333 if (len != PyList_GET_SIZE(tmp)) {
9334 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9335 goto failed;
9336 }
9337 asdl_seq_SET(posonlyargs, i, val);
9338 }
9339 Py_CLEAR(tmp);
9340 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009341 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009342 return 1;
9343 }
9344 if (tmp == NULL) {
9345 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9346 return 1;
9347 }
9348 else {
9349 int res;
9350 Py_ssize_t len;
9351 Py_ssize_t i;
9352 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009353 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 +02009354 goto failed;
9355 }
9356 len = PyList_GET_SIZE(tmp);
9357 args = _Py_asdl_seq_new(len, arena);
9358 if (args == NULL) goto failed;
9359 for (i = 0; i < len; i++) {
9360 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009361 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9362 Py_INCREF(tmp2);
9363 res = obj2ast_arg(tmp2, &val, arena);
9364 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009365 if (res != 0) goto failed;
9366 if (len != PyList_GET_SIZE(tmp)) {
9367 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9368 goto failed;
9369 }
9370 asdl_seq_SET(args, i, val);
9371 }
9372 Py_CLEAR(tmp);
9373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009374 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009375 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009376 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009377 if (tmp == NULL || tmp == Py_None) {
9378 Py_CLEAR(tmp);
9379 vararg = NULL;
9380 }
9381 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009382 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009383 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009384 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009385 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009386 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009387 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9388 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009389 return 1;
9390 }
9391 if (tmp == NULL) {
9392 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9393 return 1;
9394 }
9395 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009396 int res;
9397 Py_ssize_t len;
9398 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009399 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009400 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 +02009401 goto failed;
9402 }
9403 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009404 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009405 if (kwonlyargs == NULL) goto failed;
9406 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009407 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009408 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9409 Py_INCREF(tmp2);
9410 res = obj2ast_arg(tmp2, &val, arena);
9411 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009412 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009413 if (len != PyList_GET_SIZE(tmp)) {
9414 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9415 goto failed;
9416 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009417 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009418 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009419 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009420 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009421 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9422 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009423 return 1;
9424 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009425 if (tmp == NULL) {
9426 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9427 return 1;
9428 }
9429 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009430 int res;
9431 Py_ssize_t len;
9432 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009433 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009434 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 +02009435 goto failed;
9436 }
9437 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009438 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009439 if (kw_defaults == NULL) goto failed;
9440 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009441 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009442 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9443 Py_INCREF(tmp2);
9444 res = obj2ast_expr(tmp2, &val, arena);
9445 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009446 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009447 if (len != PyList_GET_SIZE(tmp)) {
9448 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9449 goto failed;
9450 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009451 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009452 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009453 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009454 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009455 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009456 return 1;
9457 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009458 if (tmp == NULL || tmp == Py_None) {
9459 Py_CLEAR(tmp);
9460 kwarg = NULL;
9461 }
9462 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009463 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009464 res = obj2ast_arg(tmp, &kwarg, arena);
9465 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009466 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009467 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009468 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009469 return 1;
9470 }
9471 if (tmp == NULL) {
9472 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9473 return 1;
9474 }
9475 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009476 int res;
9477 Py_ssize_t len;
9478 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009479 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009480 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 +02009481 goto failed;
9482 }
9483 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009484 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009485 if (defaults == NULL) goto failed;
9486 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009487 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009488 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9489 Py_INCREF(tmp2);
9490 res = obj2ast_expr(tmp2, &val, arena);
9491 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009492 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009493 if (len != PyList_GET_SIZE(tmp)) {
9494 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9495 goto failed;
9496 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009497 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009498 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009499 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009500 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009501 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009502 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009503 return 0;
9504failed:
9505 Py_XDECREF(tmp);
9506 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009507}
9508
9509int
9510obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9511{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009512 PyObject* tmp = NULL;
9513 identifier arg;
9514 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009515 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009516 int lineno;
9517 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009518 int end_lineno;
9519 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009520
Dino Viehlandac46eb42019-09-11 10:16:34 -07009521 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009522 return 1;
9523 }
9524 if (tmp == NULL) {
9525 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9526 return 1;
9527 }
9528 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009529 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009530 res = obj2ast_identifier(tmp, &arg, arena);
9531 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009532 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009533 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009534 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9535 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009536 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009537 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009538 if (tmp == NULL || tmp == Py_None) {
9539 Py_CLEAR(tmp);
9540 annotation = NULL;
9541 }
9542 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009543 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009544 res = obj2ast_expr(tmp, &annotation, arena);
9545 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009546 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009547 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009548 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9549 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009550 return 1;
9551 }
9552 if (tmp == NULL || tmp == Py_None) {
9553 Py_CLEAR(tmp);
9554 type_comment = NULL;
9555 }
9556 else {
9557 int res;
9558 res = obj2ast_string(tmp, &type_comment, arena);
9559 if (res != 0) goto failed;
9560 Py_CLEAR(tmp);
9561 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009562 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009563 return 1;
9564 }
9565 if (tmp == NULL) {
9566 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9567 return 1;
9568 }
9569 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009570 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009571 res = obj2ast_int(tmp, &lineno, arena);
9572 if (res != 0) goto failed;
9573 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009574 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009575 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9576 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009577 return 1;
9578 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009579 if (tmp == NULL) {
9580 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9581 return 1;
9582 }
9583 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009584 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009585 res = obj2ast_int(tmp, &col_offset, arena);
9586 if (res != 0) goto failed;
9587 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009588 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009589 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9590 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009591 return 1;
9592 }
9593 if (tmp == NULL || tmp == Py_None) {
9594 Py_CLEAR(tmp);
9595 end_lineno = 0;
9596 }
9597 else {
9598 int res;
9599 res = obj2ast_int(tmp, &end_lineno, arena);
9600 if (res != 0) goto failed;
9601 Py_CLEAR(tmp);
9602 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009603 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9604 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009605 return 1;
9606 }
9607 if (tmp == NULL || tmp == Py_None) {
9608 Py_CLEAR(tmp);
9609 end_col_offset = 0;
9610 }
9611 else {
9612 int res;
9613 res = obj2ast_int(tmp, &end_col_offset, arena);
9614 if (res != 0) goto failed;
9615 Py_CLEAR(tmp);
9616 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009617 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9618 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009619 return 0;
9620failed:
9621 Py_XDECREF(tmp);
9622 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009623}
9624
9625int
9626obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9627{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009628 PyObject* tmp = NULL;
9629 identifier arg;
9630 expr_ty value;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009631
Dino Viehlandac46eb42019-09-11 10:16:34 -07009632 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009633 return 1;
9634 }
9635 if (tmp == NULL || tmp == Py_None) {
9636 Py_CLEAR(tmp);
9637 arg = NULL;
9638 }
9639 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009640 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009641 res = obj2ast_identifier(tmp, &arg, arena);
9642 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009643 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009644 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009645 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009646 return 1;
9647 }
9648 if (tmp == NULL) {
9649 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9650 return 1;
9651 }
9652 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009653 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009654 res = obj2ast_expr(tmp, &value, arena);
9655 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009656 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009657 }
9658 *out = keyword(arg, value, arena);
9659 return 0;
9660failed:
9661 Py_XDECREF(tmp);
9662 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009663}
9664
9665int
9666obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9667{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009668 PyObject* tmp = NULL;
9669 identifier name;
9670 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009671
Dino Viehlandac46eb42019-09-11 10:16:34 -07009672 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009673 return 1;
9674 }
9675 if (tmp == NULL) {
9676 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9677 return 1;
9678 }
9679 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009680 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009681 res = obj2ast_identifier(tmp, &name, arena);
9682 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009683 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009684 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009685 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009686 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009687 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009688 if (tmp == NULL || tmp == Py_None) {
9689 Py_CLEAR(tmp);
9690 asname = NULL;
9691 }
9692 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009693 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009694 res = obj2ast_identifier(tmp, &asname, arena);
9695 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009696 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009697 }
9698 *out = alias(name, asname, arena);
9699 return 0;
9700failed:
9701 Py_XDECREF(tmp);
9702 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009703}
9704
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009705int
9706obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9707{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009708 PyObject* tmp = NULL;
9709 expr_ty context_expr;
9710 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009711
Dino Viehlandac46eb42019-09-11 10:16:34 -07009712 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9713 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009714 return 1;
9715 }
9716 if (tmp == NULL) {
9717 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9718 return 1;
9719 }
9720 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009721 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009722 res = obj2ast_expr(tmp, &context_expr, arena);
9723 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009724 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009725 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009726 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9727 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009728 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009729 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009730 if (tmp == NULL || tmp == Py_None) {
9731 Py_CLEAR(tmp);
9732 optional_vars = NULL;
9733 }
9734 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009735 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009736 res = obj2ast_expr(tmp, &optional_vars, arena);
9737 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009738 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009739 }
9740 *out = withitem(context_expr, optional_vars, arena);
9741 return 0;
9742failed:
9743 Py_XDECREF(tmp);
9744 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009745}
9746
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009747int
9748obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9749{
9750 int isinstance;
9751
9752 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009753 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009754
9755 if (obj == Py_None) {
9756 *out = NULL;
9757 return 0;
9758 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009759 tp = astmodulestate_global->TypeIgnore_type;
9760 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009761 if (isinstance == -1) {
9762 return 1;
9763 }
9764 if (isinstance) {
9765 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009766 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009767
Dino Viehlandac46eb42019-09-11 10:16:34 -07009768 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9769 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009770 return 1;
9771 }
9772 if (tmp == NULL) {
9773 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9774 return 1;
9775 }
9776 else {
9777 int res;
9778 res = obj2ast_int(tmp, &lineno, arena);
9779 if (res != 0) goto failed;
9780 Py_CLEAR(tmp);
9781 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009782 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009783 return 1;
9784 }
9785 if (tmp == NULL) {
9786 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9787 return 1;
9788 }
9789 else {
9790 int res;
9791 res = obj2ast_string(tmp, &tag, arena);
9792 if (res != 0) goto failed;
9793 Py_CLEAR(tmp);
9794 }
9795 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009796 if (*out == NULL) goto failed;
9797 return 0;
9798 }
9799
9800 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9801 failed:
9802 Py_XDECREF(tmp);
9803 return 1;
9804}
9805
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009806
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009807PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009808PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009809{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009810 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009811 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009812 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009813 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009814 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9815 goto error;
9816 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009817 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009818 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9819 goto error;
9820 }
9821 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9822 goto error;
9823 }
9824 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9825 goto error;
9826 }
9827 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9828 goto error;
9829 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009830 Py_INCREF(astmodulestate(m)->mod_type);
9831 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009832 0) {
9833 goto error;
9834 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009835 Py_INCREF(astmodulestate(m)->Module_type);
9836 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009837 astmodulestate_global->Interactive_type) < 0) {
9838 goto error;
9839 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009840 Py_INCREF(astmodulestate(m)->Interactive_type);
9841 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009842 astmodulestate_global->Expression_type) < 0) {
9843 goto error;
9844 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009845 Py_INCREF(astmodulestate(m)->Expression_type);
9846 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009847 astmodulestate_global->FunctionType_type) < 0) {
9848 goto error;
9849 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009850 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009851 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9852 goto error;
9853 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009854 Py_INCREF(astmodulestate(m)->stmt_type);
9855 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009856 astmodulestate_global->FunctionDef_type) < 0) {
9857 goto error;
9858 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009859 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9860 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009861 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9862 goto error;
9863 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009864 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9865 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009866 < 0) {
9867 goto error;
9868 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009869 Py_INCREF(astmodulestate(m)->ClassDef_type);
9870 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009871 0) {
9872 goto error;
9873 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009874 Py_INCREF(astmodulestate(m)->Return_type);
9875 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009876 0) {
9877 goto error;
9878 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009879 Py_INCREF(astmodulestate(m)->Delete_type);
9880 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009881 0) {
9882 goto error;
9883 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009884 Py_INCREF(astmodulestate(m)->Assign_type);
9885 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009886 astmodulestate_global->AugAssign_type) < 0) {
9887 goto error;
9888 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009889 Py_INCREF(astmodulestate(m)->AugAssign_type);
9890 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009891 astmodulestate_global->AnnAssign_type) < 0) {
9892 goto error;
9893 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009894 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009895 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9896 goto error;
9897 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009898 Py_INCREF(astmodulestate(m)->For_type);
9899 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009900 < 0) {
9901 goto error;
9902 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009903 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009904 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
9905 goto error;
9906 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009907 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009908 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
9909 goto error;
9910 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009911 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009912 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
9913 goto error;
9914 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009915 Py_INCREF(astmodulestate(m)->With_type);
9916 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009917 astmodulestate_global->AsyncWith_type) < 0) {
9918 goto error;
9919 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009920 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009921 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
9922 goto error;
9923 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009924 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009925 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
9926 goto error;
9927 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009928 Py_INCREF(astmodulestate(m)->Try_type);
9929 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009930 0) {
9931 goto error;
9932 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009933 Py_INCREF(astmodulestate(m)->Assert_type);
9934 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009935 0) {
9936 goto error;
9937 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009938 Py_INCREF(astmodulestate(m)->Import_type);
9939 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009940 astmodulestate_global->ImportFrom_type) < 0) {
9941 goto error;
9942 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009943 Py_INCREF(astmodulestate(m)->ImportFrom_type);
9944 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009945 0) {
9946 goto error;
9947 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009948 Py_INCREF(astmodulestate(m)->Global_type);
9949 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_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)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009954 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
9955 goto error;
9956 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009957 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009958 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
9959 goto error;
9960 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009961 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009962 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
9963 goto error;
9964 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009965 Py_INCREF(astmodulestate(m)->Break_type);
9966 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009967 < 0) {
9968 goto error;
9969 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009970 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009971 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
9972 goto error;
9973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009974 Py_INCREF(astmodulestate(m)->expr_type);
9975 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009976 0) {
9977 goto error;
9978 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009979 Py_INCREF(astmodulestate(m)->BoolOp_type);
9980 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009981 astmodulestate_global->NamedExpr_type) < 0) {
9982 goto error;
9983 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009984 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009985 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
9986 goto error;
9987 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009988 Py_INCREF(astmodulestate(m)->BinOp_type);
9989 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009990 0) {
9991 goto error;
9992 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009993 Py_INCREF(astmodulestate(m)->UnaryOp_type);
9994 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_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)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009999 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10000 goto error;
10001 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010002 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010003 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10004 goto error;
10005 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010006 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010007 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10008 goto error;
10009 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010010 Py_INCREF(astmodulestate(m)->Set_type);
10011 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010012 < 0) {
10013 goto error;
10014 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010015 Py_INCREF(astmodulestate(m)->ListComp_type);
10016 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_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)->SetComp_type);
10021 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010022 < 0) {
10023 goto error;
10024 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010025 Py_INCREF(astmodulestate(m)->DictComp_type);
10026 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010027 astmodulestate_global->GeneratorExp_type) < 0) {
10028 goto error;
10029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010030 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010031 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10032 goto error;
10033 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010034 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010035 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10036 goto error;
10037 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010038 Py_INCREF(astmodulestate(m)->Yield_type);
10039 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010040 astmodulestate_global->YieldFrom_type) < 0) {
10041 goto error;
10042 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010043 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10044 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_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)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010049 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10050 goto error;
10051 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010052 Py_INCREF(astmodulestate(m)->Call_type);
10053 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010054 astmodulestate_global->FormattedValue_type) < 0) {
10055 goto error;
10056 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010057 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10058 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010059 astmodulestate_global->JoinedStr_type) < 0) {
10060 goto error;
10061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010062 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10063 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010064 < 0) {
10065 goto error;
10066 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010067 Py_INCREF(astmodulestate(m)->Constant_type);
10068 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010069 astmodulestate_global->Attribute_type) < 0) {
10070 goto error;
10071 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010072 Py_INCREF(astmodulestate(m)->Attribute_type);
10073 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010074 astmodulestate_global->Subscript_type) < 0) {
10075 goto error;
10076 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010077 Py_INCREF(astmodulestate(m)->Subscript_type);
10078 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010079 0) {
10080 goto error;
10081 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010082 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010083 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10084 goto error;
10085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010086 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010087 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10088 goto error;
10089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010090 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010091 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10092 goto error;
10093 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010094 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010095 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10096 goto error;
10097 }
10098 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010099 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010100 astmodulestate_global->expr_context_type) < 0) {
10101 goto error;
10102 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010103 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010104 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10105 goto error;
10106 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010107 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010108 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10109 goto error;
10110 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010111 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010112 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10113 goto error;
10114 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010115 Py_INCREF(astmodulestate(m)->Del_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010116 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010117 0) {
10118 goto error;
10119 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010120 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010121 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10122 goto error;
10123 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010124 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010125 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10126 goto error;
10127 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010128 Py_INCREF(astmodulestate(m)->Or_type);
10129 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010130 < 0) {
10131 goto error;
10132 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010133 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010134 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10135 goto error;
10136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010137 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010138 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10139 goto error;
10140 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010141 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010142 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10143 goto error;
10144 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010145 Py_INCREF(astmodulestate(m)->Mult_type);
10146 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010147 0) {
10148 goto error;
10149 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010150 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010151 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10152 goto error;
10153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010154 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010155 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10156 goto error;
10157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010158 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010159 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10160 goto error;
10161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010162 Py_INCREF(astmodulestate(m)->Pow_type);
10163 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010164 0) {
10165 goto error;
10166 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010167 Py_INCREF(astmodulestate(m)->LShift_type);
10168 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010169 0) {
10170 goto error;
10171 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010172 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010173 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10174 goto error;
10175 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010176 Py_INCREF(astmodulestate(m)->BitOr_type);
10177 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010178 0) {
10179 goto error;
10180 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010181 Py_INCREF(astmodulestate(m)->BitXor_type);
10182 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010183 0) {
10184 goto error;
10185 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010186 Py_INCREF(astmodulestate(m)->BitAnd_type);
10187 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010188 < 0) {
10189 goto error;
10190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010191 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10192 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010193 0) {
10194 goto error;
10195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010196 Py_INCREF(astmodulestate(m)->unaryop_type);
10197 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010198 0) {
10199 goto error;
10200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010201 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010202 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10203 goto error;
10204 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010205 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010206 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10207 goto error;
10208 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010209 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010210 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10211 goto error;
10212 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010213 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010214 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10215 goto error;
10216 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010217 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010218 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10219 goto error;
10220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010221 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010222 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10223 goto error;
10224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010225 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010226 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10227 goto error;
10228 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010229 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010230 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10231 goto error;
10232 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010233 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010234 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10235 goto error;
10236 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010237 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010238 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10239 goto error;
10240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010241 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010242 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10243 goto error;
10244 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010245 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010246 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10247 goto error;
10248 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010249 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010250 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10251 goto error;
10252 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010253 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010254 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10255 goto error;
10256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010257 Py_INCREF(astmodulestate(m)->NotIn_type);
10258 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010259 astmodulestate_global->comprehension_type) < 0) {
10260 goto error;
10261 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010262 Py_INCREF(astmodulestate(m)->comprehension_type);
10263 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010264 astmodulestate_global->excepthandler_type) < 0) {
10265 goto error;
10266 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010267 Py_INCREF(astmodulestate(m)->excepthandler_type);
10268 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010269 astmodulestate_global->ExceptHandler_type) < 0) {
10270 goto error;
10271 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010272 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10273 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010274 astmodulestate_global->arguments_type) < 0) {
10275 goto error;
10276 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010277 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010278 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10279 goto error;
10280 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010281 Py_INCREF(astmodulestate(m)->arg_type);
10282 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010283 0) {
10284 goto error;
10285 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010286 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010287 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10288 goto error;
10289 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010290 Py_INCREF(astmodulestate(m)->alias_type);
10291 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010292 < 0) {
10293 goto error;
10294 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010295 Py_INCREF(astmodulestate(m)->withitem_type);
10296 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010297 astmodulestate_global->type_ignore_type) < 0) {
10298 goto error;
10299 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010300 Py_INCREF(astmodulestate(m)->type_ignore_type);
10301 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010302 astmodulestate_global->TypeIgnore_type) < 0) {
10303 goto error;
10304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010305 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010306 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010307error:
10308 Py_DECREF(m);
10309 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010310}
10311
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010312
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010313PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010314{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010315 if (!init_types())
10316 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010317 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010318}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010319
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010320/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10321mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010322{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010323 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010324 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010325 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010326
Steve Dowerb82e17e2019-05-23 08:45:22 -070010327 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10328 return NULL;
10329 }
10330
Dino Viehlandac46eb42019-09-11 10:16:34 -070010331 req_type[0] = astmodulestate_global->Module_type;
10332 req_type[1] = astmodulestate_global->Expression_type;
10333 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010334
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010335 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010336
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010337 if (!init_types())
10338 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010339
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010340 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10341 if (isinstance == -1)
10342 return NULL;
10343 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010344 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010345 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010346 return NULL;
10347 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010348
10349 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010350 if (obj2ast_mod(ast, &res, arena) != 0)
10351 return NULL;
10352 else
10353 return res;
10354}
10355
10356int PyAST_Check(PyObject* obj)
10357{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010358 if (!init_types())
10359 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010360 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010361}
10362
Martin v. Löwis5b222132007-06-10 09:51:05 +000010363