blob: 694987dd077881c4fbde5bf9ab60cd761944e5f7 [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"
Victor Stinner4a21e572020-04-15 02:35:41 +02007#include "structmember.h" // PyMemberDef
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*);
Pablo Galindo168660b2020-04-02 00:47:39 +01001063static const char * const keyword_attributes[] = {
1064 "lineno",
1065 "col_offset",
1066 "end_lineno",
1067 "end_col_offset",
1068};
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001069static const char * const keyword_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001070 "arg",
1071 "value",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001072};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001073static PyObject* ast2obj_alias(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001074static const char * const alias_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001075 "name",
1076 "asname",
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001077};
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001078static PyObject* ast2obj_withitem(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001079static const char * const withitem_fields[]={
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001080 "context_expr",
1081 "optional_vars",
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05001082};
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001083static PyObject* ast2obj_type_ignore(void*);
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001084static const char * const TypeIgnore_fields[]={
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001085 "lineno",
Michael J. Sullivan933e1502019-05-22 07:54:20 -07001086 "tag",
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001087};
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001088
1089
INADA Naokifc489082017-01-25 22:33:43 +09001090
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001091typedef struct {
Victor Stinner45e50de2012-03-13 01:17:31 +01001092 PyObject_HEAD
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001093 PyObject *dict;
1094} AST_object;
1095
Benjamin Peterson1767e022012-03-14 21:50:29 -05001096static void
1097ast_dealloc(AST_object *self)
1098{
INADA Naokia6296d32017-08-24 14:55:17 +09001099 /* bpo-31095: UnTrack is needed before calling any callbacks */
Eddie Elizondo0247e802019-09-14 09:38:17 -04001100 PyTypeObject *tp = Py_TYPE(self);
INADA Naokia6296d32017-08-24 14:55:17 +09001101 PyObject_GC_UnTrack(self);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001102 Py_CLEAR(self->dict);
Eddie Elizondo0247e802019-09-14 09:38:17 -04001103 freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
1104 assert(free_func != NULL);
1105 free_func(self);
1106 Py_DECREF(tp);
Benjamin Peterson1767e022012-03-14 21:50:29 -05001107}
1108
Neal Norwitz207c9f32008-03-31 04:42:11 +00001109static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001110ast_traverse(AST_object *self, visitproc visit, void *arg)
1111{
Miss Islington (bot)bcbe5c52020-05-28 08:12:23 -07001112 Py_VISIT(Py_TYPE(self));
Benjamin Peterson81071762012-07-08 11:03:46 -07001113 Py_VISIT(self->dict);
1114 return 0;
1115}
1116
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001117static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001118ast_clear(AST_object *self)
1119{
1120 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001121 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001122}
1123
1124static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001125ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1126{
1127 Py_ssize_t i, numfields = 0;
1128 int res = -1;
1129 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001130 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001131 goto cleanup;
1132 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001133 if (fields) {
1134 numfields = PySequence_Size(fields);
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001135 if (numfields == -1) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001136 goto cleanup;
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001137 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001138 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001139
Neal Norwitz207c9f32008-03-31 04:42:11 +00001140 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001141 if (numfields < PyTuple_GET_SIZE(args)) {
1142 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1143 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001144 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001145 numfields, numfields == 1 ? "" : "s");
1146 res = -1;
1147 goto cleanup;
1148 }
1149 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1150 /* cannot be reached when fields is NULL */
1151 PyObject *name = PySequence_GetItem(fields, i);
1152 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001153 res = -1;
1154 goto cleanup;
1155 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001156 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1157 Py_DECREF(name);
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001158 if (res < 0) {
INADA Naoki4c78c522017-02-24 02:48:17 +09001159 goto cleanup;
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001160 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001161 }
1162 if (kw) {
1163 i = 0; /* needed by PyDict_Next */
1164 while (PyDict_Next(kw, &i, &key, &value)) {
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001165 int contains = PySequence_Contains(fields, key);
1166 if (contains == -1) {
1167 res = -1;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001168 goto cleanup;
Miss Islington (bot)1a4e9e62020-05-24 14:32:32 -07001169 } else if (contains == 1) {
1170 Py_ssize_t p = PySequence_Index(fields, key);
1171 if (p == -1) {
1172 res = -1;
1173 goto cleanup;
1174 }
1175 if (p < PyTuple_GET_SIZE(args)) {
1176 PyErr_Format(PyExc_TypeError,
1177 "%.400s got multiple values for argument '%U'",
1178 Py_TYPE(self)->tp_name, key);
1179 res = -1;
1180 goto cleanup;
1181 }
1182 }
1183 res = PyObject_SetAttr(self, key, value);
1184 if (res < 0) {
1185 goto cleanup;
1186 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001187 }
1188 }
1189 cleanup:
1190 Py_XDECREF(fields);
1191 return res;
1192}
1193
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001194/* Pickling support */
1195static PyObject *
1196ast_type_reduce(PyObject *self, PyObject *unused)
1197{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001198 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001199 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001200 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001201 }
1202 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001203 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001204 }
1205 return Py_BuildValue("O()", Py_TYPE(self));
1206}
1207
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001208static PyMemberDef ast_type_members[] = {
1209 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1210 {NULL} /* Sentinel */
1211};
1212
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001213static PyMethodDef ast_type_methods[] = {
1214 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1215 {NULL}
1216};
1217
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001218static PyGetSetDef ast_type_getsets[] = {
1219 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1220 {NULL}
1221};
1222
Dino Viehlandac46eb42019-09-11 10:16:34 -07001223static PyType_Slot AST_type_slots[] = {
1224 {Py_tp_dealloc, ast_dealloc},
1225 {Py_tp_getattro, PyObject_GenericGetAttr},
1226 {Py_tp_setattro, PyObject_GenericSetAttr},
1227 {Py_tp_traverse, ast_traverse},
1228 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001229 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001230 {Py_tp_methods, ast_type_methods},
1231 {Py_tp_getset, ast_type_getsets},
1232 {Py_tp_init, ast_type_init},
1233 {Py_tp_alloc, PyType_GenericAlloc},
1234 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001235 {Py_tp_free, PyObject_GC_Del},
1236 {0, 0},
1237};
1238
1239static PyType_Spec AST_type_spec = {
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001240 "ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001241 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001242 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001243 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1244 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001245};
1246
Dino Viehlandac46eb42019-09-11 10:16:34 -07001247static PyObject *
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001248make_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 +00001249{
1250 PyObject *fnames, *result;
1251 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001252 fnames = PyTuple_New(num_fields);
1253 if (!fnames) return NULL;
1254 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001255 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001256 if (!field) {
1257 Py_DECREF(fnames);
1258 return NULL;
1259 }
1260 PyTuple_SET_ITEM(fnames, i, field);
1261 }
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001262 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +09001263 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001264 astmodulestate_global->_fields, fnames,
1265 astmodulestate_global->__module__,
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001266 astmodulestate_global->ast,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001267 astmodulestate_global->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001268 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001269 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001270}
1271
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001272static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001273add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001274{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001275 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001276 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001277 if (!l)
1278 return 0;
1279 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001280 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001281 if (!s) {
1282 Py_DECREF(l);
1283 return 0;
1284 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001285 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001286 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001287 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001288 Py_DECREF(l);
1289 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001290}
1291
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001292/* Conversion AST -> Python */
1293
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001294static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1295{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001296 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001297 PyObject *result = PyList_New(n);
1298 PyObject *value;
1299 if (!result)
1300 return NULL;
1301 for (i = 0; i < n; i++) {
1302 value = func(asdl_seq_GET(seq, i));
1303 if (!value) {
1304 Py_DECREF(result);
1305 return NULL;
1306 }
1307 PyList_SET_ITEM(result, i, value);
1308 }
1309 return result;
1310}
1311
1312static PyObject* ast2obj_object(void *o)
1313{
1314 if (!o)
1315 o = Py_None;
1316 Py_INCREF((PyObject*)o);
1317 return (PyObject*)o;
1318}
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001319#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001320#define ast2obj_identifier ast2obj_object
1321#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001322
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001323static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001324{
Christian Heimes217cfd12007-12-02 14:31:20 +00001325 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001326}
1327
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001328/* Conversion Python -> AST */
1329
1330static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1331{
1332 if (obj == Py_None)
1333 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001334 if (obj) {
1335 if (PyArena_AddPyObject(arena, obj) < 0) {
1336 *out = NULL;
1337 return -1;
1338 }
1339 Py_INCREF(obj);
1340 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001341 *out = obj;
1342 return 0;
1343}
1344
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001345static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1346{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001347 if (PyArena_AddPyObject(arena, obj) < 0) {
1348 *out = NULL;
1349 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001350 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001351 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001352 *out = obj;
1353 return 0;
1354}
1355
Benjamin Peterson180e6352011-07-22 11:09:07 -05001356static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001357{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001358 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1359 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001360 return 1;
1361 }
1362 return obj2ast_object(obj, out, arena);
1363}
1364
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001365static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1366{
1367 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1368 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1369 return 1;
1370 }
1371 return obj2ast_object(obj, out, arena);
1372}
1373
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001374static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1375{
1376 int i;
1377 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001378 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001379 return 1;
1380 }
1381
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001382 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001383 if (i == -1 && PyErr_Occurred())
1384 return 1;
1385 *out = i;
1386 return 0;
1387}
1388
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001389static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001390{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001391 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001392 empty_tuple = PyTuple_New(0);
1393 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001394 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1395 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001396 Py_XDECREF(empty_tuple);
1397 return -1;
1398 }
1399 Py_DECREF(empty_tuple);
1400 return 0;
1401}
1402
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001403
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001404static int init_types(void)
1405{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001406 PyObject *m;
1407 if (PyState_FindModule(&_astmodule) == NULL) {
1408 m = PyModule_Create(&_astmodule);
1409 if (!m) return 0;
1410 PyState_AddModule(m, &_astmodule);
1411 }
1412 astmodulestate *state = astmodulestate_global;
1413 if (state->initialized) return 1;
1414 if (init_identifiers() < 0) return 0;
1415 state->AST_type = PyType_FromSpec(&AST_type_spec);
1416 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001417 if (add_ast_fields() < 0) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001418 state->mod_type = make_type("mod", state->AST_type, NULL, 0,
1419 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1420 " | Interactive(stmt* body)\n"
1421 " | Expression(expr body)\n"
1422 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001423 if (!state->mod_type) return 0;
1424 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001425 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2,
1426 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001427 if (!state->Module_type) return 0;
1428 state->Interactive_type = make_type("Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001429 Interactive_fields, 1,
1430 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001431 if (!state->Interactive_type) return 0;
1432 state->Expression_type = make_type("Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001433 Expression_fields, 1,
1434 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001435 if (!state->Expression_type) return 0;
1436 state->FunctionType_type = make_type("FunctionType", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001437 FunctionType_fields, 2,
1438 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001439 if (!state->FunctionType_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001440 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0,
1441 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1442 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1443 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1444 " | Return(expr? value)\n"
1445 " | Delete(expr* targets)\n"
1446 " | Assign(expr* targets, expr value, string? type_comment)\n"
1447 " | AugAssign(expr target, operator op, expr value)\n"
1448 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1449 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1450 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1451 " | While(expr test, stmt* body, stmt* orelse)\n"
1452 " | If(expr test, stmt* body, stmt* orelse)\n"
1453 " | With(withitem* items, stmt* body, string? type_comment)\n"
1454 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1455 " | Raise(expr? exc, expr? cause)\n"
1456 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1457 " | Assert(expr test, expr? msg)\n"
1458 " | Import(alias* names)\n"
1459 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1460 " | Global(identifier* names)\n"
1461 " | Nonlocal(identifier* names)\n"
1462 " | Expr(expr value)\n"
1463 " | Pass\n"
1464 " | Break\n"
1465 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001466 if (!state->stmt_type) return 0;
1467 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001468 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1469 return 0;
1470 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1471 -1)
1472 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001473 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001474 FunctionDef_fields, 6,
1475 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001476 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001477 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1478 -1)
1479 return 0;
1480 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1481 == -1)
1482 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001483 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1484 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001485 AsyncFunctionDef_fields, 6,
1486 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001487 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001488 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1489 == -1)
1490 return 0;
1491 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1492 Py_None) == -1)
1493 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001494 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001495 ClassDef_fields, 5,
1496 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001497 if (!state->ClassDef_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001498 state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1,
1499 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001500 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001501 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1502 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001503 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1,
1504 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001505 if (!state->Delete_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001506 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3,
1507 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001508 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001509 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1510 -1)
1511 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001512 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001513 AugAssign_fields, 3,
1514 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001515 if (!state->AugAssign_type) return 0;
1516 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001517 AnnAssign_fields, 4,
1518 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001519 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001520 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1521 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001522 state->For_type = make_type("For", state->stmt_type, For_fields, 5,
1523 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001524 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001525 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1526 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001527 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001528 AsyncFor_fields, 5,
1529 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001530 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001531 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1532 -1)
1533 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001534 state->While_type = make_type("While", state->stmt_type, While_fields, 3,
1535 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001536 if (!state->While_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001537 state->If_type = make_type("If", state->stmt_type, If_fields, 3,
1538 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001539 if (!state->If_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001540 state->With_type = make_type("With", state->stmt_type, With_fields, 3,
1541 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001542 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001543 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1544 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001545 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001546 AsyncWith_fields, 3,
1547 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001548 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001549 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1550 == -1)
1551 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001552 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2,
1553 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001554 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001555 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1556 return 0;
1557 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1558 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001559 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4,
1560 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001561 if (!state->Try_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001562 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2,
1563 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001564 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001565 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1566 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001567 state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1,
1568 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001569 if (!state->Import_type) return 0;
1570 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001571 ImportFrom_fields, 3,
1572 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001573 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001574 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1575 return 0;
1576 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1577 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001578 state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1,
1579 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001580 if (!state->Global_type) return 0;
1581 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001582 Nonlocal_fields, 1,
1583 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001584 if (!state->Nonlocal_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001585 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1,
1586 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001587 if (!state->Expr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001588 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0,
1589 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001590 if (!state->Pass_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001591 state->Break_type = make_type("Break", state->stmt_type, NULL, 0,
1592 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001593 if (!state->Break_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001594 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0,
1595 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001596 if (!state->Continue_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001597 state->expr_type = make_type("expr", state->AST_type, NULL, 0,
1598 "expr = BoolOp(boolop op, expr* values)\n"
1599 " | NamedExpr(expr target, expr value)\n"
1600 " | BinOp(expr left, operator op, expr right)\n"
1601 " | UnaryOp(unaryop op, expr operand)\n"
1602 " | Lambda(arguments args, expr body)\n"
1603 " | IfExp(expr test, expr body, expr orelse)\n"
1604 " | Dict(expr* keys, expr* values)\n"
1605 " | Set(expr* elts)\n"
1606 " | ListComp(expr elt, comprehension* generators)\n"
1607 " | SetComp(expr elt, comprehension* generators)\n"
1608 " | DictComp(expr key, expr value, comprehension* generators)\n"
1609 " | GeneratorExp(expr elt, comprehension* generators)\n"
1610 " | Await(expr value)\n"
1611 " | Yield(expr? value)\n"
1612 " | YieldFrom(expr value)\n"
1613 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1614 " | Call(expr func, expr* args, keyword* keywords)\n"
1615 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1616 " | JoinedStr(expr* values)\n"
1617 " | Constant(constant value, string? kind)\n"
1618 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1619 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1620 " | Starred(expr value, expr_context ctx)\n"
1621 " | Name(identifier id, expr_context ctx)\n"
1622 " | List(expr* elts, expr_context ctx)\n"
1623 " | Tuple(expr* elts, expr_context ctx)\n"
1624 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001625 if (!state->expr_type) return 0;
1626 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001627 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1628 return 0;
1629 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1630 -1)
1631 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001632 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2,
1633 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001634 if (!state->BoolOp_type) return 0;
1635 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001636 NamedExpr_fields, 2,
1637 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001638 if (!state->NamedExpr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001639 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3,
1640 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001641 if (!state->BinOp_type) return 0;
1642 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001643 UnaryOp_fields, 2,
1644 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001645 if (!state->UnaryOp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001646 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2,
1647 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001648 if (!state->Lambda_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001649 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3,
1650 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001651 if (!state->IfExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001652 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2,
1653 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001654 if (!state->Dict_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001655 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1,
1656 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001657 if (!state->Set_type) return 0;
1658 state->ListComp_type = make_type("ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001659 ListComp_fields, 2,
1660 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001661 if (!state->ListComp_type) return 0;
1662 state->SetComp_type = make_type("SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001663 SetComp_fields, 2,
1664 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001665 if (!state->SetComp_type) return 0;
1666 state->DictComp_type = make_type("DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001667 DictComp_fields, 3,
1668 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001669 if (!state->DictComp_type) return 0;
1670 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001671 GeneratorExp_fields, 2,
1672 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001673 if (!state->GeneratorExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001674 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1,
1675 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001676 if (!state->Await_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001677 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1,
1678 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001679 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001680 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1681 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001682 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001683 YieldFrom_fields, 1,
1684 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001685 if (!state->YieldFrom_type) return 0;
1686 state->Compare_type = make_type("Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001687 Compare_fields, 3,
1688 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001689 if (!state->Compare_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001690 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3,
1691 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001692 if (!state->Call_type) return 0;
1693 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001694 FormattedValue_fields, 3,
1695 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001696 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001697 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1698 Py_None) == -1)
1699 return 0;
1700 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1701 Py_None) == -1)
1702 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001703 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001704 JoinedStr_fields, 1,
1705 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001706 if (!state->JoinedStr_type) return 0;
1707 state->Constant_type = make_type("Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001708 Constant_fields, 2,
1709 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001710 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001711 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1712 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001713 state->Attribute_type = make_type("Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001714 Attribute_fields, 3,
1715 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001716 if (!state->Attribute_type) return 0;
1717 state->Subscript_type = make_type("Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001718 Subscript_fields, 3,
1719 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001720 if (!state->Subscript_type) return 0;
1721 state->Starred_type = make_type("Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001722 Starred_fields, 2,
1723 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001724 if (!state->Starred_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001725 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2,
1726 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001727 if (!state->Name_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001728 state->List_type = make_type("List", state->expr_type, List_fields, 2,
1729 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001730 if (!state->List_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001731 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2,
1732 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001733 if (!state->Tuple_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001734 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3,
1735 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001736 if (!state->Slice_type) return 0;
1737 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1738 return 0;
1739 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1740 return 0;
1741 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1742 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001743 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001744 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001745 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001746 if (!state->expr_context_type) return 0;
1747 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001748 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0,
1749 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001750 if (!state->Load_type) return 0;
1751 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1752 NULL, NULL);
1753 if (!state->Load_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001754 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0,
1755 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001756 if (!state->Store_type) return 0;
1757 state->Store_singleton = PyType_GenericNew((PyTypeObject
1758 *)state->Store_type, NULL, NULL);
1759 if (!state->Store_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001760 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0,
1761 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001762 if (!state->Del_type) return 0;
1763 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1764 NULL, NULL);
1765 if (!state->Del_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001766 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0,
1767 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001768 if (!state->boolop_type) return 0;
1769 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001770 state->And_type = make_type("And", state->boolop_type, NULL, 0,
1771 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001772 if (!state->And_type) return 0;
1773 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1774 NULL, NULL);
1775 if (!state->And_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001776 state->Or_type = make_type("Or", state->boolop_type, NULL, 0,
1777 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001778 if (!state->Or_type) return 0;
1779 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1780 NULL, NULL);
1781 if (!state->Or_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001782 state->operator_type = make_type("operator", state->AST_type, NULL, 0,
1783 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001784 if (!state->operator_type) return 0;
1785 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001786 state->Add_type = make_type("Add", state->operator_type, NULL, 0,
1787 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001788 if (!state->Add_type) return 0;
1789 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1790 NULL, NULL);
1791 if (!state->Add_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001792 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0,
1793 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001794 if (!state->Sub_type) return 0;
1795 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1796 NULL, NULL);
1797 if (!state->Sub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001798 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0,
1799 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001800 if (!state->Mult_type) return 0;
1801 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1802 NULL, NULL);
1803 if (!state->Mult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001804 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0,
1805 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001806 if (!state->MatMult_type) return 0;
1807 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1808 *)state->MatMult_type, NULL,
1809 NULL);
1810 if (!state->MatMult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001811 state->Div_type = make_type("Div", state->operator_type, NULL, 0,
1812 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001813 if (!state->Div_type) return 0;
1814 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1815 NULL, NULL);
1816 if (!state->Div_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001817 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0,
1818 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001819 if (!state->Mod_type) return 0;
1820 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1821 NULL, NULL);
1822 if (!state->Mod_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001823 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0,
1824 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001825 if (!state->Pow_type) return 0;
1826 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1827 NULL, NULL);
1828 if (!state->Pow_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001829 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0,
1830 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001831 if (!state->LShift_type) return 0;
1832 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1833 *)state->LShift_type, NULL,
1834 NULL);
1835 if (!state->LShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001836 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0,
1837 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001838 if (!state->RShift_type) return 0;
1839 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1840 *)state->RShift_type, NULL,
1841 NULL);
1842 if (!state->RShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001843 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0,
1844 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001845 if (!state->BitOr_type) return 0;
1846 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1847 *)state->BitOr_type, NULL, NULL);
1848 if (!state->BitOr_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001849 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0,
1850 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001851 if (!state->BitXor_type) return 0;
1852 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1853 *)state->BitXor_type, NULL,
1854 NULL);
1855 if (!state->BitXor_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001856 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0,
1857 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001858 if (!state->BitAnd_type) return 0;
1859 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1860 *)state->BitAnd_type, NULL,
1861 NULL);
1862 if (!state->BitAnd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001863 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0,
1864 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001865 if (!state->FloorDiv_type) return 0;
1866 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1867 *)state->FloorDiv_type, NULL,
1868 NULL);
1869 if (!state->FloorDiv_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001870 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0,
1871 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001872 if (!state->unaryop_type) return 0;
1873 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001874 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0,
1875 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001876 if (!state->Invert_type) return 0;
1877 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1878 *)state->Invert_type, NULL,
1879 NULL);
1880 if (!state->Invert_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001881 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0,
1882 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001883 if (!state->Not_type) return 0;
1884 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1885 NULL, NULL);
1886 if (!state->Not_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001887 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0,
1888 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001889 if (!state->UAdd_type) return 0;
1890 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1891 NULL, NULL);
1892 if (!state->UAdd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001893 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0,
1894 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001895 if (!state->USub_type) return 0;
1896 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1897 NULL, NULL);
1898 if (!state->USub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001899 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0,
1900 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001901 if (!state->cmpop_type) return 0;
1902 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001903 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0,
1904 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001905 if (!state->Eq_type) return 0;
1906 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1907 NULL, NULL);
1908 if (!state->Eq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001909 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0,
1910 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001911 if (!state->NotEq_type) return 0;
1912 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1913 *)state->NotEq_type, NULL, NULL);
1914 if (!state->NotEq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001915 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0,
1916 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001917 if (!state->Lt_type) return 0;
1918 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1919 NULL, NULL);
1920 if (!state->Lt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001921 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0,
1922 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001923 if (!state->LtE_type) return 0;
1924 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1925 NULL, NULL);
1926 if (!state->LtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001927 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0,
1928 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001929 if (!state->Gt_type) return 0;
1930 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1931 NULL, NULL);
1932 if (!state->Gt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001933 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0,
1934 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001935 if (!state->GtE_type) return 0;
1936 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1937 NULL, NULL);
1938 if (!state->GtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001939 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0,
1940 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001941 if (!state->Is_type) return 0;
1942 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1943 NULL, NULL);
1944 if (!state->Is_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001945 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0,
1946 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001947 if (!state->IsNot_type) return 0;
1948 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1949 *)state->IsNot_type, NULL, NULL);
1950 if (!state->IsNot_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001951 state->In_type = make_type("In", state->cmpop_type, NULL, 0,
1952 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001953 if (!state->In_type) return 0;
1954 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1955 NULL, NULL);
1956 if (!state->In_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001957 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0,
1958 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001959 if (!state->NotIn_type) return 0;
1960 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1961 *)state->NotIn_type, NULL, NULL);
1962 if (!state->NotIn_singleton) return 0;
1963 state->comprehension_type = make_type("comprehension", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001964 comprehension_fields, 4,
1965 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001966 if (!state->comprehension_type) return 0;
1967 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1968 state->excepthandler_type = make_type("excepthandler", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001969 NULL, 0,
1970 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001971 if (!state->excepthandler_type) return 0;
1972 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1973 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001974 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1975 == -1)
1976 return 0;
1977 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1978 Py_None) == -1)
1979 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001980 state->ExceptHandler_type = make_type("ExceptHandler",
1981 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001982 ExceptHandler_fields, 3,
1983 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001984 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001985 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1986 return 0;
1987 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1988 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001989 state->arguments_type = make_type("arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001990 arguments_fields, 7,
1991 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001992 if (!state->arguments_type) return 0;
1993 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001994 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1995 return 0;
1996 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1997 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001998 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3,
1999 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002000 if (!state->arg_type) return 0;
2001 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002002 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
2003 return 0;
2004 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
2005 return 0;
2006 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
2007 return 0;
2008 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
2009 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002010 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002011 2,
2012 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002013 if (!state->keyword_type) return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01002014 if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002015 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
2016 return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01002017 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
2018 return 0;
2019 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
2020 == -1)
2021 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002022 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2,
2023 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002024 if (!state->alias_type) return 0;
2025 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002026 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
2027 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002028 state->withitem_type = make_type("withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002029 withitem_fields, 2,
2030 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002031 if (!state->withitem_type) return 0;
2032 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002033 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
2034 == -1)
2035 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002036 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0,
2037 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002038 if (!state->type_ignore_type) return 0;
2039 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
2040 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002041 TypeIgnore_fields, 2,
2042 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002043 if (!state->TypeIgnore_type) return 0;
2044 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002045 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002046}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002047
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002048static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2049static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
2050static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
2051static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
2052 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002053static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
2054static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
2055static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
2056static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
2057static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
2058 arena);
2059static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
2060 arena);
2061static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
2062static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
2063static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
2064static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002065static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002066static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
2067 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002068
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002069mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002070Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002071{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002072 mod_ty p;
2073 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2074 if (!p)
2075 return NULL;
2076 p->kind = Module_kind;
2077 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002078 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002079 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002080}
2081
2082mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002083Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002084{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002085 mod_ty p;
2086 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2087 if (!p)
2088 return NULL;
2089 p->kind = Interactive_kind;
2090 p->v.Interactive.body = body;
2091 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002092}
2093
2094mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002095Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002096{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002097 mod_ty p;
2098 if (!body) {
2099 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002100 "field 'body' is required for Expression");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002101 return NULL;
2102 }
2103 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2104 if (!p)
2105 return NULL;
2106 p->kind = Expression_kind;
2107 p->v.Expression.body = body;
2108 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002109}
2110
2111mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002112FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
2113{
2114 mod_ty p;
2115 if (!returns) {
2116 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002117 "field 'returns' is required for FunctionType");
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002118 return NULL;
2119 }
2120 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2121 if (!p)
2122 return NULL;
2123 p->kind = FunctionType_kind;
2124 p->v.FunctionType.argtypes = argtypes;
2125 p->v.FunctionType.returns = returns;
2126 return p;
2127}
2128
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002129stmt_ty
2130FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002131 decorator_list, expr_ty returns, string type_comment, int lineno,
2132 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002133{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002134 stmt_ty p;
2135 if (!name) {
2136 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002137 "field 'name' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002138 return NULL;
2139 }
2140 if (!args) {
2141 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002142 "field 'args' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002143 return NULL;
2144 }
2145 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2146 if (!p)
2147 return NULL;
2148 p->kind = FunctionDef_kind;
2149 p->v.FunctionDef.name = name;
2150 p->v.FunctionDef.args = args;
2151 p->v.FunctionDef.body = body;
2152 p->v.FunctionDef.decorator_list = decorator_list;
2153 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002154 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002155 p->lineno = lineno;
2156 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002157 p->end_lineno = end_lineno;
2158 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002159 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002160}
2161
2162stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002163AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002164 * decorator_list, expr_ty returns, string type_comment, int
2165 lineno, int col_offset, int end_lineno, int end_col_offset,
2166 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002167{
2168 stmt_ty p;
2169 if (!name) {
2170 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002171 "field 'name' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04002172 return NULL;
2173 }
2174 if (!args) {
2175 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002176 "field 'args' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04002177 return NULL;
2178 }
2179 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2180 if (!p)
2181 return NULL;
2182 p->kind = AsyncFunctionDef_kind;
2183 p->v.AsyncFunctionDef.name = name;
2184 p->v.AsyncFunctionDef.args = args;
2185 p->v.AsyncFunctionDef.body = body;
2186 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2187 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002188 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002189 p->lineno = lineno;
2190 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002191 p->end_lineno = end_lineno;
2192 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002193 return p;
2194}
2195
2196stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002197ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002198 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2199 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002200{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002201 stmt_ty p;
2202 if (!name) {
2203 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002204 "field 'name' is required for ClassDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002205 return NULL;
2206 }
2207 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2208 if (!p)
2209 return NULL;
2210 p->kind = ClassDef_kind;
2211 p->v.ClassDef.name = name;
2212 p->v.ClassDef.bases = bases;
2213 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002214 p->v.ClassDef.body = body;
2215 p->v.ClassDef.decorator_list = decorator_list;
2216 p->lineno = lineno;
2217 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002218 p->end_lineno = end_lineno;
2219 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002220 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002221}
2222
2223stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002224Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2225 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002226{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002227 stmt_ty p;
2228 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2229 if (!p)
2230 return NULL;
2231 p->kind = Return_kind;
2232 p->v.Return.value = value;
2233 p->lineno = lineno;
2234 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002235 p->end_lineno = end_lineno;
2236 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002237 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002238}
2239
2240stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002241Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2242 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002243{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002244 stmt_ty p;
2245 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2246 if (!p)
2247 return NULL;
2248 p->kind = Delete_kind;
2249 p->v.Delete.targets = targets;
2250 p->lineno = lineno;
2251 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002252 p->end_lineno = end_lineno;
2253 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002254 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002255}
2256
2257stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002258Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2259 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002260{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002261 stmt_ty p;
2262 if (!value) {
2263 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002264 "field 'value' is required for Assign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002265 return NULL;
2266 }
2267 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2268 if (!p)
2269 return NULL;
2270 p->kind = Assign_kind;
2271 p->v.Assign.targets = targets;
2272 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002273 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002274 p->lineno = lineno;
2275 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002276 p->end_lineno = end_lineno;
2277 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002278 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002279}
2280
2281stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002282AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002283 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002284{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002285 stmt_ty p;
2286 if (!target) {
2287 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002288 "field 'target' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002289 return NULL;
2290 }
2291 if (!op) {
2292 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002293 "field 'op' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002294 return NULL;
2295 }
2296 if (!value) {
2297 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002298 "field 'value' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002299 return NULL;
2300 }
2301 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2302 if (!p)
2303 return NULL;
2304 p->kind = AugAssign_kind;
2305 p->v.AugAssign.target = target;
2306 p->v.AugAssign.op = op;
2307 p->v.AugAssign.value = value;
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;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002312 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002313}
2314
2315stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002316AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002317 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2318 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002319{
2320 stmt_ty p;
2321 if (!target) {
2322 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002323 "field 'target' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002324 return NULL;
2325 }
2326 if (!annotation) {
2327 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002328 "field 'annotation' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002329 return NULL;
2330 }
2331 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2332 if (!p)
2333 return NULL;
2334 p->kind = AnnAssign_kind;
2335 p->v.AnnAssign.target = target;
2336 p->v.AnnAssign.annotation = annotation;
2337 p->v.AnnAssign.value = value;
2338 p->v.AnnAssign.simple = simple;
2339 p->lineno = lineno;
2340 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002341 p->end_lineno = end_lineno;
2342 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002343 return p;
2344}
2345
2346stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002347For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2348 type_comment, int lineno, int col_offset, int end_lineno, int
2349 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002350{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002351 stmt_ty p;
2352 if (!target) {
2353 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002354 "field 'target' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002355 return NULL;
2356 }
2357 if (!iter) {
2358 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002359 "field 'iter' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002360 return NULL;
2361 }
2362 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2363 if (!p)
2364 return NULL;
2365 p->kind = For_kind;
2366 p->v.For.target = target;
2367 p->v.For.iter = iter;
2368 p->v.For.body = body;
2369 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002370 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002371 p->lineno = lineno;
2372 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002373 p->end_lineno = end_lineno;
2374 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002375 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002376}
2377
2378stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002379AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2380 string type_comment, int lineno, int col_offset, int end_lineno, int
2381 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002382{
2383 stmt_ty p;
2384 if (!target) {
2385 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002386 "field 'target' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002387 return NULL;
2388 }
2389 if (!iter) {
2390 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002391 "field 'iter' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002392 return NULL;
2393 }
2394 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2395 if (!p)
2396 return NULL;
2397 p->kind = AsyncFor_kind;
2398 p->v.AsyncFor.target = target;
2399 p->v.AsyncFor.iter = iter;
2400 p->v.AsyncFor.body = body;
2401 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002402 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002403 p->lineno = lineno;
2404 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002405 p->end_lineno = end_lineno;
2406 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002407 return p;
2408}
2409
2410stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002411While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002412 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002413{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002414 stmt_ty p;
2415 if (!test) {
2416 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002417 "field 'test' is required for While");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002418 return NULL;
2419 }
2420 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2421 if (!p)
2422 return NULL;
2423 p->kind = While_kind;
2424 p->v.While.test = test;
2425 p->v.While.body = body;
2426 p->v.While.orelse = orelse;
2427 p->lineno = lineno;
2428 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002429 p->end_lineno = end_lineno;
2430 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002431 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002432}
2433
2434stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002435If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002436 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002437{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002438 stmt_ty p;
2439 if (!test) {
2440 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002441 "field 'test' is required for If");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002442 return NULL;
2443 }
2444 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2445 if (!p)
2446 return NULL;
2447 p->kind = If_kind;
2448 p->v.If.test = test;
2449 p->v.If.body = body;
2450 p->v.If.orelse = orelse;
2451 p->lineno = lineno;
2452 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002453 p->end_lineno = end_lineno;
2454 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002455 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002456}
2457
2458stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002459With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2460 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002461{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002462 stmt_ty p;
2463 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2464 if (!p)
2465 return NULL;
2466 p->kind = With_kind;
2467 p->v.With.items = items;
2468 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002469 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002470 p->lineno = lineno;
2471 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002472 p->end_lineno = end_lineno;
2473 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002474 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002475}
2476
2477stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002478AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2479 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002480{
2481 stmt_ty p;
2482 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2483 if (!p)
2484 return NULL;
2485 p->kind = AsyncWith_kind;
2486 p->v.AsyncWith.items = items;
2487 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002488 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002489 p->lineno = lineno;
2490 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002491 p->end_lineno = end_lineno;
2492 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002493 return p;
2494}
2495
2496stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002497Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2498 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002499{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002500 stmt_ty p;
2501 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2502 if (!p)
2503 return NULL;
2504 p->kind = Raise_kind;
2505 p->v.Raise.exc = exc;
2506 p->v.Raise.cause = cause;
2507 p->lineno = lineno;
2508 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002509 p->end_lineno = end_lineno;
2510 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002511 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002512}
2513
2514stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002515Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002516 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2517 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002518{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002519 stmt_ty p;
2520 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2521 if (!p)
2522 return NULL;
2523 p->kind = Try_kind;
2524 p->v.Try.body = body;
2525 p->v.Try.handlers = handlers;
2526 p->v.Try.orelse = orelse;
2527 p->v.Try.finalbody = finalbody;
2528 p->lineno = lineno;
2529 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002530 p->end_lineno = end_lineno;
2531 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002532 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002533}
2534
2535stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002536Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2537 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002538{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002539 stmt_ty p;
2540 if (!test) {
2541 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002542 "field 'test' is required for Assert");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002543 return NULL;
2544 }
2545 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2546 if (!p)
2547 return NULL;
2548 p->kind = Assert_kind;
2549 p->v.Assert.test = test;
2550 p->v.Assert.msg = msg;
2551 p->lineno = lineno;
2552 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002553 p->end_lineno = end_lineno;
2554 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002555 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002556}
2557
2558stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002559Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2560 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002561{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002562 stmt_ty p;
2563 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2564 if (!p)
2565 return NULL;
2566 p->kind = Import_kind;
2567 p->v.Import.names = names;
2568 p->lineno = lineno;
2569 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002570 p->end_lineno = end_lineno;
2571 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002572 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002573}
2574
2575stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002576ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002577 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002578{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002579 stmt_ty p;
2580 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2581 if (!p)
2582 return NULL;
2583 p->kind = ImportFrom_kind;
2584 p->v.ImportFrom.module = module;
2585 p->v.ImportFrom.names = names;
2586 p->v.ImportFrom.level = level;
2587 p->lineno = lineno;
2588 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002589 p->end_lineno = end_lineno;
2590 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002591 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002592}
2593
2594stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002595Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2596 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002597{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002598 stmt_ty p;
2599 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2600 if (!p)
2601 return NULL;
2602 p->kind = Global_kind;
2603 p->v.Global.names = names;
2604 p->lineno = lineno;
2605 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002606 p->end_lineno = end_lineno;
2607 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002608 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002609}
2610
2611stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002612Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2613 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002614{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002615 stmt_ty p;
2616 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2617 if (!p)
2618 return NULL;
2619 p->kind = Nonlocal_kind;
2620 p->v.Nonlocal.names = names;
2621 p->lineno = lineno;
2622 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002623 p->end_lineno = end_lineno;
2624 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002625 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002626}
2627
2628stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002629Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2630 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002631{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002632 stmt_ty p;
2633 if (!value) {
2634 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002635 "field 'value' is required for Expr");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002636 return NULL;
2637 }
2638 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2639 if (!p)
2640 return NULL;
2641 p->kind = Expr_kind;
2642 p->v.Expr.value = value;
2643 p->lineno = lineno;
2644 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002645 p->end_lineno = end_lineno;
2646 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002647 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002648}
2649
2650stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002651Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2652 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002653{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002654 stmt_ty p;
2655 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2656 if (!p)
2657 return NULL;
2658 p->kind = Pass_kind;
2659 p->lineno = lineno;
2660 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002661 p->end_lineno = end_lineno;
2662 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002663 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002664}
2665
2666stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002667Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2668 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002669{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002670 stmt_ty p;
2671 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2672 if (!p)
2673 return NULL;
2674 p->kind = Break_kind;
2675 p->lineno = lineno;
2676 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002677 p->end_lineno = end_lineno;
2678 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002679 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002680}
2681
2682stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002683Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2684 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002685{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002686 stmt_ty p;
2687 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2688 if (!p)
2689 return NULL;
2690 p->kind = Continue_kind;
2691 p->lineno = lineno;
2692 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002693 p->end_lineno = end_lineno;
2694 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002695 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002696}
2697
2698expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002699BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2700 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002701{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002702 expr_ty p;
2703 if (!op) {
2704 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002705 "field 'op' is required for BoolOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002706 return NULL;
2707 }
2708 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2709 if (!p)
2710 return NULL;
2711 p->kind = BoolOp_kind;
2712 p->v.BoolOp.op = op;
2713 p->v.BoolOp.values = values;
2714 p->lineno = lineno;
2715 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002716 p->end_lineno = end_lineno;
2717 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002718 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002719}
2720
2721expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002722NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2723 end_lineno, int end_col_offset, PyArena *arena)
2724{
2725 expr_ty p;
2726 if (!target) {
2727 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002728 "field 'target' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002729 return NULL;
2730 }
2731 if (!value) {
2732 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002733 "field 'value' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002734 return NULL;
2735 }
2736 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2737 if (!p)
2738 return NULL;
2739 p->kind = NamedExpr_kind;
2740 p->v.NamedExpr.target = target;
2741 p->v.NamedExpr.value = value;
2742 p->lineno = lineno;
2743 p->col_offset = col_offset;
2744 p->end_lineno = end_lineno;
2745 p->end_col_offset = end_col_offset;
2746 return p;
2747}
2748
2749expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002750BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002751 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002752{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002753 expr_ty p;
2754 if (!left) {
2755 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002756 "field 'left' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002757 return NULL;
2758 }
2759 if (!op) {
2760 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002761 "field 'op' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002762 return NULL;
2763 }
2764 if (!right) {
2765 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002766 "field 'right' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002767 return NULL;
2768 }
2769 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2770 if (!p)
2771 return NULL;
2772 p->kind = BinOp_kind;
2773 p->v.BinOp.left = left;
2774 p->v.BinOp.op = op;
2775 p->v.BinOp.right = right;
2776 p->lineno = lineno;
2777 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002778 p->end_lineno = end_lineno;
2779 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002780 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002781}
2782
2783expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002784UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2785 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002786{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002787 expr_ty p;
2788 if (!op) {
2789 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002790 "field 'op' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002791 return NULL;
2792 }
2793 if (!operand) {
2794 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002795 "field 'operand' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002796 return NULL;
2797 }
2798 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2799 if (!p)
2800 return NULL;
2801 p->kind = UnaryOp_kind;
2802 p->v.UnaryOp.op = op;
2803 p->v.UnaryOp.operand = operand;
2804 p->lineno = lineno;
2805 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002806 p->end_lineno = end_lineno;
2807 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002808 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002809}
2810
2811expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002812Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2813 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002814{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002815 expr_ty p;
2816 if (!args) {
2817 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002818 "field 'args' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002819 return NULL;
2820 }
2821 if (!body) {
2822 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002823 "field 'body' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002824 return NULL;
2825 }
2826 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2827 if (!p)
2828 return NULL;
2829 p->kind = Lambda_kind;
2830 p->v.Lambda.args = args;
2831 p->v.Lambda.body = body;
2832 p->lineno = lineno;
2833 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002834 p->end_lineno = end_lineno;
2835 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002836 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002837}
2838
2839expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002840IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002841 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002842{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002843 expr_ty p;
2844 if (!test) {
2845 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002846 "field 'test' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002847 return NULL;
2848 }
2849 if (!body) {
2850 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002851 "field 'body' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002852 return NULL;
2853 }
2854 if (!orelse) {
2855 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002856 "field 'orelse' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002857 return NULL;
2858 }
2859 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2860 if (!p)
2861 return NULL;
2862 p->kind = IfExp_kind;
2863 p->v.IfExp.test = test;
2864 p->v.IfExp.body = body;
2865 p->v.IfExp.orelse = orelse;
2866 p->lineno = lineno;
2867 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002868 p->end_lineno = end_lineno;
2869 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002870 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002871}
2872
2873expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002874Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2875 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002876{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002877 expr_ty p;
2878 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2879 if (!p)
2880 return NULL;
2881 p->kind = Dict_kind;
2882 p->v.Dict.keys = keys;
2883 p->v.Dict.values = values;
2884 p->lineno = lineno;
2885 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002886 p->end_lineno = end_lineno;
2887 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002888 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002889}
2890
2891expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002892Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2893 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002894{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002895 expr_ty p;
2896 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2897 if (!p)
2898 return NULL;
2899 p->kind = Set_kind;
2900 p->v.Set.elts = elts;
2901 p->lineno = lineno;
2902 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002903 p->end_lineno = end_lineno;
2904 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002905 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002906}
2907
2908expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002909ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2910 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002911{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002912 expr_ty p;
2913 if (!elt) {
2914 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002915 "field 'elt' is required for ListComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002916 return NULL;
2917 }
2918 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2919 if (!p)
2920 return NULL;
2921 p->kind = ListComp_kind;
2922 p->v.ListComp.elt = elt;
2923 p->v.ListComp.generators = generators;
2924 p->lineno = lineno;
2925 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002926 p->end_lineno = end_lineno;
2927 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002928 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002929}
2930
2931expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002932SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2933 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002934{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002935 expr_ty p;
2936 if (!elt) {
2937 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002938 "field 'elt' is required for SetComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002939 return NULL;
2940 }
2941 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2942 if (!p)
2943 return NULL;
2944 p->kind = SetComp_kind;
2945 p->v.SetComp.elt = elt;
2946 p->v.SetComp.generators = generators;
2947 p->lineno = lineno;
2948 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002949 p->end_lineno = end_lineno;
2950 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002951 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002952}
2953
2954expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002955DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002956 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002957{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002958 expr_ty p;
2959 if (!key) {
2960 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002961 "field 'key' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002962 return NULL;
2963 }
2964 if (!value) {
2965 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002966 "field 'value' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002967 return NULL;
2968 }
2969 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2970 if (!p)
2971 return NULL;
2972 p->kind = DictComp_kind;
2973 p->v.DictComp.key = key;
2974 p->v.DictComp.value = value;
2975 p->v.DictComp.generators = generators;
2976 p->lineno = lineno;
2977 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002978 p->end_lineno = end_lineno;
2979 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002980 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002981}
2982
2983expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002984GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002985 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002986{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002987 expr_ty p;
2988 if (!elt) {
2989 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002990 "field 'elt' is required for GeneratorExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002991 return NULL;
2992 }
2993 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2994 if (!p)
2995 return NULL;
2996 p->kind = GeneratorExp_kind;
2997 p->v.GeneratorExp.elt = elt;
2998 p->v.GeneratorExp.generators = generators;
2999 p->lineno = lineno;
3000 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003001 p->end_lineno = end_lineno;
3002 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003003 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003004}
3005
3006expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003007Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
3008 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04003009{
3010 expr_ty p;
3011 if (!value) {
3012 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003013 "field 'value' is required for Await");
Yury Selivanov75445082015-05-11 22:57:16 -04003014 return NULL;
3015 }
3016 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3017 if (!p)
3018 return NULL;
3019 p->kind = Await_kind;
3020 p->v.Await.value = value;
3021 p->lineno = lineno;
3022 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003023 p->end_lineno = end_lineno;
3024 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04003025 return p;
3026}
3027
3028expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003029Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
3030 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003031{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003032 expr_ty p;
3033 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3034 if (!p)
3035 return NULL;
3036 p->kind = Yield_kind;
3037 p->v.Yield.value = value;
3038 p->lineno = lineno;
3039 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003040 p->end_lineno = end_lineno;
3041 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003042 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003043}
3044
3045expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003046YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3047 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05003048{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003049 expr_ty p;
3050 if (!value) {
3051 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003052 "field 'value' is required for YieldFrom");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003053 return NULL;
3054 }
3055 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3056 if (!p)
3057 return NULL;
3058 p->kind = YieldFrom_kind;
3059 p->v.YieldFrom.value = value;
3060 p->lineno = lineno;
3061 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003062 p->end_lineno = end_lineno;
3063 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003064 return p;
Benjamin Peterson527c6222012-01-14 08:58:23 -05003065}
3066
3067expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003068Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003069 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003070{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003071 expr_ty p;
3072 if (!left) {
3073 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003074 "field 'left' is required for Compare");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003075 return NULL;
3076 }
3077 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3078 if (!p)
3079 return NULL;
3080 p->kind = Compare_kind;
3081 p->v.Compare.left = left;
3082 p->v.Compare.ops = ops;
3083 p->v.Compare.comparators = comparators;
3084 p->lineno = lineno;
3085 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003086 p->end_lineno = end_lineno;
3087 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003088 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003089}
3090
3091expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04003092Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003093 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003094{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003095 expr_ty p;
3096 if (!func) {
3097 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003098 "field 'func' is required for Call");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003099 return NULL;
3100 }
3101 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3102 if (!p)
3103 return NULL;
3104 p->kind = Call_kind;
3105 p->v.Call.func = func;
3106 p->v.Call.args = args;
3107 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003108 p->lineno = lineno;
3109 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003110 p->end_lineno = end_lineno;
3111 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003112 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003113}
3114
3115expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04003116FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
3117 int col_offset, int end_lineno, int end_col_offset, PyArena
3118 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003119{
3120 expr_ty p;
3121 if (!value) {
3122 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003123 "field 'value' is required for FormattedValue");
Eric V. Smith235a6f02015-09-19 14:51:32 -04003124 return NULL;
3125 }
3126 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3127 if (!p)
3128 return NULL;
3129 p->kind = FormattedValue_kind;
3130 p->v.FormattedValue.value = value;
3131 p->v.FormattedValue.conversion = conversion;
3132 p->v.FormattedValue.format_spec = format_spec;
3133 p->lineno = lineno;
3134 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003135 p->end_lineno = end_lineno;
3136 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003137 return p;
3138}
3139
3140expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003141JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3142 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003143{
3144 expr_ty p;
3145 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3146 if (!p)
3147 return NULL;
3148 p->kind = JoinedStr_kind;
3149 p->v.JoinedStr.values = values;
3150 p->lineno = lineno;
3151 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003152 p->end_lineno = end_lineno;
3153 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003154 return p;
3155}
3156
3157expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003158Constant(constant value, string kind, int lineno, int col_offset, int
3159 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003160{
3161 expr_ty p;
3162 if (!value) {
3163 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003164 "field 'value' is required for Constant");
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003165 return NULL;
3166 }
3167 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3168 if (!p)
3169 return NULL;
3170 p->kind = Constant_kind;
3171 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003172 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003173 p->lineno = lineno;
3174 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003175 p->end_lineno = end_lineno;
3176 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003177 return p;
3178}
3179
3180expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003181Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003182 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003183{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003184 expr_ty p;
3185 if (!value) {
3186 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003187 "field 'value' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003188 return NULL;
3189 }
3190 if (!attr) {
3191 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003192 "field 'attr' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003193 return NULL;
3194 }
3195 if (!ctx) {
3196 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003197 "field 'ctx' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003198 return NULL;
3199 }
3200 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3201 if (!p)
3202 return NULL;
3203 p->kind = Attribute_kind;
3204 p->v.Attribute.value = value;
3205 p->v.Attribute.attr = attr;
3206 p->v.Attribute.ctx = ctx;
3207 p->lineno = lineno;
3208 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003209 p->end_lineno = end_lineno;
3210 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003211 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003212}
3213
3214expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003215Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003216 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003217{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003218 expr_ty p;
3219 if (!value) {
3220 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003221 "field 'value' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003222 return NULL;
3223 }
3224 if (!slice) {
3225 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003226 "field 'slice' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003227 return NULL;
3228 }
3229 if (!ctx) {
3230 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003231 "field 'ctx' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003232 return NULL;
3233 }
3234 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3235 if (!p)
3236 return NULL;
3237 p->kind = Subscript_kind;
3238 p->v.Subscript.value = value;
3239 p->v.Subscript.slice = slice;
3240 p->v.Subscript.ctx = ctx;
3241 p->lineno = lineno;
3242 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003243 p->end_lineno = end_lineno;
3244 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003245 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003246}
3247
3248expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003249Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3250 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003251{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003252 expr_ty p;
3253 if (!value) {
3254 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003255 "field 'value' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003256 return NULL;
3257 }
3258 if (!ctx) {
3259 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003260 "field 'ctx' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003261 return NULL;
3262 }
3263 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3264 if (!p)
3265 return NULL;
3266 p->kind = Starred_kind;
3267 p->v.Starred.value = value;
3268 p->v.Starred.ctx = ctx;
3269 p->lineno = lineno;
3270 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003271 p->end_lineno = end_lineno;
3272 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003273 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003274}
3275
3276expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003277Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3278 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003279{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003280 expr_ty p;
3281 if (!id) {
3282 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003283 "field 'id' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003284 return NULL;
3285 }
3286 if (!ctx) {
3287 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003288 "field 'ctx' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003289 return NULL;
3290 }
3291 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3292 if (!p)
3293 return NULL;
3294 p->kind = Name_kind;
3295 p->v.Name.id = id;
3296 p->v.Name.ctx = ctx;
3297 p->lineno = lineno;
3298 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003299 p->end_lineno = end_lineno;
3300 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003301 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003302}
3303
3304expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003305List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3306 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003307{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003308 expr_ty p;
3309 if (!ctx) {
3310 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003311 "field 'ctx' is required for List");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003312 return NULL;
3313 }
3314 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3315 if (!p)
3316 return NULL;
3317 p->kind = List_kind;
3318 p->v.List.elts = elts;
3319 p->v.List.ctx = ctx;
3320 p->lineno = lineno;
3321 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003322 p->end_lineno = end_lineno;
3323 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003324 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003325}
3326
3327expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003328Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3329 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003330{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003331 expr_ty p;
3332 if (!ctx) {
3333 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003334 "field 'ctx' is required for Tuple");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003335 return NULL;
3336 }
3337 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3338 if (!p)
3339 return NULL;
3340 p->kind = Tuple_kind;
3341 p->v.Tuple.elts = elts;
3342 p->v.Tuple.ctx = ctx;
3343 p->lineno = lineno;
3344 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003345 p->end_lineno = end_lineno;
3346 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003347 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003348}
3349
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003350expr_ty
3351Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3352 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003353{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003354 expr_ty p;
3355 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003356 if (!p)
3357 return NULL;
3358 p->kind = Slice_kind;
3359 p->v.Slice.lower = lower;
3360 p->v.Slice.upper = upper;
3361 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003362 p->lineno = lineno;
3363 p->col_offset = col_offset;
3364 p->end_lineno = end_lineno;
3365 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003366 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003367}
3368
3369comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003370comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3371 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003372{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003373 comprehension_ty p;
3374 if (!target) {
3375 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003376 "field 'target' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003377 return NULL;
3378 }
3379 if (!iter) {
3380 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003381 "field 'iter' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003382 return NULL;
3383 }
3384 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3385 if (!p)
3386 return NULL;
3387 p->target = target;
3388 p->iter = iter;
3389 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003390 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003391 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003392}
3393
3394excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003395ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003396 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003397{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003398 excepthandler_ty p;
3399 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3400 if (!p)
3401 return NULL;
3402 p->kind = ExceptHandler_kind;
3403 p->v.ExceptHandler.type = type;
3404 p->v.ExceptHandler.name = name;
3405 p->v.ExceptHandler.body = body;
3406 p->lineno = lineno;
3407 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003408 p->end_lineno = end_lineno;
3409 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003410 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003411}
3412
3413arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003414arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003415 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3416 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003417{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003418 arguments_ty p;
3419 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3420 if (!p)
3421 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003422 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003423 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003424 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003425 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003426 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003427 p->kwarg = kwarg;
3428 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003429 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003430}
3431
Neal Norwitzc1505362006-12-28 06:47:50 +00003432arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003433arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3434 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003435{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003436 arg_ty p;
3437 if (!arg) {
3438 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003439 "field 'arg' is required for arg");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003440 return NULL;
3441 }
3442 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3443 if (!p)
3444 return NULL;
3445 p->arg = arg;
3446 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003447 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003448 p->lineno = lineno;
3449 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003450 p->end_lineno = end_lineno;
3451 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003452 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003453}
3454
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003455keyword_ty
Pablo Galindo168660b2020-04-02 00:47:39 +01003456keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3457 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003458{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003459 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003460 if (!value) {
3461 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003462 "field 'value' is required for keyword");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003463 return NULL;
3464 }
3465 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3466 if (!p)
3467 return NULL;
3468 p->arg = arg;
3469 p->value = value;
Pablo Galindo168660b2020-04-02 00:47:39 +01003470 p->lineno = lineno;
3471 p->col_offset = col_offset;
3472 p->end_lineno = end_lineno;
3473 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003474 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003475}
3476
3477alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003478alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003479{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003480 alias_ty p;
3481 if (!name) {
3482 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003483 "field 'name' is required for alias");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003484 return NULL;
3485 }
3486 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3487 if (!p)
3488 return NULL;
3489 p->name = name;
3490 p->asname = asname;
3491 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003492}
3493
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003494withitem_ty
3495withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3496{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003497 withitem_ty p;
3498 if (!context_expr) {
3499 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003500 "field 'context_expr' is required for withitem");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003501 return NULL;
3502 }
3503 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3504 if (!p)
3505 return NULL;
3506 p->context_expr = context_expr;
3507 p->optional_vars = optional_vars;
3508 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003509}
3510
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003511type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003512TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003513{
3514 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003515 if (!tag) {
3516 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003517 "field 'tag' is required for TypeIgnore");
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003518 return NULL;
3519 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003520 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3521 if (!p)
3522 return NULL;
3523 p->kind = TypeIgnore_kind;
3524 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003525 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003526 return p;
3527}
3528
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003529
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003530PyObject*
3531ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003532{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003533 mod_ty o = (mod_ty)_o;
3534 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003535 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003536 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003537 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003538 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003539
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003540 switch (o->kind) {
3541 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003542 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3543 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003544 if (!result) goto failed;
3545 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3546 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003547 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003548 goto failed;
3549 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003550 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3551 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003552 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3553 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003554 goto failed;
3555 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003556 break;
3557 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003558 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3559 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003560 if (!result) goto failed;
3561 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3562 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003563 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003564 goto failed;
3565 Py_DECREF(value);
3566 break;
3567 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003568 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3569 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003570 if (!result) goto failed;
3571 value = ast2obj_expr(o->v.Expression.body);
3572 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003573 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003574 goto failed;
3575 Py_DECREF(value);
3576 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003577 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003578 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3579 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003580 if (!result) goto failed;
3581 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3582 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003583 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3584 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003585 goto failed;
3586 Py_DECREF(value);
3587 value = ast2obj_expr(o->v.FunctionType.returns);
3588 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003589 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3590 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003591 goto failed;
3592 Py_DECREF(value);
3593 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003594 }
3595 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003596failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003597 Py_XDECREF(value);
3598 Py_XDECREF(result);
3599 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003600}
3601
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003602PyObject*
3603ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003604{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003605 stmt_ty o = (stmt_ty)_o;
3606 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003607 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003608 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003609 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003610 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003611
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003612 switch (o->kind) {
3613 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003614 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3615 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003616 if (!result) goto failed;
3617 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003618 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003619 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003620 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003621 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003622 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003623 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003624 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003625 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003626 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003627 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3628 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003629 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003630 goto failed;
3631 Py_DECREF(value);
3632 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3633 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003634 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3635 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003636 goto failed;
3637 Py_DECREF(value);
3638 value = ast2obj_expr(o->v.FunctionDef.returns);
3639 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003640 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3641 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003642 goto failed;
3643 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003644 value = ast2obj_string(o->v.FunctionDef.type_comment);
3645 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003646 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3647 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003648 goto failed;
3649 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003650 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003651 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003652 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3653 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003654 if (!result) goto failed;
3655 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3656 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003657 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003658 goto failed;
3659 Py_DECREF(value);
3660 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3661 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003662 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003663 goto failed;
3664 Py_DECREF(value);
3665 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3666 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003667 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003668 goto failed;
3669 Py_DECREF(value);
3670 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3671 ast2obj_expr);
3672 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003673 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3674 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003675 goto failed;
3676 Py_DECREF(value);
3677 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3678 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003679 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3680 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003681 goto failed;
3682 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003683 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3684 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003685 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3686 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003687 goto failed;
3688 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003689 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003690 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003691 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3692 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003693 if (!result) goto failed;
3694 value = ast2obj_identifier(o->v.ClassDef.name);
3695 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003696 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003697 goto failed;
3698 Py_DECREF(value);
3699 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3700 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003701 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003702 goto failed;
3703 Py_DECREF(value);
3704 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3705 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003706 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3707 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003708 goto failed;
3709 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003710 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3711 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003712 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003713 goto failed;
3714 Py_DECREF(value);
3715 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3716 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003717 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3718 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003719 goto failed;
3720 Py_DECREF(value);
3721 break;
3722 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003723 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3724 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003725 if (!result) goto failed;
3726 value = ast2obj_expr(o->v.Return.value);
3727 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003728 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003729 goto failed;
3730 Py_DECREF(value);
3731 break;
3732 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003733 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3734 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003735 if (!result) goto failed;
3736 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3737 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003738 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3739 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003740 goto failed;
3741 Py_DECREF(value);
3742 break;
3743 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003744 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3745 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003746 if (!result) goto failed;
3747 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3748 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003749 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3750 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003751 goto failed;
3752 Py_DECREF(value);
3753 value = ast2obj_expr(o->v.Assign.value);
3754 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003755 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003756 goto failed;
3757 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003758 value = ast2obj_string(o->v.Assign.type_comment);
3759 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003760 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3761 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003762 goto failed;
3763 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003764 break;
3765 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003766 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3767 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003768 if (!result) goto failed;
3769 value = ast2obj_expr(o->v.AugAssign.target);
3770 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003771 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3772 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003773 goto failed;
3774 Py_DECREF(value);
3775 value = ast2obj_operator(o->v.AugAssign.op);
3776 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003777 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003778 goto failed;
3779 Py_DECREF(value);
3780 value = ast2obj_expr(o->v.AugAssign.value);
3781 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003782 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003783 goto failed;
3784 Py_DECREF(value);
3785 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003786 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003787 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3788 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003789 if (!result) goto failed;
3790 value = ast2obj_expr(o->v.AnnAssign.target);
3791 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003792 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3793 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003794 goto failed;
3795 Py_DECREF(value);
3796 value = ast2obj_expr(o->v.AnnAssign.annotation);
3797 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003798 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3799 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003800 goto failed;
3801 Py_DECREF(value);
3802 value = ast2obj_expr(o->v.AnnAssign.value);
3803 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003804 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003805 goto failed;
3806 Py_DECREF(value);
3807 value = ast2obj_int(o->v.AnnAssign.simple);
3808 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003809 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3810 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003811 goto failed;
3812 Py_DECREF(value);
3813 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003814 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003815 tp = (PyTypeObject *)astmodulestate_global->For_type;
3816 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003817 if (!result) goto failed;
3818 value = ast2obj_expr(o->v.For.target);
3819 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003820 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3821 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003822 goto failed;
3823 Py_DECREF(value);
3824 value = ast2obj_expr(o->v.For.iter);
3825 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003826 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003827 goto failed;
3828 Py_DECREF(value);
3829 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3830 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003831 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003832 goto failed;
3833 Py_DECREF(value);
3834 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3835 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003836 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3837 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003838 goto failed;
3839 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003840 value = ast2obj_string(o->v.For.type_comment);
3841 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003842 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3843 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003844 goto failed;
3845 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003846 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003847 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003848 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3849 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003850 if (!result) goto failed;
3851 value = ast2obj_expr(o->v.AsyncFor.target);
3852 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003853 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3854 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003855 goto failed;
3856 Py_DECREF(value);
3857 value = ast2obj_expr(o->v.AsyncFor.iter);
3858 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003859 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003860 goto failed;
3861 Py_DECREF(value);
3862 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3863 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003864 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003865 goto failed;
3866 Py_DECREF(value);
3867 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3870 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003871 goto failed;
3872 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003873 value = ast2obj_string(o->v.AsyncFor.type_comment);
3874 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003875 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3876 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003877 goto failed;
3878 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003879 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003880 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003881 tp = (PyTypeObject *)astmodulestate_global->While_type;
3882 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003883 if (!result) goto failed;
3884 value = ast2obj_expr(o->v.While.test);
3885 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003886 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003887 goto failed;
3888 Py_DECREF(value);
3889 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3890 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003891 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003892 goto failed;
3893 Py_DECREF(value);
3894 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3895 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003896 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3897 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003898 goto failed;
3899 Py_DECREF(value);
3900 break;
3901 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003902 tp = (PyTypeObject *)astmodulestate_global->If_type;
3903 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003904 if (!result) goto failed;
3905 value = ast2obj_expr(o->v.If.test);
3906 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003907 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003908 goto failed;
3909 Py_DECREF(value);
3910 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3911 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003912 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003913 goto failed;
3914 Py_DECREF(value);
3915 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3916 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003917 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3918 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003919 goto failed;
3920 Py_DECREF(value);
3921 break;
3922 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003923 tp = (PyTypeObject *)astmodulestate_global->With_type;
3924 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003925 if (!result) goto failed;
3926 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3927 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003928 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003929 goto failed;
3930 Py_DECREF(value);
3931 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3932 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003933 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003934 goto failed;
3935 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003936 value = ast2obj_string(o->v.With.type_comment);
3937 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003938 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3939 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003940 goto failed;
3941 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003942 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003943 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003944 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3945 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003946 if (!result) goto failed;
3947 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3948 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003949 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003950 goto failed;
3951 Py_DECREF(value);
3952 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3953 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003954 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003955 goto failed;
3956 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003957 value = ast2obj_string(o->v.AsyncWith.type_comment);
3958 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003959 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3960 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003961 goto failed;
3962 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003963 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003964 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003965 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3966 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003967 if (!result) goto failed;
3968 value = ast2obj_expr(o->v.Raise.exc);
3969 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003970 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003971 goto failed;
3972 Py_DECREF(value);
3973 value = ast2obj_expr(o->v.Raise.cause);
3974 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003975 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003976 goto failed;
3977 Py_DECREF(value);
3978 break;
3979 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003980 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3981 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003982 if (!result) goto failed;
3983 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3984 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003985 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003986 goto failed;
3987 Py_DECREF(value);
3988 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3989 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003990 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3991 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003992 goto failed;
3993 Py_DECREF(value);
3994 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3995 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003996 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3997 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003998 goto failed;
3999 Py_DECREF(value);
4000 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
4001 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004002 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
4003 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004004 goto failed;
4005 Py_DECREF(value);
4006 break;
4007 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004008 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
4009 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004010 if (!result) goto failed;
4011 value = ast2obj_expr(o->v.Assert.test);
4012 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004013 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004014 goto failed;
4015 Py_DECREF(value);
4016 value = ast2obj_expr(o->v.Assert.msg);
4017 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004018 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004019 goto failed;
4020 Py_DECREF(value);
4021 break;
4022 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004023 tp = (PyTypeObject *)astmodulestate_global->Import_type;
4024 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004025 if (!result) goto failed;
4026 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
4027 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004028 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004029 goto failed;
4030 Py_DECREF(value);
4031 break;
4032 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004033 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
4034 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004035 if (!result) goto failed;
4036 value = ast2obj_identifier(o->v.ImportFrom.module);
4037 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004038 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
4039 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004040 goto failed;
4041 Py_DECREF(value);
4042 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
4043 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004044 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004045 goto failed;
4046 Py_DECREF(value);
4047 value = ast2obj_int(o->v.ImportFrom.level);
4048 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004049 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004050 goto failed;
4051 Py_DECREF(value);
4052 break;
4053 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004054 tp = (PyTypeObject *)astmodulestate_global->Global_type;
4055 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004056 if (!result) goto failed;
4057 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
4058 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004059 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004060 goto failed;
4061 Py_DECREF(value);
4062 break;
4063 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004064 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
4065 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004066 if (!result) goto failed;
4067 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
4068 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004069 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004070 goto failed;
4071 Py_DECREF(value);
4072 break;
4073 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004074 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
4075 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004076 if (!result) goto failed;
4077 value = ast2obj_expr(o->v.Expr.value);
4078 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004079 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004080 goto failed;
4081 Py_DECREF(value);
4082 break;
4083 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004084 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
4085 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004086 if (!result) goto failed;
4087 break;
4088 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004089 tp = (PyTypeObject *)astmodulestate_global->Break_type;
4090 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004091 if (!result) goto failed;
4092 break;
4093 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004094 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
4095 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004096 if (!result) goto failed;
4097 break;
4098 }
4099 value = ast2obj_int(o->lineno);
4100 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004101 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004102 goto failed;
4103 Py_DECREF(value);
4104 value = ast2obj_int(o->col_offset);
4105 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004106 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004107 goto failed;
4108 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004109 value = ast2obj_int(o->end_lineno);
4110 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004111 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004112 goto failed;
4113 Py_DECREF(value);
4114 value = ast2obj_int(o->end_col_offset);
4115 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004116 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4117 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004118 goto failed;
4119 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004120 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004121failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004122 Py_XDECREF(value);
4123 Py_XDECREF(result);
4124 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004125}
4126
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004127PyObject*
4128ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004129{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004130 expr_ty o = (expr_ty)_o;
4131 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004132 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004133 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004134 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004135 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004136
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004137 switch (o->kind) {
4138 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004139 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4140 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004141 if (!result) goto failed;
4142 value = ast2obj_boolop(o->v.BoolOp.op);
4143 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004144 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004145 goto failed;
4146 Py_DECREF(value);
4147 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4148 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004149 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4150 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004151 goto failed;
4152 Py_DECREF(value);
4153 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004154 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004155 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4156 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004157 if (!result) goto failed;
4158 value = ast2obj_expr(o->v.NamedExpr.target);
4159 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004160 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4161 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004162 goto failed;
4163 Py_DECREF(value);
4164 value = ast2obj_expr(o->v.NamedExpr.value);
4165 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004166 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004167 goto failed;
4168 Py_DECREF(value);
4169 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004170 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004171 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4172 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004173 if (!result) goto failed;
4174 value = ast2obj_expr(o->v.BinOp.left);
4175 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004176 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004177 goto failed;
4178 Py_DECREF(value);
4179 value = ast2obj_operator(o->v.BinOp.op);
4180 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004181 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004182 goto failed;
4183 Py_DECREF(value);
4184 value = ast2obj_expr(o->v.BinOp.right);
4185 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004186 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004187 goto failed;
4188 Py_DECREF(value);
4189 break;
4190 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004191 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4192 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004193 if (!result) goto failed;
4194 value = ast2obj_unaryop(o->v.UnaryOp.op);
4195 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004196 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004197 goto failed;
4198 Py_DECREF(value);
4199 value = ast2obj_expr(o->v.UnaryOp.operand);
4200 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004201 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4202 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004203 goto failed;
4204 Py_DECREF(value);
4205 break;
4206 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004207 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4208 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004209 if (!result) goto failed;
4210 value = ast2obj_arguments(o->v.Lambda.args);
4211 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004212 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004213 goto failed;
4214 Py_DECREF(value);
4215 value = ast2obj_expr(o->v.Lambda.body);
4216 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004217 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004218 goto failed;
4219 Py_DECREF(value);
4220 break;
4221 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004222 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4223 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004224 if (!result) goto failed;
4225 value = ast2obj_expr(o->v.IfExp.test);
4226 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004227 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004228 goto failed;
4229 Py_DECREF(value);
4230 value = ast2obj_expr(o->v.IfExp.body);
4231 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004232 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004233 goto failed;
4234 Py_DECREF(value);
4235 value = ast2obj_expr(o->v.IfExp.orelse);
4236 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004237 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4238 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004239 goto failed;
4240 Py_DECREF(value);
4241 break;
4242 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004243 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4244 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004245 if (!result) goto failed;
4246 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4247 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004248 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004249 goto failed;
4250 Py_DECREF(value);
4251 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4252 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004253 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4254 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004255 goto failed;
4256 Py_DECREF(value);
4257 break;
4258 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004259 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4260 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004261 if (!result) goto failed;
4262 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4263 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004264 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004265 goto failed;
4266 Py_DECREF(value);
4267 break;
4268 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004269 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4270 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004271 if (!result) goto failed;
4272 value = ast2obj_expr(o->v.ListComp.elt);
4273 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004274 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004275 goto failed;
4276 Py_DECREF(value);
4277 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4278 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004279 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4280 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004281 goto failed;
4282 Py_DECREF(value);
4283 break;
4284 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004285 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4286 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004287 if (!result) goto failed;
4288 value = ast2obj_expr(o->v.SetComp.elt);
4289 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004290 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004291 goto failed;
4292 Py_DECREF(value);
4293 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4294 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004295 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4296 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004297 goto failed;
4298 Py_DECREF(value);
4299 break;
4300 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004301 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4302 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004303 if (!result) goto failed;
4304 value = ast2obj_expr(o->v.DictComp.key);
4305 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004306 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004307 goto failed;
4308 Py_DECREF(value);
4309 value = ast2obj_expr(o->v.DictComp.value);
4310 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004311 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004312 goto failed;
4313 Py_DECREF(value);
4314 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4315 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004316 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4317 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004318 goto failed;
4319 Py_DECREF(value);
4320 break;
4321 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004322 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4323 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004324 if (!result) goto failed;
4325 value = ast2obj_expr(o->v.GeneratorExp.elt);
4326 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004327 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004328 goto failed;
4329 Py_DECREF(value);
4330 value = ast2obj_list(o->v.GeneratorExp.generators,
4331 ast2obj_comprehension);
4332 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004333 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4334 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004335 goto failed;
4336 Py_DECREF(value);
4337 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004338 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004339 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4340 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004341 if (!result) goto failed;
4342 value = ast2obj_expr(o->v.Await.value);
4343 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004344 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004345 goto failed;
4346 Py_DECREF(value);
4347 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004348 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004349 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4350 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004351 if (!result) goto failed;
4352 value = ast2obj_expr(o->v.Yield.value);
4353 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004354 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004355 goto failed;
4356 Py_DECREF(value);
4357 break;
4358 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004359 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4360 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004361 if (!result) goto failed;
4362 value = ast2obj_expr(o->v.YieldFrom.value);
4363 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004364 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004365 goto failed;
4366 Py_DECREF(value);
4367 break;
4368 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004369 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4370 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004371 if (!result) goto failed;
4372 value = ast2obj_expr(o->v.Compare.left);
4373 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004374 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004375 goto failed;
4376 Py_DECREF(value);
4377 {
4378 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4379 value = PyList_New(n);
4380 if (!value) goto failed;
4381 for(i = 0; i < n; i++)
4382 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004383 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004384 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004385 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004386 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004387 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004388 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004389 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004390 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4391 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004392 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004393 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004394 break;
4395 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004396 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4397 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004398 if (!result) goto failed;
4399 value = ast2obj_expr(o->v.Call.func);
4400 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004401 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004402 goto failed;
4403 Py_DECREF(value);
4404 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4405 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004406 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004407 goto failed;
4408 Py_DECREF(value);
4409 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4410 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004411 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4412 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004413 goto failed;
4414 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004415 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004416 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004417 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4418 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004419 if (!result) goto failed;
4420 value = ast2obj_expr(o->v.FormattedValue.value);
4421 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004422 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004423 goto failed;
4424 Py_DECREF(value);
4425 value = ast2obj_int(o->v.FormattedValue.conversion);
4426 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004427 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4428 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004429 goto failed;
4430 Py_DECREF(value);
4431 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4432 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004433 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4434 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004435 goto failed;
4436 Py_DECREF(value);
4437 break;
4438 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004439 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4440 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004441 if (!result) goto failed;
4442 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4443 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004444 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4445 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004446 goto failed;
4447 Py_DECREF(value);
4448 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004449 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004450 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4451 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004452 if (!result) goto failed;
4453 value = ast2obj_constant(o->v.Constant.value);
4454 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004455 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004456 goto failed;
4457 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004458 value = ast2obj_string(o->v.Constant.kind);
4459 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004460 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004461 goto failed;
4462 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004463 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004464 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004465 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4466 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004467 if (!result) goto failed;
4468 value = ast2obj_expr(o->v.Attribute.value);
4469 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004470 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004471 goto failed;
4472 Py_DECREF(value);
4473 value = ast2obj_identifier(o->v.Attribute.attr);
4474 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004475 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004476 goto failed;
4477 Py_DECREF(value);
4478 value = ast2obj_expr_context(o->v.Attribute.ctx);
4479 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004480 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004481 goto failed;
4482 Py_DECREF(value);
4483 break;
4484 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004485 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4486 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004487 if (!result) goto failed;
4488 value = ast2obj_expr(o->v.Subscript.value);
4489 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004490 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004491 goto failed;
4492 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004493 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004494 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004495 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004496 goto failed;
4497 Py_DECREF(value);
4498 value = ast2obj_expr_context(o->v.Subscript.ctx);
4499 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004500 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004501 goto failed;
4502 Py_DECREF(value);
4503 break;
4504 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004505 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4506 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004507 if (!result) goto failed;
4508 value = ast2obj_expr(o->v.Starred.value);
4509 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004510 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004511 goto failed;
4512 Py_DECREF(value);
4513 value = ast2obj_expr_context(o->v.Starred.ctx);
4514 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004515 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004516 goto failed;
4517 Py_DECREF(value);
4518 break;
4519 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004520 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4521 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004522 if (!result) goto failed;
4523 value = ast2obj_identifier(o->v.Name.id);
4524 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004525 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004526 goto failed;
4527 Py_DECREF(value);
4528 value = ast2obj_expr_context(o->v.Name.ctx);
4529 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004530 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004531 goto failed;
4532 Py_DECREF(value);
4533 break;
4534 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004535 tp = (PyTypeObject *)astmodulestate_global->List_type;
4536 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004537 if (!result) goto failed;
4538 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4539 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004540 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004541 goto failed;
4542 Py_DECREF(value);
4543 value = ast2obj_expr_context(o->v.List.ctx);
4544 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004545 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004546 goto failed;
4547 Py_DECREF(value);
4548 break;
4549 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004550 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4551 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004552 if (!result) goto failed;
4553 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4554 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004555 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004556 goto failed;
4557 Py_DECREF(value);
4558 value = ast2obj_expr_context(o->v.Tuple.ctx);
4559 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004560 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004561 goto failed;
4562 Py_DECREF(value);
4563 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004564 case Slice_kind:
4565 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4566 result = PyType_GenericNew(tp, NULL, NULL);
4567 if (!result) goto failed;
4568 value = ast2obj_expr(o->v.Slice.lower);
4569 if (!value) goto failed;
4570 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4571 goto failed;
4572 Py_DECREF(value);
4573 value = ast2obj_expr(o->v.Slice.upper);
4574 if (!value) goto failed;
4575 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4576 goto failed;
4577 Py_DECREF(value);
4578 value = ast2obj_expr(o->v.Slice.step);
4579 if (!value) goto failed;
4580 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4581 goto failed;
4582 Py_DECREF(value);
4583 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004584 }
4585 value = ast2obj_int(o->lineno);
4586 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004587 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004588 goto failed;
4589 Py_DECREF(value);
4590 value = ast2obj_int(o->col_offset);
4591 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004592 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004593 goto failed;
4594 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004595 value = ast2obj_int(o->end_lineno);
4596 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004597 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004598 goto failed;
4599 Py_DECREF(value);
4600 value = ast2obj_int(o->end_col_offset);
4601 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004602 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4603 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004604 goto failed;
4605 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004606 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004607failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004608 Py_XDECREF(value);
4609 Py_XDECREF(result);
4610 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004611}
4612
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004613PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004614{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004615 switch(o) {
4616 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004617 Py_INCREF(astmodulestate_global->Load_singleton);
4618 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004619 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004620 Py_INCREF(astmodulestate_global->Store_singleton);
4621 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004622 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004623 Py_INCREF(astmodulestate_global->Del_singleton);
4624 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004625 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004626 Py_UNREACHABLE();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004627}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004628PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004629{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004630 switch(o) {
4631 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004632 Py_INCREF(astmodulestate_global->And_singleton);
4633 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004634 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004635 Py_INCREF(astmodulestate_global->Or_singleton);
4636 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004637 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004638 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004639}
4640PyObject* ast2obj_operator(operator_ty o)
4641{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004642 switch(o) {
4643 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004644 Py_INCREF(astmodulestate_global->Add_singleton);
4645 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004646 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004647 Py_INCREF(astmodulestate_global->Sub_singleton);
4648 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004649 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004650 Py_INCREF(astmodulestate_global->Mult_singleton);
4651 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004652 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004653 Py_INCREF(astmodulestate_global->MatMult_singleton);
4654 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004655 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004656 Py_INCREF(astmodulestate_global->Div_singleton);
4657 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004658 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004659 Py_INCREF(astmodulestate_global->Mod_singleton);
4660 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004661 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004662 Py_INCREF(astmodulestate_global->Pow_singleton);
4663 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004664 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004665 Py_INCREF(astmodulestate_global->LShift_singleton);
4666 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004667 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004668 Py_INCREF(astmodulestate_global->RShift_singleton);
4669 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004670 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004671 Py_INCREF(astmodulestate_global->BitOr_singleton);
4672 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004673 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004674 Py_INCREF(astmodulestate_global->BitXor_singleton);
4675 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004676 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004677 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4678 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004679 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004680 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4681 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004682 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004683 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004684}
4685PyObject* ast2obj_unaryop(unaryop_ty o)
4686{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 switch(o) {
4688 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004689 Py_INCREF(astmodulestate_global->Invert_singleton);
4690 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004691 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004692 Py_INCREF(astmodulestate_global->Not_singleton);
4693 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004694 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004695 Py_INCREF(astmodulestate_global->UAdd_singleton);
4696 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004697 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004698 Py_INCREF(astmodulestate_global->USub_singleton);
4699 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004700 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004701 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004702}
4703PyObject* ast2obj_cmpop(cmpop_ty o)
4704{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004705 switch(o) {
4706 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004707 Py_INCREF(astmodulestate_global->Eq_singleton);
4708 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004709 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004710 Py_INCREF(astmodulestate_global->NotEq_singleton);
4711 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004712 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004713 Py_INCREF(astmodulestate_global->Lt_singleton);
4714 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004715 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004716 Py_INCREF(astmodulestate_global->LtE_singleton);
4717 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004718 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004719 Py_INCREF(astmodulestate_global->Gt_singleton);
4720 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004721 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004722 Py_INCREF(astmodulestate_global->GtE_singleton);
4723 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004724 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004725 Py_INCREF(astmodulestate_global->Is_singleton);
4726 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004727 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004728 Py_INCREF(astmodulestate_global->IsNot_singleton);
4729 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004730 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004731 Py_INCREF(astmodulestate_global->In_singleton);
4732 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004733 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004734 Py_INCREF(astmodulestate_global->NotIn_singleton);
4735 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004736 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004737 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004738}
4739PyObject*
4740ast2obj_comprehension(void* _o)
4741{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004742 comprehension_ty o = (comprehension_ty)_o;
4743 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004744 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004745 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004746 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004747 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004748
Dino Viehlandac46eb42019-09-11 10:16:34 -07004749 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4750 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004751 if (!result) return NULL;
4752 value = ast2obj_expr(o->target);
4753 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004754 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004755 goto failed;
4756 Py_DECREF(value);
4757 value = ast2obj_expr(o->iter);
4758 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004759 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 goto failed;
4761 Py_DECREF(value);
4762 value = ast2obj_list(o->ifs, ast2obj_expr);
4763 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004764 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 goto failed;
4766 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004767 value = ast2obj_int(o->is_async);
4768 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004769 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004770 goto failed;
4771 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004772 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004773failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004774 Py_XDECREF(value);
4775 Py_XDECREF(result);
4776 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004777}
4778
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004779PyObject*
4780ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004781{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 excepthandler_ty o = (excepthandler_ty)_o;
4783 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004784 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004785 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004786 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004787 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004788
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004789 switch (o->kind) {
4790 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004791 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4792 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004793 if (!result) goto failed;
4794 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004795 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004796 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004798 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004799 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004800 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004801 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004802 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004803 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004804 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004806 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004807 goto failed;
4808 Py_DECREF(value);
4809 break;
4810 }
4811 value = ast2obj_int(o->lineno);
4812 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004813 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004814 goto failed;
4815 Py_DECREF(value);
4816 value = ast2obj_int(o->col_offset);
4817 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004818 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004819 goto failed;
4820 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004821 value = ast2obj_int(o->end_lineno);
4822 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004823 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004824 goto failed;
4825 Py_DECREF(value);
4826 value = ast2obj_int(o->end_col_offset);
4827 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004828 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4829 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004830 goto failed;
4831 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004832 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004833failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004834 Py_XDECREF(value);
4835 Py_XDECREF(result);
4836 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004837}
4838
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004839PyObject*
4840ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004841{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004842 arguments_ty o = (arguments_ty)_o;
4843 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004844 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004845 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004846 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004847 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004848
Dino Viehlandac46eb42019-09-11 10:16:34 -07004849 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4850 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004851 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004852 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4853 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004854 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4855 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004856 goto failed;
4857 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004858 value = ast2obj_list(o->args, ast2obj_arg);
4859 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004860 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004861 goto failed;
4862 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004863 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004864 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004865 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004866 goto failed;
4867 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004868 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4869 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004870 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4871 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004872 goto failed;
4873 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004874 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004875 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004876 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4877 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 goto failed;
4879 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004880 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004881 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004882 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004883 goto failed;
4884 Py_DECREF(value);
4885 value = ast2obj_list(o->defaults, ast2obj_expr);
4886 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004887 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004888 goto failed;
4889 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004890 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004891failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004892 Py_XDECREF(value);
4893 Py_XDECREF(result);
4894 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004895}
4896
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004897PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004898ast2obj_arg(void* _o)
4899{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004900 arg_ty o = (arg_ty)_o;
4901 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004902 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004903 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004904 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004905 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004906
Dino Viehlandac46eb42019-09-11 10:16:34 -07004907 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4908 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004909 if (!result) return NULL;
4910 value = ast2obj_identifier(o->arg);
4911 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004912 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004913 goto failed;
4914 Py_DECREF(value);
4915 value = ast2obj_expr(o->annotation);
4916 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004917 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4918 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004919 goto failed;
4920 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004921 value = ast2obj_string(o->type_comment);
4922 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004923 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4924 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004925 goto failed;
4926 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004927 value = ast2obj_int(o->lineno);
4928 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004929 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004930 goto failed;
4931 Py_DECREF(value);
4932 value = ast2obj_int(o->col_offset);
4933 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004934 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004935 goto failed;
4936 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004937 value = ast2obj_int(o->end_lineno);
4938 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004939 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004940 goto failed;
4941 Py_DECREF(value);
4942 value = ast2obj_int(o->end_col_offset);
4943 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004944 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4945 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004946 goto failed;
4947 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004948 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004949failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004950 Py_XDECREF(value);
4951 Py_XDECREF(result);
4952 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004953}
4954
4955PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004956ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004957{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004958 keyword_ty o = (keyword_ty)_o;
4959 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004960 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004961 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004962 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004963 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004964
Dino Viehlandac46eb42019-09-11 10:16:34 -07004965 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4966 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004967 if (!result) return NULL;
4968 value = ast2obj_identifier(o->arg);
4969 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004970 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004971 goto failed;
4972 Py_DECREF(value);
4973 value = ast2obj_expr(o->value);
4974 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004975 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004976 goto failed;
4977 Py_DECREF(value);
Pablo Galindo168660b2020-04-02 00:47:39 +01004978 value = ast2obj_int(o->lineno);
4979 if (!value) goto failed;
4980 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
4981 goto failed;
4982 Py_DECREF(value);
4983 value = ast2obj_int(o->col_offset);
4984 if (!value) goto failed;
4985 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
4986 goto failed;
4987 Py_DECREF(value);
4988 value = ast2obj_int(o->end_lineno);
4989 if (!value) goto failed;
4990 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
4991 goto failed;
4992 Py_DECREF(value);
4993 value = ast2obj_int(o->end_col_offset);
4994 if (!value) goto failed;
4995 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4996 < 0)
4997 goto failed;
4998 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004999 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005000failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005001 Py_XDECREF(value);
5002 Py_XDECREF(result);
5003 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005004}
5005
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005006PyObject*
5007ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005008{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005009 alias_ty o = (alias_ty)_o;
5010 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005011 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005012 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005013 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005014 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005015
Dino Viehlandac46eb42019-09-11 10:16:34 -07005016 tp = (PyTypeObject *)astmodulestate_global->alias_type;
5017 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005018 if (!result) return NULL;
5019 value = ast2obj_identifier(o->name);
5020 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005021 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005022 goto failed;
5023 Py_DECREF(value);
5024 value = ast2obj_identifier(o->asname);
5025 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005026 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005027 goto failed;
5028 Py_DECREF(value);
5029 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005030failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005031 Py_XDECREF(value);
5032 Py_XDECREF(result);
5033 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005034}
5035
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005036PyObject*
5037ast2obj_withitem(void* _o)
5038{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005039 withitem_ty o = (withitem_ty)_o;
5040 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005041 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005042 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005043 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005044 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005045
Dino Viehlandac46eb42019-09-11 10:16:34 -07005046 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
5047 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005048 if (!result) return NULL;
5049 value = ast2obj_expr(o->context_expr);
5050 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005051 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
5052 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005053 goto failed;
5054 Py_DECREF(value);
5055 value = ast2obj_expr(o->optional_vars);
5056 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005057 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
5058 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005059 goto failed;
5060 Py_DECREF(value);
5061 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005062failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005063 Py_XDECREF(value);
5064 Py_XDECREF(result);
5065 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005066}
5067
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005068PyObject*
5069ast2obj_type_ignore(void* _o)
5070{
5071 type_ignore_ty o = (type_ignore_ty)_o;
5072 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005073 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005074 if (!o) {
5075 Py_RETURN_NONE;
5076 }
5077
5078 switch (o->kind) {
5079 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005080 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5081 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005082 if (!result) goto failed;
5083 value = ast2obj_int(o->v.TypeIgnore.lineno);
5084 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005085 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5086 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005087 goto failed;
5088 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005089 value = ast2obj_string(o->v.TypeIgnore.tag);
5090 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005091 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005092 goto failed;
5093 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005094 break;
5095 }
5096 return result;
5097failed:
5098 Py_XDECREF(value);
5099 Py_XDECREF(result);
5100 return NULL;
5101}
5102
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005103
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005104int
5105obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5106{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005107 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005108
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005109 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005110 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005111
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005112 if (obj == Py_None) {
5113 *out = NULL;
5114 return 0;
5115 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005116 tp = astmodulestate_global->Module_type;
5117 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005118 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005119 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005120 }
5121 if (isinstance) {
5122 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005123 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005124
Dino Viehlandac46eb42019-09-11 10:16:34 -07005125 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005126 return 1;
5127 }
5128 if (tmp == NULL) {
5129 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5130 return 1;
5131 }
5132 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005133 int res;
5134 Py_ssize_t len;
5135 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005136 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005137 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 +02005138 goto failed;
5139 }
5140 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005141 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005142 if (body == NULL) goto failed;
5143 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005144 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005145 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5146 Py_INCREF(tmp2);
5147 res = obj2ast_stmt(tmp2, &val, arena);
5148 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005149 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005150 if (len != PyList_GET_SIZE(tmp)) {
5151 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5152 goto failed;
5153 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005154 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005155 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005156 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005157 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005158 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5159 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005160 return 1;
5161 }
5162 if (tmp == NULL) {
5163 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5164 return 1;
5165 }
5166 else {
5167 int res;
5168 Py_ssize_t len;
5169 Py_ssize_t i;
5170 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005171 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 -08005172 goto failed;
5173 }
5174 len = PyList_GET_SIZE(tmp);
5175 type_ignores = _Py_asdl_seq_new(len, arena);
5176 if (type_ignores == NULL) goto failed;
5177 for (i = 0; i < len; i++) {
5178 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005179 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5180 Py_INCREF(tmp2);
5181 res = obj2ast_type_ignore(tmp2, &val, arena);
5182 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005183 if (res != 0) goto failed;
5184 if (len != PyList_GET_SIZE(tmp)) {
5185 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5186 goto failed;
5187 }
5188 asdl_seq_SET(type_ignores, i, val);
5189 }
5190 Py_CLEAR(tmp);
5191 }
5192 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005193 if (*out == NULL) goto failed;
5194 return 0;
5195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005196 tp = astmodulestate_global->Interactive_type;
5197 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005198 if (isinstance == -1) {
5199 return 1;
5200 }
5201 if (isinstance) {
5202 asdl_seq* body;
5203
Dino Viehlandac46eb42019-09-11 10:16:34 -07005204 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005205 return 1;
5206 }
5207 if (tmp == NULL) {
5208 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5209 return 1;
5210 }
5211 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005212 int res;
5213 Py_ssize_t len;
5214 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005215 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005216 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 +02005217 goto failed;
5218 }
5219 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005220 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005221 if (body == NULL) goto failed;
5222 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005223 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005224 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5225 Py_INCREF(tmp2);
5226 res = obj2ast_stmt(tmp2, &val, arena);
5227 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005228 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005229 if (len != PyList_GET_SIZE(tmp)) {
5230 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5231 goto failed;
5232 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005233 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005234 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005235 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005236 }
5237 *out = Interactive(body, arena);
5238 if (*out == NULL) goto failed;
5239 return 0;
5240 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005241 tp = astmodulestate_global->Expression_type;
5242 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005243 if (isinstance == -1) {
5244 return 1;
5245 }
5246 if (isinstance) {
5247 expr_ty body;
5248
Dino Viehlandac46eb42019-09-11 10:16:34 -07005249 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005250 return 1;
5251 }
5252 if (tmp == NULL) {
5253 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5254 return 1;
5255 }
5256 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005257 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005258 res = obj2ast_expr(tmp, &body, arena);
5259 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005260 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005261 }
5262 *out = Expression(body, arena);
5263 if (*out == NULL) goto failed;
5264 return 0;
5265 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005266 tp = astmodulestate_global->FunctionType_type;
5267 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005268 if (isinstance == -1) {
5269 return 1;
5270 }
5271 if (isinstance) {
5272 asdl_seq* argtypes;
5273 expr_ty returns;
5274
Dino Viehlandac46eb42019-09-11 10:16:34 -07005275 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5276 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005277 return 1;
5278 }
5279 if (tmp == NULL) {
5280 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5281 return 1;
5282 }
5283 else {
5284 int res;
5285 Py_ssize_t len;
5286 Py_ssize_t i;
5287 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005288 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 -08005289 goto failed;
5290 }
5291 len = PyList_GET_SIZE(tmp);
5292 argtypes = _Py_asdl_seq_new(len, arena);
5293 if (argtypes == NULL) goto failed;
5294 for (i = 0; i < len; i++) {
5295 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005296 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5297 Py_INCREF(tmp2);
5298 res = obj2ast_expr(tmp2, &val, arena);
5299 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005300 if (res != 0) goto failed;
5301 if (len != PyList_GET_SIZE(tmp)) {
5302 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5303 goto failed;
5304 }
5305 asdl_seq_SET(argtypes, i, val);
5306 }
5307 Py_CLEAR(tmp);
5308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005309 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5310 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005311 return 1;
5312 }
5313 if (tmp == NULL) {
5314 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5315 return 1;
5316 }
5317 else {
5318 int res;
5319 res = obj2ast_expr(tmp, &returns, arena);
5320 if (res != 0) goto failed;
5321 Py_CLEAR(tmp);
5322 }
5323 *out = FunctionType(argtypes, returns, arena);
5324 if (*out == NULL) goto failed;
5325 return 0;
5326 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005327
5328 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5329 failed:
5330 Py_XDECREF(tmp);
5331 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005332}
5333
5334int
5335obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5336{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005337 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005338
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005339 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005340 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005341 int lineno;
5342 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005343 int end_lineno;
5344 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005345
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005346 if (obj == Py_None) {
5347 *out = NULL;
5348 return 0;
5349 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005350 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005351 return 1;
5352 }
5353 if (tmp == NULL) {
5354 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5355 return 1;
5356 }
5357 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005358 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005359 res = obj2ast_int(tmp, &lineno, arena);
5360 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005361 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005362 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005363 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5364 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005365 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005366 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005367 if (tmp == NULL) {
5368 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5369 return 1;
5370 }
5371 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005372 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005373 res = obj2ast_int(tmp, &col_offset, arena);
5374 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005375 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005376 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005377 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5378 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005379 return 1;
5380 }
5381 if (tmp == NULL || tmp == Py_None) {
5382 Py_CLEAR(tmp);
5383 end_lineno = 0;
5384 }
5385 else {
5386 int res;
5387 res = obj2ast_int(tmp, &end_lineno, arena);
5388 if (res != 0) goto failed;
5389 Py_CLEAR(tmp);
5390 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005391 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5392 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005393 return 1;
5394 }
5395 if (tmp == NULL || tmp == Py_None) {
5396 Py_CLEAR(tmp);
5397 end_col_offset = 0;
5398 }
5399 else {
5400 int res;
5401 res = obj2ast_int(tmp, &end_col_offset, arena);
5402 if (res != 0) goto failed;
5403 Py_CLEAR(tmp);
5404 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005405 tp = astmodulestate_global->FunctionDef_type;
5406 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005407 if (isinstance == -1) {
5408 return 1;
5409 }
5410 if (isinstance) {
5411 identifier name;
5412 arguments_ty args;
5413 asdl_seq* body;
5414 asdl_seq* decorator_list;
5415 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005416 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005417
Dino Viehlandac46eb42019-09-11 10:16:34 -07005418 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005419 return 1;
5420 }
5421 if (tmp == NULL) {
5422 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5423 return 1;
5424 }
5425 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005426 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005427 res = obj2ast_identifier(tmp, &name, arena);
5428 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005429 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005430 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005431 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005432 return 1;
5433 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005434 if (tmp == NULL) {
5435 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5436 return 1;
5437 }
5438 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005439 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005440 res = obj2ast_arguments(tmp, &args, arena);
5441 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005442 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005443 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005444 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005445 return 1;
5446 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005447 if (tmp == NULL) {
5448 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5449 return 1;
5450 }
5451 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005452 int res;
5453 Py_ssize_t len;
5454 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005455 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005456 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 +02005457 goto failed;
5458 }
5459 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005460 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005461 if (body == NULL) goto failed;
5462 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005463 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005464 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5465 Py_INCREF(tmp2);
5466 res = obj2ast_stmt(tmp2, &val, arena);
5467 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005468 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005469 if (len != PyList_GET_SIZE(tmp)) {
5470 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5471 goto failed;
5472 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005473 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005474 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005475 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005476 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005477 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5478 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005479 return 1;
5480 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005481 if (tmp == NULL) {
5482 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5483 return 1;
5484 }
5485 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005486 int res;
5487 Py_ssize_t len;
5488 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005489 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005490 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 +02005491 goto failed;
5492 }
5493 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005494 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005495 if (decorator_list == NULL) goto failed;
5496 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005497 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005498 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5499 Py_INCREF(tmp2);
5500 res = obj2ast_expr(tmp2, &val, arena);
5501 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005502 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005503 if (len != PyList_GET_SIZE(tmp)) {
5504 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5505 goto failed;
5506 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005507 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005508 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005509 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005510 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005511 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5512 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005513 return 1;
5514 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005515 if (tmp == NULL || tmp == Py_None) {
5516 Py_CLEAR(tmp);
5517 returns = NULL;
5518 }
5519 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005520 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005521 res = obj2ast_expr(tmp, &returns, arena);
5522 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005523 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005524 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005525 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5526 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005527 return 1;
5528 }
5529 if (tmp == NULL || tmp == Py_None) {
5530 Py_CLEAR(tmp);
5531 type_comment = NULL;
5532 }
5533 else {
5534 int res;
5535 res = obj2ast_string(tmp, &type_comment, arena);
5536 if (res != 0) goto failed;
5537 Py_CLEAR(tmp);
5538 }
5539 *out = FunctionDef(name, args, body, decorator_list, returns,
5540 type_comment, lineno, col_offset, end_lineno,
5541 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005542 if (*out == NULL) goto failed;
5543 return 0;
5544 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005545 tp = astmodulestate_global->AsyncFunctionDef_type;
5546 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005547 if (isinstance == -1) {
5548 return 1;
5549 }
5550 if (isinstance) {
5551 identifier name;
5552 arguments_ty args;
5553 asdl_seq* body;
5554 asdl_seq* decorator_list;
5555 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005556 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005557
Dino Viehlandac46eb42019-09-11 10:16:34 -07005558 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005559 return 1;
5560 }
5561 if (tmp == NULL) {
5562 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5563 return 1;
5564 }
5565 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005566 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005567 res = obj2ast_identifier(tmp, &name, arena);
5568 if (res != 0) goto failed;
5569 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005570 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005571 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005572 return 1;
5573 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005574 if (tmp == NULL) {
5575 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5576 return 1;
5577 }
5578 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005579 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005580 res = obj2ast_arguments(tmp, &args, arena);
5581 if (res != 0) goto failed;
5582 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005583 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005584 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005585 return 1;
5586 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005587 if (tmp == NULL) {
5588 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5589 return 1;
5590 }
5591 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005592 int res;
5593 Py_ssize_t len;
5594 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005595 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005596 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 -04005597 goto failed;
5598 }
5599 len = PyList_GET_SIZE(tmp);
5600 body = _Py_asdl_seq_new(len, arena);
5601 if (body == NULL) goto failed;
5602 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005603 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005604 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5605 Py_INCREF(tmp2);
5606 res = obj2ast_stmt(tmp2, &val, arena);
5607 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005608 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005609 if (len != PyList_GET_SIZE(tmp)) {
5610 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5611 goto failed;
5612 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005613 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005614 }
5615 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005616 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005617 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5618 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005619 return 1;
5620 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005621 if (tmp == NULL) {
5622 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5623 return 1;
5624 }
5625 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005626 int res;
5627 Py_ssize_t len;
5628 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005629 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005630 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 -04005631 goto failed;
5632 }
5633 len = PyList_GET_SIZE(tmp);
5634 decorator_list = _Py_asdl_seq_new(len, arena);
5635 if (decorator_list == NULL) goto failed;
5636 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005637 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005638 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5639 Py_INCREF(tmp2);
5640 res = obj2ast_expr(tmp2, &val, arena);
5641 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005642 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005643 if (len != PyList_GET_SIZE(tmp)) {
5644 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5645 goto failed;
5646 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005647 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005648 }
5649 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005650 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005651 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5652 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005653 return 1;
5654 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005655 if (tmp == NULL || tmp == Py_None) {
5656 Py_CLEAR(tmp);
5657 returns = NULL;
5658 }
5659 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005660 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005661 res = obj2ast_expr(tmp, &returns, arena);
5662 if (res != 0) goto failed;
5663 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005664 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005665 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5666 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005667 return 1;
5668 }
5669 if (tmp == NULL || tmp == Py_None) {
5670 Py_CLEAR(tmp);
5671 type_comment = NULL;
5672 }
5673 else {
5674 int res;
5675 res = obj2ast_string(tmp, &type_comment, arena);
5676 if (res != 0) goto failed;
5677 Py_CLEAR(tmp);
5678 }
Yury Selivanov75445082015-05-11 22:57:16 -04005679 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005680 type_comment, lineno, col_offset, end_lineno,
5681 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005682 if (*out == NULL) goto failed;
5683 return 0;
5684 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005685 tp = astmodulestate_global->ClassDef_type;
5686 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005687 if (isinstance == -1) {
5688 return 1;
5689 }
5690 if (isinstance) {
5691 identifier name;
5692 asdl_seq* bases;
5693 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005694 asdl_seq* body;
5695 asdl_seq* decorator_list;
5696
Dino Viehlandac46eb42019-09-11 10:16:34 -07005697 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005698 return 1;
5699 }
5700 if (tmp == NULL) {
5701 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5702 return 1;
5703 }
5704 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005705 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005706 res = obj2ast_identifier(tmp, &name, arena);
5707 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005708 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005709 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005710 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005711 return 1;
5712 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005713 if (tmp == NULL) {
5714 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5715 return 1;
5716 }
5717 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005718 int res;
5719 Py_ssize_t len;
5720 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005721 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005722 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 +02005723 goto failed;
5724 }
5725 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005726 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005727 if (bases == NULL) goto failed;
5728 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005729 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005730 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5731 Py_INCREF(tmp2);
5732 res = obj2ast_expr(tmp2, &val, arena);
5733 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005734 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005735 if (len != PyList_GET_SIZE(tmp)) {
5736 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5737 goto failed;
5738 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005739 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005740 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005741 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005742 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005743 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5744 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005745 return 1;
5746 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005747 if (tmp == NULL) {
5748 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5749 return 1;
5750 }
5751 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005752 int res;
5753 Py_ssize_t len;
5754 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005755 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005756 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 +02005757 goto failed;
5758 }
5759 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005760 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005761 if (keywords == NULL) goto failed;
5762 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005763 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005764 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5765 Py_INCREF(tmp2);
5766 res = obj2ast_keyword(tmp2, &val, arena);
5767 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005768 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005769 if (len != PyList_GET_SIZE(tmp)) {
5770 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5771 goto failed;
5772 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005773 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005774 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005775 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005776 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005777 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005778 return 1;
5779 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005780 if (tmp == NULL) {
5781 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5782 return 1;
5783 }
5784 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005785 int res;
5786 Py_ssize_t len;
5787 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005788 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005789 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 +02005790 goto failed;
5791 }
5792 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005793 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005794 if (body == NULL) goto failed;
5795 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005796 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005797 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5798 Py_INCREF(tmp2);
5799 res = obj2ast_stmt(tmp2, &val, arena);
5800 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005801 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005802 if (len != PyList_GET_SIZE(tmp)) {
5803 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5804 goto failed;
5805 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005806 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005807 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005808 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005809 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005810 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5811 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005812 return 1;
5813 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005814 if (tmp == NULL) {
5815 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5816 return 1;
5817 }
5818 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005819 int res;
5820 Py_ssize_t len;
5821 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005822 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005823 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 +02005824 goto failed;
5825 }
5826 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005827 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005828 if (decorator_list == NULL) goto failed;
5829 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005830 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005831 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5832 Py_INCREF(tmp2);
5833 res = obj2ast_expr(tmp2, &val, arena);
5834 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005835 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005836 if (len != PyList_GET_SIZE(tmp)) {
5837 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5838 goto failed;
5839 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005840 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005841 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005842 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005843 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005844 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005845 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005846 if (*out == NULL) goto failed;
5847 return 0;
5848 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005849 tp = astmodulestate_global->Return_type;
5850 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005851 if (isinstance == -1) {
5852 return 1;
5853 }
5854 if (isinstance) {
5855 expr_ty value;
5856
Dino Viehlandac46eb42019-09-11 10:16:34 -07005857 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005858 return 1;
5859 }
5860 if (tmp == NULL || tmp == Py_None) {
5861 Py_CLEAR(tmp);
5862 value = NULL;
5863 }
5864 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005865 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005866 res = obj2ast_expr(tmp, &value, arena);
5867 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005868 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005869 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005870 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5871 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005872 if (*out == NULL) goto failed;
5873 return 0;
5874 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005875 tp = astmodulestate_global->Delete_type;
5876 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005877 if (isinstance == -1) {
5878 return 1;
5879 }
5880 if (isinstance) {
5881 asdl_seq* targets;
5882
Dino Viehlandac46eb42019-09-11 10:16:34 -07005883 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5884 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005885 return 1;
5886 }
5887 if (tmp == NULL) {
5888 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5889 return 1;
5890 }
5891 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005892 int res;
5893 Py_ssize_t len;
5894 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005895 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005896 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 +02005897 goto failed;
5898 }
5899 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005900 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005901 if (targets == NULL) goto failed;
5902 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005903 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005904 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5905 Py_INCREF(tmp2);
5906 res = obj2ast_expr(tmp2, &val, arena);
5907 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005908 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005909 if (len != PyList_GET_SIZE(tmp)) {
5910 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5911 goto failed;
5912 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005913 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005914 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005915 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005916 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005917 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5918 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005919 if (*out == NULL) goto failed;
5920 return 0;
5921 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005922 tp = astmodulestate_global->Assign_type;
5923 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005924 if (isinstance == -1) {
5925 return 1;
5926 }
5927 if (isinstance) {
5928 asdl_seq* targets;
5929 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005930 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005931
Dino Viehlandac46eb42019-09-11 10:16:34 -07005932 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5933 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005934 return 1;
5935 }
5936 if (tmp == NULL) {
5937 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5938 return 1;
5939 }
5940 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005941 int res;
5942 Py_ssize_t len;
5943 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005944 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005945 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 +02005946 goto failed;
5947 }
5948 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005949 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005950 if (targets == NULL) goto failed;
5951 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005952 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005953 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5954 Py_INCREF(tmp2);
5955 res = obj2ast_expr(tmp2, &val, arena);
5956 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005957 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005958 if (len != PyList_GET_SIZE(tmp)) {
5959 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5960 goto failed;
5961 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005962 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005963 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005964 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005965 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005966 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005967 return 1;
5968 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005969 if (tmp == NULL) {
5970 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5971 return 1;
5972 }
5973 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005974 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005975 res = obj2ast_expr(tmp, &value, arena);
5976 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005977 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005978 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005979 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5980 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005981 return 1;
5982 }
5983 if (tmp == NULL || tmp == Py_None) {
5984 Py_CLEAR(tmp);
5985 type_comment = NULL;
5986 }
5987 else {
5988 int res;
5989 res = obj2ast_string(tmp, &type_comment, arena);
5990 if (res != 0) goto failed;
5991 Py_CLEAR(tmp);
5992 }
5993 *out = Assign(targets, value, type_comment, lineno, col_offset,
5994 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005995 if (*out == NULL) goto failed;
5996 return 0;
5997 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005998 tp = astmodulestate_global->AugAssign_type;
5999 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006000 if (isinstance == -1) {
6001 return 1;
6002 }
6003 if (isinstance) {
6004 expr_ty target;
6005 operator_ty op;
6006 expr_ty value;
6007
Dino Viehlandac46eb42019-09-11 10:16:34 -07006008 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6009 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006010 return 1;
6011 }
6012 if (tmp == NULL) {
6013 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
6014 return 1;
6015 }
6016 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006017 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006018 res = obj2ast_expr(tmp, &target, arena);
6019 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006020 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006021 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006022 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006023 return 1;
6024 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006025 if (tmp == NULL) {
6026 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6027 return 1;
6028 }
6029 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006030 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006031 res = obj2ast_operator(tmp, &op, arena);
6032 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006033 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006035 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006036 return 1;
6037 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006038 if (tmp == NULL) {
6039 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6040 return 1;
6041 }
6042 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006043 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006044 res = obj2ast_expr(tmp, &value, arena);
6045 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006046 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006047 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006048 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
6049 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006050 if (*out == NULL) goto failed;
6051 return 0;
6052 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006053 tp = astmodulestate_global->AnnAssign_type;
6054 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006055 if (isinstance == -1) {
6056 return 1;
6057 }
6058 if (isinstance) {
6059 expr_ty target;
6060 expr_ty annotation;
6061 expr_ty value;
6062 int simple;
6063
Dino Viehlandac46eb42019-09-11 10:16:34 -07006064 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6065 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006066 return 1;
6067 }
6068 if (tmp == NULL) {
6069 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6070 return 1;
6071 }
6072 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006073 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006074 res = obj2ast_expr(tmp, &target, arena);
6075 if (res != 0) goto failed;
6076 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006078 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6079 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006080 return 1;
6081 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006082 if (tmp == NULL) {
6083 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6084 return 1;
6085 }
6086 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006087 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006088 res = obj2ast_expr(tmp, &annotation, arena);
6089 if (res != 0) goto failed;
6090 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006091 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006092 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006093 return 1;
6094 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006095 if (tmp == NULL || tmp == Py_None) {
6096 Py_CLEAR(tmp);
6097 value = NULL;
6098 }
6099 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006100 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006101 res = obj2ast_expr(tmp, &value, arena);
6102 if (res != 0) goto failed;
6103 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006105 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6106 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006107 return 1;
6108 }
6109 if (tmp == NULL) {
6110 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6111 return 1;
6112 }
6113 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006114 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006115 res = obj2ast_int(tmp, &simple, arena);
6116 if (res != 0) goto failed;
6117 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006118 }
6119 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006120 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006121 if (*out == NULL) goto failed;
6122 return 0;
6123 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006124 tp = astmodulestate_global->For_type;
6125 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006126 if (isinstance == -1) {
6127 return 1;
6128 }
6129 if (isinstance) {
6130 expr_ty target;
6131 expr_ty iter;
6132 asdl_seq* body;
6133 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006134 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006135
Dino Viehlandac46eb42019-09-11 10:16:34 -07006136 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6137 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006138 return 1;
6139 }
6140 if (tmp == NULL) {
6141 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6142 return 1;
6143 }
6144 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006145 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006146 res = obj2ast_expr(tmp, &target, arena);
6147 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006148 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006149 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006150 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006151 return 1;
6152 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006153 if (tmp == NULL) {
6154 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6155 return 1;
6156 }
6157 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006158 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006159 res = obj2ast_expr(tmp, &iter, arena);
6160 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006161 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006162 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006163 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006164 return 1;
6165 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006166 if (tmp == NULL) {
6167 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6168 return 1;
6169 }
6170 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006171 int res;
6172 Py_ssize_t len;
6173 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006174 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006175 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 +02006176 goto failed;
6177 }
6178 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006179 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006180 if (body == NULL) goto failed;
6181 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006182 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006183 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6184 Py_INCREF(tmp2);
6185 res = obj2ast_stmt(tmp2, &val, arena);
6186 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006187 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006188 if (len != PyList_GET_SIZE(tmp)) {
6189 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6190 goto failed;
6191 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006192 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006193 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006194 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006196 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6197 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006198 return 1;
6199 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006200 if (tmp == NULL) {
6201 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6202 return 1;
6203 }
6204 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006205 int res;
6206 Py_ssize_t len;
6207 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006208 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006209 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 +02006210 goto failed;
6211 }
6212 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006213 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006214 if (orelse == NULL) goto failed;
6215 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006216 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006217 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6218 Py_INCREF(tmp2);
6219 res = obj2ast_stmt(tmp2, &val, arena);
6220 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006221 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006222 if (len != PyList_GET_SIZE(tmp)) {
6223 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6224 goto failed;
6225 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006226 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006227 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006228 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006230 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6231 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006232 return 1;
6233 }
6234 if (tmp == NULL || tmp == Py_None) {
6235 Py_CLEAR(tmp);
6236 type_comment = NULL;
6237 }
6238 else {
6239 int res;
6240 res = obj2ast_string(tmp, &type_comment, arena);
6241 if (res != 0) goto failed;
6242 Py_CLEAR(tmp);
6243 }
6244 *out = For(target, iter, body, orelse, type_comment, lineno,
6245 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006246 if (*out == NULL) goto failed;
6247 return 0;
6248 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006249 tp = astmodulestate_global->AsyncFor_type;
6250 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006251 if (isinstance == -1) {
6252 return 1;
6253 }
6254 if (isinstance) {
6255 expr_ty target;
6256 expr_ty iter;
6257 asdl_seq* body;
6258 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006259 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006260
Dino Viehlandac46eb42019-09-11 10:16:34 -07006261 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6262 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006263 return 1;
6264 }
6265 if (tmp == NULL) {
6266 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6267 return 1;
6268 }
6269 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006270 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006271 res = obj2ast_expr(tmp, &target, arena);
6272 if (res != 0) goto failed;
6273 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006274 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006275 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006276 return 1;
6277 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006278 if (tmp == NULL) {
6279 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6280 return 1;
6281 }
6282 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006283 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006284 res = obj2ast_expr(tmp, &iter, arena);
6285 if (res != 0) goto failed;
6286 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006288 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006289 return 1;
6290 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006291 if (tmp == NULL) {
6292 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6293 return 1;
6294 }
6295 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006296 int res;
6297 Py_ssize_t len;
6298 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006299 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006300 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 -04006301 goto failed;
6302 }
6303 len = PyList_GET_SIZE(tmp);
6304 body = _Py_asdl_seq_new(len, arena);
6305 if (body == NULL) goto failed;
6306 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006307 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006308 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6309 Py_INCREF(tmp2);
6310 res = obj2ast_stmt(tmp2, &val, arena);
6311 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006312 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006313 if (len != PyList_GET_SIZE(tmp)) {
6314 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6315 goto failed;
6316 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006317 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006318 }
6319 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006320 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006321 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6322 {
Yury Selivanov75445082015-05-11 22:57:16 -04006323 return 1;
6324 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006325 if (tmp == NULL) {
6326 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6327 return 1;
6328 }
6329 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006330 int res;
6331 Py_ssize_t len;
6332 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006333 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006334 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 -04006335 goto failed;
6336 }
6337 len = PyList_GET_SIZE(tmp);
6338 orelse = _Py_asdl_seq_new(len, arena);
6339 if (orelse == NULL) goto failed;
6340 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006341 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006342 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6343 Py_INCREF(tmp2);
6344 res = obj2ast_stmt(tmp2, &val, arena);
6345 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006346 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006347 if (len != PyList_GET_SIZE(tmp)) {
6348 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6349 goto failed;
6350 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006351 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006352 }
6353 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006355 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6356 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006357 return 1;
6358 }
6359 if (tmp == NULL || tmp == Py_None) {
6360 Py_CLEAR(tmp);
6361 type_comment = NULL;
6362 }
6363 else {
6364 int res;
6365 res = obj2ast_string(tmp, &type_comment, arena);
6366 if (res != 0) goto failed;
6367 Py_CLEAR(tmp);
6368 }
6369 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6370 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006371 if (*out == NULL) goto failed;
6372 return 0;
6373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006374 tp = astmodulestate_global->While_type;
6375 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006376 if (isinstance == -1) {
6377 return 1;
6378 }
6379 if (isinstance) {
6380 expr_ty test;
6381 asdl_seq* body;
6382 asdl_seq* orelse;
6383
Dino Viehlandac46eb42019-09-11 10:16:34 -07006384 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006385 return 1;
6386 }
6387 if (tmp == NULL) {
6388 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6389 return 1;
6390 }
6391 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006392 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006393 res = obj2ast_expr(tmp, &test, arena);
6394 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006395 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006396 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006397 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006398 return 1;
6399 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006400 if (tmp == NULL) {
6401 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6402 return 1;
6403 }
6404 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006405 int res;
6406 Py_ssize_t len;
6407 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006408 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006409 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 +02006410 goto failed;
6411 }
6412 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006413 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006414 if (body == NULL) goto failed;
6415 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006416 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006417 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6418 Py_INCREF(tmp2);
6419 res = obj2ast_stmt(tmp2, &val, arena);
6420 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006421 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006422 if (len != PyList_GET_SIZE(tmp)) {
6423 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6424 goto failed;
6425 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006426 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006427 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006428 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006429 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006430 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6431 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006432 return 1;
6433 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006434 if (tmp == NULL) {
6435 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6436 return 1;
6437 }
6438 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006439 int res;
6440 Py_ssize_t len;
6441 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006442 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006443 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 +02006444 goto failed;
6445 }
6446 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006447 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006448 if (orelse == NULL) goto failed;
6449 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006450 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006451 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6452 Py_INCREF(tmp2);
6453 res = obj2ast_stmt(tmp2, &val, arena);
6454 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006455 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006456 if (len != PyList_GET_SIZE(tmp)) {
6457 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6458 goto failed;
6459 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006460 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006461 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006462 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006463 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006464 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6465 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006466 if (*out == NULL) goto failed;
6467 return 0;
6468 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006469 tp = astmodulestate_global->If_type;
6470 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006471 if (isinstance == -1) {
6472 return 1;
6473 }
6474 if (isinstance) {
6475 expr_ty test;
6476 asdl_seq* body;
6477 asdl_seq* orelse;
6478
Dino Viehlandac46eb42019-09-11 10:16:34 -07006479 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006480 return 1;
6481 }
6482 if (tmp == NULL) {
6483 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6484 return 1;
6485 }
6486 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006487 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006488 res = obj2ast_expr(tmp, &test, arena);
6489 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006490 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006491 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006492 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006493 return 1;
6494 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006495 if (tmp == NULL) {
6496 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6497 return 1;
6498 }
6499 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006500 int res;
6501 Py_ssize_t len;
6502 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006503 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006504 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 +02006505 goto failed;
6506 }
6507 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006508 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006509 if (body == NULL) goto failed;
6510 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006511 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006512 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6513 Py_INCREF(tmp2);
6514 res = obj2ast_stmt(tmp2, &val, arena);
6515 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006516 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006517 if (len != PyList_GET_SIZE(tmp)) {
6518 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6519 goto failed;
6520 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006521 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006522 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006523 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006524 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006525 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6526 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006527 return 1;
6528 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006529 if (tmp == NULL) {
6530 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6531 return 1;
6532 }
6533 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006534 int res;
6535 Py_ssize_t len;
6536 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006537 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006538 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 +02006539 goto failed;
6540 }
6541 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006542 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006543 if (orelse == NULL) goto failed;
6544 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006545 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006546 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6547 Py_INCREF(tmp2);
6548 res = obj2ast_stmt(tmp2, &val, arena);
6549 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006550 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006551 if (len != PyList_GET_SIZE(tmp)) {
6552 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6553 goto failed;
6554 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006555 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006556 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006557 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006558 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006559 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6560 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006561 if (*out == NULL) goto failed;
6562 return 0;
6563 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006564 tp = astmodulestate_global->With_type;
6565 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006566 if (isinstance == -1) {
6567 return 1;
6568 }
6569 if (isinstance) {
6570 asdl_seq* items;
6571 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006572 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006573
Dino Viehlandac46eb42019-09-11 10:16:34 -07006574 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006575 return 1;
6576 }
6577 if (tmp == NULL) {
6578 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6579 return 1;
6580 }
6581 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006582 int res;
6583 Py_ssize_t len;
6584 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006585 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006586 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 +02006587 goto failed;
6588 }
6589 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006590 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006591 if (items == NULL) goto failed;
6592 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006593 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006594 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6595 Py_INCREF(tmp2);
6596 res = obj2ast_withitem(tmp2, &val, arena);
6597 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006598 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006599 if (len != PyList_GET_SIZE(tmp)) {
6600 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6601 goto failed;
6602 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006603 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006604 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006605 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006606 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006607 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006608 return 1;
6609 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006610 if (tmp == NULL) {
6611 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6612 return 1;
6613 }
6614 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006615 int res;
6616 Py_ssize_t len;
6617 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006618 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006619 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 +02006620 goto failed;
6621 }
6622 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006623 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006624 if (body == NULL) goto failed;
6625 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006626 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006627 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6628 Py_INCREF(tmp2);
6629 res = obj2ast_stmt(tmp2, &val, arena);
6630 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006631 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006632 if (len != PyList_GET_SIZE(tmp)) {
6633 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6634 goto failed;
6635 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006636 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006637 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006638 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006639 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006640 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6641 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006642 return 1;
6643 }
6644 if (tmp == NULL || tmp == Py_None) {
6645 Py_CLEAR(tmp);
6646 type_comment = NULL;
6647 }
6648 else {
6649 int res;
6650 res = obj2ast_string(tmp, &type_comment, arena);
6651 if (res != 0) goto failed;
6652 Py_CLEAR(tmp);
6653 }
6654 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006655 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006656 if (*out == NULL) goto failed;
6657 return 0;
6658 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006659 tp = astmodulestate_global->AsyncWith_type;
6660 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006661 if (isinstance == -1) {
6662 return 1;
6663 }
6664 if (isinstance) {
6665 asdl_seq* items;
6666 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006667 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006668
Dino Viehlandac46eb42019-09-11 10:16:34 -07006669 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006670 return 1;
6671 }
6672 if (tmp == NULL) {
6673 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6674 return 1;
6675 }
6676 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006677 int res;
6678 Py_ssize_t len;
6679 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006680 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006681 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 -04006682 goto failed;
6683 }
6684 len = PyList_GET_SIZE(tmp);
6685 items = _Py_asdl_seq_new(len, arena);
6686 if (items == NULL) goto failed;
6687 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006688 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006689 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6690 Py_INCREF(tmp2);
6691 res = obj2ast_withitem(tmp2, &val, arena);
6692 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006693 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006694 if (len != PyList_GET_SIZE(tmp)) {
6695 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6696 goto failed;
6697 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006698 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006699 }
6700 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006701 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006702 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006703 return 1;
6704 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006705 if (tmp == NULL) {
6706 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6707 return 1;
6708 }
6709 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006710 int res;
6711 Py_ssize_t len;
6712 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006713 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006714 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 -04006715 goto failed;
6716 }
6717 len = PyList_GET_SIZE(tmp);
6718 body = _Py_asdl_seq_new(len, arena);
6719 if (body == NULL) goto failed;
6720 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006721 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006722 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6723 Py_INCREF(tmp2);
6724 res = obj2ast_stmt(tmp2, &val, arena);
6725 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006726 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006727 if (len != PyList_GET_SIZE(tmp)) {
6728 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6729 goto failed;
6730 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006731 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006732 }
6733 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006734 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006735 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6736 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006737 return 1;
6738 }
6739 if (tmp == NULL || tmp == Py_None) {
6740 Py_CLEAR(tmp);
6741 type_comment = NULL;
6742 }
6743 else {
6744 int res;
6745 res = obj2ast_string(tmp, &type_comment, arena);
6746 if (res != 0) goto failed;
6747 Py_CLEAR(tmp);
6748 }
6749 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6750 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006751 if (*out == NULL) goto failed;
6752 return 0;
6753 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006754 tp = astmodulestate_global->Raise_type;
6755 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006756 if (isinstance == -1) {
6757 return 1;
6758 }
6759 if (isinstance) {
6760 expr_ty exc;
6761 expr_ty cause;
6762
Dino Viehlandac46eb42019-09-11 10:16:34 -07006763 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006764 return 1;
6765 }
6766 if (tmp == NULL || tmp == Py_None) {
6767 Py_CLEAR(tmp);
6768 exc = NULL;
6769 }
6770 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006771 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006772 res = obj2ast_expr(tmp, &exc, arena);
6773 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006774 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006775 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006776 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006777 return 1;
6778 }
6779 if (tmp == NULL || tmp == Py_None) {
6780 Py_CLEAR(tmp);
6781 cause = NULL;
6782 }
6783 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006784 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006785 res = obj2ast_expr(tmp, &cause, arena);
6786 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006787 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006788 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006789 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6790 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 if (*out == NULL) goto failed;
6792 return 0;
6793 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006794 tp = astmodulestate_global->Try_type;
6795 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006796 if (isinstance == -1) {
6797 return 1;
6798 }
6799 if (isinstance) {
6800 asdl_seq* body;
6801 asdl_seq* handlers;
6802 asdl_seq* orelse;
6803 asdl_seq* finalbody;
6804
Dino Viehlandac46eb42019-09-11 10:16:34 -07006805 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006806 return 1;
6807 }
6808 if (tmp == NULL) {
6809 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6810 return 1;
6811 }
6812 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006813 int res;
6814 Py_ssize_t len;
6815 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006816 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006817 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 +02006818 goto failed;
6819 }
6820 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006821 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006822 if (body == NULL) goto failed;
6823 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006824 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006825 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6826 Py_INCREF(tmp2);
6827 res = obj2ast_stmt(tmp2, &val, arena);
6828 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006829 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006830 if (len != PyList_GET_SIZE(tmp)) {
6831 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6832 goto failed;
6833 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006834 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006835 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006836 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006837 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006838 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6839 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006840 return 1;
6841 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006842 if (tmp == NULL) {
6843 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6844 return 1;
6845 }
6846 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006847 int res;
6848 Py_ssize_t len;
6849 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006850 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006851 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 +02006852 goto failed;
6853 }
6854 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006855 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006856 if (handlers == NULL) goto failed;
6857 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006858 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006859 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6860 Py_INCREF(tmp2);
6861 res = obj2ast_excepthandler(tmp2, &val, arena);
6862 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006863 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006864 if (len != PyList_GET_SIZE(tmp)) {
6865 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6866 goto failed;
6867 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006868 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006869 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006870 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006871 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006872 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6873 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006874 return 1;
6875 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006876 if (tmp == NULL) {
6877 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6878 return 1;
6879 }
6880 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006881 int res;
6882 Py_ssize_t len;
6883 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006884 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006885 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 +02006886 goto failed;
6887 }
6888 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006889 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006890 if (orelse == NULL) goto failed;
6891 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006892 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006893 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6894 Py_INCREF(tmp2);
6895 res = obj2ast_stmt(tmp2, &val, arena);
6896 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006897 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006898 if (len != PyList_GET_SIZE(tmp)) {
6899 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6900 goto failed;
6901 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006902 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006903 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006904 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006905 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006906 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6907 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006908 return 1;
6909 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006910 if (tmp == NULL) {
6911 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6912 return 1;
6913 }
6914 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006915 int res;
6916 Py_ssize_t len;
6917 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006918 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006919 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 +02006920 goto failed;
6921 }
6922 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006923 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006924 if (finalbody == NULL) goto failed;
6925 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006926 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006927 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6928 Py_INCREF(tmp2);
6929 res = obj2ast_stmt(tmp2, &val, arena);
6930 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006931 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006932 if (len != PyList_GET_SIZE(tmp)) {
6933 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6934 goto failed;
6935 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006936 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006937 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006938 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006939 }
6940 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006941 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006942 if (*out == NULL) goto failed;
6943 return 0;
6944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006945 tp = astmodulestate_global->Assert_type;
6946 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006947 if (isinstance == -1) {
6948 return 1;
6949 }
6950 if (isinstance) {
6951 expr_ty test;
6952 expr_ty msg;
6953
Dino Viehlandac46eb42019-09-11 10:16:34 -07006954 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006955 return 1;
6956 }
6957 if (tmp == NULL) {
6958 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6959 return 1;
6960 }
6961 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006962 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006963 res = obj2ast_expr(tmp, &test, arena);
6964 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006965 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006966 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006967 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006968 return 1;
6969 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006970 if (tmp == NULL || tmp == Py_None) {
6971 Py_CLEAR(tmp);
6972 msg = NULL;
6973 }
6974 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006975 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006976 res = obj2ast_expr(tmp, &msg, arena);
6977 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006978 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006979 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006980 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6981 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 if (*out == NULL) goto failed;
6983 return 0;
6984 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006985 tp = astmodulestate_global->Import_type;
6986 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006987 if (isinstance == -1) {
6988 return 1;
6989 }
6990 if (isinstance) {
6991 asdl_seq* names;
6992
Dino Viehlandac46eb42019-09-11 10:16:34 -07006993 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006994 return 1;
6995 }
6996 if (tmp == NULL) {
6997 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6998 return 1;
6999 }
7000 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007001 int res;
7002 Py_ssize_t len;
7003 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007004 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007005 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 +02007006 goto failed;
7007 }
7008 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007009 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007010 if (names == NULL) goto failed;
7011 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007012 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007013 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7014 Py_INCREF(tmp2);
7015 res = obj2ast_alias(tmp2, &val, arena);
7016 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007017 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007018 if (len != PyList_GET_SIZE(tmp)) {
7019 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
7020 goto failed;
7021 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007022 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007023 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007024 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007025 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007026 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
7027 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007028 if (*out == NULL) goto failed;
7029 return 0;
7030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007031 tp = astmodulestate_global->ImportFrom_type;
7032 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007033 if (isinstance == -1) {
7034 return 1;
7035 }
7036 if (isinstance) {
7037 identifier module;
7038 asdl_seq* names;
7039 int level;
7040
Dino Viehlandac46eb42019-09-11 10:16:34 -07007041 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
7042 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007043 return 1;
7044 }
7045 if (tmp == NULL || tmp == Py_None) {
7046 Py_CLEAR(tmp);
7047 module = NULL;
7048 }
7049 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007050 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007051 res = obj2ast_identifier(tmp, &module, arena);
7052 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007053 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007054 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007055 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007056 return 1;
7057 }
7058 if (tmp == NULL) {
7059 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7060 return 1;
7061 }
7062 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007063 int res;
7064 Py_ssize_t len;
7065 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007066 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007067 PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007068 goto failed;
7069 }
7070 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007071 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007072 if (names == NULL) goto failed;
7073 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007074 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007075 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7076 Py_INCREF(tmp2);
7077 res = obj2ast_alias(tmp2, &val, arena);
7078 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007079 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007080 if (len != PyList_GET_SIZE(tmp)) {
7081 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7082 goto failed;
7083 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007084 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007085 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007086 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007087 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007088 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007089 return 1;
7090 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007091 if (tmp == NULL || tmp == Py_None) {
7092 Py_CLEAR(tmp);
7093 level = 0;
7094 }
7095 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007096 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007097 res = obj2ast_int(tmp, &level, arena);
7098 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007099 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007100 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007101 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7102 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007103 if (*out == NULL) goto failed;
7104 return 0;
7105 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007106 tp = astmodulestate_global->Global_type;
7107 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007108 if (isinstance == -1) {
7109 return 1;
7110 }
7111 if (isinstance) {
7112 asdl_seq* names;
7113
Dino Viehlandac46eb42019-09-11 10:16:34 -07007114 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007115 return 1;
7116 }
7117 if (tmp == NULL) {
7118 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7119 return 1;
7120 }
7121 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007122 int res;
7123 Py_ssize_t len;
7124 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007125 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007126 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 +02007127 goto failed;
7128 }
7129 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007130 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007131 if (names == NULL) goto failed;
7132 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007133 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007134 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7135 Py_INCREF(tmp2);
7136 res = obj2ast_identifier(tmp2, &val, arena);
7137 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007138 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007139 if (len != PyList_GET_SIZE(tmp)) {
7140 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7141 goto failed;
7142 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007143 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007144 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007145 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007146 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007147 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7148 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007149 if (*out == NULL) goto failed;
7150 return 0;
7151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007152 tp = astmodulestate_global->Nonlocal_type;
7153 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007154 if (isinstance == -1) {
7155 return 1;
7156 }
7157 if (isinstance) {
7158 asdl_seq* names;
7159
Dino Viehlandac46eb42019-09-11 10:16:34 -07007160 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007161 return 1;
7162 }
7163 if (tmp == NULL) {
7164 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7165 return 1;
7166 }
7167 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007168 int res;
7169 Py_ssize_t len;
7170 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007171 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007172 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 +02007173 goto failed;
7174 }
7175 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007176 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007177 if (names == NULL) goto failed;
7178 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007179 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007180 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7181 Py_INCREF(tmp2);
7182 res = obj2ast_identifier(tmp2, &val, arena);
7183 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007184 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007185 if (len != PyList_GET_SIZE(tmp)) {
7186 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7187 goto failed;
7188 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007189 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007190 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007191 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007192 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007193 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7194 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007195 if (*out == NULL) goto failed;
7196 return 0;
7197 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007198 tp = astmodulestate_global->Expr_type;
7199 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007200 if (isinstance == -1) {
7201 return 1;
7202 }
7203 if (isinstance) {
7204 expr_ty value;
7205
Dino Viehlandac46eb42019-09-11 10:16:34 -07007206 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007207 return 1;
7208 }
7209 if (tmp == NULL) {
7210 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7211 return 1;
7212 }
7213 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007214 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007215 res = obj2ast_expr(tmp, &value, arena);
7216 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007217 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007218 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007219 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7220 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007221 if (*out == NULL) goto failed;
7222 return 0;
7223 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007224 tp = astmodulestate_global->Pass_type;
7225 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007226 if (isinstance == -1) {
7227 return 1;
7228 }
7229 if (isinstance) {
7230
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007231 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007232 if (*out == NULL) goto failed;
7233 return 0;
7234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007235 tp = astmodulestate_global->Break_type;
7236 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007237 if (isinstance == -1) {
7238 return 1;
7239 }
7240 if (isinstance) {
7241
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007242 *out = Break(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007243 if (*out == NULL) goto failed;
7244 return 0;
7245 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007246 tp = astmodulestate_global->Continue_type;
7247 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007248 if (isinstance == -1) {
7249 return 1;
7250 }
7251 if (isinstance) {
7252
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007253 *out = Continue(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007254 if (*out == NULL) goto failed;
7255 return 0;
7256 }
7257
7258 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7259 failed:
7260 Py_XDECREF(tmp);
7261 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007262}
7263
7264int
7265obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7266{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007267 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007268
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007269 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007270 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007271 int lineno;
7272 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007273 int end_lineno;
7274 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007275
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007276 if (obj == Py_None) {
7277 *out = NULL;
7278 return 0;
7279 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007280 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007281 return 1;
7282 }
7283 if (tmp == NULL) {
7284 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7285 return 1;
7286 }
7287 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007288 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007289 res = obj2ast_int(tmp, &lineno, arena);
7290 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007291 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007293 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7294 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007295 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007296 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007297 if (tmp == NULL) {
7298 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7299 return 1;
7300 }
7301 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007302 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007303 res = obj2ast_int(tmp, &col_offset, arena);
7304 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007305 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007306 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007307 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7308 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007309 return 1;
7310 }
7311 if (tmp == NULL || tmp == Py_None) {
7312 Py_CLEAR(tmp);
7313 end_lineno = 0;
7314 }
7315 else {
7316 int res;
7317 res = obj2ast_int(tmp, &end_lineno, arena);
7318 if (res != 0) goto failed;
7319 Py_CLEAR(tmp);
7320 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007321 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7322 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007323 return 1;
7324 }
7325 if (tmp == NULL || tmp == Py_None) {
7326 Py_CLEAR(tmp);
7327 end_col_offset = 0;
7328 }
7329 else {
7330 int res;
7331 res = obj2ast_int(tmp, &end_col_offset, arena);
7332 if (res != 0) goto failed;
7333 Py_CLEAR(tmp);
7334 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007335 tp = astmodulestate_global->BoolOp_type;
7336 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007337 if (isinstance == -1) {
7338 return 1;
7339 }
7340 if (isinstance) {
7341 boolop_ty op;
7342 asdl_seq* values;
7343
Dino Viehlandac46eb42019-09-11 10:16:34 -07007344 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007345 return 1;
7346 }
7347 if (tmp == NULL) {
7348 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7349 return 1;
7350 }
7351 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007352 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007353 res = obj2ast_boolop(tmp, &op, arena);
7354 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007355 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007356 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007357 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7358 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007359 return 1;
7360 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007361 if (tmp == NULL) {
7362 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7363 return 1;
7364 }
7365 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007366 int res;
7367 Py_ssize_t len;
7368 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007369 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007370 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 +02007371 goto failed;
7372 }
7373 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007374 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007375 if (values == NULL) goto failed;
7376 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007377 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007378 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7379 Py_INCREF(tmp2);
7380 res = obj2ast_expr(tmp2, &val, arena);
7381 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007382 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007383 if (len != PyList_GET_SIZE(tmp)) {
7384 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7385 goto failed;
7386 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007387 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007388 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007389 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007390 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007391 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7392 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007393 if (*out == NULL) goto failed;
7394 return 0;
7395 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007396 tp = astmodulestate_global->NamedExpr_type;
7397 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007398 if (isinstance == -1) {
7399 return 1;
7400 }
7401 if (isinstance) {
7402 expr_ty target;
7403 expr_ty value;
7404
Dino Viehlandac46eb42019-09-11 10:16:34 -07007405 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7406 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007407 return 1;
7408 }
7409 if (tmp == NULL) {
7410 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7411 return 1;
7412 }
7413 else {
7414 int res;
7415 res = obj2ast_expr(tmp, &target, arena);
7416 if (res != 0) goto failed;
7417 Py_CLEAR(tmp);
7418 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007419 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007420 return 1;
7421 }
7422 if (tmp == NULL) {
7423 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7424 return 1;
7425 }
7426 else {
7427 int res;
7428 res = obj2ast_expr(tmp, &value, arena);
7429 if (res != 0) goto failed;
7430 Py_CLEAR(tmp);
7431 }
7432 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7433 end_col_offset, arena);
7434 if (*out == NULL) goto failed;
7435 return 0;
7436 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007437 tp = astmodulestate_global->BinOp_type;
7438 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007439 if (isinstance == -1) {
7440 return 1;
7441 }
7442 if (isinstance) {
7443 expr_ty left;
7444 operator_ty op;
7445 expr_ty right;
7446
Dino Viehlandac46eb42019-09-11 10:16:34 -07007447 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007448 return 1;
7449 }
7450 if (tmp == NULL) {
7451 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7452 return 1;
7453 }
7454 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007455 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007456 res = obj2ast_expr(tmp, &left, arena);
7457 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007458 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007459 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007460 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007461 return 1;
7462 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007463 if (tmp == NULL) {
7464 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7465 return 1;
7466 }
7467 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007468 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007469 res = obj2ast_operator(tmp, &op, arena);
7470 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007471 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007472 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007473 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007474 return 1;
7475 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007476 if (tmp == NULL) {
7477 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7478 return 1;
7479 }
7480 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007481 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007482 res = obj2ast_expr(tmp, &right, arena);
7483 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007484 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007485 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007486 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7487 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007488 if (*out == NULL) goto failed;
7489 return 0;
7490 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007491 tp = astmodulestate_global->UnaryOp_type;
7492 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007493 if (isinstance == -1) {
7494 return 1;
7495 }
7496 if (isinstance) {
7497 unaryop_ty op;
7498 expr_ty operand;
7499
Dino Viehlandac46eb42019-09-11 10:16:34 -07007500 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007501 return 1;
7502 }
7503 if (tmp == NULL) {
7504 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7505 return 1;
7506 }
7507 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007508 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007509 res = obj2ast_unaryop(tmp, &op, arena);
7510 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007511 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007512 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007513 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7514 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007515 return 1;
7516 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007517 if (tmp == NULL) {
7518 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7519 return 1;
7520 }
7521 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007522 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007523 res = obj2ast_expr(tmp, &operand, arena);
7524 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007525 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007526 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007527 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7528 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007529 if (*out == NULL) goto failed;
7530 return 0;
7531 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007532 tp = astmodulestate_global->Lambda_type;
7533 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007534 if (isinstance == -1) {
7535 return 1;
7536 }
7537 if (isinstance) {
7538 arguments_ty args;
7539 expr_ty body;
7540
Dino Viehlandac46eb42019-09-11 10:16:34 -07007541 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007542 return 1;
7543 }
7544 if (tmp == NULL) {
7545 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7546 return 1;
7547 }
7548 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007549 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007550 res = obj2ast_arguments(tmp, &args, arena);
7551 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007552 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007553 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007554 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007555 return 1;
7556 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007557 if (tmp == NULL) {
7558 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7559 return 1;
7560 }
7561 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007562 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007563 res = obj2ast_expr(tmp, &body, arena);
7564 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007565 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007566 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007567 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7568 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007569 if (*out == NULL) goto failed;
7570 return 0;
7571 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007572 tp = astmodulestate_global->IfExp_type;
7573 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007574 if (isinstance == -1) {
7575 return 1;
7576 }
7577 if (isinstance) {
7578 expr_ty test;
7579 expr_ty body;
7580 expr_ty orelse;
7581
Dino Viehlandac46eb42019-09-11 10:16:34 -07007582 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007583 return 1;
7584 }
7585 if (tmp == NULL) {
7586 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7587 return 1;
7588 }
7589 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007590 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007591 res = obj2ast_expr(tmp, &test, arena);
7592 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007593 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007594 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007595 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007596 return 1;
7597 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007598 if (tmp == NULL) {
7599 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7600 return 1;
7601 }
7602 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007603 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007604 res = obj2ast_expr(tmp, &body, arena);
7605 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007606 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007607 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007608 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7609 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007610 return 1;
7611 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007612 if (tmp == NULL) {
7613 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7614 return 1;
7615 }
7616 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007617 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007618 res = obj2ast_expr(tmp, &orelse, arena);
7619 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007620 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007621 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007622 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7623 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007624 if (*out == NULL) goto failed;
7625 return 0;
7626 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007627 tp = astmodulestate_global->Dict_type;
7628 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007629 if (isinstance == -1) {
7630 return 1;
7631 }
7632 if (isinstance) {
7633 asdl_seq* keys;
7634 asdl_seq* values;
7635
Dino Viehlandac46eb42019-09-11 10:16:34 -07007636 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007637 return 1;
7638 }
7639 if (tmp == NULL) {
7640 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7641 return 1;
7642 }
7643 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007644 int res;
7645 Py_ssize_t len;
7646 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007647 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007648 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 +02007649 goto failed;
7650 }
7651 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007652 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007653 if (keys == NULL) goto failed;
7654 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007655 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007656 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7657 Py_INCREF(tmp2);
7658 res = obj2ast_expr(tmp2, &val, arena);
7659 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007660 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007661 if (len != PyList_GET_SIZE(tmp)) {
7662 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7663 goto failed;
7664 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007665 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007666 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007667 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007668 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007669 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7670 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007671 return 1;
7672 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007673 if (tmp == NULL) {
7674 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7675 return 1;
7676 }
7677 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007678 int res;
7679 Py_ssize_t len;
7680 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007681 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007682 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 +02007683 goto failed;
7684 }
7685 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007686 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007687 if (values == NULL) goto failed;
7688 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007689 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007690 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7691 Py_INCREF(tmp2);
7692 res = obj2ast_expr(tmp2, &val, arena);
7693 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007694 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007695 if (len != PyList_GET_SIZE(tmp)) {
7696 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7697 goto failed;
7698 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007699 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007700 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007701 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007702 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007703 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7704 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007705 if (*out == NULL) goto failed;
7706 return 0;
7707 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007708 tp = astmodulestate_global->Set_type;
7709 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007710 if (isinstance == -1) {
7711 return 1;
7712 }
7713 if (isinstance) {
7714 asdl_seq* elts;
7715
Dino Viehlandac46eb42019-09-11 10:16:34 -07007716 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007717 return 1;
7718 }
7719 if (tmp == NULL) {
7720 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7721 return 1;
7722 }
7723 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007724 int res;
7725 Py_ssize_t len;
7726 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007727 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007728 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 +02007729 goto failed;
7730 }
7731 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007732 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007733 if (elts == NULL) goto failed;
7734 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007735 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007736 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7737 Py_INCREF(tmp2);
7738 res = obj2ast_expr(tmp2, &val, arena);
7739 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007740 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007741 if (len != PyList_GET_SIZE(tmp)) {
7742 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7743 goto failed;
7744 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007745 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007746 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007747 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007748 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007749 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007750 if (*out == NULL) goto failed;
7751 return 0;
7752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007753 tp = astmodulestate_global->ListComp_type;
7754 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007755 if (isinstance == -1) {
7756 return 1;
7757 }
7758 if (isinstance) {
7759 expr_ty elt;
7760 asdl_seq* generators;
7761
Dino Viehlandac46eb42019-09-11 10:16:34 -07007762 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007763 return 1;
7764 }
7765 if (tmp == NULL) {
7766 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7767 return 1;
7768 }
7769 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007770 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007771 res = obj2ast_expr(tmp, &elt, arena);
7772 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007773 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007774 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007775 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7776 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007777 return 1;
7778 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007779 if (tmp == NULL) {
7780 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7781 return 1;
7782 }
7783 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007784 int res;
7785 Py_ssize_t len;
7786 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007787 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007788 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 +02007789 goto failed;
7790 }
7791 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007792 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007793 if (generators == NULL) goto failed;
7794 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007795 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007796 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7797 Py_INCREF(tmp2);
7798 res = obj2ast_comprehension(tmp2, &val, arena);
7799 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007800 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007801 if (len != PyList_GET_SIZE(tmp)) {
7802 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7803 goto failed;
7804 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007805 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007806 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007807 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007808 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007809 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7810 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007811 if (*out == NULL) goto failed;
7812 return 0;
7813 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007814 tp = astmodulestate_global->SetComp_type;
7815 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007816 if (isinstance == -1) {
7817 return 1;
7818 }
7819 if (isinstance) {
7820 expr_ty elt;
7821 asdl_seq* generators;
7822
Dino Viehlandac46eb42019-09-11 10:16:34 -07007823 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007824 return 1;
7825 }
7826 if (tmp == NULL) {
7827 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7828 return 1;
7829 }
7830 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007831 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007832 res = obj2ast_expr(tmp, &elt, arena);
7833 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007834 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007835 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007836 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7837 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007838 return 1;
7839 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007840 if (tmp == NULL) {
7841 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7842 return 1;
7843 }
7844 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007845 int res;
7846 Py_ssize_t len;
7847 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007848 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007849 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 +02007850 goto failed;
7851 }
7852 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007853 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007854 if (generators == NULL) goto failed;
7855 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007856 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007857 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7858 Py_INCREF(tmp2);
7859 res = obj2ast_comprehension(tmp2, &val, arena);
7860 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007861 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007862 if (len != PyList_GET_SIZE(tmp)) {
7863 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7864 goto failed;
7865 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007866 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007867 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007868 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007869 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007870 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7871 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007872 if (*out == NULL) goto failed;
7873 return 0;
7874 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007875 tp = astmodulestate_global->DictComp_type;
7876 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007877 if (isinstance == -1) {
7878 return 1;
7879 }
7880 if (isinstance) {
7881 expr_ty key;
7882 expr_ty value;
7883 asdl_seq* generators;
7884
Dino Viehlandac46eb42019-09-11 10:16:34 -07007885 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007886 return 1;
7887 }
7888 if (tmp == NULL) {
7889 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7890 return 1;
7891 }
7892 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007893 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007894 res = obj2ast_expr(tmp, &key, arena);
7895 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007896 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007897 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007898 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007899 return 1;
7900 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007901 if (tmp == NULL) {
7902 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7903 return 1;
7904 }
7905 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007906 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007907 res = obj2ast_expr(tmp, &value, arena);
7908 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007909 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007910 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007911 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7912 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007913 return 1;
7914 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007915 if (tmp == NULL) {
7916 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7917 return 1;
7918 }
7919 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007920 int res;
7921 Py_ssize_t len;
7922 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007923 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007924 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 +02007925 goto failed;
7926 }
7927 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007928 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007929 if (generators == NULL) goto failed;
7930 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007931 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007932 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7933 Py_INCREF(tmp2);
7934 res = obj2ast_comprehension(tmp2, &val, arena);
7935 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007936 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007937 if (len != PyList_GET_SIZE(tmp)) {
7938 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7939 goto failed;
7940 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007941 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007942 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007943 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007944 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007945 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7946 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007947 if (*out == NULL) goto failed;
7948 return 0;
7949 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007950 tp = astmodulestate_global->GeneratorExp_type;
7951 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007952 if (isinstance == -1) {
7953 return 1;
7954 }
7955 if (isinstance) {
7956 expr_ty elt;
7957 asdl_seq* generators;
7958
Dino Viehlandac46eb42019-09-11 10:16:34 -07007959 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007960 return 1;
7961 }
7962 if (tmp == NULL) {
7963 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7964 return 1;
7965 }
7966 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007967 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007968 res = obj2ast_expr(tmp, &elt, arena);
7969 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007970 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007971 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007972 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7973 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007974 return 1;
7975 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007976 if (tmp == NULL) {
7977 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7978 return 1;
7979 }
7980 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007981 int res;
7982 Py_ssize_t len;
7983 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007984 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007985 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 +02007986 goto failed;
7987 }
7988 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007989 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007990 if (generators == NULL) goto failed;
7991 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007992 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007993 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7994 Py_INCREF(tmp2);
7995 res = obj2ast_comprehension(tmp2, &val, arena);
7996 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007997 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007998 if (len != PyList_GET_SIZE(tmp)) {
7999 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
8000 goto failed;
8001 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008002 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008003 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008004 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008005 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008006 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
8007 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008008 if (*out == NULL) goto failed;
8009 return 0;
8010 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008011 tp = astmodulestate_global->Await_type;
8012 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04008013 if (isinstance == -1) {
8014 return 1;
8015 }
8016 if (isinstance) {
8017 expr_ty value;
8018
Dino Viehlandac46eb42019-09-11 10:16:34 -07008019 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008020 return 1;
8021 }
8022 if (tmp == NULL) {
8023 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8024 return 1;
8025 }
8026 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008027 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04008028 res = obj2ast_expr(tmp, &value, arena);
8029 if (res != 0) goto failed;
8030 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008031 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008032 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
8033 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008034 if (*out == NULL) goto failed;
8035 return 0;
8036 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008037 tp = astmodulestate_global->Yield_type;
8038 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008039 if (isinstance == -1) {
8040 return 1;
8041 }
8042 if (isinstance) {
8043 expr_ty value;
8044
Dino Viehlandac46eb42019-09-11 10:16:34 -07008045 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008046 return 1;
8047 }
8048 if (tmp == NULL || tmp == Py_None) {
8049 Py_CLEAR(tmp);
8050 value = NULL;
8051 }
8052 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008053 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008054 res = obj2ast_expr(tmp, &value, arena);
8055 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008056 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008057 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008058 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8059 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008060 if (*out == NULL) goto failed;
8061 return 0;
8062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008063 tp = astmodulestate_global->YieldFrom_type;
8064 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008065 if (isinstance == -1) {
8066 return 1;
8067 }
8068 if (isinstance) {
8069 expr_ty value;
8070
Dino Viehlandac46eb42019-09-11 10:16:34 -07008071 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008072 return 1;
8073 }
8074 if (tmp == NULL) {
8075 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8076 return 1;
8077 }
8078 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008079 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008080 res = obj2ast_expr(tmp, &value, arena);
8081 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008082 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008083 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008084 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8085 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008086 if (*out == NULL) goto failed;
8087 return 0;
8088 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008089 tp = astmodulestate_global->Compare_type;
8090 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008091 if (isinstance == -1) {
8092 return 1;
8093 }
8094 if (isinstance) {
8095 expr_ty left;
8096 asdl_int_seq* ops;
8097 asdl_seq* comparators;
8098
Dino Viehlandac46eb42019-09-11 10:16:34 -07008099 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008100 return 1;
8101 }
8102 if (tmp == NULL) {
8103 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8104 return 1;
8105 }
8106 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008107 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008108 res = obj2ast_expr(tmp, &left, arena);
8109 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008110 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008111 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008112 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008113 return 1;
8114 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008115 if (tmp == NULL) {
8116 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8117 return 1;
8118 }
8119 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008120 int res;
8121 Py_ssize_t len;
8122 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008123 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008124 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 +02008125 goto failed;
8126 }
8127 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008128 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008129 if (ops == NULL) goto failed;
8130 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008131 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008132 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8133 Py_INCREF(tmp2);
8134 res = obj2ast_cmpop(tmp2, &val, arena);
8135 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008136 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008137 if (len != PyList_GET_SIZE(tmp)) {
8138 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8139 goto failed;
8140 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008141 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008142 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008143 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008144 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008145 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8146 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008147 return 1;
8148 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008149 if (tmp == NULL) {
8150 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8151 return 1;
8152 }
8153 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008154 int res;
8155 Py_ssize_t len;
8156 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008157 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008158 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 +02008159 goto failed;
8160 }
8161 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008162 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008163 if (comparators == NULL) goto failed;
8164 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008165 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008166 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8167 Py_INCREF(tmp2);
8168 res = obj2ast_expr(tmp2, &val, arena);
8169 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008170 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008171 if (len != PyList_GET_SIZE(tmp)) {
8172 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8173 goto failed;
8174 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008175 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008176 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008177 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008178 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008179 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8180 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008181 if (*out == NULL) goto failed;
8182 return 0;
8183 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008184 tp = astmodulestate_global->Call_type;
8185 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008186 if (isinstance == -1) {
8187 return 1;
8188 }
8189 if (isinstance) {
8190 expr_ty func;
8191 asdl_seq* args;
8192 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008193
Dino Viehlandac46eb42019-09-11 10:16:34 -07008194 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008195 return 1;
8196 }
8197 if (tmp == NULL) {
8198 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8199 return 1;
8200 }
8201 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008202 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008203 res = obj2ast_expr(tmp, &func, arena);
8204 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008205 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008206 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008207 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008208 return 1;
8209 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008210 if (tmp == NULL) {
8211 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8212 return 1;
8213 }
8214 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008215 int res;
8216 Py_ssize_t len;
8217 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008218 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008219 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 +02008220 goto failed;
8221 }
8222 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008223 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008224 if (args == NULL) goto failed;
8225 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008226 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008227 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8228 Py_INCREF(tmp2);
8229 res = obj2ast_expr(tmp2, &val, arena);
8230 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008231 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008232 if (len != PyList_GET_SIZE(tmp)) {
8233 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8234 goto failed;
8235 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008236 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008237 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008238 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008239 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008240 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8241 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008242 return 1;
8243 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008244 if (tmp == NULL) {
8245 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8246 return 1;
8247 }
8248 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008249 int res;
8250 Py_ssize_t len;
8251 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008252 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008253 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 +02008254 goto failed;
8255 }
8256 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008257 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008258 if (keywords == NULL) goto failed;
8259 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008260 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008261 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8262 Py_INCREF(tmp2);
8263 res = obj2ast_keyword(tmp2, &val, arena);
8264 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008265 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008266 if (len != PyList_GET_SIZE(tmp)) {
8267 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8268 goto failed;
8269 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008270 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008271 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008272 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008273 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008274 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8275 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008276 if (*out == NULL) goto failed;
8277 return 0;
8278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008279 tp = astmodulestate_global->FormattedValue_type;
8280 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008281 if (isinstance == -1) {
8282 return 1;
8283 }
8284 if (isinstance) {
8285 expr_ty value;
8286 int conversion;
8287 expr_ty format_spec;
8288
Dino Viehlandac46eb42019-09-11 10:16:34 -07008289 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008290 return 1;
8291 }
8292 if (tmp == NULL) {
8293 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8294 return 1;
8295 }
8296 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008297 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008298 res = obj2ast_expr(tmp, &value, arena);
8299 if (res != 0) goto failed;
8300 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008301 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008302 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8303 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008304 return 1;
8305 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008306 if (tmp == NULL || tmp == Py_None) {
8307 Py_CLEAR(tmp);
8308 conversion = 0;
8309 }
8310 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008311 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008312 res = obj2ast_int(tmp, &conversion, arena);
8313 if (res != 0) goto failed;
8314 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008315 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008316 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8317 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008318 return 1;
8319 }
8320 if (tmp == NULL || tmp == Py_None) {
8321 Py_CLEAR(tmp);
8322 format_spec = NULL;
8323 }
8324 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008325 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008326 res = obj2ast_expr(tmp, &format_spec, arena);
8327 if (res != 0) goto failed;
8328 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008329 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008330 *out = FormattedValue(value, conversion, format_spec, lineno,
8331 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008332 if (*out == NULL) goto failed;
8333 return 0;
8334 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008335 tp = astmodulestate_global->JoinedStr_type;
8336 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008337 if (isinstance == -1) {
8338 return 1;
8339 }
8340 if (isinstance) {
8341 asdl_seq* values;
8342
Dino Viehlandac46eb42019-09-11 10:16:34 -07008343 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8344 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008345 return 1;
8346 }
8347 if (tmp == NULL) {
8348 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8349 return 1;
8350 }
8351 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008352 int res;
8353 Py_ssize_t len;
8354 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008355 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008356 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 -04008357 goto failed;
8358 }
8359 len = PyList_GET_SIZE(tmp);
8360 values = _Py_asdl_seq_new(len, arena);
8361 if (values == NULL) goto failed;
8362 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008363 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008364 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8365 Py_INCREF(tmp2);
8366 res = obj2ast_expr(tmp2, &val, arena);
8367 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008368 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008369 if (len != PyList_GET_SIZE(tmp)) {
8370 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8371 goto failed;
8372 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008373 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008374 }
8375 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008376 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008377 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8378 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008379 if (*out == NULL) goto failed;
8380 return 0;
8381 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008382 tp = astmodulestate_global->Constant_type;
8383 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008384 if (isinstance == -1) {
8385 return 1;
8386 }
8387 if (isinstance) {
8388 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008389 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008390
Dino Viehlandac46eb42019-09-11 10:16:34 -07008391 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008392 return 1;
8393 }
8394 if (tmp == NULL) {
8395 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8396 return 1;
8397 }
8398 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008399 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008400 res = obj2ast_constant(tmp, &value, arena);
8401 if (res != 0) goto failed;
8402 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008403 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008404 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008405 return 1;
8406 }
8407 if (tmp == NULL || tmp == Py_None) {
8408 Py_CLEAR(tmp);
8409 kind = NULL;
8410 }
8411 else {
8412 int res;
8413 res = obj2ast_string(tmp, &kind, arena);
8414 if (res != 0) goto failed;
8415 Py_CLEAR(tmp);
8416 }
8417 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8418 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008419 if (*out == NULL) goto failed;
8420 return 0;
8421 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008422 tp = astmodulestate_global->Attribute_type;
8423 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008424 if (isinstance == -1) {
8425 return 1;
8426 }
8427 if (isinstance) {
8428 expr_ty value;
8429 identifier attr;
8430 expr_context_ty ctx;
8431
Dino Viehlandac46eb42019-09-11 10:16:34 -07008432 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008433 return 1;
8434 }
8435 if (tmp == NULL) {
8436 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8437 return 1;
8438 }
8439 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008440 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008441 res = obj2ast_expr(tmp, &value, arena);
8442 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008443 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008444 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008445 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008446 return 1;
8447 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008448 if (tmp == NULL) {
8449 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8450 return 1;
8451 }
8452 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008453 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008454 res = obj2ast_identifier(tmp, &attr, arena);
8455 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008456 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008457 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008458 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008459 return 1;
8460 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008461 if (tmp == NULL) {
8462 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8463 return 1;
8464 }
8465 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008466 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008467 res = obj2ast_expr_context(tmp, &ctx, arena);
8468 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008469 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008470 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008471 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8472 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008473 if (*out == NULL) goto failed;
8474 return 0;
8475 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008476 tp = astmodulestate_global->Subscript_type;
8477 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008478 if (isinstance == -1) {
8479 return 1;
8480 }
8481 if (isinstance) {
8482 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008483 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008484 expr_context_ty ctx;
8485
Dino Viehlandac46eb42019-09-11 10:16:34 -07008486 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008487 return 1;
8488 }
8489 if (tmp == NULL) {
8490 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8491 return 1;
8492 }
8493 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008494 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008495 res = obj2ast_expr(tmp, &value, arena);
8496 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008497 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008498 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008499 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008500 return 1;
8501 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008502 if (tmp == NULL) {
8503 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8504 return 1;
8505 }
8506 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008507 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008508 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008509 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008510 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008511 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008512 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008513 return 1;
8514 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008515 if (tmp == NULL) {
8516 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8517 return 1;
8518 }
8519 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008520 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008521 res = obj2ast_expr_context(tmp, &ctx, arena);
8522 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008523 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008524 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008525 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8526 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008527 if (*out == NULL) goto failed;
8528 return 0;
8529 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008530 tp = astmodulestate_global->Starred_type;
8531 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008532 if (isinstance == -1) {
8533 return 1;
8534 }
8535 if (isinstance) {
8536 expr_ty value;
8537 expr_context_ty ctx;
8538
Dino Viehlandac46eb42019-09-11 10:16:34 -07008539 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008540 return 1;
8541 }
8542 if (tmp == NULL) {
8543 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8544 return 1;
8545 }
8546 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008547 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008548 res = obj2ast_expr(tmp, &value, arena);
8549 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008550 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008551 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008552 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008553 return 1;
8554 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008555 if (tmp == NULL) {
8556 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8557 return 1;
8558 }
8559 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008560 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008561 res = obj2ast_expr_context(tmp, &ctx, arena);
8562 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008563 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008564 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008565 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8566 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008567 if (*out == NULL) goto failed;
8568 return 0;
8569 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008570 tp = astmodulestate_global->Name_type;
8571 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008572 if (isinstance == -1) {
8573 return 1;
8574 }
8575 if (isinstance) {
8576 identifier id;
8577 expr_context_ty ctx;
8578
Dino Viehlandac46eb42019-09-11 10:16:34 -07008579 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008580 return 1;
8581 }
8582 if (tmp == NULL) {
8583 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8584 return 1;
8585 }
8586 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008587 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008588 res = obj2ast_identifier(tmp, &id, arena);
8589 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008590 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008591 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008592 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008593 return 1;
8594 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008595 if (tmp == NULL) {
8596 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8597 return 1;
8598 }
8599 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008600 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008601 res = obj2ast_expr_context(tmp, &ctx, arena);
8602 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008603 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008604 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008605 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8606 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008607 if (*out == NULL) goto failed;
8608 return 0;
8609 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008610 tp = astmodulestate_global->List_type;
8611 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008612 if (isinstance == -1) {
8613 return 1;
8614 }
8615 if (isinstance) {
8616 asdl_seq* elts;
8617 expr_context_ty ctx;
8618
Dino Viehlandac46eb42019-09-11 10:16:34 -07008619 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008620 return 1;
8621 }
8622 if (tmp == NULL) {
8623 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8624 return 1;
8625 }
8626 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008627 int res;
8628 Py_ssize_t len;
8629 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008630 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008631 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 +02008632 goto failed;
8633 }
8634 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008635 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008636 if (elts == NULL) goto failed;
8637 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008638 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008639 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8640 Py_INCREF(tmp2);
8641 res = obj2ast_expr(tmp2, &val, arena);
8642 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008643 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008644 if (len != PyList_GET_SIZE(tmp)) {
8645 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8646 goto failed;
8647 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008648 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008649 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008650 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008651 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008652 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008653 return 1;
8654 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008655 if (tmp == NULL) {
8656 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8657 return 1;
8658 }
8659 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008660 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008661 res = obj2ast_expr_context(tmp, &ctx, arena);
8662 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008663 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008664 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008665 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8666 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008667 if (*out == NULL) goto failed;
8668 return 0;
8669 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008670 tp = astmodulestate_global->Tuple_type;
8671 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008672 if (isinstance == -1) {
8673 return 1;
8674 }
8675 if (isinstance) {
8676 asdl_seq* elts;
8677 expr_context_ty ctx;
8678
Dino Viehlandac46eb42019-09-11 10:16:34 -07008679 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008680 return 1;
8681 }
8682 if (tmp == NULL) {
8683 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8684 return 1;
8685 }
8686 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008687 int res;
8688 Py_ssize_t len;
8689 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008690 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008691 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 +02008692 goto failed;
8693 }
8694 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008695 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008696 if (elts == NULL) goto failed;
8697 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008698 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008699 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8700 Py_INCREF(tmp2);
8701 res = obj2ast_expr(tmp2, &val, arena);
8702 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008703 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008704 if (len != PyList_GET_SIZE(tmp)) {
8705 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8706 goto failed;
8707 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008708 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008709 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008710 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008711 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008712 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008713 return 1;
8714 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008715 if (tmp == NULL) {
8716 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8717 return 1;
8718 }
8719 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008720 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008721 res = obj2ast_expr_context(tmp, &ctx, arena);
8722 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008723 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008724 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008725 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8726 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008727 if (*out == NULL) goto failed;
8728 return 0;
8729 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008730 tp = astmodulestate_global->Slice_type;
8731 isinstance = PyObject_IsInstance(obj, tp);
8732 if (isinstance == -1) {
8733 return 1;
8734 }
8735 if (isinstance) {
8736 expr_ty lower;
8737 expr_ty upper;
8738 expr_ty step;
8739
8740 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8741 return 1;
8742 }
8743 if (tmp == NULL || tmp == Py_None) {
8744 Py_CLEAR(tmp);
8745 lower = NULL;
8746 }
8747 else {
8748 int res;
8749 res = obj2ast_expr(tmp, &lower, arena);
8750 if (res != 0) goto failed;
8751 Py_CLEAR(tmp);
8752 }
8753 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8754 return 1;
8755 }
8756 if (tmp == NULL || tmp == Py_None) {
8757 Py_CLEAR(tmp);
8758 upper = NULL;
8759 }
8760 else {
8761 int res;
8762 res = obj2ast_expr(tmp, &upper, arena);
8763 if (res != 0) goto failed;
8764 Py_CLEAR(tmp);
8765 }
8766 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8767 return 1;
8768 }
8769 if (tmp == NULL || tmp == Py_None) {
8770 Py_CLEAR(tmp);
8771 step = NULL;
8772 }
8773 else {
8774 int res;
8775 res = obj2ast_expr(tmp, &step, arena);
8776 if (res != 0) goto failed;
8777 Py_CLEAR(tmp);
8778 }
8779 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8780 end_col_offset, arena);
8781 if (*out == NULL) goto failed;
8782 return 0;
8783 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008784
8785 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8786 failed:
8787 Py_XDECREF(tmp);
8788 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008789}
8790
8791int
8792obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8793{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008794 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008795
Dino Viehlandac46eb42019-09-11 10:16:34 -07008796 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008797 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008798 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008799 }
8800 if (isinstance) {
8801 *out = Load;
8802 return 0;
8803 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008804 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008805 if (isinstance == -1) {
8806 return 1;
8807 }
8808 if (isinstance) {
8809 *out = Store;
8810 return 0;
8811 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008812 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008813 if (isinstance == -1) {
8814 return 1;
8815 }
8816 if (isinstance) {
8817 *out = Del;
8818 return 0;
8819 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008820
8821 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8822 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008823}
8824
8825int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008826obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8827{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008828 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008829
Dino Viehlandac46eb42019-09-11 10:16:34 -07008830 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008831 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008832 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008833 }
8834 if (isinstance) {
8835 *out = And;
8836 return 0;
8837 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008838 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008839 if (isinstance == -1) {
8840 return 1;
8841 }
8842 if (isinstance) {
8843 *out = Or;
8844 return 0;
8845 }
8846
8847 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8848 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008849}
8850
8851int
8852obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8853{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008854 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008855
Dino Viehlandac46eb42019-09-11 10:16:34 -07008856 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008857 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008858 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008859 }
8860 if (isinstance) {
8861 *out = Add;
8862 return 0;
8863 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008864 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008865 if (isinstance == -1) {
8866 return 1;
8867 }
8868 if (isinstance) {
8869 *out = Sub;
8870 return 0;
8871 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008872 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008873 if (isinstance == -1) {
8874 return 1;
8875 }
8876 if (isinstance) {
8877 *out = Mult;
8878 return 0;
8879 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008880 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008881 if (isinstance == -1) {
8882 return 1;
8883 }
8884 if (isinstance) {
8885 *out = MatMult;
8886 return 0;
8887 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008888 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008889 if (isinstance == -1) {
8890 return 1;
8891 }
8892 if (isinstance) {
8893 *out = Div;
8894 return 0;
8895 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008896 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008897 if (isinstance == -1) {
8898 return 1;
8899 }
8900 if (isinstance) {
8901 *out = Mod;
8902 return 0;
8903 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008904 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008905 if (isinstance == -1) {
8906 return 1;
8907 }
8908 if (isinstance) {
8909 *out = Pow;
8910 return 0;
8911 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008912 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008913 if (isinstance == -1) {
8914 return 1;
8915 }
8916 if (isinstance) {
8917 *out = LShift;
8918 return 0;
8919 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008920 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008921 if (isinstance == -1) {
8922 return 1;
8923 }
8924 if (isinstance) {
8925 *out = RShift;
8926 return 0;
8927 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008928 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008929 if (isinstance == -1) {
8930 return 1;
8931 }
8932 if (isinstance) {
8933 *out = BitOr;
8934 return 0;
8935 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008936 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008937 if (isinstance == -1) {
8938 return 1;
8939 }
8940 if (isinstance) {
8941 *out = BitXor;
8942 return 0;
8943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008944 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008945 if (isinstance == -1) {
8946 return 1;
8947 }
8948 if (isinstance) {
8949 *out = BitAnd;
8950 return 0;
8951 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008952 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008953 if (isinstance == -1) {
8954 return 1;
8955 }
8956 if (isinstance) {
8957 *out = FloorDiv;
8958 return 0;
8959 }
8960
8961 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8962 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008963}
8964
8965int
8966obj2ast_unaryop(PyObject* obj, unaryop_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->Invert_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 = Invert;
8976 return 0;
8977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008978 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008979 if (isinstance == -1) {
8980 return 1;
8981 }
8982 if (isinstance) {
8983 *out = Not;
8984 return 0;
8985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008986 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008987 if (isinstance == -1) {
8988 return 1;
8989 }
8990 if (isinstance) {
8991 *out = UAdd;
8992 return 0;
8993 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008994 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008995 if (isinstance == -1) {
8996 return 1;
8997 }
8998 if (isinstance) {
8999 *out = USub;
9000 return 0;
9001 }
9002
9003 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
9004 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009005}
9006
9007int
9008obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
9009{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009010 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009011
Dino Viehlandac46eb42019-09-11 10:16:34 -07009012 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009013 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009014 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009015 }
9016 if (isinstance) {
9017 *out = Eq;
9018 return 0;
9019 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009020 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009021 if (isinstance == -1) {
9022 return 1;
9023 }
9024 if (isinstance) {
9025 *out = NotEq;
9026 return 0;
9027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009028 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009029 if (isinstance == -1) {
9030 return 1;
9031 }
9032 if (isinstance) {
9033 *out = Lt;
9034 return 0;
9035 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009036 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009037 if (isinstance == -1) {
9038 return 1;
9039 }
9040 if (isinstance) {
9041 *out = LtE;
9042 return 0;
9043 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009044 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009045 if (isinstance == -1) {
9046 return 1;
9047 }
9048 if (isinstance) {
9049 *out = Gt;
9050 return 0;
9051 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009052 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009053 if (isinstance == -1) {
9054 return 1;
9055 }
9056 if (isinstance) {
9057 *out = GtE;
9058 return 0;
9059 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009060 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009061 if (isinstance == -1) {
9062 return 1;
9063 }
9064 if (isinstance) {
9065 *out = Is;
9066 return 0;
9067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009068 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009069 if (isinstance == -1) {
9070 return 1;
9071 }
9072 if (isinstance) {
9073 *out = IsNot;
9074 return 0;
9075 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009076 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009077 if (isinstance == -1) {
9078 return 1;
9079 }
9080 if (isinstance) {
9081 *out = In;
9082 return 0;
9083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009084 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009085 if (isinstance == -1) {
9086 return 1;
9087 }
9088 if (isinstance) {
9089 *out = NotIn;
9090 return 0;
9091 }
9092
9093 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9094 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009095}
9096
9097int
9098obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9099{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009100 PyObject* tmp = NULL;
9101 expr_ty target;
9102 expr_ty iter;
9103 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009104 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009105
Dino Viehlandac46eb42019-09-11 10:16:34 -07009106 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009107 return 1;
9108 }
9109 if (tmp == NULL) {
9110 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9111 return 1;
9112 }
9113 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009114 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009115 res = obj2ast_expr(tmp, &target, arena);
9116 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009117 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009118 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009119 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009120 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009121 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009122 if (tmp == NULL) {
9123 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9124 return 1;
9125 }
9126 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009127 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009128 res = obj2ast_expr(tmp, &iter, arena);
9129 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009130 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009131 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009132 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009133 return 1;
9134 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009135 if (tmp == NULL) {
9136 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9137 return 1;
9138 }
9139 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009140 int res;
9141 Py_ssize_t len;
9142 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009143 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009144 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 +02009145 goto failed;
9146 }
9147 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009148 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009149 if (ifs == NULL) goto failed;
9150 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009151 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009152 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9153 Py_INCREF(tmp2);
9154 res = obj2ast_expr(tmp2, &val, arena);
9155 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009156 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009157 if (len != PyList_GET_SIZE(tmp)) {
9158 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9159 goto failed;
9160 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009161 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009162 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009163 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009164 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009165 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009166 return 1;
9167 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009168 if (tmp == NULL) {
9169 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9170 return 1;
9171 }
9172 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009173 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009174 res = obj2ast_int(tmp, &is_async, arena);
9175 if (res != 0) goto failed;
9176 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009177 }
9178 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009179 return 0;
9180failed:
9181 Py_XDECREF(tmp);
9182 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009183}
9184
9185int
9186obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9187{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009188 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009189
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009190 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009191 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009192 int lineno;
9193 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009194 int end_lineno;
9195 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009196
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009197 if (obj == Py_None) {
9198 *out = NULL;
9199 return 0;
9200 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009201 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009202 return 1;
9203 }
9204 if (tmp == NULL) {
9205 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9206 return 1;
9207 }
9208 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009209 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009210 res = obj2ast_int(tmp, &lineno, arena);
9211 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009212 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009213 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009214 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9215 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009216 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009217 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009218 if (tmp == NULL) {
9219 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9220 return 1;
9221 }
9222 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009223 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009224 res = obj2ast_int(tmp, &col_offset, arena);
9225 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009226 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009227 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009228 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9229 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009230 return 1;
9231 }
9232 if (tmp == NULL || tmp == Py_None) {
9233 Py_CLEAR(tmp);
9234 end_lineno = 0;
9235 }
9236 else {
9237 int res;
9238 res = obj2ast_int(tmp, &end_lineno, arena);
9239 if (res != 0) goto failed;
9240 Py_CLEAR(tmp);
9241 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009242 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9243 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009244 return 1;
9245 }
9246 if (tmp == NULL || tmp == Py_None) {
9247 Py_CLEAR(tmp);
9248 end_col_offset = 0;
9249 }
9250 else {
9251 int res;
9252 res = obj2ast_int(tmp, &end_col_offset, arena);
9253 if (res != 0) goto failed;
9254 Py_CLEAR(tmp);
9255 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009256 tp = astmodulestate_global->ExceptHandler_type;
9257 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009258 if (isinstance == -1) {
9259 return 1;
9260 }
9261 if (isinstance) {
9262 expr_ty type;
9263 identifier name;
9264 asdl_seq* body;
9265
Dino Viehlandac46eb42019-09-11 10:16:34 -07009266 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009267 return 1;
9268 }
9269 if (tmp == NULL || tmp == Py_None) {
9270 Py_CLEAR(tmp);
9271 type = NULL;
9272 }
9273 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009274 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009275 res = obj2ast_expr(tmp, &type, arena);
9276 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009277 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009278 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009279 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009280 return 1;
9281 }
9282 if (tmp == NULL || tmp == Py_None) {
9283 Py_CLEAR(tmp);
9284 name = NULL;
9285 }
9286 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009287 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009288 res = obj2ast_identifier(tmp, &name, arena);
9289 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009290 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009291 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009292 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009293 return 1;
9294 }
9295 if (tmp == NULL) {
9296 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9297 return 1;
9298 }
9299 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009300 int res;
9301 Py_ssize_t len;
9302 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009303 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009304 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 +02009305 goto failed;
9306 }
9307 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009308 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009309 if (body == NULL) goto failed;
9310 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009311 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009312 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9313 Py_INCREF(tmp2);
9314 res = obj2ast_stmt(tmp2, &val, arena);
9315 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009316 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009317 if (len != PyList_GET_SIZE(tmp)) {
9318 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9319 goto failed;
9320 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009321 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009322 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009323 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009324 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009325 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9326 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009327 if (*out == NULL) goto failed;
9328 return 0;
9329 }
9330
9331 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9332 failed:
9333 Py_XDECREF(tmp);
9334 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009335}
9336
9337int
9338obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9339{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009340 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009341 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009342 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009343 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009344 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009345 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009346 arg_ty kwarg;
9347 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009348
Dino Viehlandac46eb42019-09-11 10:16:34 -07009349 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9350 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009351 return 1;
9352 }
9353 if (tmp == NULL) {
9354 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9355 return 1;
9356 }
9357 else {
9358 int res;
9359 Py_ssize_t len;
9360 Py_ssize_t i;
9361 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009362 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 +01009363 goto failed;
9364 }
9365 len = PyList_GET_SIZE(tmp);
9366 posonlyargs = _Py_asdl_seq_new(len, arena);
9367 if (posonlyargs == NULL) goto failed;
9368 for (i = 0; i < len; i++) {
9369 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009370 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9371 Py_INCREF(tmp2);
9372 res = obj2ast_arg(tmp2, &val, arena);
9373 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009374 if (res != 0) goto failed;
9375 if (len != PyList_GET_SIZE(tmp)) {
9376 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9377 goto failed;
9378 }
9379 asdl_seq_SET(posonlyargs, i, val);
9380 }
9381 Py_CLEAR(tmp);
9382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009383 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009384 return 1;
9385 }
9386 if (tmp == NULL) {
9387 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9388 return 1;
9389 }
9390 else {
9391 int res;
9392 Py_ssize_t len;
9393 Py_ssize_t i;
9394 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009395 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 +02009396 goto failed;
9397 }
9398 len = PyList_GET_SIZE(tmp);
9399 args = _Py_asdl_seq_new(len, arena);
9400 if (args == NULL) goto failed;
9401 for (i = 0; i < len; i++) {
9402 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009403 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9404 Py_INCREF(tmp2);
9405 res = obj2ast_arg(tmp2, &val, arena);
9406 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009407 if (res != 0) goto failed;
9408 if (len != PyList_GET_SIZE(tmp)) {
9409 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9410 goto failed;
9411 }
9412 asdl_seq_SET(args, i, val);
9413 }
9414 Py_CLEAR(tmp);
9415 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009416 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009417 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009418 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009419 if (tmp == NULL || tmp == Py_None) {
9420 Py_CLEAR(tmp);
9421 vararg = NULL;
9422 }
9423 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009424 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009425 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009426 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009427 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009428 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009429 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9430 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009431 return 1;
9432 }
9433 if (tmp == NULL) {
9434 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9435 return 1;
9436 }
9437 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009438 int res;
9439 Py_ssize_t len;
9440 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009441 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009442 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 +02009443 goto failed;
9444 }
9445 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009446 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009447 if (kwonlyargs == NULL) goto failed;
9448 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009449 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009450 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9451 Py_INCREF(tmp2);
9452 res = obj2ast_arg(tmp2, &val, arena);
9453 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009454 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009455 if (len != PyList_GET_SIZE(tmp)) {
9456 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9457 goto failed;
9458 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009459 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009460 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009461 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009462 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009463 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9464 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009465 return 1;
9466 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009467 if (tmp == NULL) {
9468 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9469 return 1;
9470 }
9471 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009472 int res;
9473 Py_ssize_t len;
9474 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009475 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009476 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 +02009477 goto failed;
9478 }
9479 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009480 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009481 if (kw_defaults == NULL) goto failed;
9482 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009483 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009484 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9485 Py_INCREF(tmp2);
9486 res = obj2ast_expr(tmp2, &val, arena);
9487 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009488 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009489 if (len != PyList_GET_SIZE(tmp)) {
9490 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9491 goto failed;
9492 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009493 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009494 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009495 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009496 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009497 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009498 return 1;
9499 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009500 if (tmp == NULL || tmp == Py_None) {
9501 Py_CLEAR(tmp);
9502 kwarg = NULL;
9503 }
9504 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009505 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009506 res = obj2ast_arg(tmp, &kwarg, arena);
9507 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009508 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009509 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009510 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009511 return 1;
9512 }
9513 if (tmp == NULL) {
9514 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9515 return 1;
9516 }
9517 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009518 int res;
9519 Py_ssize_t len;
9520 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009521 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009522 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 +02009523 goto failed;
9524 }
9525 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009526 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009527 if (defaults == NULL) goto failed;
9528 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009529 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009530 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9531 Py_INCREF(tmp2);
9532 res = obj2ast_expr(tmp2, &val, arena);
9533 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009534 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009535 if (len != PyList_GET_SIZE(tmp)) {
9536 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9537 goto failed;
9538 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009539 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009540 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009541 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009542 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009543 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009544 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009545 return 0;
9546failed:
9547 Py_XDECREF(tmp);
9548 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009549}
9550
9551int
9552obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9553{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009554 PyObject* tmp = NULL;
9555 identifier arg;
9556 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009557 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009558 int lineno;
9559 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009560 int end_lineno;
9561 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009562
Dino Viehlandac46eb42019-09-11 10:16:34 -07009563 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009564 return 1;
9565 }
9566 if (tmp == NULL) {
9567 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9568 return 1;
9569 }
9570 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009571 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009572 res = obj2ast_identifier(tmp, &arg, arena);
9573 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009574 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009575 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009576 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9577 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009578 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009579 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009580 if (tmp == NULL || tmp == Py_None) {
9581 Py_CLEAR(tmp);
9582 annotation = NULL;
9583 }
9584 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009585 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009586 res = obj2ast_expr(tmp, &annotation, arena);
9587 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009588 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009589 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009590 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9591 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009592 return 1;
9593 }
9594 if (tmp == NULL || tmp == Py_None) {
9595 Py_CLEAR(tmp);
9596 type_comment = NULL;
9597 }
9598 else {
9599 int res;
9600 res = obj2ast_string(tmp, &type_comment, arena);
9601 if (res != 0) goto failed;
9602 Py_CLEAR(tmp);
9603 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009604 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009605 return 1;
9606 }
9607 if (tmp == NULL) {
9608 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9609 return 1;
9610 }
9611 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009612 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009613 res = obj2ast_int(tmp, &lineno, arena);
9614 if (res != 0) goto failed;
9615 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009616 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009617 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9618 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009619 return 1;
9620 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009621 if (tmp == NULL) {
9622 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9623 return 1;
9624 }
9625 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009626 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009627 res = obj2ast_int(tmp, &col_offset, arena);
9628 if (res != 0) goto failed;
9629 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009630 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009631 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9632 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009633 return 1;
9634 }
9635 if (tmp == NULL || tmp == Py_None) {
9636 Py_CLEAR(tmp);
9637 end_lineno = 0;
9638 }
9639 else {
9640 int res;
9641 res = obj2ast_int(tmp, &end_lineno, arena);
9642 if (res != 0) goto failed;
9643 Py_CLEAR(tmp);
9644 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009645 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9646 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009647 return 1;
9648 }
9649 if (tmp == NULL || tmp == Py_None) {
9650 Py_CLEAR(tmp);
9651 end_col_offset = 0;
9652 }
9653 else {
9654 int res;
9655 res = obj2ast_int(tmp, &end_col_offset, arena);
9656 if (res != 0) goto failed;
9657 Py_CLEAR(tmp);
9658 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009659 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9660 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009661 return 0;
9662failed:
9663 Py_XDECREF(tmp);
9664 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009665}
9666
9667int
9668obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9669{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009670 PyObject* tmp = NULL;
9671 identifier arg;
9672 expr_ty value;
Pablo Galindo168660b2020-04-02 00:47:39 +01009673 int lineno;
9674 int col_offset;
9675 int end_lineno;
9676 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009677
Dino Viehlandac46eb42019-09-11 10:16:34 -07009678 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009679 return 1;
9680 }
9681 if (tmp == NULL || tmp == Py_None) {
9682 Py_CLEAR(tmp);
9683 arg = NULL;
9684 }
9685 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009686 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009687 res = obj2ast_identifier(tmp, &arg, arena);
9688 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009689 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009690 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009691 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009692 return 1;
9693 }
9694 if (tmp == NULL) {
9695 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9696 return 1;
9697 }
9698 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009699 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009700 res = obj2ast_expr(tmp, &value, arena);
9701 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009702 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009703 }
Pablo Galindo168660b2020-04-02 00:47:39 +01009704 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
9705 return 1;
9706 }
9707 if (tmp == NULL) {
9708 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
9709 return 1;
9710 }
9711 else {
9712 int res;
9713 res = obj2ast_int(tmp, &lineno, arena);
9714 if (res != 0) goto failed;
9715 Py_CLEAR(tmp);
9716 }
9717 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9718 {
9719 return 1;
9720 }
9721 if (tmp == NULL) {
9722 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
9723 return 1;
9724 }
9725 else {
9726 int res;
9727 res = obj2ast_int(tmp, &col_offset, arena);
9728 if (res != 0) goto failed;
9729 Py_CLEAR(tmp);
9730 }
9731 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9732 {
9733 return 1;
9734 }
9735 if (tmp == NULL || tmp == Py_None) {
9736 Py_CLEAR(tmp);
9737 end_lineno = 0;
9738 }
9739 else {
9740 int res;
9741 res = obj2ast_int(tmp, &end_lineno, arena);
9742 if (res != 0) goto failed;
9743 Py_CLEAR(tmp);
9744 }
9745 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9746 < 0) {
9747 return 1;
9748 }
9749 if (tmp == NULL || tmp == Py_None) {
9750 Py_CLEAR(tmp);
9751 end_col_offset = 0;
9752 }
9753 else {
9754 int res;
9755 res = obj2ast_int(tmp, &end_col_offset, arena);
9756 if (res != 0) goto failed;
9757 Py_CLEAR(tmp);
9758 }
9759 *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset,
9760 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009761 return 0;
9762failed:
9763 Py_XDECREF(tmp);
9764 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009765}
9766
9767int
9768obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9769{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009770 PyObject* tmp = NULL;
9771 identifier name;
9772 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009773
Dino Viehlandac46eb42019-09-11 10:16:34 -07009774 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009775 return 1;
9776 }
9777 if (tmp == NULL) {
9778 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9779 return 1;
9780 }
9781 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009782 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009783 res = obj2ast_identifier(tmp, &name, arena);
9784 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009785 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009786 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009787 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009788 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009789 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009790 if (tmp == NULL || tmp == Py_None) {
9791 Py_CLEAR(tmp);
9792 asname = NULL;
9793 }
9794 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009795 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009796 res = obj2ast_identifier(tmp, &asname, arena);
9797 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009798 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009799 }
9800 *out = alias(name, asname, arena);
9801 return 0;
9802failed:
9803 Py_XDECREF(tmp);
9804 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009805}
9806
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009807int
9808obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9809{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009810 PyObject* tmp = NULL;
9811 expr_ty context_expr;
9812 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009813
Dino Viehlandac46eb42019-09-11 10:16:34 -07009814 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9815 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009816 return 1;
9817 }
9818 if (tmp == NULL) {
9819 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9820 return 1;
9821 }
9822 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009823 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009824 res = obj2ast_expr(tmp, &context_expr, arena);
9825 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009826 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009827 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009828 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9829 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009830 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009831 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009832 if (tmp == NULL || tmp == Py_None) {
9833 Py_CLEAR(tmp);
9834 optional_vars = NULL;
9835 }
9836 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009837 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009838 res = obj2ast_expr(tmp, &optional_vars, arena);
9839 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009840 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009841 }
9842 *out = withitem(context_expr, optional_vars, arena);
9843 return 0;
9844failed:
9845 Py_XDECREF(tmp);
9846 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009847}
9848
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009849int
9850obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9851{
9852 int isinstance;
9853
9854 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009855 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009856
9857 if (obj == Py_None) {
9858 *out = NULL;
9859 return 0;
9860 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009861 tp = astmodulestate_global->TypeIgnore_type;
9862 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009863 if (isinstance == -1) {
9864 return 1;
9865 }
9866 if (isinstance) {
9867 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009868 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009869
Dino Viehlandac46eb42019-09-11 10:16:34 -07009870 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9871 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009872 return 1;
9873 }
9874 if (tmp == NULL) {
9875 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9876 return 1;
9877 }
9878 else {
9879 int res;
9880 res = obj2ast_int(tmp, &lineno, arena);
9881 if (res != 0) goto failed;
9882 Py_CLEAR(tmp);
9883 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009884 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009885 return 1;
9886 }
9887 if (tmp == NULL) {
9888 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9889 return 1;
9890 }
9891 else {
9892 int res;
9893 res = obj2ast_string(tmp, &tag, arena);
9894 if (res != 0) goto failed;
9895 Py_CLEAR(tmp);
9896 }
9897 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009898 if (*out == NULL) goto failed;
9899 return 0;
9900 }
9901
9902 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9903 failed:
9904 Py_XDECREF(tmp);
9905 return 1;
9906}
9907
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009908
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009909PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009910PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009911{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009912 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009913 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009914 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009915 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009916 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9917 goto error;
9918 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009919 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009920 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9921 goto error;
9922 }
9923 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9924 goto error;
9925 }
9926 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9927 goto error;
9928 }
9929 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9930 goto error;
9931 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009932 Py_INCREF(astmodulestate(m)->mod_type);
9933 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009934 0) {
9935 goto error;
9936 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009937 Py_INCREF(astmodulestate(m)->Module_type);
9938 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009939 astmodulestate_global->Interactive_type) < 0) {
9940 goto error;
9941 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009942 Py_INCREF(astmodulestate(m)->Interactive_type);
9943 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009944 astmodulestate_global->Expression_type) < 0) {
9945 goto error;
9946 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009947 Py_INCREF(astmodulestate(m)->Expression_type);
9948 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009949 astmodulestate_global->FunctionType_type) < 0) {
9950 goto error;
9951 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009952 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009953 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9954 goto error;
9955 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009956 Py_INCREF(astmodulestate(m)->stmt_type);
9957 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009958 astmodulestate_global->FunctionDef_type) < 0) {
9959 goto error;
9960 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009961 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9962 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009963 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9964 goto error;
9965 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009966 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9967 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009968 < 0) {
9969 goto error;
9970 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009971 Py_INCREF(astmodulestate(m)->ClassDef_type);
9972 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009973 0) {
9974 goto error;
9975 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009976 Py_INCREF(astmodulestate(m)->Return_type);
9977 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009978 0) {
9979 goto error;
9980 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009981 Py_INCREF(astmodulestate(m)->Delete_type);
9982 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009983 0) {
9984 goto error;
9985 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009986 Py_INCREF(astmodulestate(m)->Assign_type);
9987 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009988 astmodulestate_global->AugAssign_type) < 0) {
9989 goto error;
9990 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009991 Py_INCREF(astmodulestate(m)->AugAssign_type);
9992 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009993 astmodulestate_global->AnnAssign_type) < 0) {
9994 goto error;
9995 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009996 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009997 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9998 goto error;
9999 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010000 Py_INCREF(astmodulestate(m)->For_type);
10001 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010002 < 0) {
10003 goto error;
10004 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010005 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010006 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
10007 goto error;
10008 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010009 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010010 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
10011 goto error;
10012 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010013 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010014 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
10015 goto error;
10016 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010017 Py_INCREF(astmodulestate(m)->With_type);
10018 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010019 astmodulestate_global->AsyncWith_type) < 0) {
10020 goto error;
10021 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010022 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010023 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
10024 goto error;
10025 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010026 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010027 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
10028 goto error;
10029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010030 Py_INCREF(astmodulestate(m)->Try_type);
10031 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010032 0) {
10033 goto error;
10034 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010035 Py_INCREF(astmodulestate(m)->Assert_type);
10036 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010037 0) {
10038 goto error;
10039 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010040 Py_INCREF(astmodulestate(m)->Import_type);
10041 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010042 astmodulestate_global->ImportFrom_type) < 0) {
10043 goto error;
10044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010045 Py_INCREF(astmodulestate(m)->ImportFrom_type);
10046 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010047 0) {
10048 goto error;
10049 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010050 Py_INCREF(astmodulestate(m)->Global_type);
10051 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010052 < 0) {
10053 goto error;
10054 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010055 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010056 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10057 goto error;
10058 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010059 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010060 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10061 goto error;
10062 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010063 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010064 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10065 goto error;
10066 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010067 Py_INCREF(astmodulestate(m)->Break_type);
10068 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010069 < 0) {
10070 goto error;
10071 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010072 Py_INCREF(astmodulestate(m)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010073 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10074 goto error;
10075 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010076 Py_INCREF(astmodulestate(m)->expr_type);
10077 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010078 0) {
10079 goto error;
10080 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010081 Py_INCREF(astmodulestate(m)->BoolOp_type);
10082 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010083 astmodulestate_global->NamedExpr_type) < 0) {
10084 goto error;
10085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010086 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010087 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10088 goto error;
10089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010090 Py_INCREF(astmodulestate(m)->BinOp_type);
10091 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010092 0) {
10093 goto error;
10094 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010095 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10096 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010097 0) {
10098 goto error;
10099 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010100 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010101 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10102 goto error;
10103 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010104 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010105 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10106 goto error;
10107 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010108 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010109 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10110 goto error;
10111 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010112 Py_INCREF(astmodulestate(m)->Set_type);
10113 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010114 < 0) {
10115 goto error;
10116 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010117 Py_INCREF(astmodulestate(m)->ListComp_type);
10118 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010119 0) {
10120 goto error;
10121 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010122 Py_INCREF(astmodulestate(m)->SetComp_type);
10123 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010124 < 0) {
10125 goto error;
10126 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010127 Py_INCREF(astmodulestate(m)->DictComp_type);
10128 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010129 astmodulestate_global->GeneratorExp_type) < 0) {
10130 goto error;
10131 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010132 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010133 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10134 goto error;
10135 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010136 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010137 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10138 goto error;
10139 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010140 Py_INCREF(astmodulestate(m)->Yield_type);
10141 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010142 astmodulestate_global->YieldFrom_type) < 0) {
10143 goto error;
10144 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010145 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10146 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_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)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010151 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10152 goto error;
10153 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010154 Py_INCREF(astmodulestate(m)->Call_type);
10155 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010156 astmodulestate_global->FormattedValue_type) < 0) {
10157 goto error;
10158 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010159 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10160 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010161 astmodulestate_global->JoinedStr_type) < 0) {
10162 goto error;
10163 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010164 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10165 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010166 < 0) {
10167 goto error;
10168 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010169 Py_INCREF(astmodulestate(m)->Constant_type);
10170 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010171 astmodulestate_global->Attribute_type) < 0) {
10172 goto error;
10173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010174 Py_INCREF(astmodulestate(m)->Attribute_type);
10175 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010176 astmodulestate_global->Subscript_type) < 0) {
10177 goto error;
10178 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010179 Py_INCREF(astmodulestate(m)->Subscript_type);
10180 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010181 0) {
10182 goto error;
10183 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010184 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010185 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10186 goto error;
10187 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010188 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010189 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10190 goto error;
10191 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010192 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010193 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10194 goto error;
10195 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010196 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010197 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10198 goto error;
10199 }
10200 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010201 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010202 astmodulestate_global->expr_context_type) < 0) {
10203 goto error;
10204 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010205 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010206 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10207 goto error;
10208 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010209 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010210 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10211 goto error;
10212 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010213 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010214 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10215 goto error;
10216 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010217 Py_INCREF(astmodulestate(m)->Del_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010218 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010219 0) {
10220 goto error;
10221 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010222 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010223 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10224 goto error;
10225 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010226 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010227 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10228 goto error;
10229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010230 Py_INCREF(astmodulestate(m)->Or_type);
10231 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010232 < 0) {
10233 goto error;
10234 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010235 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010236 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10237 goto error;
10238 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010239 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010240 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10241 goto error;
10242 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010243 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010244 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10245 goto error;
10246 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010247 Py_INCREF(astmodulestate(m)->Mult_type);
10248 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010249 0) {
10250 goto error;
10251 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010252 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010253 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10254 goto error;
10255 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010256 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010257 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10258 goto error;
10259 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010260 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010261 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10262 goto error;
10263 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010264 Py_INCREF(astmodulestate(m)->Pow_type);
10265 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010266 0) {
10267 goto error;
10268 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010269 Py_INCREF(astmodulestate(m)->LShift_type);
10270 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010271 0) {
10272 goto error;
10273 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010274 Py_INCREF(astmodulestate(m)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010275 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10276 goto error;
10277 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010278 Py_INCREF(astmodulestate(m)->BitOr_type);
10279 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010280 0) {
10281 goto error;
10282 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010283 Py_INCREF(astmodulestate(m)->BitXor_type);
10284 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010285 0) {
10286 goto error;
10287 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010288 Py_INCREF(astmodulestate(m)->BitAnd_type);
10289 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010290 < 0) {
10291 goto error;
10292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010293 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10294 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010295 0) {
10296 goto error;
10297 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010298 Py_INCREF(astmodulestate(m)->unaryop_type);
10299 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010300 0) {
10301 goto error;
10302 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010303 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010304 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10305 goto error;
10306 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010307 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010308 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10309 goto error;
10310 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010311 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010312 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10313 goto error;
10314 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010315 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010316 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10317 goto error;
10318 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010319 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010320 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10321 goto error;
10322 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010323 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010324 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10325 goto error;
10326 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010327 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010328 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10329 goto error;
10330 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010331 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010332 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10333 goto error;
10334 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010335 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010336 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10337 goto error;
10338 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010339 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010340 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10341 goto error;
10342 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010343 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010344 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10345 goto error;
10346 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010347 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010348 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10349 goto error;
10350 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010351 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010352 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10353 goto error;
10354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010355 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010356 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10357 goto error;
10358 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010359 Py_INCREF(astmodulestate(m)->NotIn_type);
10360 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010361 astmodulestate_global->comprehension_type) < 0) {
10362 goto error;
10363 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010364 Py_INCREF(astmodulestate(m)->comprehension_type);
10365 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010366 astmodulestate_global->excepthandler_type) < 0) {
10367 goto error;
10368 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010369 Py_INCREF(astmodulestate(m)->excepthandler_type);
10370 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010371 astmodulestate_global->ExceptHandler_type) < 0) {
10372 goto error;
10373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010374 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10375 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010376 astmodulestate_global->arguments_type) < 0) {
10377 goto error;
10378 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010379 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010380 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10381 goto error;
10382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010383 Py_INCREF(astmodulestate(m)->arg_type);
10384 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010385 0) {
10386 goto error;
10387 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010388 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010389 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10390 goto error;
10391 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010392 Py_INCREF(astmodulestate(m)->alias_type);
10393 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010394 < 0) {
10395 goto error;
10396 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010397 Py_INCREF(astmodulestate(m)->withitem_type);
10398 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010399 astmodulestate_global->type_ignore_type) < 0) {
10400 goto error;
10401 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010402 Py_INCREF(astmodulestate(m)->type_ignore_type);
10403 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010404 astmodulestate_global->TypeIgnore_type) < 0) {
10405 goto error;
10406 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010407 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010408 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010409error:
10410 Py_DECREF(m);
10411 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010412}
10413
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010414
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010415PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010416{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010417 if (!init_types())
10418 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010419 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010420}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010421
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010422/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10423mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010424{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010425 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010426 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010427 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010428
Steve Dowerb82e17e2019-05-23 08:45:22 -070010429 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10430 return NULL;
10431 }
10432
Dino Viehlandac46eb42019-09-11 10:16:34 -070010433 req_type[0] = astmodulestate_global->Module_type;
10434 req_type[1] = astmodulestate_global->Expression_type;
10435 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010436
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010437 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010438
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010439 if (!init_types())
10440 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010441
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010442 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10443 if (isinstance == -1)
10444 return NULL;
10445 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010446 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010447 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010448 return NULL;
10449 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010450
10451 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010452 if (obj2ast_mod(ast, &res, arena) != 0)
10453 return NULL;
10454 else
10455 return res;
10456}
10457
10458int PyAST_Check(PyObject* obj)
10459{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010460 if (!init_types())
10461 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010462 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010463}
10464
Martin v. Löwis5b222132007-06-10 09:51:05 +000010465