blob: f34b1450c66ef17788999c92aef710d7201fba02 [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{
1112 Py_VISIT(self->dict);
1113 return 0;
1114}
1115
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001116static int
Benjamin Peterson81071762012-07-08 11:03:46 -07001117ast_clear(AST_object *self)
1118{
1119 Py_CLEAR(self->dict);
Serhiy Storchakaa5c42282018-05-31 07:34:34 +03001120 return 0;
Benjamin Peterson81071762012-07-08 11:03:46 -07001121}
1122
1123static int
Neal Norwitz207c9f32008-03-31 04:42:11 +00001124ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
1125{
1126 Py_ssize_t i, numfields = 0;
1127 int res = -1;
1128 PyObject *key, *value, *fields;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001129 if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), astmodulestate_global->_fields, &fields) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001130 goto cleanup;
1131 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001132 if (fields) {
1133 numfields = PySequence_Size(fields);
1134 if (numfields == -1)
1135 goto cleanup;
1136 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001137
Neal Norwitz207c9f32008-03-31 04:42:11 +00001138 res = 0; /* if no error occurs, this stays 0 to the end */
INADA Naoki4c78c522017-02-24 02:48:17 +09001139 if (numfields < PyTuple_GET_SIZE(args)) {
1140 PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
1141 "%zd positional argument%s",
Dino Viehlandac46eb42019-09-11 10:16:34 -07001142 _PyType_Name(Py_TYPE(self)),
INADA Naoki4c78c522017-02-24 02:48:17 +09001143 numfields, numfields == 1 ? "" : "s");
1144 res = -1;
1145 goto cleanup;
1146 }
1147 for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
1148 /* cannot be reached when fields is NULL */
1149 PyObject *name = PySequence_GetItem(fields, i);
1150 if (!name) {
Neal Norwitz207c9f32008-03-31 04:42:11 +00001151 res = -1;
1152 goto cleanup;
1153 }
INADA Naoki4c78c522017-02-24 02:48:17 +09001154 res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
1155 Py_DECREF(name);
1156 if (res < 0)
1157 goto cleanup;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001158 }
1159 if (kw) {
1160 i = 0; /* needed by PyDict_Next */
1161 while (PyDict_Next(kw, &i, &key, &value)) {
1162 res = PyObject_SetAttr(self, key, value);
1163 if (res < 0)
1164 goto cleanup;
1165 }
1166 }
1167 cleanup:
1168 Py_XDECREF(fields);
1169 return res;
1170}
1171
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001172/* Pickling support */
1173static PyObject *
1174ast_type_reduce(PyObject *self, PyObject *unused)
1175{
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001176 PyObject *dict;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001177 if (_PyObject_LookupAttr(self, astmodulestate_global->__dict__, &dict) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001178 return NULL;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001179 }
1180 if (dict) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02001181 return Py_BuildValue("O()N", Py_TYPE(self), dict);
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001182 }
1183 return Py_BuildValue("O()", Py_TYPE(self));
1184}
1185
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001186static PyMemberDef ast_type_members[] = {
1187 {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
1188 {NULL} /* Sentinel */
1189};
1190
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001191static PyMethodDef ast_type_methods[] = {
1192 {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
1193 {NULL}
1194};
1195
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001196static PyGetSetDef ast_type_getsets[] = {
1197 {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
1198 {NULL}
1199};
1200
Dino Viehlandac46eb42019-09-11 10:16:34 -07001201static PyType_Slot AST_type_slots[] = {
1202 {Py_tp_dealloc, ast_dealloc},
1203 {Py_tp_getattro, PyObject_GenericGetAttr},
1204 {Py_tp_setattro, PyObject_GenericSetAttr},
1205 {Py_tp_traverse, ast_traverse},
1206 {Py_tp_clear, ast_clear},
Eddie Elizondo3368f3c2019-09-19 09:29:05 -07001207 {Py_tp_members, ast_type_members},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001208 {Py_tp_methods, ast_type_methods},
1209 {Py_tp_getset, ast_type_getsets},
1210 {Py_tp_init, ast_type_init},
1211 {Py_tp_alloc, PyType_GenericAlloc},
1212 {Py_tp_new, PyType_GenericNew},
Dino Viehlandac46eb42019-09-11 10:16:34 -07001213 {Py_tp_free, PyObject_GC_Del},
1214 {0, 0},
1215};
1216
1217static PyType_Spec AST_type_spec = {
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001218 "ast.AST",
Benjamin Peterson7e0dbfb2012-03-12 09:46:44 -07001219 sizeof(AST_object),
Neal Norwitz207c9f32008-03-31 04:42:11 +00001220 0,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001221 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1222 AST_type_slots
Neal Norwitz207c9f32008-03-31 04:42:11 +00001223};
1224
Dino Viehlandac46eb42019-09-11 10:16:34 -07001225static PyObject *
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001226make_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 +00001227{
1228 PyObject *fnames, *result;
1229 int i;
Neal Norwitzee9b10a2008-03-31 05:29:39 +00001230 fnames = PyTuple_New(num_fields);
1231 if (!fnames) return NULL;
1232 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001233 PyObject *field = PyUnicode_InternFromString(fields[i]);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001234 if (!field) {
1235 Py_DECREF(fnames);
1236 return NULL;
1237 }
1238 PyTuple_SET_ITEM(fnames, i, field);
1239 }
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001240 result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOs}",
INADA Naokifc489082017-01-25 22:33:43 +09001241 type, base,
Dino Viehlandac46eb42019-09-11 10:16:34 -07001242 astmodulestate_global->_fields, fnames,
1243 astmodulestate_global->__module__,
Serhiy Storchakabace59d2020-03-22 20:33:34 +02001244 astmodulestate_global->ast,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001245 astmodulestate_global->__doc__, doc);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001246 Py_DECREF(fnames);
Dino Viehlandac46eb42019-09-11 10:16:34 -07001247 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001248}
1249
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001250static int
Dino Viehlandac46eb42019-09-11 10:16:34 -07001251add_attributes(PyObject *type, const char * const *attrs, int num_fields)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001252{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001253 int i, result;
Neal Norwitz207c9f32008-03-31 04:42:11 +00001254 PyObject *s, *l = PyTuple_New(num_fields);
Benjamin Peterson3e5cd1d2010-06-27 21:45:24 +00001255 if (!l)
1256 return 0;
1257 for (i = 0; i < num_fields; i++) {
Serhiy Storchaka43c97312019-09-10 13:02:30 +03001258 s = PyUnicode_InternFromString(attrs[i]);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001259 if (!s) {
1260 Py_DECREF(l);
1261 return 0;
1262 }
Neal Norwitz207c9f32008-03-31 04:42:11 +00001263 PyTuple_SET_ITEM(l, i, s);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001264 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07001265 result = PyObject_SetAttr(type, astmodulestate_global->_attributes, l) >= 0;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001266 Py_DECREF(l);
1267 return result;
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001268}
1269
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001270/* Conversion AST -> Python */
1271
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001272static PyObject* ast2obj_list(asdl_seq *seq, PyObject* (*func)(void*))
1273{
Benjamin Peterson77fa9372012-05-15 10:10:27 -07001274 Py_ssize_t i, n = asdl_seq_LEN(seq);
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001275 PyObject *result = PyList_New(n);
1276 PyObject *value;
1277 if (!result)
1278 return NULL;
1279 for (i = 0; i < n; i++) {
1280 value = func(asdl_seq_GET(seq, i));
1281 if (!value) {
1282 Py_DECREF(result);
1283 return NULL;
1284 }
1285 PyList_SET_ITEM(result, i, value);
1286 }
1287 return result;
1288}
1289
1290static PyObject* ast2obj_object(void *o)
1291{
1292 if (!o)
1293 o = Py_None;
1294 Py_INCREF((PyObject*)o);
1295 return (PyObject*)o;
1296}
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001297#define ast2obj_constant ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001298#define ast2obj_identifier ast2obj_object
1299#define ast2obj_string ast2obj_object
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001300
Thomas Woutersa44f3a32007-02-26 18:20:15 +00001301static PyObject* ast2obj_int(long b)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001302{
Christian Heimes217cfd12007-12-02 14:31:20 +00001303 return PyLong_FromLong(b);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00001304}
1305
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001306/* Conversion Python -> AST */
1307
1308static int obj2ast_object(PyObject* obj, PyObject** out, PyArena* arena)
1309{
1310 if (obj == Py_None)
1311 obj = NULL;
Christian Heimes70c94e72013-07-27 00:33:13 +02001312 if (obj) {
1313 if (PyArena_AddPyObject(arena, obj) < 0) {
1314 *out = NULL;
1315 return -1;
1316 }
1317 Py_INCREF(obj);
1318 }
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001319 *out = obj;
1320 return 0;
1321}
1322
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001323static int obj2ast_constant(PyObject* obj, PyObject** out, PyArena* arena)
1324{
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001325 if (PyArena_AddPyObject(arena, obj) < 0) {
1326 *out = NULL;
1327 return -1;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001328 }
Serhiy Storchaka3f228112018-09-27 17:42:37 +03001329 Py_INCREF(obj);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01001330 *out = obj;
1331 return 0;
1332}
1333
Benjamin Peterson180e6352011-07-22 11:09:07 -05001334static int obj2ast_identifier(PyObject* obj, PyObject** out, PyArena* arena)
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001335{
Benjamin Peterson180e6352011-07-22 11:09:07 -05001336 if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
1337 PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
Benjamin Peterson2193d2b2011-07-22 10:50:23 -05001338 return 1;
1339 }
1340 return obj2ast_object(obj, out, arena);
1341}
1342
Guido van Rossumdcfcd142019-01-31 03:40:27 -08001343static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
1344{
1345 if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
1346 PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
1347 return 1;
1348 }
1349 return obj2ast_object(obj, out, arena);
1350}
1351
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001352static int obj2ast_int(PyObject* obj, int* out, PyArena* arena)
1353{
1354 int i;
1355 if (!PyLong_Check(obj)) {
Amaury Forgeot d'Arc5e8f8102011-11-22 21:52:30 +01001356 PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001357 return 1;
1358 }
1359
Serhiy Storchaka56f6e762015-09-06 21:25:30 +03001360 i = _PyLong_AsInt(obj);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001361 if (i == -1 && PyErr_Occurred())
1362 return 1;
1363 *out = i;
1364 return 0;
1365}
1366
Benjamin Peterson1a6e0d02008-10-25 15:49:17 +00001367static int add_ast_fields(void)
Benjamin Petersonce825f12008-10-24 23:11:02 +00001368{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001369 PyObject *empty_tuple;
Benjamin Petersonce825f12008-10-24 23:11:02 +00001370 empty_tuple = PyTuple_New(0);
1371 if (!empty_tuple ||
Dino Viehlandac46eb42019-09-11 10:16:34 -07001372 PyObject_SetAttrString(astmodulestate_global->AST_type, "_fields", empty_tuple) < 0 ||
1373 PyObject_SetAttrString(astmodulestate_global->AST_type, "_attributes", empty_tuple) < 0) {
Benjamin Petersonce825f12008-10-24 23:11:02 +00001374 Py_XDECREF(empty_tuple);
1375 return -1;
1376 }
1377 Py_DECREF(empty_tuple);
1378 return 0;
1379}
1380
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00001381
Martin v. Löwisbd260da2006-02-26 19:42:26 +00001382static int init_types(void)
1383{
Dino Viehlandac46eb42019-09-11 10:16:34 -07001384 PyObject *m;
1385 if (PyState_FindModule(&_astmodule) == NULL) {
1386 m = PyModule_Create(&_astmodule);
1387 if (!m) return 0;
1388 PyState_AddModule(m, &_astmodule);
1389 }
1390 astmodulestate *state = astmodulestate_global;
1391 if (state->initialized) return 1;
1392 if (init_identifiers() < 0) return 0;
1393 state->AST_type = PyType_FromSpec(&AST_type_spec);
1394 if (!state->AST_type) return 0;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02001395 if (add_ast_fields() < 0) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001396 state->mod_type = make_type("mod", state->AST_type, NULL, 0,
1397 "mod = Module(stmt* body, type_ignore* type_ignores)\n"
1398 " | Interactive(stmt* body)\n"
1399 " | Expression(expr body)\n"
1400 " | FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001401 if (!state->mod_type) return 0;
1402 if (!add_attributes(state->mod_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001403 state->Module_type = make_type("Module", state->mod_type, Module_fields, 2,
1404 "Module(stmt* body, type_ignore* type_ignores)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001405 if (!state->Module_type) return 0;
1406 state->Interactive_type = make_type("Interactive", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001407 Interactive_fields, 1,
1408 "Interactive(stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001409 if (!state->Interactive_type) return 0;
1410 state->Expression_type = make_type("Expression", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001411 Expression_fields, 1,
1412 "Expression(expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001413 if (!state->Expression_type) return 0;
1414 state->FunctionType_type = make_type("FunctionType", state->mod_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001415 FunctionType_fields, 2,
1416 "FunctionType(expr* argtypes, expr returns)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001417 if (!state->FunctionType_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001418 state->stmt_type = make_type("stmt", state->AST_type, NULL, 0,
1419 "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1420 " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)\n"
1421 " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)\n"
1422 " | Return(expr? value)\n"
1423 " | Delete(expr* targets)\n"
1424 " | Assign(expr* targets, expr value, string? type_comment)\n"
1425 " | AugAssign(expr target, operator op, expr value)\n"
1426 " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
1427 " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1428 " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
1429 " | While(expr test, stmt* body, stmt* orelse)\n"
1430 " | If(expr test, stmt* body, stmt* orelse)\n"
1431 " | With(withitem* items, stmt* body, string? type_comment)\n"
1432 " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
1433 " | Raise(expr? exc, expr? cause)\n"
1434 " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
1435 " | Assert(expr test, expr? msg)\n"
1436 " | Import(alias* names)\n"
1437 " | ImportFrom(identifier? module, alias* names, int? level)\n"
1438 " | Global(identifier* names)\n"
1439 " | Nonlocal(identifier* names)\n"
1440 " | Expr(expr value)\n"
1441 " | Pass\n"
1442 " | Break\n"
1443 " | Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001444 if (!state->stmt_type) return 0;
1445 if (!add_attributes(state->stmt_type, stmt_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001446 if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
1447 return 0;
1448 if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
1449 -1)
1450 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001451 state->FunctionDef_type = make_type("FunctionDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001452 FunctionDef_fields, 6,
1453 "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001454 if (!state->FunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001455 if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
1456 -1)
1457 return 0;
1458 if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
1459 == -1)
1460 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001461 state->AsyncFunctionDef_type = make_type("AsyncFunctionDef",
1462 state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001463 AsyncFunctionDef_fields, 6,
1464 "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001465 if (!state->AsyncFunctionDef_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001466 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
1467 == -1)
1468 return 0;
1469 if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
1470 Py_None) == -1)
1471 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001472 state->ClassDef_type = make_type("ClassDef", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001473 ClassDef_fields, 5,
1474 "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001475 if (!state->ClassDef_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001476 state->Return_type = make_type("Return", state->stmt_type, Return_fields, 1,
1477 "Return(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001478 if (!state->Return_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001479 if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
1480 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001481 state->Delete_type = make_type("Delete", state->stmt_type, Delete_fields, 1,
1482 "Delete(expr* targets)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001483 if (!state->Delete_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001484 state->Assign_type = make_type("Assign", state->stmt_type, Assign_fields, 3,
1485 "Assign(expr* targets, expr value, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001486 if (!state->Assign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001487 if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
1488 -1)
1489 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001490 state->AugAssign_type = make_type("AugAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001491 AugAssign_fields, 3,
1492 "AugAssign(expr target, operator op, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001493 if (!state->AugAssign_type) return 0;
1494 state->AnnAssign_type = make_type("AnnAssign", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001495 AnnAssign_fields, 4,
1496 "AnnAssign(expr target, expr annotation, expr? value, int simple)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001497 if (!state->AnnAssign_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001498 if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
1499 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001500 state->For_type = make_type("For", state->stmt_type, For_fields, 5,
1501 "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001502 if (!state->For_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001503 if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
1504 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001505 state->AsyncFor_type = make_type("AsyncFor", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001506 AsyncFor_fields, 5,
1507 "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001508 if (!state->AsyncFor_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001509 if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
1510 -1)
1511 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001512 state->While_type = make_type("While", state->stmt_type, While_fields, 3,
1513 "While(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001514 if (!state->While_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001515 state->If_type = make_type("If", state->stmt_type, If_fields, 3,
1516 "If(expr test, stmt* body, stmt* orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001517 if (!state->If_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001518 state->With_type = make_type("With", state->stmt_type, With_fields, 3,
1519 "With(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001520 if (!state->With_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001521 if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
1522 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001523 state->AsyncWith_type = make_type("AsyncWith", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001524 AsyncWith_fields, 3,
1525 "AsyncWith(withitem* items, stmt* body, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001526 if (!state->AsyncWith_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001527 if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
1528 == -1)
1529 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001530 state->Raise_type = make_type("Raise", state->stmt_type, Raise_fields, 2,
1531 "Raise(expr? exc, expr? cause)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001532 if (!state->Raise_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001533 if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
1534 return 0;
1535 if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
1536 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001537 state->Try_type = make_type("Try", state->stmt_type, Try_fields, 4,
1538 "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001539 if (!state->Try_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001540 state->Assert_type = make_type("Assert", state->stmt_type, Assert_fields, 2,
1541 "Assert(expr test, expr? msg)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001542 if (!state->Assert_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001543 if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
1544 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001545 state->Import_type = make_type("Import", state->stmt_type, Import_fields, 1,
1546 "Import(alias* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001547 if (!state->Import_type) return 0;
1548 state->ImportFrom_type = make_type("ImportFrom", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001549 ImportFrom_fields, 3,
1550 "ImportFrom(identifier? module, alias* names, int? level)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001551 if (!state->ImportFrom_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001552 if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
1553 return 0;
1554 if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
1555 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001556 state->Global_type = make_type("Global", state->stmt_type, Global_fields, 1,
1557 "Global(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001558 if (!state->Global_type) return 0;
1559 state->Nonlocal_type = make_type("Nonlocal", state->stmt_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001560 Nonlocal_fields, 1,
1561 "Nonlocal(identifier* names)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001562 if (!state->Nonlocal_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001563 state->Expr_type = make_type("Expr", state->stmt_type, Expr_fields, 1,
1564 "Expr(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001565 if (!state->Expr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001566 state->Pass_type = make_type("Pass", state->stmt_type, NULL, 0,
1567 "Pass");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001568 if (!state->Pass_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001569 state->Break_type = make_type("Break", state->stmt_type, NULL, 0,
1570 "Break");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001571 if (!state->Break_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001572 state->Continue_type = make_type("Continue", state->stmt_type, NULL, 0,
1573 "Continue");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001574 if (!state->Continue_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001575 state->expr_type = make_type("expr", state->AST_type, NULL, 0,
1576 "expr = BoolOp(boolop op, expr* values)\n"
1577 " | NamedExpr(expr target, expr value)\n"
1578 " | BinOp(expr left, operator op, expr right)\n"
1579 " | UnaryOp(unaryop op, expr operand)\n"
1580 " | Lambda(arguments args, expr body)\n"
1581 " | IfExp(expr test, expr body, expr orelse)\n"
1582 " | Dict(expr* keys, expr* values)\n"
1583 " | Set(expr* elts)\n"
1584 " | ListComp(expr elt, comprehension* generators)\n"
1585 " | SetComp(expr elt, comprehension* generators)\n"
1586 " | DictComp(expr key, expr value, comprehension* generators)\n"
1587 " | GeneratorExp(expr elt, comprehension* generators)\n"
1588 " | Await(expr value)\n"
1589 " | Yield(expr? value)\n"
1590 " | YieldFrom(expr value)\n"
1591 " | Compare(expr left, cmpop* ops, expr* comparators)\n"
1592 " | Call(expr func, expr* args, keyword* keywords)\n"
1593 " | FormattedValue(expr value, int? conversion, expr? format_spec)\n"
1594 " | JoinedStr(expr* values)\n"
1595 " | Constant(constant value, string? kind)\n"
1596 " | Attribute(expr value, identifier attr, expr_context ctx)\n"
1597 " | Subscript(expr value, expr slice, expr_context ctx)\n"
1598 " | Starred(expr value, expr_context ctx)\n"
1599 " | Name(identifier id, expr_context ctx)\n"
1600 " | List(expr* elts, expr_context ctx)\n"
1601 " | Tuple(expr* elts, expr_context ctx)\n"
1602 " | Slice(expr? lower, expr? upper, expr? step)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001603 if (!state->expr_type) return 0;
1604 if (!add_attributes(state->expr_type, expr_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001605 if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
1606 return 0;
1607 if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
1608 -1)
1609 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001610 state->BoolOp_type = make_type("BoolOp", state->expr_type, BoolOp_fields, 2,
1611 "BoolOp(boolop op, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001612 if (!state->BoolOp_type) return 0;
1613 state->NamedExpr_type = make_type("NamedExpr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001614 NamedExpr_fields, 2,
1615 "NamedExpr(expr target, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001616 if (!state->NamedExpr_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001617 state->BinOp_type = make_type("BinOp", state->expr_type, BinOp_fields, 3,
1618 "BinOp(expr left, operator op, expr right)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001619 if (!state->BinOp_type) return 0;
1620 state->UnaryOp_type = make_type("UnaryOp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001621 UnaryOp_fields, 2,
1622 "UnaryOp(unaryop op, expr operand)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001623 if (!state->UnaryOp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001624 state->Lambda_type = make_type("Lambda", state->expr_type, Lambda_fields, 2,
1625 "Lambda(arguments args, expr body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001626 if (!state->Lambda_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001627 state->IfExp_type = make_type("IfExp", state->expr_type, IfExp_fields, 3,
1628 "IfExp(expr test, expr body, expr orelse)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001629 if (!state->IfExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001630 state->Dict_type = make_type("Dict", state->expr_type, Dict_fields, 2,
1631 "Dict(expr* keys, expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001632 if (!state->Dict_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001633 state->Set_type = make_type("Set", state->expr_type, Set_fields, 1,
1634 "Set(expr* elts)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001635 if (!state->Set_type) return 0;
1636 state->ListComp_type = make_type("ListComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001637 ListComp_fields, 2,
1638 "ListComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001639 if (!state->ListComp_type) return 0;
1640 state->SetComp_type = make_type("SetComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001641 SetComp_fields, 2,
1642 "SetComp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001643 if (!state->SetComp_type) return 0;
1644 state->DictComp_type = make_type("DictComp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001645 DictComp_fields, 3,
1646 "DictComp(expr key, expr value, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001647 if (!state->DictComp_type) return 0;
1648 state->GeneratorExp_type = make_type("GeneratorExp", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001649 GeneratorExp_fields, 2,
1650 "GeneratorExp(expr elt, comprehension* generators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001651 if (!state->GeneratorExp_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001652 state->Await_type = make_type("Await", state->expr_type, Await_fields, 1,
1653 "Await(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001654 if (!state->Await_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001655 state->Yield_type = make_type("Yield", state->expr_type, Yield_fields, 1,
1656 "Yield(expr? value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001657 if (!state->Yield_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001658 if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
1659 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001660 state->YieldFrom_type = make_type("YieldFrom", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001661 YieldFrom_fields, 1,
1662 "YieldFrom(expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001663 if (!state->YieldFrom_type) return 0;
1664 state->Compare_type = make_type("Compare", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001665 Compare_fields, 3,
1666 "Compare(expr left, cmpop* ops, expr* comparators)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001667 if (!state->Compare_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001668 state->Call_type = make_type("Call", state->expr_type, Call_fields, 3,
1669 "Call(expr func, expr* args, keyword* keywords)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001670 if (!state->Call_type) return 0;
1671 state->FormattedValue_type = make_type("FormattedValue", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001672 FormattedValue_fields, 3,
1673 "FormattedValue(expr value, int? conversion, expr? format_spec)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001674 if (!state->FormattedValue_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001675 if (PyObject_SetAttr(state->FormattedValue_type, state->conversion,
1676 Py_None) == -1)
1677 return 0;
1678 if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
1679 Py_None) == -1)
1680 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001681 state->JoinedStr_type = make_type("JoinedStr", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001682 JoinedStr_fields, 1,
1683 "JoinedStr(expr* values)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001684 if (!state->JoinedStr_type) return 0;
1685 state->Constant_type = make_type("Constant", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001686 Constant_fields, 2,
1687 "Constant(constant value, string? kind)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001688 if (!state->Constant_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001689 if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
1690 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001691 state->Attribute_type = make_type("Attribute", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001692 Attribute_fields, 3,
1693 "Attribute(expr value, identifier attr, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001694 if (!state->Attribute_type) return 0;
1695 state->Subscript_type = make_type("Subscript", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001696 Subscript_fields, 3,
1697 "Subscript(expr value, expr slice, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001698 if (!state->Subscript_type) return 0;
1699 state->Starred_type = make_type("Starred", state->expr_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001700 Starred_fields, 2,
1701 "Starred(expr value, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001702 if (!state->Starred_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001703 state->Name_type = make_type("Name", state->expr_type, Name_fields, 2,
1704 "Name(identifier id, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001705 if (!state->Name_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001706 state->List_type = make_type("List", state->expr_type, List_fields, 2,
1707 "List(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001708 if (!state->List_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001709 state->Tuple_type = make_type("Tuple", state->expr_type, Tuple_fields, 2,
1710 "Tuple(expr* elts, expr_context ctx)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001711 if (!state->Tuple_type) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001712 state->Slice_type = make_type("Slice", state->expr_type, Slice_fields, 3,
1713 "Slice(expr? lower, expr? upper, expr? step)");
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02001714 if (!state->Slice_type) return 0;
1715 if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
1716 return 0;
1717 if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
1718 return 0;
1719 if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
1720 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001721 state->expr_context_type = make_type("expr_context", state->AST_type, NULL,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001722 0,
Serhiy Storchaka6b975982020-03-17 23:41:08 +02001723 "expr_context = Load | Store | Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001724 if (!state->expr_context_type) return 0;
1725 if (!add_attributes(state->expr_context_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001726 state->Load_type = make_type("Load", state->expr_context_type, NULL, 0,
1727 "Load");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001728 if (!state->Load_type) return 0;
1729 state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
1730 NULL, NULL);
1731 if (!state->Load_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001732 state->Store_type = make_type("Store", state->expr_context_type, NULL, 0,
1733 "Store");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001734 if (!state->Store_type) return 0;
1735 state->Store_singleton = PyType_GenericNew((PyTypeObject
1736 *)state->Store_type, NULL, NULL);
1737 if (!state->Store_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001738 state->Del_type = make_type("Del", state->expr_context_type, NULL, 0,
1739 "Del");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001740 if (!state->Del_type) return 0;
1741 state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
1742 NULL, NULL);
1743 if (!state->Del_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001744 state->boolop_type = make_type("boolop", state->AST_type, NULL, 0,
1745 "boolop = And | Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001746 if (!state->boolop_type) return 0;
1747 if (!add_attributes(state->boolop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001748 state->And_type = make_type("And", state->boolop_type, NULL, 0,
1749 "And");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001750 if (!state->And_type) return 0;
1751 state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
1752 NULL, NULL);
1753 if (!state->And_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001754 state->Or_type = make_type("Or", state->boolop_type, NULL, 0,
1755 "Or");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001756 if (!state->Or_type) return 0;
1757 state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
1758 NULL, NULL);
1759 if (!state->Or_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001760 state->operator_type = make_type("operator", state->AST_type, NULL, 0,
1761 "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001762 if (!state->operator_type) return 0;
1763 if (!add_attributes(state->operator_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001764 state->Add_type = make_type("Add", state->operator_type, NULL, 0,
1765 "Add");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001766 if (!state->Add_type) return 0;
1767 state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
1768 NULL, NULL);
1769 if (!state->Add_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001770 state->Sub_type = make_type("Sub", state->operator_type, NULL, 0,
1771 "Sub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001772 if (!state->Sub_type) return 0;
1773 state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
1774 NULL, NULL);
1775 if (!state->Sub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001776 state->Mult_type = make_type("Mult", state->operator_type, NULL, 0,
1777 "Mult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001778 if (!state->Mult_type) return 0;
1779 state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
1780 NULL, NULL);
1781 if (!state->Mult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001782 state->MatMult_type = make_type("MatMult", state->operator_type, NULL, 0,
1783 "MatMult");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001784 if (!state->MatMult_type) return 0;
1785 state->MatMult_singleton = PyType_GenericNew((PyTypeObject
1786 *)state->MatMult_type, NULL,
1787 NULL);
1788 if (!state->MatMult_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001789 state->Div_type = make_type("Div", state->operator_type, NULL, 0,
1790 "Div");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001791 if (!state->Div_type) return 0;
1792 state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
1793 NULL, NULL);
1794 if (!state->Div_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001795 state->Mod_type = make_type("Mod", state->operator_type, NULL, 0,
1796 "Mod");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001797 if (!state->Mod_type) return 0;
1798 state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
1799 NULL, NULL);
1800 if (!state->Mod_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001801 state->Pow_type = make_type("Pow", state->operator_type, NULL, 0,
1802 "Pow");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001803 if (!state->Pow_type) return 0;
1804 state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
1805 NULL, NULL);
1806 if (!state->Pow_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001807 state->LShift_type = make_type("LShift", state->operator_type, NULL, 0,
1808 "LShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001809 if (!state->LShift_type) return 0;
1810 state->LShift_singleton = PyType_GenericNew((PyTypeObject
1811 *)state->LShift_type, NULL,
1812 NULL);
1813 if (!state->LShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001814 state->RShift_type = make_type("RShift", state->operator_type, NULL, 0,
1815 "RShift");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001816 if (!state->RShift_type) return 0;
1817 state->RShift_singleton = PyType_GenericNew((PyTypeObject
1818 *)state->RShift_type, NULL,
1819 NULL);
1820 if (!state->RShift_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001821 state->BitOr_type = make_type("BitOr", state->operator_type, NULL, 0,
1822 "BitOr");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001823 if (!state->BitOr_type) return 0;
1824 state->BitOr_singleton = PyType_GenericNew((PyTypeObject
1825 *)state->BitOr_type, NULL, NULL);
1826 if (!state->BitOr_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001827 state->BitXor_type = make_type("BitXor", state->operator_type, NULL, 0,
1828 "BitXor");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001829 if (!state->BitXor_type) return 0;
1830 state->BitXor_singleton = PyType_GenericNew((PyTypeObject
1831 *)state->BitXor_type, NULL,
1832 NULL);
1833 if (!state->BitXor_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001834 state->BitAnd_type = make_type("BitAnd", state->operator_type, NULL, 0,
1835 "BitAnd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001836 if (!state->BitAnd_type) return 0;
1837 state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
1838 *)state->BitAnd_type, NULL,
1839 NULL);
1840 if (!state->BitAnd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001841 state->FloorDiv_type = make_type("FloorDiv", state->operator_type, NULL, 0,
1842 "FloorDiv");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001843 if (!state->FloorDiv_type) return 0;
1844 state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
1845 *)state->FloorDiv_type, NULL,
1846 NULL);
1847 if (!state->FloorDiv_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001848 state->unaryop_type = make_type("unaryop", state->AST_type, NULL, 0,
1849 "unaryop = Invert | Not | UAdd | USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001850 if (!state->unaryop_type) return 0;
1851 if (!add_attributes(state->unaryop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001852 state->Invert_type = make_type("Invert", state->unaryop_type, NULL, 0,
1853 "Invert");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001854 if (!state->Invert_type) return 0;
1855 state->Invert_singleton = PyType_GenericNew((PyTypeObject
1856 *)state->Invert_type, NULL,
1857 NULL);
1858 if (!state->Invert_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001859 state->Not_type = make_type("Not", state->unaryop_type, NULL, 0,
1860 "Not");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001861 if (!state->Not_type) return 0;
1862 state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
1863 NULL, NULL);
1864 if (!state->Not_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001865 state->UAdd_type = make_type("UAdd", state->unaryop_type, NULL, 0,
1866 "UAdd");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001867 if (!state->UAdd_type) return 0;
1868 state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
1869 NULL, NULL);
1870 if (!state->UAdd_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001871 state->USub_type = make_type("USub", state->unaryop_type, NULL, 0,
1872 "USub");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001873 if (!state->USub_type) return 0;
1874 state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
1875 NULL, NULL);
1876 if (!state->USub_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001877 state->cmpop_type = make_type("cmpop", state->AST_type, NULL, 0,
1878 "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001879 if (!state->cmpop_type) return 0;
1880 if (!add_attributes(state->cmpop_type, NULL, 0)) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001881 state->Eq_type = make_type("Eq", state->cmpop_type, NULL, 0,
1882 "Eq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001883 if (!state->Eq_type) return 0;
1884 state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
1885 NULL, NULL);
1886 if (!state->Eq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001887 state->NotEq_type = make_type("NotEq", state->cmpop_type, NULL, 0,
1888 "NotEq");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001889 if (!state->NotEq_type) return 0;
1890 state->NotEq_singleton = PyType_GenericNew((PyTypeObject
1891 *)state->NotEq_type, NULL, NULL);
1892 if (!state->NotEq_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001893 state->Lt_type = make_type("Lt", state->cmpop_type, NULL, 0,
1894 "Lt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001895 if (!state->Lt_type) return 0;
1896 state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
1897 NULL, NULL);
1898 if (!state->Lt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001899 state->LtE_type = make_type("LtE", state->cmpop_type, NULL, 0,
1900 "LtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001901 if (!state->LtE_type) return 0;
1902 state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
1903 NULL, NULL);
1904 if (!state->LtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001905 state->Gt_type = make_type("Gt", state->cmpop_type, NULL, 0,
1906 "Gt");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001907 if (!state->Gt_type) return 0;
1908 state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
1909 NULL, NULL);
1910 if (!state->Gt_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001911 state->GtE_type = make_type("GtE", state->cmpop_type, NULL, 0,
1912 "GtE");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001913 if (!state->GtE_type) return 0;
1914 state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
1915 NULL, NULL);
1916 if (!state->GtE_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001917 state->Is_type = make_type("Is", state->cmpop_type, NULL, 0,
1918 "Is");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001919 if (!state->Is_type) return 0;
1920 state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
1921 NULL, NULL);
1922 if (!state->Is_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001923 state->IsNot_type = make_type("IsNot", state->cmpop_type, NULL, 0,
1924 "IsNot");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001925 if (!state->IsNot_type) return 0;
1926 state->IsNot_singleton = PyType_GenericNew((PyTypeObject
1927 *)state->IsNot_type, NULL, NULL);
1928 if (!state->IsNot_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001929 state->In_type = make_type("In", state->cmpop_type, NULL, 0,
1930 "In");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001931 if (!state->In_type) return 0;
1932 state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
1933 NULL, NULL);
1934 if (!state->In_singleton) return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001935 state->NotIn_type = make_type("NotIn", state->cmpop_type, NULL, 0,
1936 "NotIn");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001937 if (!state->NotIn_type) return 0;
1938 state->NotIn_singleton = PyType_GenericNew((PyTypeObject
1939 *)state->NotIn_type, NULL, NULL);
1940 if (!state->NotIn_singleton) return 0;
1941 state->comprehension_type = make_type("comprehension", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001942 comprehension_fields, 4,
1943 "comprehension(expr target, expr iter, expr* ifs, int is_async)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001944 if (!state->comprehension_type) return 0;
1945 if (!add_attributes(state->comprehension_type, NULL, 0)) return 0;
1946 state->excepthandler_type = make_type("excepthandler", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001947 NULL, 0,
1948 "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001949 if (!state->excepthandler_type) return 0;
1950 if (!add_attributes(state->excepthandler_type, excepthandler_attributes,
1951 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001952 if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
1953 == -1)
1954 return 0;
1955 if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
1956 Py_None) == -1)
1957 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001958 state->ExceptHandler_type = make_type("ExceptHandler",
1959 state->excepthandler_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001960 ExceptHandler_fields, 3,
1961 "ExceptHandler(expr? type, identifier? name, stmt* body)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001962 if (!state->ExceptHandler_type) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001963 if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
1964 return 0;
1965 if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
1966 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001967 state->arguments_type = make_type("arguments", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001968 arguments_fields, 7,
1969 "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001970 if (!state->arguments_type) return 0;
1971 if (!add_attributes(state->arguments_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001972 if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
1973 return 0;
1974 if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
1975 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001976 state->arg_type = make_type("arg", state->AST_type, arg_fields, 3,
1977 "arg(identifier arg, expr? annotation, string? type_comment)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001978 if (!state->arg_type) return 0;
1979 if (!add_attributes(state->arg_type, arg_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001980 if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
1981 return 0;
1982 if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
1983 return 0;
1984 if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
1985 return 0;
1986 if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
1987 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07001988 state->keyword_type = make_type("keyword", state->AST_type, keyword_fields,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03001989 2,
1990 "keyword(identifier? arg, expr value)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07001991 if (!state->keyword_type) return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01001992 if (!add_attributes(state->keyword_type, keyword_attributes, 4)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02001993 if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
1994 return 0;
Pablo Galindo168660b2020-04-02 00:47:39 +01001995 if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
1996 return 0;
1997 if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
1998 == -1)
1999 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002000 state->alias_type = make_type("alias", state->AST_type, alias_fields, 2,
2001 "alias(identifier name, identifier? asname)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002002 if (!state->alias_type) return 0;
2003 if (!add_attributes(state->alias_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002004 if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
2005 return 0;
Dino Viehlandac46eb42019-09-11 10:16:34 -07002006 state->withitem_type = make_type("withitem", state->AST_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002007 withitem_fields, 2,
2008 "withitem(expr context_expr, expr? optional_vars)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002009 if (!state->withitem_type) return 0;
2010 if (!add_attributes(state->withitem_type, NULL, 0)) return 0;
Serhiy Storchakab7e95252020-03-10 00:07:47 +02002011 if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
2012 == -1)
2013 return 0;
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002014 state->type_ignore_type = make_type("type_ignore", state->AST_type, NULL, 0,
2015 "type_ignore = TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002016 if (!state->type_ignore_type) return 0;
2017 if (!add_attributes(state->type_ignore_type, NULL, 0)) return 0;
2018 state->TypeIgnore_type = make_type("TypeIgnore", state->type_ignore_type,
Batuhan Taşkaya4ab362c2020-03-16 11:12:53 +03002019 TypeIgnore_fields, 2,
2020 "TypeIgnore(int lineno, string tag)");
Dino Viehlandac46eb42019-09-11 10:16:34 -07002021 if (!state->TypeIgnore_type) return 0;
2022 state->initialized = 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002023 return 1;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00002024}
Neal Norwitz7b5a6042005-11-13 19:14:20 +00002025
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002026static int obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena);
2027static int obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena);
2028static int obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena);
2029static int obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena*
2030 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002031static int obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena);
2032static int obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena);
2033static int obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena);
2034static int obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena);
2035static int obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena*
2036 arena);
2037static int obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena*
2038 arena);
2039static int obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena);
2040static int obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena);
2041static int obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena);
2042static int obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena);
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05002043static int obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002044static int obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena*
2045 arena);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00002046
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002047mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002048Module(asdl_seq * body, asdl_seq * type_ignores, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002049{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002050 mod_ty p;
2051 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2052 if (!p)
2053 return NULL;
2054 p->kind = Module_kind;
2055 p->v.Module.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002056 p->v.Module.type_ignores = type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002057 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002058}
2059
2060mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002061Interactive(asdl_seq * body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002062{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002063 mod_ty p;
2064 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2065 if (!p)
2066 return NULL;
2067 p->kind = Interactive_kind;
2068 p->v.Interactive.body = body;
2069 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002070}
2071
2072mod_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00002073Expression(expr_ty body, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002074{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002075 mod_ty p;
2076 if (!body) {
2077 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002078 "field 'body' is required for Expression");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002079 return NULL;
2080 }
2081 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2082 if (!p)
2083 return NULL;
2084 p->kind = Expression_kind;
2085 p->v.Expression.body = body;
2086 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002087}
2088
2089mod_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002090FunctionType(asdl_seq * argtypes, expr_ty returns, PyArena *arena)
2091{
2092 mod_ty p;
2093 if (!returns) {
2094 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002095 "field 'returns' is required for FunctionType");
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002096 return NULL;
2097 }
2098 p = (mod_ty)PyArena_Malloc(arena, sizeof(*p));
2099 if (!p)
2100 return NULL;
2101 p->kind = FunctionType_kind;
2102 p->v.FunctionType.argtypes = argtypes;
2103 p->v.FunctionType.returns = returns;
2104 return p;
2105}
2106
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002107stmt_ty
2108FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq *
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002109 decorator_list, expr_ty returns, string type_comment, int lineno,
2110 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002111{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002112 stmt_ty p;
2113 if (!name) {
2114 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002115 "field 'name' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002116 return NULL;
2117 }
2118 if (!args) {
2119 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002120 "field 'args' is required for FunctionDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002121 return NULL;
2122 }
2123 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2124 if (!p)
2125 return NULL;
2126 p->kind = FunctionDef_kind;
2127 p->v.FunctionDef.name = name;
2128 p->v.FunctionDef.args = args;
2129 p->v.FunctionDef.body = body;
2130 p->v.FunctionDef.decorator_list = decorator_list;
2131 p->v.FunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002132 p->v.FunctionDef.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002133 p->lineno = lineno;
2134 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002135 p->end_lineno = end_lineno;
2136 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002137 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002138}
2139
2140stmt_ty
Yury Selivanov75445082015-05-11 22:57:16 -04002141AsyncFunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002142 * decorator_list, expr_ty returns, string type_comment, int
2143 lineno, int col_offset, int end_lineno, int end_col_offset,
2144 PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002145{
2146 stmt_ty p;
2147 if (!name) {
2148 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002149 "field 'name' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04002150 return NULL;
2151 }
2152 if (!args) {
2153 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002154 "field 'args' is required for AsyncFunctionDef");
Yury Selivanov75445082015-05-11 22:57:16 -04002155 return NULL;
2156 }
2157 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2158 if (!p)
2159 return NULL;
2160 p->kind = AsyncFunctionDef_kind;
2161 p->v.AsyncFunctionDef.name = name;
2162 p->v.AsyncFunctionDef.args = args;
2163 p->v.AsyncFunctionDef.body = body;
2164 p->v.AsyncFunctionDef.decorator_list = decorator_list;
2165 p->v.AsyncFunctionDef.returns = returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002166 p->v.AsyncFunctionDef.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002167 p->lineno = lineno;
2168 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002169 p->end_lineno = end_lineno;
2170 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002171 return p;
2172}
2173
2174stmt_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04002175ClassDef(identifier name, asdl_seq * bases, asdl_seq * keywords, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002176 body, asdl_seq * decorator_list, int lineno, int col_offset, int
2177 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002178{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002179 stmt_ty p;
2180 if (!name) {
2181 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002182 "field 'name' is required for ClassDef");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002183 return NULL;
2184 }
2185 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2186 if (!p)
2187 return NULL;
2188 p->kind = ClassDef_kind;
2189 p->v.ClassDef.name = name;
2190 p->v.ClassDef.bases = bases;
2191 p->v.ClassDef.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002192 p->v.ClassDef.body = body;
2193 p->v.ClassDef.decorator_list = decorator_list;
2194 p->lineno = lineno;
2195 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002196 p->end_lineno = end_lineno;
2197 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002198 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002199}
2200
2201stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002202Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
2203 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002204{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002205 stmt_ty p;
2206 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2207 if (!p)
2208 return NULL;
2209 p->kind = Return_kind;
2210 p->v.Return.value = value;
2211 p->lineno = lineno;
2212 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002213 p->end_lineno = end_lineno;
2214 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002215 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002216}
2217
2218stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002219Delete(asdl_seq * targets, int lineno, int col_offset, int end_lineno, int
2220 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002221{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002222 stmt_ty p;
2223 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2224 if (!p)
2225 return NULL;
2226 p->kind = Delete_kind;
2227 p->v.Delete.targets = targets;
2228 p->lineno = lineno;
2229 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002230 p->end_lineno = end_lineno;
2231 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002232 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002233}
2234
2235stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002236Assign(asdl_seq * targets, expr_ty value, string type_comment, int lineno, int
2237 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002238{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002239 stmt_ty p;
2240 if (!value) {
2241 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002242 "field 'value' is required for Assign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002243 return NULL;
2244 }
2245 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2246 if (!p)
2247 return NULL;
2248 p->kind = Assign_kind;
2249 p->v.Assign.targets = targets;
2250 p->v.Assign.value = value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002251 p->v.Assign.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002252 p->lineno = lineno;
2253 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002254 p->end_lineno = end_lineno;
2255 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002256 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002257}
2258
2259stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002260AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002261 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002262{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002263 stmt_ty p;
2264 if (!target) {
2265 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002266 "field 'target' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002267 return NULL;
2268 }
2269 if (!op) {
2270 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002271 "field 'op' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002272 return NULL;
2273 }
2274 if (!value) {
2275 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002276 "field 'value' is required for AugAssign");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002277 return NULL;
2278 }
2279 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2280 if (!p)
2281 return NULL;
2282 p->kind = AugAssign_kind;
2283 p->v.AugAssign.target = target;
2284 p->v.AugAssign.op = op;
2285 p->v.AugAssign.value = value;
2286 p->lineno = lineno;
2287 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002288 p->end_lineno = end_lineno;
2289 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002290 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002291}
2292
2293stmt_ty
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002294AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002295 lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2296 *arena)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002297{
2298 stmt_ty p;
2299 if (!target) {
2300 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002301 "field 'target' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002302 return NULL;
2303 }
2304 if (!annotation) {
2305 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002306 "field 'annotation' is required for AnnAssign");
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002307 return NULL;
2308 }
2309 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2310 if (!p)
2311 return NULL;
2312 p->kind = AnnAssign_kind;
2313 p->v.AnnAssign.target = target;
2314 p->v.AnnAssign.annotation = annotation;
2315 p->v.AnnAssign.value = value;
2316 p->v.AnnAssign.simple = simple;
2317 p->lineno = lineno;
2318 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002319 p->end_lineno = end_lineno;
2320 p->end_col_offset = end_col_offset;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07002321 return p;
2322}
2323
2324stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002325For(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse, string
2326 type_comment, int lineno, int col_offset, int end_lineno, int
2327 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002328{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002329 stmt_ty p;
2330 if (!target) {
2331 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002332 "field 'target' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002333 return NULL;
2334 }
2335 if (!iter) {
2336 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002337 "field 'iter' is required for For");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002338 return NULL;
2339 }
2340 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2341 if (!p)
2342 return NULL;
2343 p->kind = For_kind;
2344 p->v.For.target = target;
2345 p->v.For.iter = iter;
2346 p->v.For.body = body;
2347 p->v.For.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002348 p->v.For.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002349 p->lineno = lineno;
2350 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002351 p->end_lineno = end_lineno;
2352 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002353 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002354}
2355
2356stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002357AsyncFor(expr_ty target, expr_ty iter, asdl_seq * body, asdl_seq * orelse,
2358 string type_comment, int lineno, int col_offset, int end_lineno, int
2359 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002360{
2361 stmt_ty p;
2362 if (!target) {
2363 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002364 "field 'target' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002365 return NULL;
2366 }
2367 if (!iter) {
2368 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002369 "field 'iter' is required for AsyncFor");
Yury Selivanov75445082015-05-11 22:57:16 -04002370 return NULL;
2371 }
2372 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2373 if (!p)
2374 return NULL;
2375 p->kind = AsyncFor_kind;
2376 p->v.AsyncFor.target = target;
2377 p->v.AsyncFor.iter = iter;
2378 p->v.AsyncFor.body = body;
2379 p->v.AsyncFor.orelse = orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002380 p->v.AsyncFor.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002381 p->lineno = lineno;
2382 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002383 p->end_lineno = end_lineno;
2384 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002385 return p;
2386}
2387
2388stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002389While(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002390 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002391{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002392 stmt_ty p;
2393 if (!test) {
2394 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002395 "field 'test' is required for While");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002396 return NULL;
2397 }
2398 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2399 if (!p)
2400 return NULL;
2401 p->kind = While_kind;
2402 p->v.While.test = test;
2403 p->v.While.body = body;
2404 p->v.While.orelse = orelse;
2405 p->lineno = lineno;
2406 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002407 p->end_lineno = end_lineno;
2408 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002409 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002410}
2411
2412stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002413If(expr_ty test, asdl_seq * body, asdl_seq * orelse, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002414 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002415{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002416 stmt_ty p;
2417 if (!test) {
2418 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002419 "field 'test' is required for If");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002420 return NULL;
2421 }
2422 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2423 if (!p)
2424 return NULL;
2425 p->kind = If_kind;
2426 p->v.If.test = test;
2427 p->v.If.body = body;
2428 p->v.If.orelse = orelse;
2429 p->lineno = lineno;
2430 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002431 p->end_lineno = end_lineno;
2432 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002433 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002434}
2435
2436stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002437With(asdl_seq * items, asdl_seq * body, string type_comment, int lineno, int
2438 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossumc2e20742006-02-27 22:32:47 +00002439{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002440 stmt_ty p;
2441 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2442 if (!p)
2443 return NULL;
2444 p->kind = With_kind;
2445 p->v.With.items = items;
2446 p->v.With.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002447 p->v.With.type_comment = type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002448 p->lineno = lineno;
2449 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002450 p->end_lineno = end_lineno;
2451 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002452 return p;
Guido van Rossumc2e20742006-02-27 22:32:47 +00002453}
2454
2455stmt_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002456AsyncWith(asdl_seq * items, asdl_seq * body, string type_comment, int lineno,
2457 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002458{
2459 stmt_ty p;
2460 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2461 if (!p)
2462 return NULL;
2463 p->kind = AsyncWith_kind;
2464 p->v.AsyncWith.items = items;
2465 p->v.AsyncWith.body = body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08002466 p->v.AsyncWith.type_comment = type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04002467 p->lineno = lineno;
2468 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002469 p->end_lineno = end_lineno;
2470 p->end_col_offset = end_col_offset;
Yury Selivanov75445082015-05-11 22:57:16 -04002471 return p;
2472}
2473
2474stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002475Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int end_lineno,
2476 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002477{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002478 stmt_ty p;
2479 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2480 if (!p)
2481 return NULL;
2482 p->kind = Raise_kind;
2483 p->v.Raise.exc = exc;
2484 p->v.Raise.cause = cause;
2485 p->lineno = lineno;
2486 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002487 p->end_lineno = end_lineno;
2488 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002489 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002490}
2491
2492stmt_ty
Benjamin Peterson43af12b2011-05-29 11:43:10 -05002493Try(asdl_seq * body, asdl_seq * handlers, asdl_seq * orelse, asdl_seq *
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002494 finalbody, int lineno, int col_offset, int end_lineno, int end_col_offset,
2495 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002496{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002497 stmt_ty p;
2498 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2499 if (!p)
2500 return NULL;
2501 p->kind = Try_kind;
2502 p->v.Try.body = body;
2503 p->v.Try.handlers = handlers;
2504 p->v.Try.orelse = orelse;
2505 p->v.Try.finalbody = finalbody;
2506 p->lineno = lineno;
2507 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002508 p->end_lineno = end_lineno;
2509 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002510 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002511}
2512
2513stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002514Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int end_lineno,
2515 int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002516{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002517 stmt_ty p;
2518 if (!test) {
2519 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002520 "field 'test' is required for Assert");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002521 return NULL;
2522 }
2523 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2524 if (!p)
2525 return NULL;
2526 p->kind = Assert_kind;
2527 p->v.Assert.test = test;
2528 p->v.Assert.msg = msg;
2529 p->lineno = lineno;
2530 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002531 p->end_lineno = end_lineno;
2532 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002533 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002534}
2535
2536stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002537Import(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2538 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002539{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002540 stmt_ty p;
2541 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2542 if (!p)
2543 return NULL;
2544 p->kind = Import_kind;
2545 p->v.Import.names = names;
2546 p->lineno = lineno;
2547 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002548 p->end_lineno = end_lineno;
2549 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002550 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002551}
2552
2553stmt_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002554ImportFrom(identifier module, asdl_seq * names, int level, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002555 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002556{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002557 stmt_ty p;
2558 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2559 if (!p)
2560 return NULL;
2561 p->kind = ImportFrom_kind;
2562 p->v.ImportFrom.module = module;
2563 p->v.ImportFrom.names = names;
2564 p->v.ImportFrom.level = level;
2565 p->lineno = lineno;
2566 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002567 p->end_lineno = end_lineno;
2568 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002569 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002570}
2571
2572stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002573Global(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2574 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002575{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002576 stmt_ty p;
2577 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2578 if (!p)
2579 return NULL;
2580 p->kind = Global_kind;
2581 p->v.Global.names = names;
2582 p->lineno = lineno;
2583 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002584 p->end_lineno = end_lineno;
2585 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002586 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002587}
2588
2589stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002590Nonlocal(asdl_seq * names, int lineno, int col_offset, int end_lineno, int
2591 end_col_offset, PyArena *arena)
Jeremy Hylton81e95022007-02-27 06:50:52 +00002592{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002593 stmt_ty p;
2594 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2595 if (!p)
2596 return NULL;
2597 p->kind = Nonlocal_kind;
2598 p->v.Nonlocal.names = names;
2599 p->lineno = lineno;
2600 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002601 p->end_lineno = end_lineno;
2602 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002603 return p;
Jeremy Hylton81e95022007-02-27 06:50:52 +00002604}
2605
2606stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002607Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
2608 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002609{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002610 stmt_ty p;
2611 if (!value) {
2612 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002613 "field 'value' is required for Expr");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002614 return NULL;
2615 }
2616 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2617 if (!p)
2618 return NULL;
2619 p->kind = Expr_kind;
2620 p->v.Expr.value = value;
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 Hylton3e0055f2005-10-20 19:59:25 +00002626}
2627
2628stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002629Pass(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2630 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002631{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002632 stmt_ty p;
2633 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2634 if (!p)
2635 return NULL;
2636 p->kind = Pass_kind;
2637 p->lineno = lineno;
2638 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002639 p->end_lineno = end_lineno;
2640 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002641 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002642}
2643
2644stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002645Break(int lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
2646 *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002647{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002648 stmt_ty p;
2649 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2650 if (!p)
2651 return NULL;
2652 p->kind = Break_kind;
2653 p->lineno = lineno;
2654 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002655 p->end_lineno = end_lineno;
2656 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002657 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002658}
2659
2660stmt_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002661Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
2662 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002663{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002664 stmt_ty p;
2665 p = (stmt_ty)PyArena_Malloc(arena, sizeof(*p));
2666 if (!p)
2667 return NULL;
2668 p->kind = Continue_kind;
2669 p->lineno = lineno;
2670 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002671 p->end_lineno = end_lineno;
2672 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002673 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002674}
2675
2676expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002677BoolOp(boolop_ty op, asdl_seq * values, int lineno, int col_offset, int
2678 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002679{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002680 expr_ty p;
2681 if (!op) {
2682 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002683 "field 'op' is required for BoolOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002684 return NULL;
2685 }
2686 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2687 if (!p)
2688 return NULL;
2689 p->kind = BoolOp_kind;
2690 p->v.BoolOp.op = op;
2691 p->v.BoolOp.values = values;
2692 p->lineno = lineno;
2693 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002694 p->end_lineno = end_lineno;
2695 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002696 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002697}
2698
2699expr_ty
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002700NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
2701 end_lineno, int end_col_offset, PyArena *arena)
2702{
2703 expr_ty p;
2704 if (!target) {
2705 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002706 "field 'target' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002707 return NULL;
2708 }
2709 if (!value) {
2710 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002711 "field 'value' is required for NamedExpr");
Emily Morehouse8f59ee02019-01-24 16:49:56 -07002712 return NULL;
2713 }
2714 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2715 if (!p)
2716 return NULL;
2717 p->kind = NamedExpr_kind;
2718 p->v.NamedExpr.target = target;
2719 p->v.NamedExpr.value = value;
2720 p->lineno = lineno;
2721 p->col_offset = col_offset;
2722 p->end_lineno = end_lineno;
2723 p->end_col_offset = end_col_offset;
2724 return p;
2725}
2726
2727expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002728BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002729 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002730{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002731 expr_ty p;
2732 if (!left) {
2733 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002734 "field 'left' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002735 return NULL;
2736 }
2737 if (!op) {
2738 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002739 "field 'op' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002740 return NULL;
2741 }
2742 if (!right) {
2743 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002744 "field 'right' is required for BinOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002745 return NULL;
2746 }
2747 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2748 if (!p)
2749 return NULL;
2750 p->kind = BinOp_kind;
2751 p->v.BinOp.left = left;
2752 p->v.BinOp.op = op;
2753 p->v.BinOp.right = right;
2754 p->lineno = lineno;
2755 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002756 p->end_lineno = end_lineno;
2757 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002758 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002759}
2760
2761expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002762UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
2763 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002764{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002765 expr_ty p;
2766 if (!op) {
2767 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002768 "field 'op' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002769 return NULL;
2770 }
2771 if (!operand) {
2772 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002773 "field 'operand' is required for UnaryOp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002774 return NULL;
2775 }
2776 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2777 if (!p)
2778 return NULL;
2779 p->kind = UnaryOp_kind;
2780 p->v.UnaryOp.op = op;
2781 p->v.UnaryOp.operand = operand;
2782 p->lineno = lineno;
2783 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002784 p->end_lineno = end_lineno;
2785 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002786 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002787}
2788
2789expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002790Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
2791 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002792{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002793 expr_ty p;
2794 if (!args) {
2795 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002796 "field 'args' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002797 return NULL;
2798 }
2799 if (!body) {
2800 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002801 "field 'body' is required for Lambda");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002802 return NULL;
2803 }
2804 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2805 if (!p)
2806 return NULL;
2807 p->kind = Lambda_kind;
2808 p->v.Lambda.args = args;
2809 p->v.Lambda.body = body;
2810 p->lineno = lineno;
2811 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002812 p->end_lineno = end_lineno;
2813 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002814 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002815}
2816
2817expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002818IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002819 int end_lineno, int end_col_offset, PyArena *arena)
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002820{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002821 expr_ty p;
2822 if (!test) {
2823 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002824 "field 'test' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002825 return NULL;
2826 }
2827 if (!body) {
2828 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002829 "field 'body' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002830 return NULL;
2831 }
2832 if (!orelse) {
2833 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002834 "field 'orelse' is required for IfExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002835 return NULL;
2836 }
2837 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2838 if (!p)
2839 return NULL;
2840 p->kind = IfExp_kind;
2841 p->v.IfExp.test = test;
2842 p->v.IfExp.body = body;
2843 p->v.IfExp.orelse = orelse;
2844 p->lineno = lineno;
2845 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002846 p->end_lineno = end_lineno;
2847 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002848 return p;
Thomas Woutersdca3b9c2006-02-27 00:24:13 +00002849}
2850
2851expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002852Dict(asdl_seq * keys, asdl_seq * values, int lineno, int col_offset, int
2853 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002854{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002855 expr_ty p;
2856 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2857 if (!p)
2858 return NULL;
2859 p->kind = Dict_kind;
2860 p->v.Dict.keys = keys;
2861 p->v.Dict.values = values;
2862 p->lineno = lineno;
2863 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002864 p->end_lineno = end_lineno;
2865 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002866 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002867}
2868
2869expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002870Set(asdl_seq * elts, int lineno, int col_offset, int end_lineno, int
2871 end_col_offset, PyArena *arena)
Guido van Rossum86e58e22006-08-28 15:27:34 +00002872{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002873 expr_ty p;
2874 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2875 if (!p)
2876 return NULL;
2877 p->kind = Set_kind;
2878 p->v.Set.elts = elts;
2879 p->lineno = lineno;
2880 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002881 p->end_lineno = end_lineno;
2882 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002883 return p;
Guido van Rossum86e58e22006-08-28 15:27:34 +00002884}
2885
2886expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002887ListComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2888 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002889{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002890 expr_ty p;
2891 if (!elt) {
2892 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002893 "field 'elt' is required for ListComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002894 return NULL;
2895 }
2896 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2897 if (!p)
2898 return NULL;
2899 p->kind = ListComp_kind;
2900 p->v.ListComp.elt = elt;
2901 p->v.ListComp.generators = generators;
2902 p->lineno = lineno;
2903 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002904 p->end_lineno = end_lineno;
2905 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002906 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002907}
2908
2909expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002910SetComp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset, int
2911 end_lineno, int end_col_offset, PyArena *arena)
Nick Coghlan650f0d02007-04-15 12:05:43 +00002912{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002913 expr_ty p;
2914 if (!elt) {
2915 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002916 "field 'elt' is required for SetComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002917 return NULL;
2918 }
2919 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2920 if (!p)
2921 return NULL;
2922 p->kind = SetComp_kind;
2923 p->v.SetComp.elt = elt;
2924 p->v.SetComp.generators = generators;
2925 p->lineno = lineno;
2926 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002927 p->end_lineno = end_lineno;
2928 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002929 return p;
Nick Coghlan650f0d02007-04-15 12:05:43 +00002930}
2931
2932expr_ty
Guido van Rossum992d4a32007-07-11 13:09:30 +00002933DictComp(expr_ty key, expr_ty value, asdl_seq * generators, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002934 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum992d4a32007-07-11 13:09:30 +00002935{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002936 expr_ty p;
2937 if (!key) {
2938 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002939 "field 'key' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002940 return NULL;
2941 }
2942 if (!value) {
2943 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002944 "field 'value' is required for DictComp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002945 return NULL;
2946 }
2947 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2948 if (!p)
2949 return NULL;
2950 p->kind = DictComp_kind;
2951 p->v.DictComp.key = key;
2952 p->v.DictComp.value = value;
2953 p->v.DictComp.generators = generators;
2954 p->lineno = lineno;
2955 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002956 p->end_lineno = end_lineno;
2957 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002958 return p;
Guido van Rossum992d4a32007-07-11 13:09:30 +00002959}
2960
2961expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00002962GeneratorExp(expr_ty elt, asdl_seq * generators, int lineno, int col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002963 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002964{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002965 expr_ty p;
2966 if (!elt) {
2967 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002968 "field 'elt' is required for GeneratorExp");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002969 return NULL;
2970 }
2971 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2972 if (!p)
2973 return NULL;
2974 p->kind = GeneratorExp_kind;
2975 p->v.GeneratorExp.elt = elt;
2976 p->v.GeneratorExp.generators = generators;
2977 p->lineno = lineno;
2978 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002979 p->end_lineno = end_lineno;
2980 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02002981 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00002982}
2983
2984expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00002985Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
2986 end_col_offset, PyArena *arena)
Yury Selivanov75445082015-05-11 22:57:16 -04002987{
2988 expr_ty p;
2989 if (!value) {
2990 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03002991 "field 'value' is required for Await");
Yury Selivanov75445082015-05-11 22:57:16 -04002992 return NULL;
2993 }
2994 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
2995 if (!p)
2996 return NULL;
2997 p->kind = Await_kind;
2998 p->v.Await.value = value;
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;
Yury Selivanov75445082015-05-11 22:57:16 -04003003 return p;
3004}
3005
3006expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003007Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
3008 end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003009{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003010 expr_ty p;
3011 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3012 if (!p)
3013 return NULL;
3014 p->kind = Yield_kind;
3015 p->v.Yield.value = value;
3016 p->lineno = lineno;
3017 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003018 p->end_lineno = end_lineno;
3019 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003020 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003021}
3022
3023expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003024YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
3025 end_col_offset, PyArena *arena)
Benjamin Peterson527c6222012-01-14 08:58:23 -05003026{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003027 expr_ty p;
3028 if (!value) {
3029 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003030 "field 'value' is required for YieldFrom");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003031 return NULL;
3032 }
3033 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3034 if (!p)
3035 return NULL;
3036 p->kind = YieldFrom_kind;
3037 p->v.YieldFrom.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;
Benjamin Peterson527c6222012-01-14 08:58:23 -05003043}
3044
3045expr_ty
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00003046Compare(expr_ty left, asdl_int_seq * ops, asdl_seq * comparators, int lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003047 int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003048{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003049 expr_ty p;
3050 if (!left) {
3051 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003052 "field 'left' is required for Compare");
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 = Compare_kind;
3059 p->v.Compare.left = left;
3060 p->v.Compare.ops = ops;
3061 p->v.Compare.comparators = comparators;
3062 p->lineno = lineno;
3063 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003064 p->end_lineno = end_lineno;
3065 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003066 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003067}
3068
3069expr_ty
Benjamin Peterson025e9eb2015-05-05 20:16:41 -04003070Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003071 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003072{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003073 expr_ty p;
3074 if (!func) {
3075 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003076 "field 'func' is required for Call");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003077 return NULL;
3078 }
3079 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3080 if (!p)
3081 return NULL;
3082 p->kind = Call_kind;
3083 p->v.Call.func = func;
3084 p->v.Call.args = args;
3085 p->v.Call.keywords = keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003086 p->lineno = lineno;
3087 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003088 p->end_lineno = end_lineno;
3089 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003090 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003091}
3092
3093expr_ty
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04003094FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int lineno,
3095 int col_offset, int end_lineno, int end_col_offset, PyArena
3096 *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003097{
3098 expr_ty p;
3099 if (!value) {
3100 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003101 "field 'value' is required for FormattedValue");
Eric V. Smith235a6f02015-09-19 14:51:32 -04003102 return NULL;
3103 }
3104 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3105 if (!p)
3106 return NULL;
3107 p->kind = FormattedValue_kind;
3108 p->v.FormattedValue.value = value;
3109 p->v.FormattedValue.conversion = conversion;
3110 p->v.FormattedValue.format_spec = format_spec;
3111 p->lineno = lineno;
3112 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003113 p->end_lineno = end_lineno;
3114 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003115 return p;
3116}
3117
3118expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003119JoinedStr(asdl_seq * values, int lineno, int col_offset, int end_lineno, int
3120 end_col_offset, PyArena *arena)
Eric V. Smith235a6f02015-09-19 14:51:32 -04003121{
3122 expr_ty p;
3123 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3124 if (!p)
3125 return NULL;
3126 p->kind = JoinedStr_kind;
3127 p->v.JoinedStr.values = values;
3128 p->lineno = lineno;
3129 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003130 p->end_lineno = end_lineno;
3131 p->end_col_offset = end_col_offset;
Eric V. Smith235a6f02015-09-19 14:51:32 -04003132 return p;
3133}
3134
3135expr_ty
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003136Constant(constant value, string kind, int lineno, int col_offset, int
3137 end_lineno, int end_col_offset, PyArena *arena)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003138{
3139 expr_ty p;
3140 if (!value) {
3141 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003142 "field 'value' is required for Constant");
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003143 return NULL;
3144 }
3145 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3146 if (!p)
3147 return NULL;
3148 p->kind = Constant_kind;
3149 p->v.Constant.value = value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07003150 p->v.Constant.kind = kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003151 p->lineno = lineno;
3152 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003153 p->end_lineno = end_lineno;
3154 p->end_col_offset = end_col_offset;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01003155 return p;
3156}
3157
3158expr_ty
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003159Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003160 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003161{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003162 expr_ty p;
3163 if (!value) {
3164 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003165 "field 'value' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003166 return NULL;
3167 }
3168 if (!attr) {
3169 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003170 "field 'attr' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003171 return NULL;
3172 }
3173 if (!ctx) {
3174 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003175 "field 'ctx' is required for Attribute");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003176 return NULL;
3177 }
3178 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3179 if (!p)
3180 return NULL;
3181 p->kind = Attribute_kind;
3182 p->v.Attribute.value = value;
3183 p->v.Attribute.attr = attr;
3184 p->v.Attribute.ctx = ctx;
3185 p->lineno = lineno;
3186 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003187 p->end_lineno = end_lineno;
3188 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003189 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003190}
3191
3192expr_ty
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003193Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003194 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003195{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003196 expr_ty p;
3197 if (!value) {
3198 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003199 "field 'value' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003200 return NULL;
3201 }
3202 if (!slice) {
3203 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003204 "field 'slice' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003205 return NULL;
3206 }
3207 if (!ctx) {
3208 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003209 "field 'ctx' is required for Subscript");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003210 return NULL;
3211 }
3212 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3213 if (!p)
3214 return NULL;
3215 p->kind = Subscript_kind;
3216 p->v.Subscript.value = value;
3217 p->v.Subscript.slice = slice;
3218 p->v.Subscript.ctx = ctx;
3219 p->lineno = lineno;
3220 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003221 p->end_lineno = end_lineno;
3222 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003223 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003224}
3225
3226expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003227Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset, int
3228 end_lineno, int end_col_offset, PyArena *arena)
Guido van Rossum0368b722007-05-11 16:50:42 +00003229{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003230 expr_ty p;
3231 if (!value) {
3232 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003233 "field 'value' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003234 return NULL;
3235 }
3236 if (!ctx) {
3237 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003238 "field 'ctx' is required for Starred");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003239 return NULL;
3240 }
3241 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3242 if (!p)
3243 return NULL;
3244 p->kind = Starred_kind;
3245 p->v.Starred.value = value;
3246 p->v.Starred.ctx = ctx;
3247 p->lineno = lineno;
3248 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003249 p->end_lineno = end_lineno;
3250 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003251 return p;
Guido van Rossum0368b722007-05-11 16:50:42 +00003252}
3253
3254expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003255Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
3256 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003257{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003258 expr_ty p;
3259 if (!id) {
3260 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003261 "field 'id' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003262 return NULL;
3263 }
3264 if (!ctx) {
3265 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003266 "field 'ctx' is required for Name");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003267 return NULL;
3268 }
3269 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3270 if (!p)
3271 return NULL;
3272 p->kind = Name_kind;
3273 p->v.Name.id = id;
3274 p->v.Name.ctx = ctx;
3275 p->lineno = lineno;
3276 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003277 p->end_lineno = end_lineno;
3278 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003279 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003280}
3281
3282expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003283List(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3284 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003285{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003286 expr_ty p;
3287 if (!ctx) {
3288 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003289 "field 'ctx' is required for List");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003290 return NULL;
3291 }
3292 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3293 if (!p)
3294 return NULL;
3295 p->kind = List_kind;
3296 p->v.List.elts = elts;
3297 p->v.List.ctx = ctx;
3298 p->lineno = lineno;
3299 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003300 p->end_lineno = end_lineno;
3301 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003302 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003303}
3304
3305expr_ty
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003306Tuple(asdl_seq * elts, expr_context_ty ctx, int lineno, int col_offset, int
3307 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003308{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003309 expr_ty p;
3310 if (!ctx) {
3311 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003312 "field 'ctx' is required for Tuple");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003313 return NULL;
3314 }
3315 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
3316 if (!p)
3317 return NULL;
3318 p->kind = Tuple_kind;
3319 p->v.Tuple.elts = elts;
3320 p->v.Tuple.ctx = ctx;
3321 p->lineno = lineno;
3322 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003323 p->end_lineno = end_lineno;
3324 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003325 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003326}
3327
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003328expr_ty
3329Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int col_offset,
3330 int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003331{
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003332 expr_ty p;
3333 p = (expr_ty)PyArena_Malloc(arena, sizeof(*p));
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003334 if (!p)
3335 return NULL;
3336 p->kind = Slice_kind;
3337 p->v.Slice.lower = lower;
3338 p->v.Slice.upper = upper;
3339 p->v.Slice.step = step;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02003340 p->lineno = lineno;
3341 p->col_offset = col_offset;
3342 p->end_lineno = end_lineno;
3343 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003344 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003345}
3346
3347comprehension_ty
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003348comprehension(expr_ty target, expr_ty iter, asdl_seq * ifs, int is_async,
3349 PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003350{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003351 comprehension_ty p;
3352 if (!target) {
3353 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003354 "field 'target' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003355 return NULL;
3356 }
3357 if (!iter) {
3358 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003359 "field 'iter' is required for comprehension");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003360 return NULL;
3361 }
3362 p = (comprehension_ty)PyArena_Malloc(arena, sizeof(*p));
3363 if (!p)
3364 return NULL;
3365 p->target = target;
3366 p->iter = iter;
3367 p->ifs = ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07003368 p->is_async = is_async;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003369 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003370}
3371
3372excepthandler_ty
Neal Norwitzad74aa82008-03-31 05:14:30 +00003373ExceptHandler(expr_ty type, identifier name, asdl_seq * body, int lineno, int
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003374 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003375{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003376 excepthandler_ty p;
3377 p = (excepthandler_ty)PyArena_Malloc(arena, sizeof(*p));
3378 if (!p)
3379 return NULL;
3380 p->kind = ExceptHandler_kind;
3381 p->v.ExceptHandler.type = type;
3382 p->v.ExceptHandler.name = name;
3383 p->v.ExceptHandler.body = body;
3384 p->lineno = lineno;
3385 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003386 p->end_lineno = end_lineno;
3387 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003388 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003389}
3390
3391arguments_ty
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003392arguments(asdl_seq * posonlyargs, asdl_seq * args, arg_ty vararg, asdl_seq *
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003393 kwonlyargs, asdl_seq * kw_defaults, arg_ty kwarg, asdl_seq *
3394 defaults, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003395{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003396 arguments_ty p;
3397 p = (arguments_ty)PyArena_Malloc(arena, sizeof(*p));
3398 if (!p)
3399 return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01003400 p->posonlyargs = posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02003401 p->args = args;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003402 p->vararg = vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003403 p->kwonlyargs = kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003404 p->kw_defaults = kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02003405 p->kwarg = kwarg;
3406 p->defaults = defaults;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003407 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003408}
3409
Neal Norwitzc1505362006-12-28 06:47:50 +00003410arg_ty
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003411arg(identifier arg, expr_ty annotation, string type_comment, int lineno, int
3412 col_offset, int end_lineno, int end_col_offset, PyArena *arena)
Neal Norwitzc1505362006-12-28 06:47:50 +00003413{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003414 arg_ty p;
3415 if (!arg) {
3416 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003417 "field 'arg' is required for arg");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003418 return NULL;
3419 }
3420 p = (arg_ty)PyArena_Malloc(arena, sizeof(*p));
3421 if (!p)
3422 return NULL;
3423 p->arg = arg;
3424 p->annotation = annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003425 p->type_comment = type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01003426 p->lineno = lineno;
3427 p->col_offset = col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00003428 p->end_lineno = end_lineno;
3429 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003430 return p;
Neal Norwitzc1505362006-12-28 06:47:50 +00003431}
3432
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003433keyword_ty
Pablo Galindo168660b2020-04-02 00:47:39 +01003434keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
3435 end_lineno, int end_col_offset, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003436{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003437 keyword_ty p;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003438 if (!value) {
3439 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003440 "field 'value' is required for keyword");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003441 return NULL;
3442 }
3443 p = (keyword_ty)PyArena_Malloc(arena, sizeof(*p));
3444 if (!p)
3445 return NULL;
3446 p->arg = arg;
3447 p->value = value;
Pablo Galindo168660b2020-04-02 00:47:39 +01003448 p->lineno = lineno;
3449 p->col_offset = col_offset;
3450 p->end_lineno = end_lineno;
3451 p->end_col_offset = end_col_offset;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003452 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003453}
3454
3455alias_ty
Neal Norwitzadb69fc2005-12-17 20:54:49 +00003456alias(identifier name, identifier asname, PyArena *arena)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003457{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003458 alias_ty p;
3459 if (!name) {
3460 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003461 "field 'name' is required for alias");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003462 return NULL;
3463 }
3464 p = (alias_ty)PyArena_Malloc(arena, sizeof(*p));
3465 if (!p)
3466 return NULL;
3467 p->name = name;
3468 p->asname = asname;
3469 return p;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003470}
3471
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003472withitem_ty
3473withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
3474{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003475 withitem_ty p;
3476 if (!context_expr) {
3477 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003478 "field 'context_expr' is required for withitem");
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003479 return NULL;
3480 }
3481 p = (withitem_ty)PyArena_Malloc(arena, sizeof(*p));
3482 if (!p)
3483 return NULL;
3484 p->context_expr = context_expr;
3485 p->optional_vars = optional_vars;
3486 return p;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05003487}
3488
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003489type_ignore_ty
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003490TypeIgnore(int lineno, string tag, PyArena *arena)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003491{
3492 type_ignore_ty p;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003493 if (!tag) {
3494 PyErr_SetString(PyExc_ValueError,
Batuhan Taskaya091951a2020-05-06 17:29:32 +03003495 "field 'tag' is required for TypeIgnore");
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003496 return NULL;
3497 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003498 p = (type_ignore_ty)PyArena_Malloc(arena, sizeof(*p));
3499 if (!p)
3500 return NULL;
3501 p->kind = TypeIgnore_kind;
3502 p->v.TypeIgnore.lineno = lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07003503 p->v.TypeIgnore.tag = tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003504 return p;
3505}
3506
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003507
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003508PyObject*
3509ast2obj_mod(void* _o)
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003510{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003511 mod_ty o = (mod_ty)_o;
3512 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003513 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003514 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003515 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003516 }
Neal Norwitz7b5a6042005-11-13 19:14:20 +00003517
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003518 switch (o->kind) {
3519 case Module_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003520 tp = (PyTypeObject *)astmodulestate_global->Module_type;
3521 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003522 if (!result) goto failed;
3523 value = ast2obj_list(o->v.Module.body, ast2obj_stmt);
3524 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003525 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003526 goto failed;
3527 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003528 value = ast2obj_list(o->v.Module.type_ignores, ast2obj_type_ignore);
3529 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003530 if (PyObject_SetAttr(result, astmodulestate_global->type_ignores,
3531 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003532 goto failed;
3533 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003534 break;
3535 case Interactive_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003536 tp = (PyTypeObject *)astmodulestate_global->Interactive_type;
3537 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003538 if (!result) goto failed;
3539 value = ast2obj_list(o->v.Interactive.body, ast2obj_stmt);
3540 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003541 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003542 goto failed;
3543 Py_DECREF(value);
3544 break;
3545 case Expression_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003546 tp = (PyTypeObject *)astmodulestate_global->Expression_type;
3547 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003548 if (!result) goto failed;
3549 value = ast2obj_expr(o->v.Expression.body);
3550 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003551 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003552 goto failed;
3553 Py_DECREF(value);
3554 break;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003555 case FunctionType_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003556 tp = (PyTypeObject *)astmodulestate_global->FunctionType_type;
3557 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003558 if (!result) goto failed;
3559 value = ast2obj_list(o->v.FunctionType.argtypes, ast2obj_expr);
3560 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003561 if (PyObject_SetAttr(result, astmodulestate_global->argtypes, value) ==
3562 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003563 goto failed;
3564 Py_DECREF(value);
3565 value = ast2obj_expr(o->v.FunctionType.returns);
3566 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003567 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3568 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003569 goto failed;
3570 Py_DECREF(value);
3571 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003572 }
3573 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003574failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003575 Py_XDECREF(value);
3576 Py_XDECREF(result);
3577 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003578}
3579
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003580PyObject*
3581ast2obj_stmt(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00003582{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003583 stmt_ty o = (stmt_ty)_o;
3584 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003585 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003586 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02003587 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003588 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00003589
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003590 switch (o->kind) {
3591 case FunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003592 tp = (PyTypeObject *)astmodulestate_global->FunctionDef_type;
3593 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003594 if (!result) goto failed;
3595 value = ast2obj_identifier(o->v.FunctionDef.name);
Martin v. Löwis577b5b92006-02-27 15:23:19 +00003596 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003597 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003598 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003599 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003600 value = ast2obj_arguments(o->v.FunctionDef.args);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00003601 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003602 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003603 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00003604 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003605 value = ast2obj_list(o->v.FunctionDef.body, ast2obj_stmt);
3606 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003607 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003608 goto failed;
3609 Py_DECREF(value);
3610 value = ast2obj_list(o->v.FunctionDef.decorator_list, ast2obj_expr);
3611 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003612 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3613 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003614 goto failed;
3615 Py_DECREF(value);
3616 value = ast2obj_expr(o->v.FunctionDef.returns);
3617 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003618 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3619 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003620 goto failed;
3621 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003622 value = ast2obj_string(o->v.FunctionDef.type_comment);
3623 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003624 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3625 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003626 goto failed;
3627 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003628 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003629 case AsyncFunctionDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003630 tp = (PyTypeObject *)astmodulestate_global->AsyncFunctionDef_type;
3631 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003632 if (!result) goto failed;
3633 value = ast2obj_identifier(o->v.AsyncFunctionDef.name);
3634 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003635 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003636 goto failed;
3637 Py_DECREF(value);
3638 value = ast2obj_arguments(o->v.AsyncFunctionDef.args);
3639 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003640 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003641 goto failed;
3642 Py_DECREF(value);
3643 value = ast2obj_list(o->v.AsyncFunctionDef.body, ast2obj_stmt);
3644 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003645 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003646 goto failed;
3647 Py_DECREF(value);
3648 value = ast2obj_list(o->v.AsyncFunctionDef.decorator_list,
3649 ast2obj_expr);
3650 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003651 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3652 value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003653 goto failed;
3654 Py_DECREF(value);
3655 value = ast2obj_expr(o->v.AsyncFunctionDef.returns);
3656 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003657 if (PyObject_SetAttr(result, astmodulestate_global->returns, value) ==
3658 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003659 goto failed;
3660 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003661 value = ast2obj_string(o->v.AsyncFunctionDef.type_comment);
3662 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003663 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3664 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003665 goto failed;
3666 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003667 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003668 case ClassDef_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003669 tp = (PyTypeObject *)astmodulestate_global->ClassDef_type;
3670 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003671 if (!result) goto failed;
3672 value = ast2obj_identifier(o->v.ClassDef.name);
3673 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003674 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003675 goto failed;
3676 Py_DECREF(value);
3677 value = ast2obj_list(o->v.ClassDef.bases, ast2obj_expr);
3678 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003679 if (PyObject_SetAttr(result, astmodulestate_global->bases, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003680 goto failed;
3681 Py_DECREF(value);
3682 value = ast2obj_list(o->v.ClassDef.keywords, ast2obj_keyword);
3683 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003684 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
3685 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003686 goto failed;
3687 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003688 value = ast2obj_list(o->v.ClassDef.body, ast2obj_stmt);
3689 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003690 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003691 goto failed;
3692 Py_DECREF(value);
3693 value = ast2obj_list(o->v.ClassDef.decorator_list, ast2obj_expr);
3694 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003695 if (PyObject_SetAttr(result, astmodulestate_global->decorator_list,
3696 value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003697 goto failed;
3698 Py_DECREF(value);
3699 break;
3700 case Return_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003701 tp = (PyTypeObject *)astmodulestate_global->Return_type;
3702 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003703 if (!result) goto failed;
3704 value = ast2obj_expr(o->v.Return.value);
3705 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003706 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003707 goto failed;
3708 Py_DECREF(value);
3709 break;
3710 case Delete_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003711 tp = (PyTypeObject *)astmodulestate_global->Delete_type;
3712 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003713 if (!result) goto failed;
3714 value = ast2obj_list(o->v.Delete.targets, ast2obj_expr);
3715 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003716 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3717 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003718 goto failed;
3719 Py_DECREF(value);
3720 break;
3721 case Assign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003722 tp = (PyTypeObject *)astmodulestate_global->Assign_type;
3723 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003724 if (!result) goto failed;
3725 value = ast2obj_list(o->v.Assign.targets, ast2obj_expr);
3726 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003727 if (PyObject_SetAttr(result, astmodulestate_global->targets, value) ==
3728 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003729 goto failed;
3730 Py_DECREF(value);
3731 value = ast2obj_expr(o->v.Assign.value);
3732 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003733 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003734 goto failed;
3735 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003736 value = ast2obj_string(o->v.Assign.type_comment);
3737 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003738 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3739 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003740 goto failed;
3741 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003742 break;
3743 case AugAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003744 tp = (PyTypeObject *)astmodulestate_global->AugAssign_type;
3745 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003746 if (!result) goto failed;
3747 value = ast2obj_expr(o->v.AugAssign.target);
3748 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003749 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3750 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003751 goto failed;
3752 Py_DECREF(value);
3753 value = ast2obj_operator(o->v.AugAssign.op);
3754 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003755 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003756 goto failed;
3757 Py_DECREF(value);
3758 value = ast2obj_expr(o->v.AugAssign.value);
3759 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003760 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003761 goto failed;
3762 Py_DECREF(value);
3763 break;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003764 case AnnAssign_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003765 tp = (PyTypeObject *)astmodulestate_global->AnnAssign_type;
3766 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003767 if (!result) goto failed;
3768 value = ast2obj_expr(o->v.AnnAssign.target);
3769 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003770 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3771 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003772 goto failed;
3773 Py_DECREF(value);
3774 value = ast2obj_expr(o->v.AnnAssign.annotation);
3775 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003776 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value)
3777 == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003778 goto failed;
3779 Py_DECREF(value);
3780 value = ast2obj_expr(o->v.AnnAssign.value);
3781 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003782 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003783 goto failed;
3784 Py_DECREF(value);
3785 value = ast2obj_int(o->v.AnnAssign.simple);
3786 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003787 if (PyObject_SetAttr(result, astmodulestate_global->simple, value) ==
3788 -1)
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07003789 goto failed;
3790 Py_DECREF(value);
3791 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003792 case For_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003793 tp = (PyTypeObject *)astmodulestate_global->For_type;
3794 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003795 if (!result) goto failed;
3796 value = ast2obj_expr(o->v.For.target);
3797 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003798 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3799 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003800 goto failed;
3801 Py_DECREF(value);
3802 value = ast2obj_expr(o->v.For.iter);
3803 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003804 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003805 goto failed;
3806 Py_DECREF(value);
3807 value = ast2obj_list(o->v.For.body, ast2obj_stmt);
3808 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003809 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003810 goto failed;
3811 Py_DECREF(value);
3812 value = ast2obj_list(o->v.For.orelse, ast2obj_stmt);
3813 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003814 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3815 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003816 goto failed;
3817 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003818 value = ast2obj_string(o->v.For.type_comment);
3819 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003820 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3821 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003822 goto failed;
3823 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003824 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003825 case AsyncFor_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003826 tp = (PyTypeObject *)astmodulestate_global->AsyncFor_type;
3827 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003828 if (!result) goto failed;
3829 value = ast2obj_expr(o->v.AsyncFor.target);
3830 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003831 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
3832 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003833 goto failed;
3834 Py_DECREF(value);
3835 value = ast2obj_expr(o->v.AsyncFor.iter);
3836 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003837 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003838 goto failed;
3839 Py_DECREF(value);
3840 value = ast2obj_list(o->v.AsyncFor.body, ast2obj_stmt);
3841 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003842 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003843 goto failed;
3844 Py_DECREF(value);
3845 value = ast2obj_list(o->v.AsyncFor.orelse, ast2obj_stmt);
3846 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003847 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3848 -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003849 goto failed;
3850 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003851 value = ast2obj_string(o->v.AsyncFor.type_comment);
3852 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003853 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3854 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003855 goto failed;
3856 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003857 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003858 case While_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003859 tp = (PyTypeObject *)astmodulestate_global->While_type;
3860 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003861 if (!result) goto failed;
3862 value = ast2obj_expr(o->v.While.test);
3863 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003864 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003865 goto failed;
3866 Py_DECREF(value);
3867 value = ast2obj_list(o->v.While.body, ast2obj_stmt);
3868 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003869 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003870 goto failed;
3871 Py_DECREF(value);
3872 value = ast2obj_list(o->v.While.orelse, ast2obj_stmt);
3873 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003874 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3875 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003876 goto failed;
3877 Py_DECREF(value);
3878 break;
3879 case If_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003880 tp = (PyTypeObject *)astmodulestate_global->If_type;
3881 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003882 if (!result) goto failed;
3883 value = ast2obj_expr(o->v.If.test);
3884 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003885 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003886 goto failed;
3887 Py_DECREF(value);
3888 value = ast2obj_list(o->v.If.body, ast2obj_stmt);
3889 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003890 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003891 goto failed;
3892 Py_DECREF(value);
3893 value = ast2obj_list(o->v.If.orelse, ast2obj_stmt);
3894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003895 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3896 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003897 goto failed;
3898 Py_DECREF(value);
3899 break;
3900 case With_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003901 tp = (PyTypeObject *)astmodulestate_global->With_type;
3902 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003903 if (!result) goto failed;
3904 value = ast2obj_list(o->v.With.items, ast2obj_withitem);
3905 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003906 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003907 goto failed;
3908 Py_DECREF(value);
3909 value = ast2obj_list(o->v.With.body, ast2obj_stmt);
3910 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003911 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003912 goto failed;
3913 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003914 value = ast2obj_string(o->v.With.type_comment);
3915 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003916 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3917 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003918 goto failed;
3919 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003920 break;
Yury Selivanov75445082015-05-11 22:57:16 -04003921 case AsyncWith_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003922 tp = (PyTypeObject *)astmodulestate_global->AsyncWith_type;
3923 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04003924 if (!result) goto failed;
3925 value = ast2obj_list(o->v.AsyncWith.items, ast2obj_withitem);
3926 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003927 if (PyObject_SetAttr(result, astmodulestate_global->items, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003928 goto failed;
3929 Py_DECREF(value);
3930 value = ast2obj_list(o->v.AsyncWith.body, ast2obj_stmt);
3931 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003932 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04003933 goto failed;
3934 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003935 value = ast2obj_string(o->v.AsyncWith.type_comment);
3936 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003937 if (PyObject_SetAttr(result, astmodulestate_global->type_comment,
3938 value) == -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08003939 goto failed;
3940 Py_DECREF(value);
Yury Selivanov75445082015-05-11 22:57:16 -04003941 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003942 case Raise_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003943 tp = (PyTypeObject *)astmodulestate_global->Raise_type;
3944 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003945 if (!result) goto failed;
3946 value = ast2obj_expr(o->v.Raise.exc);
3947 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003948 if (PyObject_SetAttr(result, astmodulestate_global->exc, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003949 goto failed;
3950 Py_DECREF(value);
3951 value = ast2obj_expr(o->v.Raise.cause);
3952 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003953 if (PyObject_SetAttr(result, astmodulestate_global->cause, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003954 goto failed;
3955 Py_DECREF(value);
3956 break;
3957 case Try_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003958 tp = (PyTypeObject *)astmodulestate_global->Try_type;
3959 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003960 if (!result) goto failed;
3961 value = ast2obj_list(o->v.Try.body, ast2obj_stmt);
3962 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003963 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003964 goto failed;
3965 Py_DECREF(value);
3966 value = ast2obj_list(o->v.Try.handlers, ast2obj_excepthandler);
3967 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003968 if (PyObject_SetAttr(result, astmodulestate_global->handlers, value) ==
3969 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003970 goto failed;
3971 Py_DECREF(value);
3972 value = ast2obj_list(o->v.Try.orelse, ast2obj_stmt);
3973 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003974 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
3975 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003976 goto failed;
3977 Py_DECREF(value);
3978 value = ast2obj_list(o->v.Try.finalbody, ast2obj_stmt);
3979 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003980 if (PyObject_SetAttr(result, astmodulestate_global->finalbody, value)
3981 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003982 goto failed;
3983 Py_DECREF(value);
3984 break;
3985 case Assert_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07003986 tp = (PyTypeObject *)astmodulestate_global->Assert_type;
3987 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003988 if (!result) goto failed;
3989 value = ast2obj_expr(o->v.Assert.test);
3990 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003991 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003992 goto failed;
3993 Py_DECREF(value);
3994 value = ast2obj_expr(o->v.Assert.msg);
3995 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07003996 if (PyObject_SetAttr(result, astmodulestate_global->msg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02003997 goto failed;
3998 Py_DECREF(value);
3999 break;
4000 case Import_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004001 tp = (PyTypeObject *)astmodulestate_global->Import_type;
4002 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004003 if (!result) goto failed;
4004 value = ast2obj_list(o->v.Import.names, ast2obj_alias);
4005 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004006 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004007 goto failed;
4008 Py_DECREF(value);
4009 break;
4010 case ImportFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004011 tp = (PyTypeObject *)astmodulestate_global->ImportFrom_type;
4012 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004013 if (!result) goto failed;
4014 value = ast2obj_identifier(o->v.ImportFrom.module);
4015 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004016 if (PyObject_SetAttr(result, astmodulestate_global->module, value) ==
4017 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004018 goto failed;
4019 Py_DECREF(value);
4020 value = ast2obj_list(o->v.ImportFrom.names, ast2obj_alias);
4021 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004022 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004023 goto failed;
4024 Py_DECREF(value);
4025 value = ast2obj_int(o->v.ImportFrom.level);
4026 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004027 if (PyObject_SetAttr(result, astmodulestate_global->level, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004028 goto failed;
4029 Py_DECREF(value);
4030 break;
4031 case Global_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004032 tp = (PyTypeObject *)astmodulestate_global->Global_type;
4033 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004034 if (!result) goto failed;
4035 value = ast2obj_list(o->v.Global.names, ast2obj_identifier);
4036 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004037 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004038 goto failed;
4039 Py_DECREF(value);
4040 break;
4041 case Nonlocal_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004042 tp = (PyTypeObject *)astmodulestate_global->Nonlocal_type;
4043 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004044 if (!result) goto failed;
4045 value = ast2obj_list(o->v.Nonlocal.names, ast2obj_identifier);
4046 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004047 if (PyObject_SetAttr(result, astmodulestate_global->names, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004048 goto failed;
4049 Py_DECREF(value);
4050 break;
4051 case Expr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004052 tp = (PyTypeObject *)astmodulestate_global->Expr_type;
4053 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004054 if (!result) goto failed;
4055 value = ast2obj_expr(o->v.Expr.value);
4056 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004057 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004058 goto failed;
4059 Py_DECREF(value);
4060 break;
4061 case Pass_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004062 tp = (PyTypeObject *)astmodulestate_global->Pass_type;
4063 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004064 if (!result) goto failed;
4065 break;
4066 case Break_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004067 tp = (PyTypeObject *)astmodulestate_global->Break_type;
4068 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004069 if (!result) goto failed;
4070 break;
4071 case Continue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004072 tp = (PyTypeObject *)astmodulestate_global->Continue_type;
4073 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004074 if (!result) goto failed;
4075 break;
4076 }
4077 value = ast2obj_int(o->lineno);
4078 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004079 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004080 goto failed;
4081 Py_DECREF(value);
4082 value = ast2obj_int(o->col_offset);
4083 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004084 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004085 goto failed;
4086 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004087 value = ast2obj_int(o->end_lineno);
4088 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004089 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004090 goto failed;
4091 Py_DECREF(value);
4092 value = ast2obj_int(o->end_col_offset);
4093 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004094 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4095 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004096 goto failed;
4097 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004098 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004099failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004100 Py_XDECREF(value);
4101 Py_XDECREF(result);
4102 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004103}
4104
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004105PyObject*
4106ast2obj_expr(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004107{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004108 expr_ty o = (expr_ty)_o;
4109 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004110 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004111 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004112 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004113 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004114
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004115 switch (o->kind) {
4116 case BoolOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004117 tp = (PyTypeObject *)astmodulestate_global->BoolOp_type;
4118 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004119 if (!result) goto failed;
4120 value = ast2obj_boolop(o->v.BoolOp.op);
4121 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004122 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004123 goto failed;
4124 Py_DECREF(value);
4125 value = ast2obj_list(o->v.BoolOp.values, ast2obj_expr);
4126 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004127 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4128 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004129 goto failed;
4130 Py_DECREF(value);
4131 break;
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004132 case NamedExpr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004133 tp = (PyTypeObject *)astmodulestate_global->NamedExpr_type;
4134 result = PyType_GenericNew(tp, NULL, NULL);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004135 if (!result) goto failed;
4136 value = ast2obj_expr(o->v.NamedExpr.target);
4137 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004138 if (PyObject_SetAttr(result, astmodulestate_global->target, value) ==
4139 -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004140 goto failed;
4141 Py_DECREF(value);
4142 value = ast2obj_expr(o->v.NamedExpr.value);
4143 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004144 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Emily Morehouse8f59ee02019-01-24 16:49:56 -07004145 goto failed;
4146 Py_DECREF(value);
4147 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004148 case BinOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004149 tp = (PyTypeObject *)astmodulestate_global->BinOp_type;
4150 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004151 if (!result) goto failed;
4152 value = ast2obj_expr(o->v.BinOp.left);
4153 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004154 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004155 goto failed;
4156 Py_DECREF(value);
4157 value = ast2obj_operator(o->v.BinOp.op);
4158 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004159 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004160 goto failed;
4161 Py_DECREF(value);
4162 value = ast2obj_expr(o->v.BinOp.right);
4163 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004164 if (PyObject_SetAttr(result, astmodulestate_global->right, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004165 goto failed;
4166 Py_DECREF(value);
4167 break;
4168 case UnaryOp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004169 tp = (PyTypeObject *)astmodulestate_global->UnaryOp_type;
4170 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004171 if (!result) goto failed;
4172 value = ast2obj_unaryop(o->v.UnaryOp.op);
4173 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004174 if (PyObject_SetAttr(result, astmodulestate_global->op, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004175 goto failed;
4176 Py_DECREF(value);
4177 value = ast2obj_expr(o->v.UnaryOp.operand);
4178 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004179 if (PyObject_SetAttr(result, astmodulestate_global->operand, value) ==
4180 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004181 goto failed;
4182 Py_DECREF(value);
4183 break;
4184 case Lambda_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004185 tp = (PyTypeObject *)astmodulestate_global->Lambda_type;
4186 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004187 if (!result) goto failed;
4188 value = ast2obj_arguments(o->v.Lambda.args);
4189 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004190 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004191 goto failed;
4192 Py_DECREF(value);
4193 value = ast2obj_expr(o->v.Lambda.body);
4194 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004195 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004196 goto failed;
4197 Py_DECREF(value);
4198 break;
4199 case IfExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004200 tp = (PyTypeObject *)astmodulestate_global->IfExp_type;
4201 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004202 if (!result) goto failed;
4203 value = ast2obj_expr(o->v.IfExp.test);
4204 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004205 if (PyObject_SetAttr(result, astmodulestate_global->test, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004206 goto failed;
4207 Py_DECREF(value);
4208 value = ast2obj_expr(o->v.IfExp.body);
4209 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004210 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004211 goto failed;
4212 Py_DECREF(value);
4213 value = ast2obj_expr(o->v.IfExp.orelse);
4214 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004215 if (PyObject_SetAttr(result, astmodulestate_global->orelse, value) ==
4216 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004217 goto failed;
4218 Py_DECREF(value);
4219 break;
4220 case Dict_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004221 tp = (PyTypeObject *)astmodulestate_global->Dict_type;
4222 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004223 if (!result) goto failed;
4224 value = ast2obj_list(o->v.Dict.keys, ast2obj_expr);
4225 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004226 if (PyObject_SetAttr(result, astmodulestate_global->keys, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004227 goto failed;
4228 Py_DECREF(value);
4229 value = ast2obj_list(o->v.Dict.values, ast2obj_expr);
4230 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004231 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4232 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004233 goto failed;
4234 Py_DECREF(value);
4235 break;
4236 case Set_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004237 tp = (PyTypeObject *)astmodulestate_global->Set_type;
4238 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004239 if (!result) goto failed;
4240 value = ast2obj_list(o->v.Set.elts, ast2obj_expr);
4241 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004242 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004243 goto failed;
4244 Py_DECREF(value);
4245 break;
4246 case ListComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004247 tp = (PyTypeObject *)astmodulestate_global->ListComp_type;
4248 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004249 if (!result) goto failed;
4250 value = ast2obj_expr(o->v.ListComp.elt);
4251 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004252 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004253 goto failed;
4254 Py_DECREF(value);
4255 value = ast2obj_list(o->v.ListComp.generators, ast2obj_comprehension);
4256 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004257 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4258 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004259 goto failed;
4260 Py_DECREF(value);
4261 break;
4262 case SetComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004263 tp = (PyTypeObject *)astmodulestate_global->SetComp_type;
4264 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004265 if (!result) goto failed;
4266 value = ast2obj_expr(o->v.SetComp.elt);
4267 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004268 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004269 goto failed;
4270 Py_DECREF(value);
4271 value = ast2obj_list(o->v.SetComp.generators, ast2obj_comprehension);
4272 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004273 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4274 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004275 goto failed;
4276 Py_DECREF(value);
4277 break;
4278 case DictComp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004279 tp = (PyTypeObject *)astmodulestate_global->DictComp_type;
4280 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004281 if (!result) goto failed;
4282 value = ast2obj_expr(o->v.DictComp.key);
4283 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004284 if (PyObject_SetAttr(result, astmodulestate_global->key, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004285 goto failed;
4286 Py_DECREF(value);
4287 value = ast2obj_expr(o->v.DictComp.value);
4288 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004289 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004290 goto failed;
4291 Py_DECREF(value);
4292 value = ast2obj_list(o->v.DictComp.generators, ast2obj_comprehension);
4293 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004294 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4295 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004296 goto failed;
4297 Py_DECREF(value);
4298 break;
4299 case GeneratorExp_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004300 tp = (PyTypeObject *)astmodulestate_global->GeneratorExp_type;
4301 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004302 if (!result) goto failed;
4303 value = ast2obj_expr(o->v.GeneratorExp.elt);
4304 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004305 if (PyObject_SetAttr(result, astmodulestate_global->elt, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004306 goto failed;
4307 Py_DECREF(value);
4308 value = ast2obj_list(o->v.GeneratorExp.generators,
4309 ast2obj_comprehension);
4310 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004311 if (PyObject_SetAttr(result, astmodulestate_global->generators, value)
4312 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004313 goto failed;
4314 Py_DECREF(value);
4315 break;
Yury Selivanov75445082015-05-11 22:57:16 -04004316 case Await_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004317 tp = (PyTypeObject *)astmodulestate_global->Await_type;
4318 result = PyType_GenericNew(tp, NULL, NULL);
Yury Selivanov75445082015-05-11 22:57:16 -04004319 if (!result) goto failed;
4320 value = ast2obj_expr(o->v.Await.value);
4321 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004322 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Yury Selivanov75445082015-05-11 22:57:16 -04004323 goto failed;
4324 Py_DECREF(value);
4325 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004326 case Yield_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004327 tp = (PyTypeObject *)astmodulestate_global->Yield_type;
4328 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004329 if (!result) goto failed;
4330 value = ast2obj_expr(o->v.Yield.value);
4331 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004332 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004333 goto failed;
4334 Py_DECREF(value);
4335 break;
4336 case YieldFrom_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004337 tp = (PyTypeObject *)astmodulestate_global->YieldFrom_type;
4338 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004339 if (!result) goto failed;
4340 value = ast2obj_expr(o->v.YieldFrom.value);
4341 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004342 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004343 goto failed;
4344 Py_DECREF(value);
4345 break;
4346 case Compare_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004347 tp = (PyTypeObject *)astmodulestate_global->Compare_type;
4348 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004349 if (!result) goto failed;
4350 value = ast2obj_expr(o->v.Compare.left);
4351 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004352 if (PyObject_SetAttr(result, astmodulestate_global->left, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004353 goto failed;
4354 Py_DECREF(value);
4355 {
4356 Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
4357 value = PyList_New(n);
4358 if (!value) goto failed;
4359 for(i = 0; i < n; i++)
4360 PyList_SET_ITEM(value, i, ast2obj_cmpop((cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004361 }
Martin v. Löwis577b5b92006-02-27 15:23:19 +00004362 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004363 if (PyObject_SetAttr(result, astmodulestate_global->ops, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004364 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004365 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004366 value = ast2obj_list(o->v.Compare.comparators, ast2obj_expr);
Martin v. Löwis49c5da12006-03-01 22:49:05 +00004367 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004368 if (PyObject_SetAttr(result, astmodulestate_global->comparators, value)
4369 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004370 goto failed;
Martin v. Löwis03e5bc02006-03-02 00:31:27 +00004371 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004372 break;
4373 case Call_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004374 tp = (PyTypeObject *)astmodulestate_global->Call_type;
4375 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004376 if (!result) goto failed;
4377 value = ast2obj_expr(o->v.Call.func);
4378 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004379 if (PyObject_SetAttr(result, astmodulestate_global->func, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004380 goto failed;
4381 Py_DECREF(value);
4382 value = ast2obj_list(o->v.Call.args, ast2obj_expr);
4383 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004384 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004385 goto failed;
4386 Py_DECREF(value);
4387 value = ast2obj_list(o->v.Call.keywords, ast2obj_keyword);
4388 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004389 if (PyObject_SetAttr(result, astmodulestate_global->keywords, value) ==
4390 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004391 goto failed;
4392 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004393 break;
Eric V. Smith235a6f02015-09-19 14:51:32 -04004394 case FormattedValue_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004395 tp = (PyTypeObject *)astmodulestate_global->FormattedValue_type;
4396 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004397 if (!result) goto failed;
4398 value = ast2obj_expr(o->v.FormattedValue.value);
4399 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004400 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004401 goto failed;
4402 Py_DECREF(value);
4403 value = ast2obj_int(o->v.FormattedValue.conversion);
4404 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004405 if (PyObject_SetAttr(result, astmodulestate_global->conversion, value)
4406 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004407 goto failed;
4408 Py_DECREF(value);
4409 value = ast2obj_expr(o->v.FormattedValue.format_spec);
4410 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004411 if (PyObject_SetAttr(result, astmodulestate_global->format_spec, value)
4412 == -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004413 goto failed;
4414 Py_DECREF(value);
4415 break;
4416 case JoinedStr_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004417 tp = (PyTypeObject *)astmodulestate_global->JoinedStr_type;
4418 result = PyType_GenericNew(tp, NULL, NULL);
Eric V. Smith235a6f02015-09-19 14:51:32 -04004419 if (!result) goto failed;
4420 value = ast2obj_list(o->v.JoinedStr.values, ast2obj_expr);
4421 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004422 if (PyObject_SetAttr(result, astmodulestate_global->values, value) ==
4423 -1)
Eric V. Smith235a6f02015-09-19 14:51:32 -04004424 goto failed;
4425 Py_DECREF(value);
4426 break;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004427 case Constant_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004428 tp = (PyTypeObject *)astmodulestate_global->Constant_type;
4429 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004430 if (!result) goto failed;
4431 value = ast2obj_constant(o->v.Constant.value);
4432 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004433 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004434 goto failed;
4435 Py_DECREF(value);
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004436 value = ast2obj_string(o->v.Constant.kind);
4437 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004438 if (PyObject_SetAttr(result, astmodulestate_global->kind, value) == -1)
Guido van Rossum10f8ce62019-03-13 13:00:46 -07004439 goto failed;
4440 Py_DECREF(value);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01004441 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004442 case Attribute_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004443 tp = (PyTypeObject *)astmodulestate_global->Attribute_type;
4444 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004445 if (!result) goto failed;
4446 value = ast2obj_expr(o->v.Attribute.value);
4447 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004448 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004449 goto failed;
4450 Py_DECREF(value);
4451 value = ast2obj_identifier(o->v.Attribute.attr);
4452 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004453 if (PyObject_SetAttr(result, astmodulestate_global->attr, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004454 goto failed;
4455 Py_DECREF(value);
4456 value = ast2obj_expr_context(o->v.Attribute.ctx);
4457 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004458 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004459 goto failed;
4460 Py_DECREF(value);
4461 break;
4462 case Subscript_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004463 tp = (PyTypeObject *)astmodulestate_global->Subscript_type;
4464 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004465 if (!result) goto failed;
4466 value = ast2obj_expr(o->v.Subscript.value);
4467 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004468 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004469 goto failed;
4470 Py_DECREF(value);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004471 value = ast2obj_expr(o->v.Subscript.slice);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004472 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004473 if (PyObject_SetAttr(result, astmodulestate_global->slice, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004474 goto failed;
4475 Py_DECREF(value);
4476 value = ast2obj_expr_context(o->v.Subscript.ctx);
4477 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004478 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004479 goto failed;
4480 Py_DECREF(value);
4481 break;
4482 case Starred_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004483 tp = (PyTypeObject *)astmodulestate_global->Starred_type;
4484 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004485 if (!result) goto failed;
4486 value = ast2obj_expr(o->v.Starred.value);
4487 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004488 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004489 goto failed;
4490 Py_DECREF(value);
4491 value = ast2obj_expr_context(o->v.Starred.ctx);
4492 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004493 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004494 goto failed;
4495 Py_DECREF(value);
4496 break;
4497 case Name_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004498 tp = (PyTypeObject *)astmodulestate_global->Name_type;
4499 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004500 if (!result) goto failed;
4501 value = ast2obj_identifier(o->v.Name.id);
4502 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004503 if (PyObject_SetAttr(result, astmodulestate_global->id, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004504 goto failed;
4505 Py_DECREF(value);
4506 value = ast2obj_expr_context(o->v.Name.ctx);
4507 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004508 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004509 goto failed;
4510 Py_DECREF(value);
4511 break;
4512 case List_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004513 tp = (PyTypeObject *)astmodulestate_global->List_type;
4514 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004515 if (!result) goto failed;
4516 value = ast2obj_list(o->v.List.elts, ast2obj_expr);
4517 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004518 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004519 goto failed;
4520 Py_DECREF(value);
4521 value = ast2obj_expr_context(o->v.List.ctx);
4522 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004523 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004524 goto failed;
4525 Py_DECREF(value);
4526 break;
4527 case Tuple_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004528 tp = (PyTypeObject *)astmodulestate_global->Tuple_type;
4529 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004530 if (!result) goto failed;
4531 value = ast2obj_list(o->v.Tuple.elts, ast2obj_expr);
4532 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004533 if (PyObject_SetAttr(result, astmodulestate_global->elts, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004534 goto failed;
4535 Py_DECREF(value);
4536 value = ast2obj_expr_context(o->v.Tuple.ctx);
4537 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004538 if (PyObject_SetAttr(result, astmodulestate_global->ctx, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004539 goto failed;
4540 Py_DECREF(value);
4541 break;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02004542 case Slice_kind:
4543 tp = (PyTypeObject *)astmodulestate_global->Slice_type;
4544 result = PyType_GenericNew(tp, NULL, NULL);
4545 if (!result) goto failed;
4546 value = ast2obj_expr(o->v.Slice.lower);
4547 if (!value) goto failed;
4548 if (PyObject_SetAttr(result, astmodulestate_global->lower, value) == -1)
4549 goto failed;
4550 Py_DECREF(value);
4551 value = ast2obj_expr(o->v.Slice.upper);
4552 if (!value) goto failed;
4553 if (PyObject_SetAttr(result, astmodulestate_global->upper, value) == -1)
4554 goto failed;
4555 Py_DECREF(value);
4556 value = ast2obj_expr(o->v.Slice.step);
4557 if (!value) goto failed;
4558 if (PyObject_SetAttr(result, astmodulestate_global->step, value) == -1)
4559 goto failed;
4560 Py_DECREF(value);
4561 break;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004562 }
4563 value = ast2obj_int(o->lineno);
4564 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004565 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004566 goto failed;
4567 Py_DECREF(value);
4568 value = ast2obj_int(o->col_offset);
4569 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004570 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004571 goto failed;
4572 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004573 value = ast2obj_int(o->end_lineno);
4574 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004575 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004576 goto failed;
4577 Py_DECREF(value);
4578 value = ast2obj_int(o->end_col_offset);
4579 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004580 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4581 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004582 goto failed;
4583 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004584 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004585failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004586 Py_XDECREF(value);
4587 Py_XDECREF(result);
4588 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004589}
4590
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004591PyObject* ast2obj_expr_context(expr_context_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004592{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004593 switch(o) {
4594 case Load:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004595 Py_INCREF(astmodulestate_global->Load_singleton);
4596 return astmodulestate_global->Load_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004597 case Store:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004598 Py_INCREF(astmodulestate_global->Store_singleton);
4599 return astmodulestate_global->Store_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004600 case Del:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004601 Py_INCREF(astmodulestate_global->Del_singleton);
4602 return astmodulestate_global->Del_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004603 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004604 Py_UNREACHABLE();
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004605}
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004606PyObject* ast2obj_boolop(boolop_ty o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004607{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004608 switch(o) {
4609 case And:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004610 Py_INCREF(astmodulestate_global->And_singleton);
4611 return astmodulestate_global->And_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004612 case Or:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004613 Py_INCREF(astmodulestate_global->Or_singleton);
4614 return astmodulestate_global->Or_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004615 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004616 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004617}
4618PyObject* ast2obj_operator(operator_ty o)
4619{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004620 switch(o) {
4621 case Add:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004622 Py_INCREF(astmodulestate_global->Add_singleton);
4623 return astmodulestate_global->Add_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004624 case Sub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004625 Py_INCREF(astmodulestate_global->Sub_singleton);
4626 return astmodulestate_global->Sub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004627 case Mult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004628 Py_INCREF(astmodulestate_global->Mult_singleton);
4629 return astmodulestate_global->Mult_singleton;
Benjamin Petersond51374e2014-04-09 23:55:56 -04004630 case MatMult:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004631 Py_INCREF(astmodulestate_global->MatMult_singleton);
4632 return astmodulestate_global->MatMult_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004633 case Div:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004634 Py_INCREF(astmodulestate_global->Div_singleton);
4635 return astmodulestate_global->Div_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004636 case Mod:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004637 Py_INCREF(astmodulestate_global->Mod_singleton);
4638 return astmodulestate_global->Mod_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004639 case Pow:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004640 Py_INCREF(astmodulestate_global->Pow_singleton);
4641 return astmodulestate_global->Pow_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004642 case LShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004643 Py_INCREF(astmodulestate_global->LShift_singleton);
4644 return astmodulestate_global->LShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004645 case RShift:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004646 Py_INCREF(astmodulestate_global->RShift_singleton);
4647 return astmodulestate_global->RShift_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004648 case BitOr:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004649 Py_INCREF(astmodulestate_global->BitOr_singleton);
4650 return astmodulestate_global->BitOr_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004651 case BitXor:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004652 Py_INCREF(astmodulestate_global->BitXor_singleton);
4653 return astmodulestate_global->BitXor_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004654 case BitAnd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004655 Py_INCREF(astmodulestate_global->BitAnd_singleton);
4656 return astmodulestate_global->BitAnd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004657 case FloorDiv:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004658 Py_INCREF(astmodulestate_global->FloorDiv_singleton);
4659 return astmodulestate_global->FloorDiv_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004660 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004661 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004662}
4663PyObject* ast2obj_unaryop(unaryop_ty o)
4664{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004665 switch(o) {
4666 case Invert:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004667 Py_INCREF(astmodulestate_global->Invert_singleton);
4668 return astmodulestate_global->Invert_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004669 case Not:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004670 Py_INCREF(astmodulestate_global->Not_singleton);
4671 return astmodulestate_global->Not_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004672 case UAdd:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004673 Py_INCREF(astmodulestate_global->UAdd_singleton);
4674 return astmodulestate_global->UAdd_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004675 case USub:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004676 Py_INCREF(astmodulestate_global->USub_singleton);
4677 return astmodulestate_global->USub_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004678 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004679 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004680}
4681PyObject* ast2obj_cmpop(cmpop_ty o)
4682{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004683 switch(o) {
4684 case Eq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004685 Py_INCREF(astmodulestate_global->Eq_singleton);
4686 return astmodulestate_global->Eq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004687 case NotEq:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004688 Py_INCREF(astmodulestate_global->NotEq_singleton);
4689 return astmodulestate_global->NotEq_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004690 case Lt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004691 Py_INCREF(astmodulestate_global->Lt_singleton);
4692 return astmodulestate_global->Lt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004693 case LtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004694 Py_INCREF(astmodulestate_global->LtE_singleton);
4695 return astmodulestate_global->LtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004696 case Gt:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004697 Py_INCREF(astmodulestate_global->Gt_singleton);
4698 return astmodulestate_global->Gt_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004699 case GtE:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004700 Py_INCREF(astmodulestate_global->GtE_singleton);
4701 return astmodulestate_global->GtE_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004702 case Is:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004703 Py_INCREF(astmodulestate_global->Is_singleton);
4704 return astmodulestate_global->Is_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004705 case IsNot:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004706 Py_INCREF(astmodulestate_global->IsNot_singleton);
4707 return astmodulestate_global->IsNot_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004708 case In:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004709 Py_INCREF(astmodulestate_global->In_singleton);
4710 return astmodulestate_global->In_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004711 case NotIn:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004712 Py_INCREF(astmodulestate_global->NotIn_singleton);
4713 return astmodulestate_global->NotIn_singleton;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004714 }
Batuhan Taskaya091951a2020-05-06 17:29:32 +03004715 Py_UNREACHABLE();
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004716}
4717PyObject*
4718ast2obj_comprehension(void* _o)
4719{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004720 comprehension_ty o = (comprehension_ty)_o;
4721 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004722 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004723 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004724 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004725 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004726
Dino Viehlandac46eb42019-09-11 10:16:34 -07004727 tp = (PyTypeObject *)astmodulestate_global->comprehension_type;
4728 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004729 if (!result) return NULL;
4730 value = ast2obj_expr(o->target);
4731 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004732 if (PyObject_SetAttr(result, astmodulestate_global->target, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004733 goto failed;
4734 Py_DECREF(value);
4735 value = ast2obj_expr(o->iter);
4736 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004737 if (PyObject_SetAttr(result, astmodulestate_global->iter, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004738 goto failed;
4739 Py_DECREF(value);
4740 value = ast2obj_list(o->ifs, ast2obj_expr);
4741 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004742 if (PyObject_SetAttr(result, astmodulestate_global->ifs, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004743 goto failed;
4744 Py_DECREF(value);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004745 value = ast2obj_int(o->is_async);
4746 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004747 if (PyObject_SetAttr(result, astmodulestate_global->is_async, value) == -1)
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07004748 goto failed;
4749 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004750 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004751failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004752 Py_XDECREF(value);
4753 Py_XDECREF(result);
4754 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004755}
4756
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004757PyObject*
4758ast2obj_excepthandler(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004759{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004760 excepthandler_ty o = (excepthandler_ty)_o;
4761 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004762 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004763 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004764 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004765 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004766
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004767 switch (o->kind) {
4768 case ExceptHandler_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07004769 tp = (PyTypeObject *)astmodulestate_global->ExceptHandler_type;
4770 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004771 if (!result) goto failed;
4772 value = ast2obj_expr(o->v.ExceptHandler.type);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004773 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004774 if (PyObject_SetAttr(result, astmodulestate_global->type, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004775 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004776 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004777 value = ast2obj_identifier(o->v.ExceptHandler.name);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004778 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004779 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004780 goto failed;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004781 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004782 value = ast2obj_list(o->v.ExceptHandler.body, ast2obj_stmt);
4783 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004784 if (PyObject_SetAttr(result, astmodulestate_global->body, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004785 goto failed;
4786 Py_DECREF(value);
4787 break;
4788 }
4789 value = ast2obj_int(o->lineno);
4790 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004791 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004792 goto failed;
4793 Py_DECREF(value);
4794 value = ast2obj_int(o->col_offset);
4795 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004796 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004797 goto failed;
4798 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004799 value = ast2obj_int(o->end_lineno);
4800 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004801 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004802 goto failed;
4803 Py_DECREF(value);
4804 value = ast2obj_int(o->end_col_offset);
4805 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004806 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4807 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004808 goto failed;
4809 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004810 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004811failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004812 Py_XDECREF(value);
4813 Py_XDECREF(result);
4814 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004815}
4816
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004817PyObject*
4818ast2obj_arguments(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004819{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004820 arguments_ty o = (arguments_ty)_o;
4821 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004822 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004823 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004824 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004825 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004826
Dino Viehlandac46eb42019-09-11 10:16:34 -07004827 tp = (PyTypeObject *)astmodulestate_global->arguments_type;
4828 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004829 if (!result) return NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004830 value = ast2obj_list(o->posonlyargs, ast2obj_arg);
4831 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004832 if (PyObject_SetAttr(result, astmodulestate_global->posonlyargs, value) ==
4833 -1)
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01004834 goto failed;
4835 Py_DECREF(value);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004836 value = ast2obj_list(o->args, ast2obj_arg);
4837 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004838 if (PyObject_SetAttr(result, astmodulestate_global->args, value) == -1)
Pablo Galindocd6e83b2019-07-15 01:32:18 +02004839 goto failed;
4840 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004841 value = ast2obj_arg(o->vararg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004842 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004843 if (PyObject_SetAttr(result, astmodulestate_global->vararg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004844 goto failed;
4845 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004846 value = ast2obj_list(o->kwonlyargs, ast2obj_arg);
4847 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004848 if (PyObject_SetAttr(result, astmodulestate_global->kwonlyargs, value) ==
4849 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004850 goto failed;
4851 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004852 value = ast2obj_list(o->kw_defaults, ast2obj_expr);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004853 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004854 if (PyObject_SetAttr(result, astmodulestate_global->kw_defaults, value) ==
4855 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004856 goto failed;
4857 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004858 value = ast2obj_arg(o->kwarg);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004859 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004860 if (PyObject_SetAttr(result, astmodulestate_global->kwarg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004861 goto failed;
4862 Py_DECREF(value);
4863 value = ast2obj_list(o->defaults, ast2obj_expr);
4864 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004865 if (PyObject_SetAttr(result, astmodulestate_global->defaults, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004866 goto failed;
4867 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004868 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004869failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004870 Py_XDECREF(value);
4871 Py_XDECREF(result);
4872 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004873}
4874
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004875PyObject*
Neal Norwitzc1505362006-12-28 06:47:50 +00004876ast2obj_arg(void* _o)
4877{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004878 arg_ty o = (arg_ty)_o;
4879 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004880 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004881 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004882 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004883 }
Neal Norwitzc1505362006-12-28 06:47:50 +00004884
Dino Viehlandac46eb42019-09-11 10:16:34 -07004885 tp = (PyTypeObject *)astmodulestate_global->arg_type;
4886 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004887 if (!result) return NULL;
4888 value = ast2obj_identifier(o->arg);
4889 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004890 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004891 goto failed;
4892 Py_DECREF(value);
4893 value = ast2obj_expr(o->annotation);
4894 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004895 if (PyObject_SetAttr(result, astmodulestate_global->annotation, value) ==
4896 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004897 goto failed;
4898 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004899 value = ast2obj_string(o->type_comment);
4900 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004901 if (PyObject_SetAttr(result, astmodulestate_global->type_comment, value) ==
4902 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08004903 goto failed;
4904 Py_DECREF(value);
Victor Stinneree4b59c2013-07-27 00:01:35 +02004905 value = ast2obj_int(o->lineno);
4906 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004907 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004908 goto failed;
4909 Py_DECREF(value);
4910 value = ast2obj_int(o->col_offset);
4911 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004912 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
Victor Stinneree4b59c2013-07-27 00:01:35 +02004913 goto failed;
4914 Py_DECREF(value);
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004915 value = ast2obj_int(o->end_lineno);
4916 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004917 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004918 goto failed;
4919 Py_DECREF(value);
4920 value = ast2obj_int(o->end_col_offset);
4921 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004922 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4923 < 0)
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00004924 goto failed;
4925 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004926 return result;
Neal Norwitzc1505362006-12-28 06:47:50 +00004927failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004928 Py_XDECREF(value);
4929 Py_XDECREF(result);
4930 return NULL;
Neal Norwitzc1505362006-12-28 06:47:50 +00004931}
4932
4933PyObject*
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004934ast2obj_keyword(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004935{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004936 keyword_ty o = (keyword_ty)_o;
4937 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004938 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004939 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004940 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004941 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004942
Dino Viehlandac46eb42019-09-11 10:16:34 -07004943 tp = (PyTypeObject *)astmodulestate_global->keyword_type;
4944 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004945 if (!result) return NULL;
4946 value = ast2obj_identifier(o->arg);
4947 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004948 if (PyObject_SetAttr(result, astmodulestate_global->arg, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004949 goto failed;
4950 Py_DECREF(value);
4951 value = ast2obj_expr(o->value);
4952 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004953 if (PyObject_SetAttr(result, astmodulestate_global->value, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004954 goto failed;
4955 Py_DECREF(value);
Pablo Galindo168660b2020-04-02 00:47:39 +01004956 value = ast2obj_int(o->lineno);
4957 if (!value) goto failed;
4958 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) < 0)
4959 goto failed;
4960 Py_DECREF(value);
4961 value = ast2obj_int(o->col_offset);
4962 if (!value) goto failed;
4963 if (PyObject_SetAttr(result, astmodulestate_global->col_offset, value) < 0)
4964 goto failed;
4965 Py_DECREF(value);
4966 value = ast2obj_int(o->end_lineno);
4967 if (!value) goto failed;
4968 if (PyObject_SetAttr(result, astmodulestate_global->end_lineno, value) < 0)
4969 goto failed;
4970 Py_DECREF(value);
4971 value = ast2obj_int(o->end_col_offset);
4972 if (!value) goto failed;
4973 if (PyObject_SetAttr(result, astmodulestate_global->end_col_offset, value)
4974 < 0)
4975 goto failed;
4976 Py_DECREF(value);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004977 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004978failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004979 Py_XDECREF(value);
4980 Py_XDECREF(result);
4981 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004982}
4983
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004984PyObject*
4985ast2obj_alias(void* _o)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00004986{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004987 alias_ty o = (alias_ty)_o;
4988 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004989 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004990 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02004991 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004992 }
Martin v. Löwisbd260da2006-02-26 19:42:26 +00004993
Dino Viehlandac46eb42019-09-11 10:16:34 -07004994 tp = (PyTypeObject *)astmodulestate_global->alias_type;
4995 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02004996 if (!result) return NULL;
4997 value = ast2obj_identifier(o->name);
4998 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07004999 if (PyObject_SetAttr(result, astmodulestate_global->name, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005000 goto failed;
5001 Py_DECREF(value);
5002 value = ast2obj_identifier(o->asname);
5003 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005004 if (PyObject_SetAttr(result, astmodulestate_global->asname, value) == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005005 goto failed;
5006 Py_DECREF(value);
5007 return result;
Martin v. Löwisbd260da2006-02-26 19:42:26 +00005008failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005009 Py_XDECREF(value);
5010 Py_XDECREF(result);
5011 return NULL;
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005012}
5013
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005014PyObject*
5015ast2obj_withitem(void* _o)
5016{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005017 withitem_ty o = (withitem_ty)_o;
5018 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005019 PyTypeObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005020 if (!o) {
Serhiy Storchaka228b12e2017-01-23 09:47:21 +02005021 Py_RETURN_NONE;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005022 }
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005023
Dino Viehlandac46eb42019-09-11 10:16:34 -07005024 tp = (PyTypeObject *)astmodulestate_global->withitem_type;
5025 result = PyType_GenericNew(tp, NULL, NULL);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005026 if (!result) return NULL;
5027 value = ast2obj_expr(o->context_expr);
5028 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005029 if (PyObject_SetAttr(result, astmodulestate_global->context_expr, value) ==
5030 -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005031 goto failed;
5032 Py_DECREF(value);
5033 value = ast2obj_expr(o->optional_vars);
5034 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005035 if (PyObject_SetAttr(result, astmodulestate_global->optional_vars, value)
5036 == -1)
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005037 goto failed;
5038 Py_DECREF(value);
5039 return result;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005040failed:
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005041 Py_XDECREF(value);
5042 Py_XDECREF(result);
5043 return NULL;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05005044}
5045
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005046PyObject*
5047ast2obj_type_ignore(void* _o)
5048{
5049 type_ignore_ty o = (type_ignore_ty)_o;
5050 PyObject *result = NULL, *value = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005051 PyTypeObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005052 if (!o) {
5053 Py_RETURN_NONE;
5054 }
5055
5056 switch (o->kind) {
5057 case TypeIgnore_kind:
Dino Viehlandac46eb42019-09-11 10:16:34 -07005058 tp = (PyTypeObject *)astmodulestate_global->TypeIgnore_type;
5059 result = PyType_GenericNew(tp, NULL, NULL);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005060 if (!result) goto failed;
5061 value = ast2obj_int(o->v.TypeIgnore.lineno);
5062 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005063 if (PyObject_SetAttr(result, astmodulestate_global->lineno, value) ==
5064 -1)
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005065 goto failed;
5066 Py_DECREF(value);
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005067 value = ast2obj_string(o->v.TypeIgnore.tag);
5068 if (!value) goto failed;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005069 if (PyObject_SetAttr(result, astmodulestate_global->tag, value) == -1)
Michael J. Sullivan933e1502019-05-22 07:54:20 -07005070 goto failed;
5071 Py_DECREF(value);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005072 break;
5073 }
5074 return result;
5075failed:
5076 Py_XDECREF(value);
5077 Py_XDECREF(result);
5078 return NULL;
5079}
5080
Jeremy Hylton3e0055f2005-10-20 19:59:25 +00005081
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005082int
5083obj2ast_mod(PyObject* obj, mod_ty* out, PyArena* arena)
5084{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005085 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005086
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005087 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005088 PyObject *tp;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005089
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005090 if (obj == Py_None) {
5091 *out = NULL;
5092 return 0;
5093 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005094 tp = astmodulestate_global->Module_type;
5095 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005096 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005097 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005098 }
5099 if (isinstance) {
5100 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005101 asdl_seq* type_ignores;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005102
Dino Viehlandac46eb42019-09-11 10:16:34 -07005103 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005104 return 1;
5105 }
5106 if (tmp == NULL) {
5107 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Module");
5108 return 1;
5109 }
5110 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005111 int res;
5112 Py_ssize_t len;
5113 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005114 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005115 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 +02005116 goto failed;
5117 }
5118 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005119 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005120 if (body == NULL) goto failed;
5121 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005122 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005123 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5124 Py_INCREF(tmp2);
5125 res = obj2ast_stmt(tmp2, &val, arena);
5126 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005127 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005128 if (len != PyList_GET_SIZE(tmp)) {
5129 PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
5130 goto failed;
5131 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005132 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005133 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005134 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005135 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005136 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_ignores,
5137 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005138 return 1;
5139 }
5140 if (tmp == NULL) {
5141 PyErr_SetString(PyExc_TypeError, "required field \"type_ignores\" missing from Module");
5142 return 1;
5143 }
5144 else {
5145 int res;
5146 Py_ssize_t len;
5147 Py_ssize_t i;
5148 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005149 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 -08005150 goto failed;
5151 }
5152 len = PyList_GET_SIZE(tmp);
5153 type_ignores = _Py_asdl_seq_new(len, arena);
5154 if (type_ignores == NULL) goto failed;
5155 for (i = 0; i < len; i++) {
5156 type_ignore_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005157 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5158 Py_INCREF(tmp2);
5159 res = obj2ast_type_ignore(tmp2, &val, arena);
5160 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005161 if (res != 0) goto failed;
5162 if (len != PyList_GET_SIZE(tmp)) {
5163 PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
5164 goto failed;
5165 }
5166 asdl_seq_SET(type_ignores, i, val);
5167 }
5168 Py_CLEAR(tmp);
5169 }
5170 *out = Module(body, type_ignores, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005171 if (*out == NULL) goto failed;
5172 return 0;
5173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005174 tp = astmodulestate_global->Interactive_type;
5175 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005176 if (isinstance == -1) {
5177 return 1;
5178 }
5179 if (isinstance) {
5180 asdl_seq* body;
5181
Dino Viehlandac46eb42019-09-11 10:16:34 -07005182 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005183 return 1;
5184 }
5185 if (tmp == NULL) {
5186 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Interactive");
5187 return 1;
5188 }
5189 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005190 int res;
5191 Py_ssize_t len;
5192 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005193 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005194 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 +02005195 goto failed;
5196 }
5197 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005198 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005199 if (body == NULL) goto failed;
5200 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005201 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005202 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5203 Py_INCREF(tmp2);
5204 res = obj2ast_stmt(tmp2, &val, arena);
5205 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005206 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005207 if (len != PyList_GET_SIZE(tmp)) {
5208 PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
5209 goto failed;
5210 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005211 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005212 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005213 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005214 }
5215 *out = Interactive(body, arena);
5216 if (*out == NULL) goto failed;
5217 return 0;
5218 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005219 tp = astmodulestate_global->Expression_type;
5220 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005221 if (isinstance == -1) {
5222 return 1;
5223 }
5224 if (isinstance) {
5225 expr_ty body;
5226
Dino Viehlandac46eb42019-09-11 10:16:34 -07005227 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005228 return 1;
5229 }
5230 if (tmp == NULL) {
5231 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
5232 return 1;
5233 }
5234 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005235 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005236 res = obj2ast_expr(tmp, &body, arena);
5237 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005238 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005239 }
5240 *out = Expression(body, arena);
5241 if (*out == NULL) goto failed;
5242 return 0;
5243 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005244 tp = astmodulestate_global->FunctionType_type;
5245 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005246 if (isinstance == -1) {
5247 return 1;
5248 }
5249 if (isinstance) {
5250 asdl_seq* argtypes;
5251 expr_ty returns;
5252
Dino Viehlandac46eb42019-09-11 10:16:34 -07005253 if (_PyObject_LookupAttr(obj, astmodulestate_global->argtypes, &tmp) <
5254 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005255 return 1;
5256 }
5257 if (tmp == NULL) {
5258 PyErr_SetString(PyExc_TypeError, "required field \"argtypes\" missing from FunctionType");
5259 return 1;
5260 }
5261 else {
5262 int res;
5263 Py_ssize_t len;
5264 Py_ssize_t i;
5265 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005266 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 -08005267 goto failed;
5268 }
5269 len = PyList_GET_SIZE(tmp);
5270 argtypes = _Py_asdl_seq_new(len, arena);
5271 if (argtypes == NULL) goto failed;
5272 for (i = 0; i < len; i++) {
5273 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005274 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5275 Py_INCREF(tmp2);
5276 res = obj2ast_expr(tmp2, &val, arena);
5277 Py_DECREF(tmp2);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005278 if (res != 0) goto failed;
5279 if (len != PyList_GET_SIZE(tmp)) {
5280 PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
5281 goto failed;
5282 }
5283 asdl_seq_SET(argtypes, i, val);
5284 }
5285 Py_CLEAR(tmp);
5286 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005287 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5288 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005289 return 1;
5290 }
5291 if (tmp == NULL) {
5292 PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
5293 return 1;
5294 }
5295 else {
5296 int res;
5297 res = obj2ast_expr(tmp, &returns, arena);
5298 if (res != 0) goto failed;
5299 Py_CLEAR(tmp);
5300 }
5301 *out = FunctionType(argtypes, returns, arena);
5302 if (*out == NULL) goto failed;
5303 return 0;
5304 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005305
5306 PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
5307 failed:
5308 Py_XDECREF(tmp);
5309 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005310}
5311
5312int
5313obj2ast_stmt(PyObject* obj, stmt_ty* out, PyArena* arena)
5314{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005315 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005316
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005317 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07005318 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005319 int lineno;
5320 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005321 int end_lineno;
5322 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005323
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005324 if (obj == Py_None) {
5325 *out = NULL;
5326 return 0;
5327 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005328 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005329 return 1;
5330 }
5331 if (tmp == NULL) {
5332 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
5333 return 1;
5334 }
5335 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005336 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005337 res = obj2ast_int(tmp, &lineno, arena);
5338 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005339 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005340 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005341 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
5342 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00005343 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005344 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005345 if (tmp == NULL) {
5346 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
5347 return 1;
5348 }
5349 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005350 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005351 res = obj2ast_int(tmp, &col_offset, arena);
5352 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005353 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005354 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005355 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
5356 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005357 return 1;
5358 }
5359 if (tmp == NULL || tmp == Py_None) {
5360 Py_CLEAR(tmp);
5361 end_lineno = 0;
5362 }
5363 else {
5364 int res;
5365 res = obj2ast_int(tmp, &end_lineno, arena);
5366 if (res != 0) goto failed;
5367 Py_CLEAR(tmp);
5368 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005369 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
5370 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005371 return 1;
5372 }
5373 if (tmp == NULL || tmp == Py_None) {
5374 Py_CLEAR(tmp);
5375 end_col_offset = 0;
5376 }
5377 else {
5378 int res;
5379 res = obj2ast_int(tmp, &end_col_offset, arena);
5380 if (res != 0) goto failed;
5381 Py_CLEAR(tmp);
5382 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005383 tp = astmodulestate_global->FunctionDef_type;
5384 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005385 if (isinstance == -1) {
5386 return 1;
5387 }
5388 if (isinstance) {
5389 identifier name;
5390 arguments_ty args;
5391 asdl_seq* body;
5392 asdl_seq* decorator_list;
5393 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005394 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005395
Dino Viehlandac46eb42019-09-11 10:16:34 -07005396 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005397 return 1;
5398 }
5399 if (tmp == NULL) {
5400 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
5401 return 1;
5402 }
5403 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005404 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005405 res = obj2ast_identifier(tmp, &name, arena);
5406 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005407 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005408 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005409 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005410 return 1;
5411 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005412 if (tmp == NULL) {
5413 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
5414 return 1;
5415 }
5416 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005417 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005418 res = obj2ast_arguments(tmp, &args, arena);
5419 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005420 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005421 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005422 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005423 return 1;
5424 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005425 if (tmp == NULL) {
5426 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from FunctionDef");
5427 return 1;
5428 }
5429 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005430 int res;
5431 Py_ssize_t len;
5432 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005433 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005434 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 +02005435 goto failed;
5436 }
5437 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005438 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005439 if (body == NULL) goto failed;
5440 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005441 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005442 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5443 Py_INCREF(tmp2);
5444 res = obj2ast_stmt(tmp2, &val, arena);
5445 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005446 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005447 if (len != PyList_GET_SIZE(tmp)) {
5448 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
5449 goto failed;
5450 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005451 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005452 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005453 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005454 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005455 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5456 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005457 return 1;
5458 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005459 if (tmp == NULL) {
5460 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from FunctionDef");
5461 return 1;
5462 }
5463 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005464 int res;
5465 Py_ssize_t len;
5466 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005467 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005468 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 +02005469 goto failed;
5470 }
5471 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005472 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005473 if (decorator_list == NULL) goto failed;
5474 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005475 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005476 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5477 Py_INCREF(tmp2);
5478 res = obj2ast_expr(tmp2, &val, arena);
5479 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005480 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005481 if (len != PyList_GET_SIZE(tmp)) {
5482 PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
5483 goto failed;
5484 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005485 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005486 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005487 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005488 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005489 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5490 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005491 return 1;
5492 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005493 if (tmp == NULL || tmp == Py_None) {
5494 Py_CLEAR(tmp);
5495 returns = NULL;
5496 }
5497 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005498 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005499 res = obj2ast_expr(tmp, &returns, arena);
5500 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005501 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005502 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005503 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5504 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005505 return 1;
5506 }
5507 if (tmp == NULL || tmp == Py_None) {
5508 Py_CLEAR(tmp);
5509 type_comment = NULL;
5510 }
5511 else {
5512 int res;
5513 res = obj2ast_string(tmp, &type_comment, arena);
5514 if (res != 0) goto failed;
5515 Py_CLEAR(tmp);
5516 }
5517 *out = FunctionDef(name, args, body, decorator_list, returns,
5518 type_comment, lineno, col_offset, end_lineno,
5519 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005520 if (*out == NULL) goto failed;
5521 return 0;
5522 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005523 tp = astmodulestate_global->AsyncFunctionDef_type;
5524 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04005525 if (isinstance == -1) {
5526 return 1;
5527 }
5528 if (isinstance) {
5529 identifier name;
5530 arguments_ty args;
5531 asdl_seq* body;
5532 asdl_seq* decorator_list;
5533 expr_ty returns;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005534 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04005535
Dino Viehlandac46eb42019-09-11 10:16:34 -07005536 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005537 return 1;
5538 }
5539 if (tmp == NULL) {
5540 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
5541 return 1;
5542 }
5543 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005544 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005545 res = obj2ast_identifier(tmp, &name, arena);
5546 if (res != 0) goto failed;
5547 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005548 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005549 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005550 return 1;
5551 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005552 if (tmp == NULL) {
5553 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
5554 return 1;
5555 }
5556 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005557 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005558 res = obj2ast_arguments(tmp, &args, arena);
5559 if (res != 0) goto failed;
5560 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005561 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005562 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005563 return 1;
5564 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005565 if (tmp == NULL) {
5566 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFunctionDef");
5567 return 1;
5568 }
5569 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005570 int res;
5571 Py_ssize_t len;
5572 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005573 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005574 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 -04005575 goto failed;
5576 }
5577 len = PyList_GET_SIZE(tmp);
5578 body = _Py_asdl_seq_new(len, arena);
5579 if (body == NULL) goto failed;
5580 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005581 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005582 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5583 Py_INCREF(tmp2);
5584 res = obj2ast_stmt(tmp2, &val, arena);
5585 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005586 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005587 if (len != PyList_GET_SIZE(tmp)) {
5588 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
5589 goto failed;
5590 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005591 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005592 }
5593 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005594 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005595 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5596 &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005597 return 1;
5598 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005599 if (tmp == NULL) {
5600 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from AsyncFunctionDef");
5601 return 1;
5602 }
5603 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005604 int res;
5605 Py_ssize_t len;
5606 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04005607 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005608 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 -04005609 goto failed;
5610 }
5611 len = PyList_GET_SIZE(tmp);
5612 decorator_list = _Py_asdl_seq_new(len, arena);
5613 if (decorator_list == NULL) goto failed;
5614 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005615 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005616 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5617 Py_INCREF(tmp2);
5618 res = obj2ast_expr(tmp2, &val, arena);
5619 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04005620 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005621 if (len != PyList_GET_SIZE(tmp)) {
5622 PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
5623 goto failed;
5624 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005625 asdl_seq_SET(decorator_list, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04005626 }
5627 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005628 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005629 if (_PyObject_LookupAttr(obj, astmodulestate_global->returns, &tmp) <
5630 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04005631 return 1;
5632 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005633 if (tmp == NULL || tmp == Py_None) {
5634 Py_CLEAR(tmp);
5635 returns = NULL;
5636 }
5637 else {
Yury Selivanov75445082015-05-11 22:57:16 -04005638 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04005639 res = obj2ast_expr(tmp, &returns, arena);
5640 if (res != 0) goto failed;
5641 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04005642 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005643 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5644 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005645 return 1;
5646 }
5647 if (tmp == NULL || tmp == Py_None) {
5648 Py_CLEAR(tmp);
5649 type_comment = NULL;
5650 }
5651 else {
5652 int res;
5653 res = obj2ast_string(tmp, &type_comment, arena);
5654 if (res != 0) goto failed;
5655 Py_CLEAR(tmp);
5656 }
Yury Selivanov75445082015-05-11 22:57:16 -04005657 *out = AsyncFunctionDef(name, args, body, decorator_list, returns,
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005658 type_comment, lineno, col_offset, end_lineno,
5659 end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04005660 if (*out == NULL) goto failed;
5661 return 0;
5662 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005663 tp = astmodulestate_global->ClassDef_type;
5664 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005665 if (isinstance == -1) {
5666 return 1;
5667 }
5668 if (isinstance) {
5669 identifier name;
5670 asdl_seq* bases;
5671 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005672 asdl_seq* body;
5673 asdl_seq* decorator_list;
5674
Dino Viehlandac46eb42019-09-11 10:16:34 -07005675 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005676 return 1;
5677 }
5678 if (tmp == NULL) {
5679 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
5680 return 1;
5681 }
5682 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005683 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005684 res = obj2ast_identifier(tmp, &name, arena);
5685 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005686 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005687 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005688 if (_PyObject_LookupAttr(obj, astmodulestate_global->bases, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005689 return 1;
5690 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005691 if (tmp == NULL) {
5692 PyErr_SetString(PyExc_TypeError, "required field \"bases\" missing from ClassDef");
5693 return 1;
5694 }
5695 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005696 int res;
5697 Py_ssize_t len;
5698 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005699 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005700 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 +02005701 goto failed;
5702 }
5703 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005704 bases = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005705 if (bases == NULL) goto failed;
5706 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005707 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005708 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5709 Py_INCREF(tmp2);
5710 res = obj2ast_expr(tmp2, &val, arena);
5711 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005712 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005713 if (len != PyList_GET_SIZE(tmp)) {
5714 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
5715 goto failed;
5716 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005717 asdl_seq_SET(bases, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005718 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005719 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005720 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005721 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
5722 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005723 return 1;
5724 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005725 if (tmp == NULL) {
5726 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from ClassDef");
5727 return 1;
5728 }
5729 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005730 int res;
5731 Py_ssize_t len;
5732 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005733 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005734 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 +02005735 goto failed;
5736 }
5737 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005738 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005739 if (keywords == NULL) goto failed;
5740 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005741 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005742 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5743 Py_INCREF(tmp2);
5744 res = obj2ast_keyword(tmp2, &val, arena);
5745 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005746 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005747 if (len != PyList_GET_SIZE(tmp)) {
5748 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
5749 goto failed;
5750 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005751 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005752 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005753 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005754 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005755 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005756 return 1;
5757 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005758 if (tmp == NULL) {
5759 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ClassDef");
5760 return 1;
5761 }
5762 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005763 int res;
5764 Py_ssize_t len;
5765 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005766 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005767 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 +02005768 goto failed;
5769 }
5770 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005771 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005772 if (body == NULL) goto failed;
5773 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005774 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005775 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5776 Py_INCREF(tmp2);
5777 res = obj2ast_stmt(tmp2, &val, arena);
5778 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005779 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005780 if (len != PyList_GET_SIZE(tmp)) {
5781 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
5782 goto failed;
5783 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005784 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005785 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005786 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005787 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005788 if (_PyObject_LookupAttr(obj, astmodulestate_global->decorator_list,
5789 &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005790 return 1;
5791 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005792 if (tmp == NULL) {
5793 PyErr_SetString(PyExc_TypeError, "required field \"decorator_list\" missing from ClassDef");
5794 return 1;
5795 }
5796 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005797 int res;
5798 Py_ssize_t len;
5799 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005800 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005801 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 +02005802 goto failed;
5803 }
5804 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005805 decorator_list = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005806 if (decorator_list == NULL) goto failed;
5807 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005808 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005809 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5810 Py_INCREF(tmp2);
5811 res = obj2ast_expr(tmp2, &val, arena);
5812 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005813 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005814 if (len != PyList_GET_SIZE(tmp)) {
5815 PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
5816 goto failed;
5817 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005818 asdl_seq_SET(decorator_list, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005819 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005820 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005821 }
Serhiy Storchaka73cbe7a2018-05-29 12:04:55 +03005822 *out = ClassDef(name, bases, keywords, body, decorator_list, lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005823 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005824 if (*out == NULL) goto failed;
5825 return 0;
5826 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005827 tp = astmodulestate_global->Return_type;
5828 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005829 if (isinstance == -1) {
5830 return 1;
5831 }
5832 if (isinstance) {
5833 expr_ty value;
5834
Dino Viehlandac46eb42019-09-11 10:16:34 -07005835 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005836 return 1;
5837 }
5838 if (tmp == NULL || tmp == Py_None) {
5839 Py_CLEAR(tmp);
5840 value = NULL;
5841 }
5842 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005843 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005844 res = obj2ast_expr(tmp, &value, arena);
5845 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005846 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005847 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005848 *out = Return(value, lineno, col_offset, end_lineno, end_col_offset,
5849 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005850 if (*out == NULL) goto failed;
5851 return 0;
5852 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005853 tp = astmodulestate_global->Delete_type;
5854 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005855 if (isinstance == -1) {
5856 return 1;
5857 }
5858 if (isinstance) {
5859 asdl_seq* targets;
5860
Dino Viehlandac46eb42019-09-11 10:16:34 -07005861 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5862 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005863 return 1;
5864 }
5865 if (tmp == NULL) {
5866 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Delete");
5867 return 1;
5868 }
5869 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005870 int res;
5871 Py_ssize_t len;
5872 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005873 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005874 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 +02005875 goto failed;
5876 }
5877 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005878 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005879 if (targets == NULL) goto failed;
5880 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005881 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005882 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5883 Py_INCREF(tmp2);
5884 res = obj2ast_expr(tmp2, &val, arena);
5885 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005886 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005887 if (len != PyList_GET_SIZE(tmp)) {
5888 PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
5889 goto failed;
5890 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005891 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005892 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005893 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005894 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00005895 *out = Delete(targets, lineno, col_offset, end_lineno, end_col_offset,
5896 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005897 if (*out == NULL) goto failed;
5898 return 0;
5899 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005900 tp = astmodulestate_global->Assign_type;
5901 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005902 if (isinstance == -1) {
5903 return 1;
5904 }
5905 if (isinstance) {
5906 asdl_seq* targets;
5907 expr_ty value;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005908 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005909
Dino Viehlandac46eb42019-09-11 10:16:34 -07005910 if (_PyObject_LookupAttr(obj, astmodulestate_global->targets, &tmp) <
5911 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005912 return 1;
5913 }
5914 if (tmp == NULL) {
5915 PyErr_SetString(PyExc_TypeError, "required field \"targets\" missing from Assign");
5916 return 1;
5917 }
5918 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005919 int res;
5920 Py_ssize_t len;
5921 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005922 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07005923 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 +02005924 goto failed;
5925 }
5926 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02005927 targets = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005928 if (targets == NULL) goto failed;
5929 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005930 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03005931 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
5932 Py_INCREF(tmp2);
5933 res = obj2ast_expr(tmp2, &val, arena);
5934 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005935 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03005936 if (len != PyList_GET_SIZE(tmp)) {
5937 PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
5938 goto failed;
5939 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07005940 asdl_seq_SET(targets, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005941 }
Victor Stinner1acc1292013-07-27 00:03:47 +02005942 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005944 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005945 return 1;
5946 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005947 if (tmp == NULL) {
5948 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
5949 return 1;
5950 }
5951 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005952 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005953 res = obj2ast_expr(tmp, &value, arena);
5954 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005955 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005956 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005957 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
5958 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08005959 return 1;
5960 }
5961 if (tmp == NULL || tmp == Py_None) {
5962 Py_CLEAR(tmp);
5963 type_comment = NULL;
5964 }
5965 else {
5966 int res;
5967 res = obj2ast_string(tmp, &type_comment, arena);
5968 if (res != 0) goto failed;
5969 Py_CLEAR(tmp);
5970 }
5971 *out = Assign(targets, value, type_comment, lineno, col_offset,
5972 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005973 if (*out == NULL) goto failed;
5974 return 0;
5975 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07005976 tp = astmodulestate_global->AugAssign_type;
5977 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005978 if (isinstance == -1) {
5979 return 1;
5980 }
5981 if (isinstance) {
5982 expr_ty target;
5983 operator_ty op;
5984 expr_ty value;
5985
Dino Viehlandac46eb42019-09-11 10:16:34 -07005986 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
5987 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005988 return 1;
5989 }
5990 if (tmp == NULL) {
5991 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
5992 return 1;
5993 }
5994 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005995 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02005996 res = obj2ast_expr(tmp, &target, arena);
5997 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02005998 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02005999 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006000 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006001 return 1;
6002 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006003 if (tmp == NULL) {
6004 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
6005 return 1;
6006 }
6007 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006008 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006009 res = obj2ast_operator(tmp, &op, arena);
6010 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006011 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006012 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006013 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006014 return 1;
6015 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006016 if (tmp == NULL) {
6017 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
6018 return 1;
6019 }
6020 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006021 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006022 res = obj2ast_expr(tmp, &value, arena);
6023 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006024 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006025 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006026 *out = AugAssign(target, op, value, lineno, col_offset, end_lineno,
6027 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006028 if (*out == NULL) goto failed;
6029 return 0;
6030 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006031 tp = astmodulestate_global->AnnAssign_type;
6032 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006033 if (isinstance == -1) {
6034 return 1;
6035 }
6036 if (isinstance) {
6037 expr_ty target;
6038 expr_ty annotation;
6039 expr_ty value;
6040 int simple;
6041
Dino Viehlandac46eb42019-09-11 10:16:34 -07006042 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6043 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006044 return 1;
6045 }
6046 if (tmp == NULL) {
6047 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
6048 return 1;
6049 }
6050 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006051 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006052 res = obj2ast_expr(tmp, &target, arena);
6053 if (res != 0) goto failed;
6054 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006055 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006056 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp)
6057 < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006058 return 1;
6059 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006060 if (tmp == NULL) {
6061 PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
6062 return 1;
6063 }
6064 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006065 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006066 res = obj2ast_expr(tmp, &annotation, arena);
6067 if (res != 0) goto failed;
6068 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006069 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006070 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006071 return 1;
6072 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006073 if (tmp == NULL || tmp == Py_None) {
6074 Py_CLEAR(tmp);
6075 value = NULL;
6076 }
6077 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006078 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006079 res = obj2ast_expr(tmp, &value, arena);
6080 if (res != 0) goto failed;
6081 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006082 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006083 if (_PyObject_LookupAttr(obj, astmodulestate_global->simple, &tmp) < 0)
6084 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006085 return 1;
6086 }
6087 if (tmp == NULL) {
6088 PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
6089 return 1;
6090 }
6091 else {
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006092 int res;
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006093 res = obj2ast_int(tmp, &simple, arena);
6094 if (res != 0) goto failed;
6095 Py_CLEAR(tmp);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006096 }
6097 *out = AnnAssign(target, annotation, value, simple, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006098 end_lineno, end_col_offset, arena);
Yury Selivanovf8cb8a12016-09-08 20:50:03 -07006099 if (*out == NULL) goto failed;
6100 return 0;
6101 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006102 tp = astmodulestate_global->For_type;
6103 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006104 if (isinstance == -1) {
6105 return 1;
6106 }
6107 if (isinstance) {
6108 expr_ty target;
6109 expr_ty iter;
6110 asdl_seq* body;
6111 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006112 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006113
Dino Viehlandac46eb42019-09-11 10:16:34 -07006114 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6115 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006116 return 1;
6117 }
6118 if (tmp == NULL) {
6119 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
6120 return 1;
6121 }
6122 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006123 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006124 res = obj2ast_expr(tmp, &target, arena);
6125 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006126 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006127 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006128 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006129 return 1;
6130 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006131 if (tmp == NULL) {
6132 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
6133 return 1;
6134 }
6135 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006136 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006137 res = obj2ast_expr(tmp, &iter, arena);
6138 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006139 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006140 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006141 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006142 return 1;
6143 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006144 if (tmp == NULL) {
6145 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from For");
6146 return 1;
6147 }
6148 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006149 int res;
6150 Py_ssize_t len;
6151 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006152 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006153 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 +02006154 goto failed;
6155 }
6156 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006157 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006158 if (body == NULL) goto failed;
6159 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006160 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006161 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6162 Py_INCREF(tmp2);
6163 res = obj2ast_stmt(tmp2, &val, arena);
6164 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006165 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006166 if (len != PyList_GET_SIZE(tmp)) {
6167 PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
6168 goto failed;
6169 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006170 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006171 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006172 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006174 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6175 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006176 return 1;
6177 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006178 if (tmp == NULL) {
6179 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from For");
6180 return 1;
6181 }
6182 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006183 int res;
6184 Py_ssize_t len;
6185 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006186 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006187 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 +02006188 goto failed;
6189 }
6190 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006191 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006192 if (orelse == NULL) goto failed;
6193 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006194 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006195 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6196 Py_INCREF(tmp2);
6197 res = obj2ast_stmt(tmp2, &val, arena);
6198 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006199 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006200 if (len != PyList_GET_SIZE(tmp)) {
6201 PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
6202 goto failed;
6203 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006204 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006205 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006206 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006207 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006208 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6209 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006210 return 1;
6211 }
6212 if (tmp == NULL || tmp == Py_None) {
6213 Py_CLEAR(tmp);
6214 type_comment = NULL;
6215 }
6216 else {
6217 int res;
6218 res = obj2ast_string(tmp, &type_comment, arena);
6219 if (res != 0) goto failed;
6220 Py_CLEAR(tmp);
6221 }
6222 *out = For(target, iter, body, orelse, type_comment, lineno,
6223 col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006224 if (*out == NULL) goto failed;
6225 return 0;
6226 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006227 tp = astmodulestate_global->AsyncFor_type;
6228 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006229 if (isinstance == -1) {
6230 return 1;
6231 }
6232 if (isinstance) {
6233 expr_ty target;
6234 expr_ty iter;
6235 asdl_seq* body;
6236 asdl_seq* orelse;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006237 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006238
Dino Viehlandac46eb42019-09-11 10:16:34 -07006239 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
6240 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006241 return 1;
6242 }
6243 if (tmp == NULL) {
6244 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
6245 return 1;
6246 }
6247 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006248 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006249 res = obj2ast_expr(tmp, &target, arena);
6250 if (res != 0) goto failed;
6251 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006252 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006253 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006254 return 1;
6255 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006256 if (tmp == NULL) {
6257 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
6258 return 1;
6259 }
6260 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006261 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04006262 res = obj2ast_expr(tmp, &iter, arena);
6263 if (res != 0) goto failed;
6264 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006265 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006266 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006267 return 1;
6268 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006269 if (tmp == NULL) {
6270 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncFor");
6271 return 1;
6272 }
6273 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006274 int res;
6275 Py_ssize_t len;
6276 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006277 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006278 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 -04006279 goto failed;
6280 }
6281 len = PyList_GET_SIZE(tmp);
6282 body = _Py_asdl_seq_new(len, arena);
6283 if (body == NULL) goto failed;
6284 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006285 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006286 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6287 Py_INCREF(tmp2);
6288 res = obj2ast_stmt(tmp2, &val, arena);
6289 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006290 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006291 if (len != PyList_GET_SIZE(tmp)) {
6292 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
6293 goto failed;
6294 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006295 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006296 }
6297 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006298 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006299 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6300 {
Yury Selivanov75445082015-05-11 22:57:16 -04006301 return 1;
6302 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006303 if (tmp == NULL) {
6304 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from AsyncFor");
6305 return 1;
6306 }
6307 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006308 int res;
6309 Py_ssize_t len;
6310 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006311 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006312 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 -04006313 goto failed;
6314 }
6315 len = PyList_GET_SIZE(tmp);
6316 orelse = _Py_asdl_seq_new(len, arena);
6317 if (orelse == NULL) goto failed;
6318 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006319 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006320 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6321 Py_INCREF(tmp2);
6322 res = obj2ast_stmt(tmp2, &val, arena);
6323 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006324 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006325 if (len != PyList_GET_SIZE(tmp)) {
6326 PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
6327 goto failed;
6328 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006329 asdl_seq_SET(orelse, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006330 }
6331 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006332 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006333 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6334 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006335 return 1;
6336 }
6337 if (tmp == NULL || tmp == Py_None) {
6338 Py_CLEAR(tmp);
6339 type_comment = NULL;
6340 }
6341 else {
6342 int res;
6343 res = obj2ast_string(tmp, &type_comment, arena);
6344 if (res != 0) goto failed;
6345 Py_CLEAR(tmp);
6346 }
6347 *out = AsyncFor(target, iter, body, orelse, type_comment, lineno,
6348 col_offset, end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006349 if (*out == NULL) goto failed;
6350 return 0;
6351 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006352 tp = astmodulestate_global->While_type;
6353 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006354 if (isinstance == -1) {
6355 return 1;
6356 }
6357 if (isinstance) {
6358 expr_ty test;
6359 asdl_seq* body;
6360 asdl_seq* orelse;
6361
Dino Viehlandac46eb42019-09-11 10:16:34 -07006362 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006363 return 1;
6364 }
6365 if (tmp == NULL) {
6366 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
6367 return 1;
6368 }
6369 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006370 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006371 res = obj2ast_expr(tmp, &test, arena);
6372 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006373 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006374 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006375 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006376 return 1;
6377 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006378 if (tmp == NULL) {
6379 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from While");
6380 return 1;
6381 }
6382 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006383 int res;
6384 Py_ssize_t len;
6385 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006386 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006387 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 +02006388 goto failed;
6389 }
6390 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006391 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006392 if (body == NULL) goto failed;
6393 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006394 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006395 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6396 Py_INCREF(tmp2);
6397 res = obj2ast_stmt(tmp2, &val, arena);
6398 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006399 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006400 if (len != PyList_GET_SIZE(tmp)) {
6401 PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
6402 goto failed;
6403 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006404 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006405 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006406 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006407 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006408 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6409 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006410 return 1;
6411 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006412 if (tmp == NULL) {
6413 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from While");
6414 return 1;
6415 }
6416 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006417 int res;
6418 Py_ssize_t len;
6419 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006420 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006421 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 +02006422 goto failed;
6423 }
6424 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006425 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006426 if (orelse == NULL) goto failed;
6427 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006428 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006429 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6430 Py_INCREF(tmp2);
6431 res = obj2ast_stmt(tmp2, &val, arena);
6432 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006433 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006434 if (len != PyList_GET_SIZE(tmp)) {
6435 PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
6436 goto failed;
6437 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006438 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006439 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006440 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006441 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006442 *out = While(test, body, orelse, lineno, col_offset, end_lineno,
6443 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006444 if (*out == NULL) goto failed;
6445 return 0;
6446 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006447 tp = astmodulestate_global->If_type;
6448 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006449 if (isinstance == -1) {
6450 return 1;
6451 }
6452 if (isinstance) {
6453 expr_ty test;
6454 asdl_seq* body;
6455 asdl_seq* orelse;
6456
Dino Viehlandac46eb42019-09-11 10:16:34 -07006457 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006458 return 1;
6459 }
6460 if (tmp == NULL) {
6461 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
6462 return 1;
6463 }
6464 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006465 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006466 res = obj2ast_expr(tmp, &test, arena);
6467 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006468 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006469 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006470 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006471 return 1;
6472 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006473 if (tmp == NULL) {
6474 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from If");
6475 return 1;
6476 }
6477 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006478 int res;
6479 Py_ssize_t len;
6480 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006481 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006482 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 +02006483 goto failed;
6484 }
6485 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006486 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006487 if (body == NULL) goto failed;
6488 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006489 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006490 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6491 Py_INCREF(tmp2);
6492 res = obj2ast_stmt(tmp2, &val, arena);
6493 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006494 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006495 if (len != PyList_GET_SIZE(tmp)) {
6496 PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
6497 goto failed;
6498 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006499 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006500 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006501 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006502 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006503 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6504 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006505 return 1;
6506 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006507 if (tmp == NULL) {
6508 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from If");
6509 return 1;
6510 }
6511 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006512 int res;
6513 Py_ssize_t len;
6514 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006515 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006516 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 +02006517 goto failed;
6518 }
6519 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006520 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006521 if (orelse == NULL) goto failed;
6522 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006523 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006524 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6525 Py_INCREF(tmp2);
6526 res = obj2ast_stmt(tmp2, &val, arena);
6527 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006528 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006529 if (len != PyList_GET_SIZE(tmp)) {
6530 PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
6531 goto failed;
6532 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006533 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006534 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006535 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006536 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006537 *out = If(test, body, orelse, lineno, col_offset, end_lineno,
6538 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006539 if (*out == NULL) goto failed;
6540 return 0;
6541 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006542 tp = astmodulestate_global->With_type;
6543 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006544 if (isinstance == -1) {
6545 return 1;
6546 }
6547 if (isinstance) {
6548 asdl_seq* items;
6549 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006550 string type_comment;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006551
Dino Viehlandac46eb42019-09-11 10:16:34 -07006552 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006553 return 1;
6554 }
6555 if (tmp == NULL) {
6556 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from With");
6557 return 1;
6558 }
6559 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006560 int res;
6561 Py_ssize_t len;
6562 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006563 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006564 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 +02006565 goto failed;
6566 }
6567 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006568 items = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006569 if (items == NULL) goto failed;
6570 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006571 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006572 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6573 Py_INCREF(tmp2);
6574 res = obj2ast_withitem(tmp2, &val, arena);
6575 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006576 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006577 if (len != PyList_GET_SIZE(tmp)) {
6578 PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
6579 goto failed;
6580 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006581 asdl_seq_SET(items, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006582 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006583 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006584 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006585 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006586 return 1;
6587 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006588 if (tmp == NULL) {
6589 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from With");
6590 return 1;
6591 }
6592 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006593 int res;
6594 Py_ssize_t len;
6595 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006596 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006597 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 +02006598 goto failed;
6599 }
6600 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006601 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006602 if (body == NULL) goto failed;
6603 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006604 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006605 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6606 Py_INCREF(tmp2);
6607 res = obj2ast_stmt(tmp2, &val, arena);
6608 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006609 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006610 if (len != PyList_GET_SIZE(tmp)) {
6611 PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
6612 goto failed;
6613 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006614 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006615 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006616 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006617 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006618 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6619 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006620 return 1;
6621 }
6622 if (tmp == NULL || tmp == Py_None) {
6623 Py_CLEAR(tmp);
6624 type_comment = NULL;
6625 }
6626 else {
6627 int res;
6628 res = obj2ast_string(tmp, &type_comment, arena);
6629 if (res != 0) goto failed;
6630 Py_CLEAR(tmp);
6631 }
6632 *out = With(items, body, type_comment, lineno, col_offset, end_lineno,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006633 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006634 if (*out == NULL) goto failed;
6635 return 0;
6636 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006637 tp = astmodulestate_global->AsyncWith_type;
6638 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04006639 if (isinstance == -1) {
6640 return 1;
6641 }
6642 if (isinstance) {
6643 asdl_seq* items;
6644 asdl_seq* body;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006645 string type_comment;
Yury Selivanov75445082015-05-11 22:57:16 -04006646
Dino Viehlandac46eb42019-09-11 10:16:34 -07006647 if (_PyObject_LookupAttr(obj, astmodulestate_global->items, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006648 return 1;
6649 }
6650 if (tmp == NULL) {
6651 PyErr_SetString(PyExc_TypeError, "required field \"items\" missing from AsyncWith");
6652 return 1;
6653 }
6654 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006655 int res;
6656 Py_ssize_t len;
6657 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006658 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006659 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 -04006660 goto failed;
6661 }
6662 len = PyList_GET_SIZE(tmp);
6663 items = _Py_asdl_seq_new(len, arena);
6664 if (items == NULL) goto failed;
6665 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006666 withitem_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006667 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6668 Py_INCREF(tmp2);
6669 res = obj2ast_withitem(tmp2, &val, arena);
6670 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006671 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006672 if (len != PyList_GET_SIZE(tmp)) {
6673 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
6674 goto failed;
6675 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006676 asdl_seq_SET(items, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006677 }
6678 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006679 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006680 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Yury Selivanov75445082015-05-11 22:57:16 -04006681 return 1;
6682 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006683 if (tmp == NULL) {
6684 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from AsyncWith");
6685 return 1;
6686 }
6687 else {
Yury Selivanov75445082015-05-11 22:57:16 -04006688 int res;
6689 Py_ssize_t len;
6690 Py_ssize_t i;
Yury Selivanov75445082015-05-11 22:57:16 -04006691 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006692 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 -04006693 goto failed;
6694 }
6695 len = PyList_GET_SIZE(tmp);
6696 body = _Py_asdl_seq_new(len, arena);
6697 if (body == NULL) goto failed;
6698 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006699 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006700 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6701 Py_INCREF(tmp2);
6702 res = obj2ast_stmt(tmp2, &val, arena);
6703 Py_DECREF(tmp2);
Yury Selivanov75445082015-05-11 22:57:16 -04006704 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006705 if (len != PyList_GET_SIZE(tmp)) {
6706 PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
6707 goto failed;
6708 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006709 asdl_seq_SET(body, i, val);
Yury Selivanov75445082015-05-11 22:57:16 -04006710 }
6711 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04006712 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006713 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment,
6714 &tmp) < 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08006715 return 1;
6716 }
6717 if (tmp == NULL || tmp == Py_None) {
6718 Py_CLEAR(tmp);
6719 type_comment = NULL;
6720 }
6721 else {
6722 int res;
6723 res = obj2ast_string(tmp, &type_comment, arena);
6724 if (res != 0) goto failed;
6725 Py_CLEAR(tmp);
6726 }
6727 *out = AsyncWith(items, body, type_comment, lineno, col_offset,
6728 end_lineno, end_col_offset, arena);
Yury Selivanov75445082015-05-11 22:57:16 -04006729 if (*out == NULL) goto failed;
6730 return 0;
6731 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006732 tp = astmodulestate_global->Raise_type;
6733 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006734 if (isinstance == -1) {
6735 return 1;
6736 }
6737 if (isinstance) {
6738 expr_ty exc;
6739 expr_ty cause;
6740
Dino Viehlandac46eb42019-09-11 10:16:34 -07006741 if (_PyObject_LookupAttr(obj, astmodulestate_global->exc, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006742 return 1;
6743 }
6744 if (tmp == NULL || tmp == Py_None) {
6745 Py_CLEAR(tmp);
6746 exc = NULL;
6747 }
6748 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006749 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006750 res = obj2ast_expr(tmp, &exc, arena);
6751 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006752 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006753 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006754 if (_PyObject_LookupAttr(obj, astmodulestate_global->cause, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006755 return 1;
6756 }
6757 if (tmp == NULL || tmp == Py_None) {
6758 Py_CLEAR(tmp);
6759 cause = NULL;
6760 }
6761 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006762 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006763 res = obj2ast_expr(tmp, &cause, arena);
6764 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006765 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006766 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006767 *out = Raise(exc, cause, lineno, col_offset, end_lineno,
6768 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006769 if (*out == NULL) goto failed;
6770 return 0;
6771 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006772 tp = astmodulestate_global->Try_type;
6773 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006774 if (isinstance == -1) {
6775 return 1;
6776 }
6777 if (isinstance) {
6778 asdl_seq* body;
6779 asdl_seq* handlers;
6780 asdl_seq* orelse;
6781 asdl_seq* finalbody;
6782
Dino Viehlandac46eb42019-09-11 10:16:34 -07006783 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006784 return 1;
6785 }
6786 if (tmp == NULL) {
6787 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Try");
6788 return 1;
6789 }
6790 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006791 int res;
6792 Py_ssize_t len;
6793 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006794 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006795 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 +02006796 goto failed;
6797 }
6798 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006799 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006800 if (body == NULL) goto failed;
6801 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006802 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006803 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6804 Py_INCREF(tmp2);
6805 res = obj2ast_stmt(tmp2, &val, arena);
6806 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006807 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006808 if (len != PyList_GET_SIZE(tmp)) {
6809 PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
6810 goto failed;
6811 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006812 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006813 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006814 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006815 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006816 if (_PyObject_LookupAttr(obj, astmodulestate_global->handlers, &tmp) <
6817 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006818 return 1;
6819 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006820 if (tmp == NULL) {
6821 PyErr_SetString(PyExc_TypeError, "required field \"handlers\" missing from Try");
6822 return 1;
6823 }
6824 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006825 int res;
6826 Py_ssize_t len;
6827 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006828 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006829 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 +02006830 goto failed;
6831 }
6832 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006833 handlers = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006834 if (handlers == NULL) goto failed;
6835 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006836 excepthandler_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006837 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6838 Py_INCREF(tmp2);
6839 res = obj2ast_excepthandler(tmp2, &val, arena);
6840 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006841 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006842 if (len != PyList_GET_SIZE(tmp)) {
6843 PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
6844 goto failed;
6845 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006846 asdl_seq_SET(handlers, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006847 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006848 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006849 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006850 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
6851 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006852 return 1;
6853 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006854 if (tmp == NULL) {
6855 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from Try");
6856 return 1;
6857 }
6858 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006859 int res;
6860 Py_ssize_t len;
6861 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006862 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006863 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 +02006864 goto failed;
6865 }
6866 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006867 orelse = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006868 if (orelse == NULL) goto failed;
6869 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006870 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006871 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6872 Py_INCREF(tmp2);
6873 res = obj2ast_stmt(tmp2, &val, arena);
6874 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006875 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006876 if (len != PyList_GET_SIZE(tmp)) {
6877 PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
6878 goto failed;
6879 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006880 asdl_seq_SET(orelse, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006881 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006882 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006883 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006884 if (_PyObject_LookupAttr(obj, astmodulestate_global->finalbody, &tmp) <
6885 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006886 return 1;
6887 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006888 if (tmp == NULL) {
6889 PyErr_SetString(PyExc_TypeError, "required field \"finalbody\" missing from Try");
6890 return 1;
6891 }
6892 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006893 int res;
6894 Py_ssize_t len;
6895 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006896 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006897 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 +02006898 goto failed;
6899 }
6900 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006901 finalbody = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006902 if (finalbody == NULL) goto failed;
6903 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006904 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006905 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6906 Py_INCREF(tmp2);
6907 res = obj2ast_stmt(tmp2, &val, arena);
6908 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006909 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006910 if (len != PyList_GET_SIZE(tmp)) {
6911 PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
6912 goto failed;
6913 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006914 asdl_seq_SET(finalbody, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006915 }
Victor Stinner1acc1292013-07-27 00:03:47 +02006916 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006917 }
6918 *out = Try(body, handlers, orelse, finalbody, lineno, col_offset,
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006919 end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006920 if (*out == NULL) goto failed;
6921 return 0;
6922 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006923 tp = astmodulestate_global->Assert_type;
6924 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006925 if (isinstance == -1) {
6926 return 1;
6927 }
6928 if (isinstance) {
6929 expr_ty test;
6930 expr_ty msg;
6931
Dino Viehlandac46eb42019-09-11 10:16:34 -07006932 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006933 return 1;
6934 }
6935 if (tmp == NULL) {
6936 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
6937 return 1;
6938 }
6939 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006940 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006941 res = obj2ast_expr(tmp, &test, arena);
6942 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006943 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006944 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006945 if (_PyObject_LookupAttr(obj, astmodulestate_global->msg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006946 return 1;
6947 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006948 if (tmp == NULL || tmp == Py_None) {
6949 Py_CLEAR(tmp);
6950 msg = NULL;
6951 }
6952 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006953 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006954 res = obj2ast_expr(tmp, &msg, arena);
6955 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02006956 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006957 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00006958 *out = Assert(test, msg, lineno, col_offset, end_lineno,
6959 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006960 if (*out == NULL) goto failed;
6961 return 0;
6962 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07006963 tp = astmodulestate_global->Import_type;
6964 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006965 if (isinstance == -1) {
6966 return 1;
6967 }
6968 if (isinstance) {
6969 asdl_seq* names;
6970
Dino Viehlandac46eb42019-09-11 10:16:34 -07006971 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02006972 return 1;
6973 }
6974 if (tmp == NULL) {
6975 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Import");
6976 return 1;
6977 }
6978 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006979 int res;
6980 Py_ssize_t len;
6981 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006982 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07006983 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 +02006984 goto failed;
6985 }
6986 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02006987 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006988 if (names == NULL) goto failed;
6989 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07006990 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03006991 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
6992 Py_INCREF(tmp2);
6993 res = obj2ast_alias(tmp2, &val, arena);
6994 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02006995 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03006996 if (len != PyList_GET_SIZE(tmp)) {
6997 PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
6998 goto failed;
6999 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007000 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007001 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007002 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007003 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007004 *out = Import(names, lineno, col_offset, end_lineno, end_col_offset,
7005 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007006 if (*out == NULL) goto failed;
7007 return 0;
7008 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007009 tp = astmodulestate_global->ImportFrom_type;
7010 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007011 if (isinstance == -1) {
7012 return 1;
7013 }
7014 if (isinstance) {
7015 identifier module;
7016 asdl_seq* names;
7017 int level;
7018
Dino Viehlandac46eb42019-09-11 10:16:34 -07007019 if (_PyObject_LookupAttr(obj, astmodulestate_global->module, &tmp) < 0)
7020 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007021 return 1;
7022 }
7023 if (tmp == NULL || tmp == Py_None) {
7024 Py_CLEAR(tmp);
7025 module = NULL;
7026 }
7027 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007028 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007029 res = obj2ast_identifier(tmp, &module, arena);
7030 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007031 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007032 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007033 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007034 return 1;
7035 }
7036 if (tmp == NULL) {
7037 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from ImportFrom");
7038 return 1;
7039 }
7040 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007041 int res;
7042 Py_ssize_t len;
7043 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007044 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007045 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 +02007046 goto failed;
7047 }
7048 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007049 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007050 if (names == NULL) goto failed;
7051 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007052 alias_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007053 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7054 Py_INCREF(tmp2);
7055 res = obj2ast_alias(tmp2, &val, arena);
7056 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007057 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007058 if (len != PyList_GET_SIZE(tmp)) {
7059 PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
7060 goto failed;
7061 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007062 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007063 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007064 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007065 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007066 if (_PyObject_LookupAttr(obj, astmodulestate_global->level, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007067 return 1;
7068 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007069 if (tmp == NULL || tmp == Py_None) {
7070 Py_CLEAR(tmp);
7071 level = 0;
7072 }
7073 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007074 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007075 res = obj2ast_int(tmp, &level, arena);
7076 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007077 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007078 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007079 *out = ImportFrom(module, names, level, lineno, col_offset, end_lineno,
7080 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007081 if (*out == NULL) goto failed;
7082 return 0;
7083 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007084 tp = astmodulestate_global->Global_type;
7085 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007086 if (isinstance == -1) {
7087 return 1;
7088 }
7089 if (isinstance) {
7090 asdl_seq* names;
7091
Dino Viehlandac46eb42019-09-11 10:16:34 -07007092 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007093 return 1;
7094 }
7095 if (tmp == NULL) {
7096 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Global");
7097 return 1;
7098 }
7099 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007100 int res;
7101 Py_ssize_t len;
7102 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007103 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007104 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 +02007105 goto failed;
7106 }
7107 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007108 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007109 if (names == NULL) goto failed;
7110 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007111 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007112 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7113 Py_INCREF(tmp2);
7114 res = obj2ast_identifier(tmp2, &val, arena);
7115 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007116 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007117 if (len != PyList_GET_SIZE(tmp)) {
7118 PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
7119 goto failed;
7120 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007121 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007122 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007123 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007124 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007125 *out = Global(names, lineno, col_offset, end_lineno, end_col_offset,
7126 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007127 if (*out == NULL) goto failed;
7128 return 0;
7129 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007130 tp = astmodulestate_global->Nonlocal_type;
7131 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007132 if (isinstance == -1) {
7133 return 1;
7134 }
7135 if (isinstance) {
7136 asdl_seq* names;
7137
Dino Viehlandac46eb42019-09-11 10:16:34 -07007138 if (_PyObject_LookupAttr(obj, astmodulestate_global->names, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007139 return 1;
7140 }
7141 if (tmp == NULL) {
7142 PyErr_SetString(PyExc_TypeError, "required field \"names\" missing from Nonlocal");
7143 return 1;
7144 }
7145 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007146 int res;
7147 Py_ssize_t len;
7148 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007149 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007150 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 +02007151 goto failed;
7152 }
7153 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007154 names = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007155 if (names == NULL) goto failed;
7156 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007157 identifier val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007158 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7159 Py_INCREF(tmp2);
7160 res = obj2ast_identifier(tmp2, &val, arena);
7161 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007162 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007163 if (len != PyList_GET_SIZE(tmp)) {
7164 PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
7165 goto failed;
7166 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007167 asdl_seq_SET(names, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007168 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007169 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007170 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007171 *out = Nonlocal(names, lineno, col_offset, end_lineno, end_col_offset,
7172 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007173 if (*out == NULL) goto failed;
7174 return 0;
7175 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007176 tp = astmodulestate_global->Expr_type;
7177 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007178 if (isinstance == -1) {
7179 return 1;
7180 }
7181 if (isinstance) {
7182 expr_ty value;
7183
Dino Viehlandac46eb42019-09-11 10:16:34 -07007184 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007185 return 1;
7186 }
7187 if (tmp == NULL) {
7188 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
7189 return 1;
7190 }
7191 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007192 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007193 res = obj2ast_expr(tmp, &value, arena);
7194 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007195 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007196 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007197 *out = Expr(value, lineno, col_offset, end_lineno, end_col_offset,
7198 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007199 if (*out == NULL) goto failed;
7200 return 0;
7201 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007202 tp = astmodulestate_global->Pass_type;
7203 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007204 if (isinstance == -1) {
7205 return 1;
7206 }
7207 if (isinstance) {
7208
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007209 *out = Pass(lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007210 if (*out == NULL) goto failed;
7211 return 0;
7212 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007213 tp = astmodulestate_global->Break_type;
7214 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007215 if (isinstance == -1) {
7216 return 1;
7217 }
7218 if (isinstance) {
7219
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007220 *out = Break(lineno, col_offset, end_lineno, end_col_offset, 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->Continue_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 = Continue(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 }
7235
7236 PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
7237 failed:
7238 Py_XDECREF(tmp);
7239 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007240}
7241
7242int
7243obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
7244{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007245 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007246
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007247 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07007248 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007249 int lineno;
7250 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007251 int end_lineno;
7252 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007253
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007254 if (obj == Py_None) {
7255 *out = NULL;
7256 return 0;
7257 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007258 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007259 return 1;
7260 }
7261 if (tmp == NULL) {
7262 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
7263 return 1;
7264 }
7265 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007266 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007267 res = obj2ast_int(tmp, &lineno, arena);
7268 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007269 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007270 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007271 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
7272 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00007273 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007274 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007275 if (tmp == NULL) {
7276 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
7277 return 1;
7278 }
7279 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007280 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007281 res = obj2ast_int(tmp, &col_offset, arena);
7282 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007283 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007284 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007285 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
7286 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007287 return 1;
7288 }
7289 if (tmp == NULL || tmp == Py_None) {
7290 Py_CLEAR(tmp);
7291 end_lineno = 0;
7292 }
7293 else {
7294 int res;
7295 res = obj2ast_int(tmp, &end_lineno, arena);
7296 if (res != 0) goto failed;
7297 Py_CLEAR(tmp);
7298 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007299 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
7300 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007301 return 1;
7302 }
7303 if (tmp == NULL || tmp == Py_None) {
7304 Py_CLEAR(tmp);
7305 end_col_offset = 0;
7306 }
7307 else {
7308 int res;
7309 res = obj2ast_int(tmp, &end_col_offset, arena);
7310 if (res != 0) goto failed;
7311 Py_CLEAR(tmp);
7312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007313 tp = astmodulestate_global->BoolOp_type;
7314 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007315 if (isinstance == -1) {
7316 return 1;
7317 }
7318 if (isinstance) {
7319 boolop_ty op;
7320 asdl_seq* values;
7321
Dino Viehlandac46eb42019-09-11 10:16:34 -07007322 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007323 return 1;
7324 }
7325 if (tmp == NULL) {
7326 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
7327 return 1;
7328 }
7329 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007330 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007331 res = obj2ast_boolop(tmp, &op, arena);
7332 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007333 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007334 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007335 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7336 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007337 return 1;
7338 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007339 if (tmp == NULL) {
7340 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from BoolOp");
7341 return 1;
7342 }
7343 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007344 int res;
7345 Py_ssize_t len;
7346 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007347 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007348 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 +02007349 goto failed;
7350 }
7351 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007352 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007353 if (values == NULL) goto failed;
7354 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007355 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007356 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7357 Py_INCREF(tmp2);
7358 res = obj2ast_expr(tmp2, &val, arena);
7359 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007360 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007361 if (len != PyList_GET_SIZE(tmp)) {
7362 PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
7363 goto failed;
7364 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007365 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007366 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007367 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007368 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007369 *out = BoolOp(op, values, lineno, col_offset, end_lineno,
7370 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007371 if (*out == NULL) goto failed;
7372 return 0;
7373 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007374 tp = astmodulestate_global->NamedExpr_type;
7375 isinstance = PyObject_IsInstance(obj, tp);
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007376 if (isinstance == -1) {
7377 return 1;
7378 }
7379 if (isinstance) {
7380 expr_ty target;
7381 expr_ty value;
7382
Dino Viehlandac46eb42019-09-11 10:16:34 -07007383 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0)
7384 {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007385 return 1;
7386 }
7387 if (tmp == NULL) {
7388 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
7389 return 1;
7390 }
7391 else {
7392 int res;
7393 res = obj2ast_expr(tmp, &target, arena);
7394 if (res != 0) goto failed;
7395 Py_CLEAR(tmp);
7396 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007397 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Emily Morehouse8f59ee02019-01-24 16:49:56 -07007398 return 1;
7399 }
7400 if (tmp == NULL) {
7401 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
7402 return 1;
7403 }
7404 else {
7405 int res;
7406 res = obj2ast_expr(tmp, &value, arena);
7407 if (res != 0) goto failed;
7408 Py_CLEAR(tmp);
7409 }
7410 *out = NamedExpr(target, value, lineno, col_offset, end_lineno,
7411 end_col_offset, arena);
7412 if (*out == NULL) goto failed;
7413 return 0;
7414 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007415 tp = astmodulestate_global->BinOp_type;
7416 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007417 if (isinstance == -1) {
7418 return 1;
7419 }
7420 if (isinstance) {
7421 expr_ty left;
7422 operator_ty op;
7423 expr_ty right;
7424
Dino Viehlandac46eb42019-09-11 10:16:34 -07007425 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007426 return 1;
7427 }
7428 if (tmp == NULL) {
7429 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
7430 return 1;
7431 }
7432 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007433 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007434 res = obj2ast_expr(tmp, &left, arena);
7435 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007436 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007437 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007438 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007439 return 1;
7440 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007441 if (tmp == NULL) {
7442 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
7443 return 1;
7444 }
7445 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007446 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007447 res = obj2ast_operator(tmp, &op, arena);
7448 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007449 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007450 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007451 if (_PyObject_LookupAttr(obj, astmodulestate_global->right, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007452 return 1;
7453 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007454 if (tmp == NULL) {
7455 PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
7456 return 1;
7457 }
7458 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007459 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007460 res = obj2ast_expr(tmp, &right, arena);
7461 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007462 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007463 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007464 *out = BinOp(left, op, right, lineno, col_offset, end_lineno,
7465 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007466 if (*out == NULL) goto failed;
7467 return 0;
7468 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007469 tp = astmodulestate_global->UnaryOp_type;
7470 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007471 if (isinstance == -1) {
7472 return 1;
7473 }
7474 if (isinstance) {
7475 unaryop_ty op;
7476 expr_ty operand;
7477
Dino Viehlandac46eb42019-09-11 10:16:34 -07007478 if (_PyObject_LookupAttr(obj, astmodulestate_global->op, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007479 return 1;
7480 }
7481 if (tmp == NULL) {
7482 PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
7483 return 1;
7484 }
7485 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007486 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007487 res = obj2ast_unaryop(tmp, &op, arena);
7488 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007489 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007490 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007491 if (_PyObject_LookupAttr(obj, astmodulestate_global->operand, &tmp) <
7492 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007493 return 1;
7494 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007495 if (tmp == NULL) {
7496 PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
7497 return 1;
7498 }
7499 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007500 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007501 res = obj2ast_expr(tmp, &operand, arena);
7502 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007503 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007504 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007505 *out = UnaryOp(op, operand, lineno, col_offset, end_lineno,
7506 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007507 if (*out == NULL) goto failed;
7508 return 0;
7509 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007510 tp = astmodulestate_global->Lambda_type;
7511 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007512 if (isinstance == -1) {
7513 return 1;
7514 }
7515 if (isinstance) {
7516 arguments_ty args;
7517 expr_ty body;
7518
Dino Viehlandac46eb42019-09-11 10:16:34 -07007519 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007520 return 1;
7521 }
7522 if (tmp == NULL) {
7523 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
7524 return 1;
7525 }
7526 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007527 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007528 res = obj2ast_arguments(tmp, &args, arena);
7529 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007530 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007531 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007532 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007533 return 1;
7534 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007535 if (tmp == NULL) {
7536 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
7537 return 1;
7538 }
7539 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007540 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007541 res = obj2ast_expr(tmp, &body, arena);
7542 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007543 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007544 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007545 *out = Lambda(args, body, lineno, col_offset, end_lineno,
7546 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007547 if (*out == NULL) goto failed;
7548 return 0;
7549 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007550 tp = astmodulestate_global->IfExp_type;
7551 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007552 if (isinstance == -1) {
7553 return 1;
7554 }
7555 if (isinstance) {
7556 expr_ty test;
7557 expr_ty body;
7558 expr_ty orelse;
7559
Dino Viehlandac46eb42019-09-11 10:16:34 -07007560 if (_PyObject_LookupAttr(obj, astmodulestate_global->test, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007561 return 1;
7562 }
7563 if (tmp == NULL) {
7564 PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
7565 return 1;
7566 }
7567 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007568 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007569 res = obj2ast_expr(tmp, &test, arena);
7570 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007571 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007572 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007573 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007574 return 1;
7575 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007576 if (tmp == NULL) {
7577 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
7578 return 1;
7579 }
7580 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007581 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007582 res = obj2ast_expr(tmp, &body, arena);
7583 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007584 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007585 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007586 if (_PyObject_LookupAttr(obj, astmodulestate_global->orelse, &tmp) < 0)
7587 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007588 return 1;
7589 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007590 if (tmp == NULL) {
7591 PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
7592 return 1;
7593 }
7594 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007595 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007596 res = obj2ast_expr(tmp, &orelse, arena);
7597 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007598 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007599 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007600 *out = IfExp(test, body, orelse, lineno, col_offset, end_lineno,
7601 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007602 if (*out == NULL) goto failed;
7603 return 0;
7604 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007605 tp = astmodulestate_global->Dict_type;
7606 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007607 if (isinstance == -1) {
7608 return 1;
7609 }
7610 if (isinstance) {
7611 asdl_seq* keys;
7612 asdl_seq* values;
7613
Dino Viehlandac46eb42019-09-11 10:16:34 -07007614 if (_PyObject_LookupAttr(obj, astmodulestate_global->keys, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007615 return 1;
7616 }
7617 if (tmp == NULL) {
7618 PyErr_SetString(PyExc_TypeError, "required field \"keys\" missing from Dict");
7619 return 1;
7620 }
7621 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007622 int res;
7623 Py_ssize_t len;
7624 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007625 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007626 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 +02007627 goto failed;
7628 }
7629 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007630 keys = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007631 if (keys == NULL) goto failed;
7632 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007633 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007634 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7635 Py_INCREF(tmp2);
7636 res = obj2ast_expr(tmp2, &val, arena);
7637 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007638 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007639 if (len != PyList_GET_SIZE(tmp)) {
7640 PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
7641 goto failed;
7642 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007643 asdl_seq_SET(keys, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007644 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007645 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007646 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007647 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
7648 {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007649 return 1;
7650 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007651 if (tmp == NULL) {
7652 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from Dict");
7653 return 1;
7654 }
7655 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007656 int res;
7657 Py_ssize_t len;
7658 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007659 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007660 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 +02007661 goto failed;
7662 }
7663 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007664 values = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007665 if (values == NULL) goto failed;
7666 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007667 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007668 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7669 Py_INCREF(tmp2);
7670 res = obj2ast_expr(tmp2, &val, arena);
7671 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007672 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007673 if (len != PyList_GET_SIZE(tmp)) {
7674 PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
7675 goto failed;
7676 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007677 asdl_seq_SET(values, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007678 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007679 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007680 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007681 *out = Dict(keys, values, lineno, col_offset, end_lineno,
7682 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007683 if (*out == NULL) goto failed;
7684 return 0;
7685 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007686 tp = astmodulestate_global->Set_type;
7687 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007688 if (isinstance == -1) {
7689 return 1;
7690 }
7691 if (isinstance) {
7692 asdl_seq* elts;
7693
Dino Viehlandac46eb42019-09-11 10:16:34 -07007694 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007695 return 1;
7696 }
7697 if (tmp == NULL) {
7698 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Set");
7699 return 1;
7700 }
7701 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007702 int res;
7703 Py_ssize_t len;
7704 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007705 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007706 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 +02007707 goto failed;
7708 }
7709 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007710 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007711 if (elts == NULL) goto failed;
7712 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007713 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007714 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7715 Py_INCREF(tmp2);
7716 res = obj2ast_expr(tmp2, &val, arena);
7717 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007718 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007719 if (len != PyList_GET_SIZE(tmp)) {
7720 PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
7721 goto failed;
7722 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007723 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007724 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007725 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007726 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007727 *out = Set(elts, lineno, col_offset, end_lineno, end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007728 if (*out == NULL) goto failed;
7729 return 0;
7730 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007731 tp = astmodulestate_global->ListComp_type;
7732 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007733 if (isinstance == -1) {
7734 return 1;
7735 }
7736 if (isinstance) {
7737 expr_ty elt;
7738 asdl_seq* generators;
7739
Dino Viehlandac46eb42019-09-11 10:16:34 -07007740 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007741 return 1;
7742 }
7743 if (tmp == NULL) {
7744 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
7745 return 1;
7746 }
7747 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007748 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007749 res = obj2ast_expr(tmp, &elt, arena);
7750 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007751 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007752 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007753 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7754 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007755 return 1;
7756 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007757 if (tmp == NULL) {
7758 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from ListComp");
7759 return 1;
7760 }
7761 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007762 int res;
7763 Py_ssize_t len;
7764 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007765 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007766 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 +02007767 goto failed;
7768 }
7769 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007770 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007771 if (generators == NULL) goto failed;
7772 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007773 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007774 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7775 Py_INCREF(tmp2);
7776 res = obj2ast_comprehension(tmp2, &val, arena);
7777 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007778 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007779 if (len != PyList_GET_SIZE(tmp)) {
7780 PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
7781 goto failed;
7782 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007783 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007784 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007785 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007786 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007787 *out = ListComp(elt, generators, lineno, col_offset, end_lineno,
7788 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007789 if (*out == NULL) goto failed;
7790 return 0;
7791 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007792 tp = astmodulestate_global->SetComp_type;
7793 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007794 if (isinstance == -1) {
7795 return 1;
7796 }
7797 if (isinstance) {
7798 expr_ty elt;
7799 asdl_seq* generators;
7800
Dino Viehlandac46eb42019-09-11 10:16:34 -07007801 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007802 return 1;
7803 }
7804 if (tmp == NULL) {
7805 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
7806 return 1;
7807 }
7808 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007809 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007810 res = obj2ast_expr(tmp, &elt, arena);
7811 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007812 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007813 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007814 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7815 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007816 return 1;
7817 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007818 if (tmp == NULL) {
7819 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from SetComp");
7820 return 1;
7821 }
7822 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007823 int res;
7824 Py_ssize_t len;
7825 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007826 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007827 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 +02007828 goto failed;
7829 }
7830 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007831 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007832 if (generators == NULL) goto failed;
7833 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007834 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007835 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7836 Py_INCREF(tmp2);
7837 res = obj2ast_comprehension(tmp2, &val, arena);
7838 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007839 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007840 if (len != PyList_GET_SIZE(tmp)) {
7841 PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
7842 goto failed;
7843 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007844 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007845 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007846 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007847 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007848 *out = SetComp(elt, generators, lineno, col_offset, end_lineno,
7849 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007850 if (*out == NULL) goto failed;
7851 return 0;
7852 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007853 tp = astmodulestate_global->DictComp_type;
7854 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007855 if (isinstance == -1) {
7856 return 1;
7857 }
7858 if (isinstance) {
7859 expr_ty key;
7860 expr_ty value;
7861 asdl_seq* generators;
7862
Dino Viehlandac46eb42019-09-11 10:16:34 -07007863 if (_PyObject_LookupAttr(obj, astmodulestate_global->key, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007864 return 1;
7865 }
7866 if (tmp == NULL) {
7867 PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
7868 return 1;
7869 }
7870 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007871 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007872 res = obj2ast_expr(tmp, &key, arena);
7873 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007874 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007875 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007876 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007877 return 1;
7878 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007879 if (tmp == NULL) {
7880 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
7881 return 1;
7882 }
7883 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007884 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007885 res = obj2ast_expr(tmp, &value, arena);
7886 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007887 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007888 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007889 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7890 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007891 return 1;
7892 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007893 if (tmp == NULL) {
7894 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from DictComp");
7895 return 1;
7896 }
7897 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007898 int res;
7899 Py_ssize_t len;
7900 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007901 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007902 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 +02007903 goto failed;
7904 }
7905 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007906 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007907 if (generators == NULL) goto failed;
7908 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007909 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007910 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7911 Py_INCREF(tmp2);
7912 res = obj2ast_comprehension(tmp2, &val, arena);
7913 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007914 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007915 if (len != PyList_GET_SIZE(tmp)) {
7916 PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
7917 goto failed;
7918 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007919 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007920 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007921 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007922 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007923 *out = DictComp(key, value, generators, lineno, col_offset, end_lineno,
7924 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007925 if (*out == NULL) goto failed;
7926 return 0;
7927 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007928 tp = astmodulestate_global->GeneratorExp_type;
7929 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007930 if (isinstance == -1) {
7931 return 1;
7932 }
7933 if (isinstance) {
7934 expr_ty elt;
7935 asdl_seq* generators;
7936
Dino Viehlandac46eb42019-09-11 10:16:34 -07007937 if (_PyObject_LookupAttr(obj, astmodulestate_global->elt, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007938 return 1;
7939 }
7940 if (tmp == NULL) {
7941 PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
7942 return 1;
7943 }
7944 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007945 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007946 res = obj2ast_expr(tmp, &elt, arena);
7947 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02007948 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007949 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007950 if (_PyObject_LookupAttr(obj, astmodulestate_global->generators, &tmp)
7951 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007952 return 1;
7953 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007954 if (tmp == NULL) {
7955 PyErr_SetString(PyExc_TypeError, "required field \"generators\" missing from GeneratorExp");
7956 return 1;
7957 }
7958 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007959 int res;
7960 Py_ssize_t len;
7961 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007962 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07007963 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 +02007964 goto failed;
7965 }
7966 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02007967 generators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007968 if (generators == NULL) goto failed;
7969 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007970 comprehension_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03007971 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
7972 Py_INCREF(tmp2);
7973 res = obj2ast_comprehension(tmp2, &val, arena);
7974 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007975 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03007976 if (len != PyList_GET_SIZE(tmp)) {
7977 PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
7978 goto failed;
7979 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07007980 asdl_seq_SET(generators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007981 }
Victor Stinner1acc1292013-07-27 00:03:47 +02007982 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007983 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00007984 *out = GeneratorExp(elt, generators, lineno, col_offset, end_lineno,
7985 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02007986 if (*out == NULL) goto failed;
7987 return 0;
7988 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07007989 tp = astmodulestate_global->Await_type;
7990 isinstance = PyObject_IsInstance(obj, tp);
Yury Selivanov75445082015-05-11 22:57:16 -04007991 if (isinstance == -1) {
7992 return 1;
7993 }
7994 if (isinstance) {
7995 expr_ty value;
7996
Dino Viehlandac46eb42019-09-11 10:16:34 -07007997 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02007998 return 1;
7999 }
8000 if (tmp == NULL) {
8001 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
8002 return 1;
8003 }
8004 else {
Yury Selivanov75445082015-05-11 22:57:16 -04008005 int res;
Yury Selivanov75445082015-05-11 22:57:16 -04008006 res = obj2ast_expr(tmp, &value, arena);
8007 if (res != 0) goto failed;
8008 Py_CLEAR(tmp);
Yury Selivanov75445082015-05-11 22:57:16 -04008009 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008010 *out = Await(value, lineno, col_offset, end_lineno, end_col_offset,
8011 arena);
Yury Selivanov75445082015-05-11 22:57:16 -04008012 if (*out == NULL) goto failed;
8013 return 0;
8014 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008015 tp = astmodulestate_global->Yield_type;
8016 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008017 if (isinstance == -1) {
8018 return 1;
8019 }
8020 if (isinstance) {
8021 expr_ty value;
8022
Dino Viehlandac46eb42019-09-11 10:16:34 -07008023 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008024 return 1;
8025 }
8026 if (tmp == NULL || tmp == Py_None) {
8027 Py_CLEAR(tmp);
8028 value = NULL;
8029 }
8030 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008031 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008032 res = obj2ast_expr(tmp, &value, arena);
8033 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008034 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008035 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008036 *out = Yield(value, lineno, col_offset, end_lineno, end_col_offset,
8037 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008038 if (*out == NULL) goto failed;
8039 return 0;
8040 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008041 tp = astmodulestate_global->YieldFrom_type;
8042 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008043 if (isinstance == -1) {
8044 return 1;
8045 }
8046 if (isinstance) {
8047 expr_ty value;
8048
Dino Viehlandac46eb42019-09-11 10:16:34 -07008049 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008050 return 1;
8051 }
8052 if (tmp == NULL) {
8053 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
8054 return 1;
8055 }
8056 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008057 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008058 res = obj2ast_expr(tmp, &value, arena);
8059 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008060 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008061 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008062 *out = YieldFrom(value, lineno, col_offset, end_lineno, end_col_offset,
8063 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008064 if (*out == NULL) goto failed;
8065 return 0;
8066 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008067 tp = astmodulestate_global->Compare_type;
8068 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008069 if (isinstance == -1) {
8070 return 1;
8071 }
8072 if (isinstance) {
8073 expr_ty left;
8074 asdl_int_seq* ops;
8075 asdl_seq* comparators;
8076
Dino Viehlandac46eb42019-09-11 10:16:34 -07008077 if (_PyObject_LookupAttr(obj, astmodulestate_global->left, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008078 return 1;
8079 }
8080 if (tmp == NULL) {
8081 PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
8082 return 1;
8083 }
8084 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008085 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008086 res = obj2ast_expr(tmp, &left, arena);
8087 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008088 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008090 if (_PyObject_LookupAttr(obj, astmodulestate_global->ops, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008091 return 1;
8092 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008093 if (tmp == NULL) {
8094 PyErr_SetString(PyExc_TypeError, "required field \"ops\" missing from Compare");
8095 return 1;
8096 }
8097 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008098 int res;
8099 Py_ssize_t len;
8100 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008101 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008102 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 +02008103 goto failed;
8104 }
8105 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008106 ops = _Py_asdl_int_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008107 if (ops == NULL) goto failed;
8108 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008109 cmpop_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008110 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8111 Py_INCREF(tmp2);
8112 res = obj2ast_cmpop(tmp2, &val, arena);
8113 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008114 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008115 if (len != PyList_GET_SIZE(tmp)) {
8116 PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
8117 goto failed;
8118 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008119 asdl_seq_SET(ops, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008120 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008121 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008122 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008123 if (_PyObject_LookupAttr(obj, astmodulestate_global->comparators, &tmp)
8124 < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008125 return 1;
8126 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008127 if (tmp == NULL) {
8128 PyErr_SetString(PyExc_TypeError, "required field \"comparators\" missing from Compare");
8129 return 1;
8130 }
8131 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008132 int res;
8133 Py_ssize_t len;
8134 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008135 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008136 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 +02008137 goto failed;
8138 }
8139 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008140 comparators = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008141 if (comparators == NULL) goto failed;
8142 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008143 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008144 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8145 Py_INCREF(tmp2);
8146 res = obj2ast_expr(tmp2, &val, arena);
8147 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008148 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008149 if (len != PyList_GET_SIZE(tmp)) {
8150 PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
8151 goto failed;
8152 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008153 asdl_seq_SET(comparators, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008154 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008155 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008156 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008157 *out = Compare(left, ops, comparators, lineno, col_offset, end_lineno,
8158 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008159 if (*out == NULL) goto failed;
8160 return 0;
8161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008162 tp = astmodulestate_global->Call_type;
8163 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008164 if (isinstance == -1) {
8165 return 1;
8166 }
8167 if (isinstance) {
8168 expr_ty func;
8169 asdl_seq* args;
8170 asdl_seq* keywords;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008171
Dino Viehlandac46eb42019-09-11 10:16:34 -07008172 if (_PyObject_LookupAttr(obj, astmodulestate_global->func, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008173 return 1;
8174 }
8175 if (tmp == NULL) {
8176 PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
8177 return 1;
8178 }
8179 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008180 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008181 res = obj2ast_expr(tmp, &func, arena);
8182 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008183 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008184 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008185 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008186 return 1;
8187 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008188 if (tmp == NULL) {
8189 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Call");
8190 return 1;
8191 }
8192 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008193 int res;
8194 Py_ssize_t len;
8195 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008196 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008197 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 +02008198 goto failed;
8199 }
8200 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008201 args = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008202 if (args == NULL) goto failed;
8203 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008204 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008205 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8206 Py_INCREF(tmp2);
8207 res = obj2ast_expr(tmp2, &val, arena);
8208 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008209 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008210 if (len != PyList_GET_SIZE(tmp)) {
8211 PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
8212 goto failed;
8213 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008214 asdl_seq_SET(args, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008215 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008216 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008217 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008218 if (_PyObject_LookupAttr(obj, astmodulestate_global->keywords, &tmp) <
8219 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008220 return 1;
8221 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008222 if (tmp == NULL) {
8223 PyErr_SetString(PyExc_TypeError, "required field \"keywords\" missing from Call");
8224 return 1;
8225 }
8226 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008227 int res;
8228 Py_ssize_t len;
8229 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008230 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008231 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 +02008232 goto failed;
8233 }
8234 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008235 keywords = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008236 if (keywords == NULL) goto failed;
8237 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008238 keyword_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008239 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8240 Py_INCREF(tmp2);
8241 res = obj2ast_keyword(tmp2, &val, arena);
8242 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008243 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008244 if (len != PyList_GET_SIZE(tmp)) {
8245 PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
8246 goto failed;
8247 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008248 asdl_seq_SET(keywords, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008249 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008250 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008251 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008252 *out = Call(func, args, keywords, lineno, col_offset, end_lineno,
8253 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008254 if (*out == NULL) goto failed;
8255 return 0;
8256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008257 tp = astmodulestate_global->FormattedValue_type;
8258 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008259 if (isinstance == -1) {
8260 return 1;
8261 }
8262 if (isinstance) {
8263 expr_ty value;
8264 int conversion;
8265 expr_ty format_spec;
8266
Dino Viehlandac46eb42019-09-11 10:16:34 -07008267 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008268 return 1;
8269 }
8270 if (tmp == NULL) {
8271 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
8272 return 1;
8273 }
8274 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008275 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008276 res = obj2ast_expr(tmp, &value, arena);
8277 if (res != 0) goto failed;
8278 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008279 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008280 if (_PyObject_LookupAttr(obj, astmodulestate_global->conversion, &tmp)
8281 < 0) {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008282 return 1;
8283 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008284 if (tmp == NULL || tmp == Py_None) {
8285 Py_CLEAR(tmp);
8286 conversion = 0;
8287 }
8288 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008289 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008290 res = obj2ast_int(tmp, &conversion, arena);
8291 if (res != 0) goto failed;
8292 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008293 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008294 if (_PyObject_LookupAttr(obj, astmodulestate_global->format_spec, &tmp)
8295 < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008296 return 1;
8297 }
8298 if (tmp == NULL || tmp == Py_None) {
8299 Py_CLEAR(tmp);
8300 format_spec = NULL;
8301 }
8302 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008303 int res;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008304 res = obj2ast_expr(tmp, &format_spec, arena);
8305 if (res != 0) goto failed;
8306 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008307 }
Eric V. Smith6f6ff8a2019-05-27 15:31:52 -04008308 *out = FormattedValue(value, conversion, format_spec, lineno,
8309 col_offset, end_lineno, end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008310 if (*out == NULL) goto failed;
8311 return 0;
8312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008313 tp = astmodulestate_global->JoinedStr_type;
8314 isinstance = PyObject_IsInstance(obj, tp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008315 if (isinstance == -1) {
8316 return 1;
8317 }
8318 if (isinstance) {
8319 asdl_seq* values;
8320
Dino Viehlandac46eb42019-09-11 10:16:34 -07008321 if (_PyObject_LookupAttr(obj, astmodulestate_global->values, &tmp) < 0)
8322 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008323 return 1;
8324 }
8325 if (tmp == NULL) {
8326 PyErr_SetString(PyExc_TypeError, "required field \"values\" missing from JoinedStr");
8327 return 1;
8328 }
8329 else {
Eric V. Smith235a6f02015-09-19 14:51:32 -04008330 int res;
8331 Py_ssize_t len;
8332 Py_ssize_t i;
Eric V. Smith235a6f02015-09-19 14:51:32 -04008333 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008334 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 -04008335 goto failed;
8336 }
8337 len = PyList_GET_SIZE(tmp);
8338 values = _Py_asdl_seq_new(len, arena);
8339 if (values == NULL) goto failed;
8340 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008341 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008342 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8343 Py_INCREF(tmp2);
8344 res = obj2ast_expr(tmp2, &val, arena);
8345 Py_DECREF(tmp2);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008346 if (res != 0) goto failed;
Serhiy Storchaka5e808552016-10-07 21:55:49 +03008347 if (len != PyList_GET_SIZE(tmp)) {
8348 PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
8349 goto failed;
8350 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008351 asdl_seq_SET(values, i, val);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008352 }
8353 Py_CLEAR(tmp);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008354 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008355 *out = JoinedStr(values, lineno, col_offset, end_lineno,
8356 end_col_offset, arena);
Eric V. Smith235a6f02015-09-19 14:51:32 -04008357 if (*out == NULL) goto failed;
8358 return 0;
8359 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008360 tp = astmodulestate_global->Constant_type;
8361 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008362 if (isinstance == -1) {
8363 return 1;
8364 }
8365 if (isinstance) {
8366 constant value;
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008367 string kind;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008368
Dino Viehlandac46eb42019-09-11 10:16:34 -07008369 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008370 return 1;
8371 }
8372 if (tmp == NULL) {
8373 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
8374 return 1;
8375 }
8376 else {
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008377 int res;
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008378 res = obj2ast_constant(tmp, &value, arena);
8379 if (res != 0) goto failed;
8380 Py_CLEAR(tmp);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008381 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008382 if (_PyObject_LookupAttr(obj, astmodulestate_global->kind, &tmp) < 0) {
Guido van Rossum10f8ce62019-03-13 13:00:46 -07008383 return 1;
8384 }
8385 if (tmp == NULL || tmp == Py_None) {
8386 Py_CLEAR(tmp);
8387 kind = NULL;
8388 }
8389 else {
8390 int res;
8391 res = obj2ast_string(tmp, &kind, arena);
8392 if (res != 0) goto failed;
8393 Py_CLEAR(tmp);
8394 }
8395 *out = Constant(value, kind, lineno, col_offset, end_lineno,
8396 end_col_offset, arena);
Victor Stinnerf2c1aa12016-01-26 00:40:57 +01008397 if (*out == NULL) goto failed;
8398 return 0;
8399 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008400 tp = astmodulestate_global->Attribute_type;
8401 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008402 if (isinstance == -1) {
8403 return 1;
8404 }
8405 if (isinstance) {
8406 expr_ty value;
8407 identifier attr;
8408 expr_context_ty ctx;
8409
Dino Viehlandac46eb42019-09-11 10:16:34 -07008410 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008411 return 1;
8412 }
8413 if (tmp == NULL) {
8414 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
8415 return 1;
8416 }
8417 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008418 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008419 res = obj2ast_expr(tmp, &value, arena);
8420 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008421 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008422 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008423 if (_PyObject_LookupAttr(obj, astmodulestate_global->attr, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008424 return 1;
8425 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008426 if (tmp == NULL) {
8427 PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
8428 return 1;
8429 }
8430 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008431 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008432 res = obj2ast_identifier(tmp, &attr, arena);
8433 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008434 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008435 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008436 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008437 return 1;
8438 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008439 if (tmp == NULL) {
8440 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
8441 return 1;
8442 }
8443 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008444 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008445 res = obj2ast_expr_context(tmp, &ctx, arena);
8446 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008447 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008448 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008449 *out = Attribute(value, attr, ctx, lineno, col_offset, end_lineno,
8450 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008451 if (*out == NULL) goto failed;
8452 return 0;
8453 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008454 tp = astmodulestate_global->Subscript_type;
8455 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008456 if (isinstance == -1) {
8457 return 1;
8458 }
8459 if (isinstance) {
8460 expr_ty value;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008461 expr_ty slice;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008462 expr_context_ty ctx;
8463
Dino Viehlandac46eb42019-09-11 10:16:34 -07008464 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008465 return 1;
8466 }
8467 if (tmp == NULL) {
8468 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
8469 return 1;
8470 }
8471 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008472 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008473 res = obj2ast_expr(tmp, &value, arena);
8474 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008475 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008476 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008477 if (_PyObject_LookupAttr(obj, astmodulestate_global->slice, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008478 return 1;
8479 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008480 if (tmp == NULL) {
8481 PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
8482 return 1;
8483 }
8484 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008485 int res;
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008486 res = obj2ast_expr(tmp, &slice, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008487 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008488 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008489 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008490 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008491 return 1;
8492 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008493 if (tmp == NULL) {
8494 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
8495 return 1;
8496 }
8497 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008498 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008499 res = obj2ast_expr_context(tmp, &ctx, arena);
8500 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008501 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008502 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008503 *out = Subscript(value, slice, ctx, lineno, col_offset, end_lineno,
8504 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008505 if (*out == NULL) goto failed;
8506 return 0;
8507 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008508 tp = astmodulestate_global->Starred_type;
8509 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008510 if (isinstance == -1) {
8511 return 1;
8512 }
8513 if (isinstance) {
8514 expr_ty value;
8515 expr_context_ty ctx;
8516
Dino Viehlandac46eb42019-09-11 10:16:34 -07008517 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008518 return 1;
8519 }
8520 if (tmp == NULL) {
8521 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
8522 return 1;
8523 }
8524 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008525 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008526 res = obj2ast_expr(tmp, &value, arena);
8527 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008528 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008529 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008530 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008531 return 1;
8532 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008533 if (tmp == NULL) {
8534 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
8535 return 1;
8536 }
8537 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008538 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008539 res = obj2ast_expr_context(tmp, &ctx, arena);
8540 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008541 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008542 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008543 *out = Starred(value, ctx, lineno, col_offset, end_lineno,
8544 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008545 if (*out == NULL) goto failed;
8546 return 0;
8547 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008548 tp = astmodulestate_global->Name_type;
8549 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008550 if (isinstance == -1) {
8551 return 1;
8552 }
8553 if (isinstance) {
8554 identifier id;
8555 expr_context_ty ctx;
8556
Dino Viehlandac46eb42019-09-11 10:16:34 -07008557 if (_PyObject_LookupAttr(obj, astmodulestate_global->id, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008558 return 1;
8559 }
8560 if (tmp == NULL) {
8561 PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
8562 return 1;
8563 }
8564 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008565 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008566 res = obj2ast_identifier(tmp, &id, arena);
8567 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008568 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008569 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008570 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008571 return 1;
8572 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008573 if (tmp == NULL) {
8574 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
8575 return 1;
8576 }
8577 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008578 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008579 res = obj2ast_expr_context(tmp, &ctx, arena);
8580 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008581 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008582 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008583 *out = Name(id, ctx, lineno, col_offset, end_lineno, end_col_offset,
8584 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008585 if (*out == NULL) goto failed;
8586 return 0;
8587 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008588 tp = astmodulestate_global->List_type;
8589 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008590 if (isinstance == -1) {
8591 return 1;
8592 }
8593 if (isinstance) {
8594 asdl_seq* elts;
8595 expr_context_ty ctx;
8596
Dino Viehlandac46eb42019-09-11 10:16:34 -07008597 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008598 return 1;
8599 }
8600 if (tmp == NULL) {
8601 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from List");
8602 return 1;
8603 }
8604 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008605 int res;
8606 Py_ssize_t len;
8607 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008608 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008609 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 +02008610 goto failed;
8611 }
8612 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008613 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008614 if (elts == NULL) goto failed;
8615 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008616 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008617 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8618 Py_INCREF(tmp2);
8619 res = obj2ast_expr(tmp2, &val, arena);
8620 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008621 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008622 if (len != PyList_GET_SIZE(tmp)) {
8623 PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
8624 goto failed;
8625 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008626 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008627 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008628 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008629 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008630 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008631 return 1;
8632 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008633 if (tmp == NULL) {
8634 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
8635 return 1;
8636 }
8637 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008638 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008639 res = obj2ast_expr_context(tmp, &ctx, arena);
8640 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008641 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008642 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008643 *out = List(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8644 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008645 if (*out == NULL) goto failed;
8646 return 0;
8647 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008648 tp = astmodulestate_global->Tuple_type;
8649 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008650 if (isinstance == -1) {
8651 return 1;
8652 }
8653 if (isinstance) {
8654 asdl_seq* elts;
8655 expr_context_ty ctx;
8656
Dino Viehlandac46eb42019-09-11 10:16:34 -07008657 if (_PyObject_LookupAttr(obj, astmodulestate_global->elts, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008658 return 1;
8659 }
8660 if (tmp == NULL) {
8661 PyErr_SetString(PyExc_TypeError, "required field \"elts\" missing from Tuple");
8662 return 1;
8663 }
8664 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008665 int res;
8666 Py_ssize_t len;
8667 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008668 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07008669 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 +02008670 goto failed;
8671 }
8672 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02008673 elts = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008674 if (elts == NULL) goto failed;
8675 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008676 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03008677 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
8678 Py_INCREF(tmp2);
8679 res = obj2ast_expr(tmp2, &val, arena);
8680 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008681 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03008682 if (len != PyList_GET_SIZE(tmp)) {
8683 PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
8684 goto failed;
8685 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07008686 asdl_seq_SET(elts, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008687 }
Victor Stinner1acc1292013-07-27 00:03:47 +02008688 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008689 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008690 if (_PyObject_LookupAttr(obj, astmodulestate_global->ctx, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008691 return 1;
8692 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02008693 if (tmp == NULL) {
8694 PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
8695 return 1;
8696 }
8697 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008698 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008699 res = obj2ast_expr_context(tmp, &ctx, arena);
8700 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02008701 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008702 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00008703 *out = Tuple(elts, ctx, lineno, col_offset, end_lineno, end_col_offset,
8704 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008705 if (*out == NULL) goto failed;
8706 return 0;
8707 }
Serhiy Storchaka13d52c22020-03-10 18:52:34 +02008708 tp = astmodulestate_global->Slice_type;
8709 isinstance = PyObject_IsInstance(obj, tp);
8710 if (isinstance == -1) {
8711 return 1;
8712 }
8713 if (isinstance) {
8714 expr_ty lower;
8715 expr_ty upper;
8716 expr_ty step;
8717
8718 if (_PyObject_LookupAttr(obj, astmodulestate_global->lower, &tmp) < 0) {
8719 return 1;
8720 }
8721 if (tmp == NULL || tmp == Py_None) {
8722 Py_CLEAR(tmp);
8723 lower = NULL;
8724 }
8725 else {
8726 int res;
8727 res = obj2ast_expr(tmp, &lower, arena);
8728 if (res != 0) goto failed;
8729 Py_CLEAR(tmp);
8730 }
8731 if (_PyObject_LookupAttr(obj, astmodulestate_global->upper, &tmp) < 0) {
8732 return 1;
8733 }
8734 if (tmp == NULL || tmp == Py_None) {
8735 Py_CLEAR(tmp);
8736 upper = NULL;
8737 }
8738 else {
8739 int res;
8740 res = obj2ast_expr(tmp, &upper, arena);
8741 if (res != 0) goto failed;
8742 Py_CLEAR(tmp);
8743 }
8744 if (_PyObject_LookupAttr(obj, astmodulestate_global->step, &tmp) < 0) {
8745 return 1;
8746 }
8747 if (tmp == NULL || tmp == Py_None) {
8748 Py_CLEAR(tmp);
8749 step = NULL;
8750 }
8751 else {
8752 int res;
8753 res = obj2ast_expr(tmp, &step, arena);
8754 if (res != 0) goto failed;
8755 Py_CLEAR(tmp);
8756 }
8757 *out = Slice(lower, upper, step, lineno, col_offset, end_lineno,
8758 end_col_offset, arena);
8759 if (*out == NULL) goto failed;
8760 return 0;
8761 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008762
8763 PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
8764 failed:
8765 Py_XDECREF(tmp);
8766 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008767}
8768
8769int
8770obj2ast_expr_context(PyObject* obj, expr_context_ty* out, PyArena* arena)
8771{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008772 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008773
Dino Viehlandac46eb42019-09-11 10:16:34 -07008774 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Load_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008775 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008776 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008777 }
8778 if (isinstance) {
8779 *out = Load;
8780 return 0;
8781 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008782 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Store_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008783 if (isinstance == -1) {
8784 return 1;
8785 }
8786 if (isinstance) {
8787 *out = Store;
8788 return 0;
8789 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008790 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Del_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008791 if (isinstance == -1) {
8792 return 1;
8793 }
8794 if (isinstance) {
8795 *out = Del;
8796 return 0;
8797 }
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008798
8799 PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
8800 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008801}
8802
8803int
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008804obj2ast_boolop(PyObject* obj, boolop_ty* out, PyArena* arena)
8805{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008806 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008807
Dino Viehlandac46eb42019-09-11 10:16:34 -07008808 isinstance = PyObject_IsInstance(obj, astmodulestate_global->And_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008809 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008810 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008811 }
8812 if (isinstance) {
8813 *out = And;
8814 return 0;
8815 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008816 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Or_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008817 if (isinstance == -1) {
8818 return 1;
8819 }
8820 if (isinstance) {
8821 *out = Or;
8822 return 0;
8823 }
8824
8825 PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
8826 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008827}
8828
8829int
8830obj2ast_operator(PyObject* obj, operator_ty* out, PyArena* arena)
8831{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008832 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008833
Dino Viehlandac46eb42019-09-11 10:16:34 -07008834 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Add_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008835 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008836 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008837 }
8838 if (isinstance) {
8839 *out = Add;
8840 return 0;
8841 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008842 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Sub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008843 if (isinstance == -1) {
8844 return 1;
8845 }
8846 if (isinstance) {
8847 *out = Sub;
8848 return 0;
8849 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008850 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mult_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008851 if (isinstance == -1) {
8852 return 1;
8853 }
8854 if (isinstance) {
8855 *out = Mult;
8856 return 0;
8857 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008858 isinstance = PyObject_IsInstance(obj, astmodulestate_global->MatMult_type);
Benjamin Petersond51374e2014-04-09 23:55:56 -04008859 if (isinstance == -1) {
8860 return 1;
8861 }
8862 if (isinstance) {
8863 *out = MatMult;
8864 return 0;
8865 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008866 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Div_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008867 if (isinstance == -1) {
8868 return 1;
8869 }
8870 if (isinstance) {
8871 *out = Div;
8872 return 0;
8873 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008874 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Mod_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008875 if (isinstance == -1) {
8876 return 1;
8877 }
8878 if (isinstance) {
8879 *out = Mod;
8880 return 0;
8881 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008882 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Pow_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008883 if (isinstance == -1) {
8884 return 1;
8885 }
8886 if (isinstance) {
8887 *out = Pow;
8888 return 0;
8889 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008890 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008891 if (isinstance == -1) {
8892 return 1;
8893 }
8894 if (isinstance) {
8895 *out = LShift;
8896 return 0;
8897 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008898 isinstance = PyObject_IsInstance(obj, astmodulestate_global->RShift_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008899 if (isinstance == -1) {
8900 return 1;
8901 }
8902 if (isinstance) {
8903 *out = RShift;
8904 return 0;
8905 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008906 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitOr_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008907 if (isinstance == -1) {
8908 return 1;
8909 }
8910 if (isinstance) {
8911 *out = BitOr;
8912 return 0;
8913 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008914 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitXor_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008915 if (isinstance == -1) {
8916 return 1;
8917 }
8918 if (isinstance) {
8919 *out = BitXor;
8920 return 0;
8921 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008922 isinstance = PyObject_IsInstance(obj, astmodulestate_global->BitAnd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008923 if (isinstance == -1) {
8924 return 1;
8925 }
8926 if (isinstance) {
8927 *out = BitAnd;
8928 return 0;
8929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008930 isinstance = PyObject_IsInstance(obj, astmodulestate_global->FloorDiv_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008931 if (isinstance == -1) {
8932 return 1;
8933 }
8934 if (isinstance) {
8935 *out = FloorDiv;
8936 return 0;
8937 }
8938
8939 PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
8940 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008941}
8942
8943int
8944obj2ast_unaryop(PyObject* obj, unaryop_ty* out, PyArena* arena)
8945{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008946 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008947
Dino Viehlandac46eb42019-09-11 10:16:34 -07008948 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Invert_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008949 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008950 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008951 }
8952 if (isinstance) {
8953 *out = Invert;
8954 return 0;
8955 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008956 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Not_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008957 if (isinstance == -1) {
8958 return 1;
8959 }
8960 if (isinstance) {
8961 *out = Not;
8962 return 0;
8963 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008964 isinstance = PyObject_IsInstance(obj, astmodulestate_global->UAdd_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008965 if (isinstance == -1) {
8966 return 1;
8967 }
8968 if (isinstance) {
8969 *out = UAdd;
8970 return 0;
8971 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008972 isinstance = PyObject_IsInstance(obj, astmodulestate_global->USub_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008973 if (isinstance == -1) {
8974 return 1;
8975 }
8976 if (isinstance) {
8977 *out = USub;
8978 return 0;
8979 }
8980
8981 PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
8982 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008983}
8984
8985int
8986obj2ast_cmpop(PyObject* obj, cmpop_ty* out, PyArena* arena)
8987{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008988 int isinstance;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008989
Dino Viehlandac46eb42019-09-11 10:16:34 -07008990 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Eq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008991 if (isinstance == -1) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00008992 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008993 }
8994 if (isinstance) {
8995 *out = Eq;
8996 return 0;
8997 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07008998 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotEq_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02008999 if (isinstance == -1) {
9000 return 1;
9001 }
9002 if (isinstance) {
9003 *out = NotEq;
9004 return 0;
9005 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009006 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Lt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009007 if (isinstance == -1) {
9008 return 1;
9009 }
9010 if (isinstance) {
9011 *out = Lt;
9012 return 0;
9013 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009014 isinstance = PyObject_IsInstance(obj, astmodulestate_global->LtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009015 if (isinstance == -1) {
9016 return 1;
9017 }
9018 if (isinstance) {
9019 *out = LtE;
9020 return 0;
9021 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009022 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Gt_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009023 if (isinstance == -1) {
9024 return 1;
9025 }
9026 if (isinstance) {
9027 *out = Gt;
9028 return 0;
9029 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009030 isinstance = PyObject_IsInstance(obj, astmodulestate_global->GtE_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009031 if (isinstance == -1) {
9032 return 1;
9033 }
9034 if (isinstance) {
9035 *out = GtE;
9036 return 0;
9037 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009038 isinstance = PyObject_IsInstance(obj, astmodulestate_global->Is_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009039 if (isinstance == -1) {
9040 return 1;
9041 }
9042 if (isinstance) {
9043 *out = Is;
9044 return 0;
9045 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009046 isinstance = PyObject_IsInstance(obj, astmodulestate_global->IsNot_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009047 if (isinstance == -1) {
9048 return 1;
9049 }
9050 if (isinstance) {
9051 *out = IsNot;
9052 return 0;
9053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009054 isinstance = PyObject_IsInstance(obj, astmodulestate_global->In_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009055 if (isinstance == -1) {
9056 return 1;
9057 }
9058 if (isinstance) {
9059 *out = In;
9060 return 0;
9061 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009062 isinstance = PyObject_IsInstance(obj, astmodulestate_global->NotIn_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009063 if (isinstance == -1) {
9064 return 1;
9065 }
9066 if (isinstance) {
9067 *out = NotIn;
9068 return 0;
9069 }
9070
9071 PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
9072 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009073}
9074
9075int
9076obj2ast_comprehension(PyObject* obj, comprehension_ty* out, PyArena* arena)
9077{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009078 PyObject* tmp = NULL;
9079 expr_ty target;
9080 expr_ty iter;
9081 asdl_seq* ifs;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009082 int is_async;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009083
Dino Viehlandac46eb42019-09-11 10:16:34 -07009084 if (_PyObject_LookupAttr(obj, astmodulestate_global->target, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009085 return 1;
9086 }
9087 if (tmp == NULL) {
9088 PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
9089 return 1;
9090 }
9091 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009092 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009093 res = obj2ast_expr(tmp, &target, arena);
9094 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009095 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009096 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009097 if (_PyObject_LookupAttr(obj, astmodulestate_global->iter, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009098 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009099 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009100 if (tmp == NULL) {
9101 PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
9102 return 1;
9103 }
9104 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009105 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009106 res = obj2ast_expr(tmp, &iter, arena);
9107 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009108 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009110 if (_PyObject_LookupAttr(obj, astmodulestate_global->ifs, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009111 return 1;
9112 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009113 if (tmp == NULL) {
9114 PyErr_SetString(PyExc_TypeError, "required field \"ifs\" missing from comprehension");
9115 return 1;
9116 }
9117 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009118 int res;
9119 Py_ssize_t len;
9120 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009121 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009122 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 +02009123 goto failed;
9124 }
9125 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009126 ifs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009127 if (ifs == NULL) goto failed;
9128 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009129 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009130 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9131 Py_INCREF(tmp2);
9132 res = obj2ast_expr(tmp2, &val, arena);
9133 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009134 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009135 if (len != PyList_GET_SIZE(tmp)) {
9136 PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
9137 goto failed;
9138 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009139 asdl_seq_SET(ifs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009140 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009141 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009142 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009143 if (_PyObject_LookupAttr(obj, astmodulestate_global->is_async, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009144 return 1;
9145 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009146 if (tmp == NULL) {
9147 PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
9148 return 1;
9149 }
9150 else {
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009151 int res;
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009152 res = obj2ast_int(tmp, &is_async, arena);
9153 if (res != 0) goto failed;
9154 Py_CLEAR(tmp);
Yury Selivanov52c4e7c2016-09-09 10:36:01 -07009155 }
9156 *out = comprehension(target, iter, ifs, is_async, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009157 return 0;
9158failed:
9159 Py_XDECREF(tmp);
9160 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009161}
9162
9163int
9164obj2ast_excepthandler(PyObject* obj, excepthandler_ty* out, PyArena* arena)
9165{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009166 int isinstance;
Neal Norwitzad74aa82008-03-31 05:14:30 +00009167
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009168 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009169 PyObject *tp;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009170 int lineno;
9171 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009172 int end_lineno;
9173 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009174
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009175 if (obj == Py_None) {
9176 *out = NULL;
9177 return 0;
9178 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009179 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009180 return 1;
9181 }
9182 if (tmp == NULL) {
9183 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
9184 return 1;
9185 }
9186 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009187 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009188 res = obj2ast_int(tmp, &lineno, arena);
9189 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009190 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009191 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009192 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9193 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009194 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009195 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009196 if (tmp == NULL) {
9197 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
9198 return 1;
9199 }
9200 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009201 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009202 res = obj2ast_int(tmp, &col_offset, arena);
9203 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009204 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009205 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009206 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9207 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009208 return 1;
9209 }
9210 if (tmp == NULL || tmp == Py_None) {
9211 Py_CLEAR(tmp);
9212 end_lineno = 0;
9213 }
9214 else {
9215 int res;
9216 res = obj2ast_int(tmp, &end_lineno, arena);
9217 if (res != 0) goto failed;
9218 Py_CLEAR(tmp);
9219 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009220 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9221 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009222 return 1;
9223 }
9224 if (tmp == NULL || tmp == Py_None) {
9225 Py_CLEAR(tmp);
9226 end_col_offset = 0;
9227 }
9228 else {
9229 int res;
9230 res = obj2ast_int(tmp, &end_col_offset, arena);
9231 if (res != 0) goto failed;
9232 Py_CLEAR(tmp);
9233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009234 tp = astmodulestate_global->ExceptHandler_type;
9235 isinstance = PyObject_IsInstance(obj, tp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009236 if (isinstance == -1) {
9237 return 1;
9238 }
9239 if (isinstance) {
9240 expr_ty type;
9241 identifier name;
9242 asdl_seq* body;
9243
Dino Viehlandac46eb42019-09-11 10:16:34 -07009244 if (_PyObject_LookupAttr(obj, astmodulestate_global->type, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009245 return 1;
9246 }
9247 if (tmp == NULL || tmp == Py_None) {
9248 Py_CLEAR(tmp);
9249 type = NULL;
9250 }
9251 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009252 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009253 res = obj2ast_expr(tmp, &type, arena);
9254 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009255 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009256 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009257 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009258 return 1;
9259 }
9260 if (tmp == NULL || tmp == Py_None) {
9261 Py_CLEAR(tmp);
9262 name = NULL;
9263 }
9264 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009265 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009266 res = obj2ast_identifier(tmp, &name, arena);
9267 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009268 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009269 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009270 if (_PyObject_LookupAttr(obj, astmodulestate_global->body, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009271 return 1;
9272 }
9273 if (tmp == NULL) {
9274 PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from ExceptHandler");
9275 return 1;
9276 }
9277 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009278 int res;
9279 Py_ssize_t len;
9280 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009281 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009282 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 +02009283 goto failed;
9284 }
9285 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009286 body = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009287 if (body == NULL) goto failed;
9288 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009289 stmt_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009290 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9291 Py_INCREF(tmp2);
9292 res = obj2ast_stmt(tmp2, &val, arena);
9293 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009294 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009295 if (len != PyList_GET_SIZE(tmp)) {
9296 PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
9297 goto failed;
9298 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009299 asdl_seq_SET(body, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009300 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009301 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009302 }
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009303 *out = ExceptHandler(type, name, body, lineno, col_offset, end_lineno,
9304 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009305 if (*out == NULL) goto failed;
9306 return 0;
9307 }
9308
9309 PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
9310 failed:
9311 Py_XDECREF(tmp);
9312 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009313}
9314
9315int
9316obj2ast_arguments(PyObject* obj, arguments_ty* out, PyArena* arena)
9317{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009318 PyObject* tmp = NULL;
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009319 asdl_seq* posonlyargs;
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009320 asdl_seq* args;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009321 arg_ty vararg;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009322 asdl_seq* kwonlyargs;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009323 asdl_seq* kw_defaults;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009324 arg_ty kwarg;
9325 asdl_seq* defaults;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009326
Dino Viehlandac46eb42019-09-11 10:16:34 -07009327 if (_PyObject_LookupAttr(obj, astmodulestate_global->posonlyargs, &tmp) <
9328 0) {
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009329 return 1;
9330 }
9331 if (tmp == NULL) {
9332 PyErr_SetString(PyExc_TypeError, "required field \"posonlyargs\" missing from arguments");
9333 return 1;
9334 }
9335 else {
9336 int res;
9337 Py_ssize_t len;
9338 Py_ssize_t i;
9339 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009340 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 +01009341 goto failed;
9342 }
9343 len = PyList_GET_SIZE(tmp);
9344 posonlyargs = _Py_asdl_seq_new(len, arena);
9345 if (posonlyargs == NULL) goto failed;
9346 for (i = 0; i < len; i++) {
9347 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009348 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9349 Py_INCREF(tmp2);
9350 res = obj2ast_arg(tmp2, &val, arena);
9351 Py_DECREF(tmp2);
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009352 if (res != 0) goto failed;
9353 if (len != PyList_GET_SIZE(tmp)) {
9354 PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
9355 goto failed;
9356 }
9357 asdl_seq_SET(posonlyargs, i, val);
9358 }
9359 Py_CLEAR(tmp);
9360 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009361 if (_PyObject_LookupAttr(obj, astmodulestate_global->args, &tmp) < 0) {
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009362 return 1;
9363 }
9364 if (tmp == NULL) {
9365 PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from arguments");
9366 return 1;
9367 }
9368 else {
9369 int res;
9370 Py_ssize_t len;
9371 Py_ssize_t i;
9372 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009373 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 +02009374 goto failed;
9375 }
9376 len = PyList_GET_SIZE(tmp);
9377 args = _Py_asdl_seq_new(len, arena);
9378 if (args == NULL) goto failed;
9379 for (i = 0; i < len; i++) {
9380 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009381 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9382 Py_INCREF(tmp2);
9383 res = obj2ast_arg(tmp2, &val, arena);
9384 Py_DECREF(tmp2);
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009385 if (res != 0) goto failed;
9386 if (len != PyList_GET_SIZE(tmp)) {
9387 PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
9388 goto failed;
9389 }
9390 asdl_seq_SET(args, i, val);
9391 }
9392 Py_CLEAR(tmp);
9393 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009394 if (_PyObject_LookupAttr(obj, astmodulestate_global->vararg, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009395 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009396 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009397 if (tmp == NULL || tmp == Py_None) {
9398 Py_CLEAR(tmp);
9399 vararg = NULL;
9400 }
9401 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009402 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009403 res = obj2ast_arg(tmp, &vararg, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009404 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009405 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009406 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009407 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwonlyargs, &tmp) < 0)
9408 {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009409 return 1;
9410 }
9411 if (tmp == NULL) {
9412 PyErr_SetString(PyExc_TypeError, "required field \"kwonlyargs\" missing from arguments");
9413 return 1;
9414 }
9415 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009416 int res;
9417 Py_ssize_t len;
9418 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009419 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009420 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 +02009421 goto failed;
9422 }
9423 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009424 kwonlyargs = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009425 if (kwonlyargs == NULL) goto failed;
9426 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009427 arg_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009428 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9429 Py_INCREF(tmp2);
9430 res = obj2ast_arg(tmp2, &val, arena);
9431 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009432 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009433 if (len != PyList_GET_SIZE(tmp)) {
9434 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
9435 goto failed;
9436 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009437 asdl_seq_SET(kwonlyargs, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009438 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009439 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009440 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009441 if (_PyObject_LookupAttr(obj, astmodulestate_global->kw_defaults, &tmp) <
9442 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009443 return 1;
9444 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009445 if (tmp == NULL) {
9446 PyErr_SetString(PyExc_TypeError, "required field \"kw_defaults\" missing from arguments");
9447 return 1;
9448 }
9449 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009450 int res;
9451 Py_ssize_t len;
9452 Py_ssize_t i;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009453 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009454 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 +02009455 goto failed;
9456 }
9457 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009458 kw_defaults = _Py_asdl_seq_new(len, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009459 if (kw_defaults == NULL) goto failed;
9460 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009461 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009462 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9463 Py_INCREF(tmp2);
9464 res = obj2ast_expr(tmp2, &val, arena);
9465 Py_DECREF(tmp2);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009466 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009467 if (len != PyList_GET_SIZE(tmp)) {
9468 PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
9469 goto failed;
9470 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009471 asdl_seq_SET(kw_defaults, i, val);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009472 }
Victor Stinner1acc1292013-07-27 00:03:47 +02009473 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009474 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009475 if (_PyObject_LookupAttr(obj, astmodulestate_global->kwarg, &tmp) < 0) {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009476 return 1;
9477 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009478 if (tmp == NULL || tmp == Py_None) {
9479 Py_CLEAR(tmp);
9480 kwarg = NULL;
9481 }
9482 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009483 int res;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009484 res = obj2ast_arg(tmp, &kwarg, arena);
9485 if (res != 0) goto failed;
Victor Stinnerb3189902013-07-27 00:04:42 +02009486 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009487 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009488 if (_PyObject_LookupAttr(obj, astmodulestate_global->defaults, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009489 return 1;
9490 }
9491 if (tmp == NULL) {
9492 PyErr_SetString(PyExc_TypeError, "required field \"defaults\" missing from arguments");
9493 return 1;
9494 }
9495 else {
Victor Stinneree4b59c2013-07-27 00:01:35 +02009496 int res;
9497 Py_ssize_t len;
9498 Py_ssize_t i;
Victor Stinneree4b59c2013-07-27 00:01:35 +02009499 if (!PyList_Check(tmp)) {
Dino Viehlandac46eb42019-09-11 10:16:34 -07009500 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 +02009501 goto failed;
9502 }
9503 len = PyList_GET_SIZE(tmp);
Antoine Pitroud01d396e2013-10-12 22:52:43 +02009504 defaults = _Py_asdl_seq_new(len, arena);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009505 if (defaults == NULL) goto failed;
9506 for (i = 0; i < len; i++) {
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009507 expr_ty val;
Serhiy Storchaka43c97312019-09-10 13:02:30 +03009508 PyObject *tmp2 = PyList_GET_ITEM(tmp, i);
9509 Py_INCREF(tmp2);
9510 res = obj2ast_expr(tmp2, &val, arena);
9511 Py_DECREF(tmp2);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009512 if (res != 0) goto failed;
Serhiy Storchakacf380602016-10-07 21:51:28 +03009513 if (len != PyList_GET_SIZE(tmp)) {
9514 PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
9515 goto failed;
9516 }
Yuan Chao Chou2af565b2017-08-04 10:53:12 -07009517 asdl_seq_SET(defaults, i, val);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009518 }
Victor Stinnerb3189902013-07-27 00:04:42 +02009519 Py_CLEAR(tmp);
Victor Stinneree4b59c2013-07-27 00:01:35 +02009520 }
Pablo Galindocd6e83b2019-07-15 01:32:18 +02009521 *out = arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg,
Pablo Galindo8c77b8c2019-04-29 13:36:57 +01009522 defaults, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009523 return 0;
9524failed:
9525 Py_XDECREF(tmp);
9526 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009527}
9528
9529int
9530obj2ast_arg(PyObject* obj, arg_ty* out, PyArena* arena)
9531{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009532 PyObject* tmp = NULL;
9533 identifier arg;
9534 expr_ty annotation;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009535 string type_comment;
Victor Stinnerc106c682015-11-06 17:01:48 +01009536 int lineno;
9537 int col_offset;
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009538 int end_lineno;
9539 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009540
Dino Viehlandac46eb42019-09-11 10:16:34 -07009541 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009542 return 1;
9543 }
9544 if (tmp == NULL) {
9545 PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
9546 return 1;
9547 }
9548 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009549 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009550 res = obj2ast_identifier(tmp, &arg, arena);
9551 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009552 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009553 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009554 if (_PyObject_LookupAttr(obj, astmodulestate_global->annotation, &tmp) < 0)
9555 {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009556 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009557 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009558 if (tmp == NULL || tmp == Py_None) {
9559 Py_CLEAR(tmp);
9560 annotation = NULL;
9561 }
9562 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009563 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009564 res = obj2ast_expr(tmp, &annotation, arena);
9565 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009566 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009567 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009568 if (_PyObject_LookupAttr(obj, astmodulestate_global->type_comment, &tmp) <
9569 0) {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009570 return 1;
9571 }
9572 if (tmp == NULL || tmp == Py_None) {
9573 Py_CLEAR(tmp);
9574 type_comment = NULL;
9575 }
9576 else {
9577 int res;
9578 res = obj2ast_string(tmp, &type_comment, arena);
9579 if (res != 0) goto failed;
9580 Py_CLEAR(tmp);
9581 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009582 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009583 return 1;
9584 }
9585 if (tmp == NULL) {
9586 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
9587 return 1;
9588 }
9589 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009590 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009591 res = obj2ast_int(tmp, &lineno, arena);
9592 if (res != 0) goto failed;
9593 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009594 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009595 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9596 {
Victor Stinnerc106c682015-11-06 17:01:48 +01009597 return 1;
9598 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009599 if (tmp == NULL) {
9600 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
9601 return 1;
9602 }
9603 else {
Victor Stinnerc106c682015-11-06 17:01:48 +01009604 int res;
Victor Stinnerc106c682015-11-06 17:01:48 +01009605 res = obj2ast_int(tmp, &col_offset, arena);
9606 if (res != 0) goto failed;
9607 Py_CLEAR(tmp);
Victor Stinnerc106c682015-11-06 17:01:48 +01009608 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009609 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9610 {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009611 return 1;
9612 }
9613 if (tmp == NULL || tmp == Py_None) {
9614 Py_CLEAR(tmp);
9615 end_lineno = 0;
9616 }
9617 else {
9618 int res;
9619 res = obj2ast_int(tmp, &end_lineno, arena);
9620 if (res != 0) goto failed;
9621 Py_CLEAR(tmp);
9622 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009623 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9624 < 0) {
Ivan Levkivskyi9932a222019-01-22 11:18:22 +00009625 return 1;
9626 }
9627 if (tmp == NULL || tmp == Py_None) {
9628 Py_CLEAR(tmp);
9629 end_col_offset = 0;
9630 }
9631 else {
9632 int res;
9633 res = obj2ast_int(tmp, &end_col_offset, arena);
9634 if (res != 0) goto failed;
9635 Py_CLEAR(tmp);
9636 }
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009637 *out = arg(arg, annotation, type_comment, lineno, col_offset, end_lineno,
9638 end_col_offset, arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009639 return 0;
9640failed:
9641 Py_XDECREF(tmp);
9642 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009643}
9644
9645int
9646obj2ast_keyword(PyObject* obj, keyword_ty* out, PyArena* arena)
9647{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009648 PyObject* tmp = NULL;
9649 identifier arg;
9650 expr_ty value;
Pablo Galindo168660b2020-04-02 00:47:39 +01009651 int lineno;
9652 int col_offset;
9653 int end_lineno;
9654 int end_col_offset;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009655
Dino Viehlandac46eb42019-09-11 10:16:34 -07009656 if (_PyObject_LookupAttr(obj, astmodulestate_global->arg, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009657 return 1;
9658 }
9659 if (tmp == NULL || tmp == Py_None) {
9660 Py_CLEAR(tmp);
9661 arg = NULL;
9662 }
9663 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009664 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009665 res = obj2ast_identifier(tmp, &arg, arena);
9666 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009667 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009668 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009669 if (_PyObject_LookupAttr(obj, astmodulestate_global->value, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009670 return 1;
9671 }
9672 if (tmp == NULL) {
9673 PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
9674 return 1;
9675 }
9676 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009677 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009678 res = obj2ast_expr(tmp, &value, arena);
9679 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009680 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009681 }
Pablo Galindo168660b2020-04-02 00:47:39 +01009682 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0) {
9683 return 1;
9684 }
9685 if (tmp == NULL) {
9686 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
9687 return 1;
9688 }
9689 else {
9690 int res;
9691 res = obj2ast_int(tmp, &lineno, arena);
9692 if (res != 0) goto failed;
9693 Py_CLEAR(tmp);
9694 }
9695 if (_PyObject_LookupAttr(obj, astmodulestate_global->col_offset, &tmp) < 0)
9696 {
9697 return 1;
9698 }
9699 if (tmp == NULL) {
9700 PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
9701 return 1;
9702 }
9703 else {
9704 int res;
9705 res = obj2ast_int(tmp, &col_offset, arena);
9706 if (res != 0) goto failed;
9707 Py_CLEAR(tmp);
9708 }
9709 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_lineno, &tmp) < 0)
9710 {
9711 return 1;
9712 }
9713 if (tmp == NULL || tmp == Py_None) {
9714 Py_CLEAR(tmp);
9715 end_lineno = 0;
9716 }
9717 else {
9718 int res;
9719 res = obj2ast_int(tmp, &end_lineno, arena);
9720 if (res != 0) goto failed;
9721 Py_CLEAR(tmp);
9722 }
9723 if (_PyObject_LookupAttr(obj, astmodulestate_global->end_col_offset, &tmp)
9724 < 0) {
9725 return 1;
9726 }
9727 if (tmp == NULL || tmp == Py_None) {
9728 Py_CLEAR(tmp);
9729 end_col_offset = 0;
9730 }
9731 else {
9732 int res;
9733 res = obj2ast_int(tmp, &end_col_offset, arena);
9734 if (res != 0) goto failed;
9735 Py_CLEAR(tmp);
9736 }
9737 *out = keyword(arg, value, lineno, col_offset, end_lineno, end_col_offset,
9738 arena);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009739 return 0;
9740failed:
9741 Py_XDECREF(tmp);
9742 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009743}
9744
9745int
9746obj2ast_alias(PyObject* obj, alias_ty* out, PyArena* arena)
9747{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009748 PyObject* tmp = NULL;
9749 identifier name;
9750 identifier asname;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009751
Dino Viehlandac46eb42019-09-11 10:16:34 -07009752 if (_PyObject_LookupAttr(obj, astmodulestate_global->name, &tmp) < 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009753 return 1;
9754 }
9755 if (tmp == NULL) {
9756 PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
9757 return 1;
9758 }
9759 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009760 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009761 res = obj2ast_identifier(tmp, &name, arena);
9762 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009763 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009764 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009765 if (_PyObject_LookupAttr(obj, astmodulestate_global->asname, &tmp) < 0) {
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009766 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009767 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009768 if (tmp == NULL || tmp == Py_None) {
9769 Py_CLEAR(tmp);
9770 asname = NULL;
9771 }
9772 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009773 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009774 res = obj2ast_identifier(tmp, &asname, arena);
9775 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009776 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009777 }
9778 *out = alias(name, asname, arena);
9779 return 0;
9780failed:
9781 Py_XDECREF(tmp);
9782 return 1;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009783}
9784
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009785int
9786obj2ast_withitem(PyObject* obj, withitem_ty* out, PyArena* arena)
9787{
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009788 PyObject* tmp = NULL;
9789 expr_ty context_expr;
9790 expr_ty optional_vars;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009791
Dino Viehlandac46eb42019-09-11 10:16:34 -07009792 if (_PyObject_LookupAttr(obj, astmodulestate_global->context_expr, &tmp) <
9793 0) {
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009794 return 1;
9795 }
9796 if (tmp == NULL) {
9797 PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
9798 return 1;
9799 }
9800 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009801 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009802 res = obj2ast_expr(tmp, &context_expr, arena);
9803 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009804 Py_CLEAR(tmp);
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009805 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009806 if (_PyObject_LookupAttr(obj, astmodulestate_global->optional_vars, &tmp) <
9807 0) {
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009808 return 1;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009809 }
Serhiy Storchakaf320be72018-01-25 10:49:40 +02009810 if (tmp == NULL || tmp == Py_None) {
9811 Py_CLEAR(tmp);
9812 optional_vars = NULL;
9813 }
9814 else {
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009815 int res;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009816 res = obj2ast_expr(tmp, &optional_vars, arena);
9817 if (res != 0) goto failed;
Victor Stinner1acc1292013-07-27 00:03:47 +02009818 Py_CLEAR(tmp);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009819 }
9820 *out = withitem(context_expr, optional_vars, arena);
9821 return 0;
9822failed:
9823 Py_XDECREF(tmp);
9824 return 1;
Benjamin Petersonbf1bbc12011-05-27 13:58:08 -05009825}
9826
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009827int
9828obj2ast_type_ignore(PyObject* obj, type_ignore_ty* out, PyArena* arena)
9829{
9830 int isinstance;
9831
9832 PyObject *tmp = NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009833 PyObject *tp;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009834
9835 if (obj == Py_None) {
9836 *out = NULL;
9837 return 0;
9838 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009839 tp = astmodulestate_global->TypeIgnore_type;
9840 isinstance = PyObject_IsInstance(obj, tp);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009841 if (isinstance == -1) {
9842 return 1;
9843 }
9844 if (isinstance) {
9845 int lineno;
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009846 string tag;
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009847
Dino Viehlandac46eb42019-09-11 10:16:34 -07009848 if (_PyObject_LookupAttr(obj, astmodulestate_global->lineno, &tmp) < 0)
9849 {
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009850 return 1;
9851 }
9852 if (tmp == NULL) {
9853 PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
9854 return 1;
9855 }
9856 else {
9857 int res;
9858 res = obj2ast_int(tmp, &lineno, arena);
9859 if (res != 0) goto failed;
9860 Py_CLEAR(tmp);
9861 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009862 if (_PyObject_LookupAttr(obj, astmodulestate_global->tag, &tmp) < 0) {
Michael J. Sullivan933e1502019-05-22 07:54:20 -07009863 return 1;
9864 }
9865 if (tmp == NULL) {
9866 PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
9867 return 1;
9868 }
9869 else {
9870 int res;
9871 res = obj2ast_string(tmp, &tag, arena);
9872 if (res != 0) goto failed;
9873 Py_CLEAR(tmp);
9874 }
9875 *out = TypeIgnore(lineno, tag, arena);
Guido van Rossumdcfcd142019-01-31 03:40:27 -08009876 if (*out == NULL) goto failed;
9877 return 0;
9878 }
9879
9880 PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
9881 failed:
9882 Py_XDECREF(tmp);
9883 return 1;
9884}
9885
Martin v. Löwis618dc5e2008-03-30 20:03:44 +00009886
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009887PyMODINIT_FUNC
Martin v. Löwis1a214512008-06-11 05:26:20 +00009888PyInit__ast(void)
Martin v. Löwis577b5b92006-02-27 15:23:19 +00009889{
Dino Viehlandac46eb42019-09-11 10:16:34 -07009890 PyObject *m;
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009891 if (!init_types()) return NULL;
Dino Viehlandac46eb42019-09-11 10:16:34 -07009892 m = PyState_FindModule(&_astmodule);
Victor Stinnerce72e1c2013-07-27 00:00:36 +02009893 if (!m) return NULL;
Brandt Bucherd2f96672020-02-06 06:45:46 -08009894 if (PyModule_AddObject(m, "AST", astmodulestate_global->AST_type) < 0) {
9895 goto error;
9896 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009897 Py_INCREF(astmodulestate(m)->AST_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009898 if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
9899 goto error;
9900 }
9901 if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
9902 goto error;
9903 }
9904 if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
9905 goto error;
9906 }
9907 if (PyModule_AddObject(m, "mod", astmodulestate_global->mod_type) < 0) {
9908 goto error;
9909 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009910 Py_INCREF(astmodulestate(m)->mod_type);
9911 if (PyModule_AddObject(m, "Module", astmodulestate_global->Module_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009912 0) {
9913 goto error;
9914 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009915 Py_INCREF(astmodulestate(m)->Module_type);
9916 if (PyModule_AddObject(m, "Interactive",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009917 astmodulestate_global->Interactive_type) < 0) {
9918 goto error;
9919 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009920 Py_INCREF(astmodulestate(m)->Interactive_type);
9921 if (PyModule_AddObject(m, "Expression",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009922 astmodulestate_global->Expression_type) < 0) {
9923 goto error;
9924 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009925 Py_INCREF(astmodulestate(m)->Expression_type);
9926 if (PyModule_AddObject(m, "FunctionType",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009927 astmodulestate_global->FunctionType_type) < 0) {
9928 goto error;
9929 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009930 Py_INCREF(astmodulestate(m)->FunctionType_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009931 if (PyModule_AddObject(m, "stmt", astmodulestate_global->stmt_type) < 0) {
9932 goto error;
9933 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009934 Py_INCREF(astmodulestate(m)->stmt_type);
9935 if (PyModule_AddObject(m, "FunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009936 astmodulestate_global->FunctionDef_type) < 0) {
9937 goto error;
9938 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009939 Py_INCREF(astmodulestate(m)->FunctionDef_type);
9940 if (PyModule_AddObject(m, "AsyncFunctionDef",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009941 astmodulestate_global->AsyncFunctionDef_type) < 0) {
9942 goto error;
9943 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009944 Py_INCREF(astmodulestate(m)->AsyncFunctionDef_type);
9945 if (PyModule_AddObject(m, "ClassDef", astmodulestate_global->ClassDef_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009946 < 0) {
9947 goto error;
9948 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009949 Py_INCREF(astmodulestate(m)->ClassDef_type);
9950 if (PyModule_AddObject(m, "Return", astmodulestate_global->Return_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009951 0) {
9952 goto error;
9953 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009954 Py_INCREF(astmodulestate(m)->Return_type);
9955 if (PyModule_AddObject(m, "Delete", astmodulestate_global->Delete_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009956 0) {
9957 goto error;
9958 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009959 Py_INCREF(astmodulestate(m)->Delete_type);
9960 if (PyModule_AddObject(m, "Assign", astmodulestate_global->Assign_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -08009961 0) {
9962 goto error;
9963 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009964 Py_INCREF(astmodulestate(m)->Assign_type);
9965 if (PyModule_AddObject(m, "AugAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009966 astmodulestate_global->AugAssign_type) < 0) {
9967 goto error;
9968 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009969 Py_INCREF(astmodulestate(m)->AugAssign_type);
9970 if (PyModule_AddObject(m, "AnnAssign",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009971 astmodulestate_global->AnnAssign_type) < 0) {
9972 goto error;
9973 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009974 Py_INCREF(astmodulestate(m)->AnnAssign_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009975 if (PyModule_AddObject(m, "For", astmodulestate_global->For_type) < 0) {
9976 goto error;
9977 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009978 Py_INCREF(astmodulestate(m)->For_type);
9979 if (PyModule_AddObject(m, "AsyncFor", astmodulestate_global->AsyncFor_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -08009980 < 0) {
9981 goto error;
9982 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009983 Py_INCREF(astmodulestate(m)->AsyncFor_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009984 if (PyModule_AddObject(m, "While", astmodulestate_global->While_type) < 0) {
9985 goto error;
9986 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009987 Py_INCREF(astmodulestate(m)->While_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009988 if (PyModule_AddObject(m, "If", astmodulestate_global->If_type) < 0) {
9989 goto error;
9990 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009991 Py_INCREF(astmodulestate(m)->If_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -08009992 if (PyModule_AddObject(m, "With", astmodulestate_global->With_type) < 0) {
9993 goto error;
9994 }
Dino Viehlandac46eb42019-09-11 10:16:34 -07009995 Py_INCREF(astmodulestate(m)->With_type);
9996 if (PyModule_AddObject(m, "AsyncWith",
Brandt Bucherd2f96672020-02-06 06:45:46 -08009997 astmodulestate_global->AsyncWith_type) < 0) {
9998 goto error;
9999 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010000 Py_INCREF(astmodulestate(m)->AsyncWith_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010001 if (PyModule_AddObject(m, "Raise", astmodulestate_global->Raise_type) < 0) {
10002 goto error;
10003 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010004 Py_INCREF(astmodulestate(m)->Raise_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010005 if (PyModule_AddObject(m, "Try", astmodulestate_global->Try_type) < 0) {
10006 goto error;
10007 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010008 Py_INCREF(astmodulestate(m)->Try_type);
10009 if (PyModule_AddObject(m, "Assert", astmodulestate_global->Assert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010010 0) {
10011 goto error;
10012 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010013 Py_INCREF(astmodulestate(m)->Assert_type);
10014 if (PyModule_AddObject(m, "Import", astmodulestate_global->Import_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010015 0) {
10016 goto error;
10017 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010018 Py_INCREF(astmodulestate(m)->Import_type);
10019 if (PyModule_AddObject(m, "ImportFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010020 astmodulestate_global->ImportFrom_type) < 0) {
10021 goto error;
10022 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010023 Py_INCREF(astmodulestate(m)->ImportFrom_type);
10024 if (PyModule_AddObject(m, "Global", astmodulestate_global->Global_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010025 0) {
10026 goto error;
10027 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010028 Py_INCREF(astmodulestate(m)->Global_type);
10029 if (PyModule_AddObject(m, "Nonlocal", astmodulestate_global->Nonlocal_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010030 < 0) {
10031 goto error;
10032 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010033 Py_INCREF(astmodulestate(m)->Nonlocal_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010034 if (PyModule_AddObject(m, "Expr", astmodulestate_global->Expr_type) < 0) {
10035 goto error;
10036 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010037 Py_INCREF(astmodulestate(m)->Expr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010038 if (PyModule_AddObject(m, "Pass", astmodulestate_global->Pass_type) < 0) {
10039 goto error;
10040 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010041 Py_INCREF(astmodulestate(m)->Pass_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010042 if (PyModule_AddObject(m, "Break", astmodulestate_global->Break_type) < 0) {
10043 goto error;
10044 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010045 Py_INCREF(astmodulestate(m)->Break_type);
10046 if (PyModule_AddObject(m, "Continue", astmodulestate_global->Continue_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)->Continue_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010051 if (PyModule_AddObject(m, "expr", astmodulestate_global->expr_type) < 0) {
10052 goto error;
10053 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010054 Py_INCREF(astmodulestate(m)->expr_type);
10055 if (PyModule_AddObject(m, "BoolOp", astmodulestate_global->BoolOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010056 0) {
10057 goto error;
10058 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010059 Py_INCREF(astmodulestate(m)->BoolOp_type);
10060 if (PyModule_AddObject(m, "NamedExpr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010061 astmodulestate_global->NamedExpr_type) < 0) {
10062 goto error;
10063 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010064 Py_INCREF(astmodulestate(m)->NamedExpr_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010065 if (PyModule_AddObject(m, "BinOp", astmodulestate_global->BinOp_type) < 0) {
10066 goto error;
10067 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010068 Py_INCREF(astmodulestate(m)->BinOp_type);
10069 if (PyModule_AddObject(m, "UnaryOp", astmodulestate_global->UnaryOp_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010070 0) {
10071 goto error;
10072 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010073 Py_INCREF(astmodulestate(m)->UnaryOp_type);
10074 if (PyModule_AddObject(m, "Lambda", astmodulestate_global->Lambda_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010075 0) {
10076 goto error;
10077 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010078 Py_INCREF(astmodulestate(m)->Lambda_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010079 if (PyModule_AddObject(m, "IfExp", astmodulestate_global->IfExp_type) < 0) {
10080 goto error;
10081 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010082 Py_INCREF(astmodulestate(m)->IfExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010083 if (PyModule_AddObject(m, "Dict", astmodulestate_global->Dict_type) < 0) {
10084 goto error;
10085 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010086 Py_INCREF(astmodulestate(m)->Dict_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010087 if (PyModule_AddObject(m, "Set", astmodulestate_global->Set_type) < 0) {
10088 goto error;
10089 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010090 Py_INCREF(astmodulestate(m)->Set_type);
10091 if (PyModule_AddObject(m, "ListComp", astmodulestate_global->ListComp_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)->ListComp_type);
10096 if (PyModule_AddObject(m, "SetComp", astmodulestate_global->SetComp_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)->SetComp_type);
10101 if (PyModule_AddObject(m, "DictComp", astmodulestate_global->DictComp_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010102 < 0) {
10103 goto error;
10104 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010105 Py_INCREF(astmodulestate(m)->DictComp_type);
10106 if (PyModule_AddObject(m, "GeneratorExp",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010107 astmodulestate_global->GeneratorExp_type) < 0) {
10108 goto error;
10109 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010110 Py_INCREF(astmodulestate(m)->GeneratorExp_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010111 if (PyModule_AddObject(m, "Await", astmodulestate_global->Await_type) < 0) {
10112 goto error;
10113 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010114 Py_INCREF(astmodulestate(m)->Await_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010115 if (PyModule_AddObject(m, "Yield", astmodulestate_global->Yield_type) < 0) {
10116 goto error;
10117 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010118 Py_INCREF(astmodulestate(m)->Yield_type);
10119 if (PyModule_AddObject(m, "YieldFrom",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010120 astmodulestate_global->YieldFrom_type) < 0) {
10121 goto error;
10122 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010123 Py_INCREF(astmodulestate(m)->YieldFrom_type);
10124 if (PyModule_AddObject(m, "Compare", astmodulestate_global->Compare_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010125 0) {
10126 goto error;
10127 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010128 Py_INCREF(astmodulestate(m)->Compare_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010129 if (PyModule_AddObject(m, "Call", astmodulestate_global->Call_type) < 0) {
10130 goto error;
10131 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010132 Py_INCREF(astmodulestate(m)->Call_type);
10133 if (PyModule_AddObject(m, "FormattedValue",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010134 astmodulestate_global->FormattedValue_type) < 0) {
10135 goto error;
10136 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010137 Py_INCREF(astmodulestate(m)->FormattedValue_type);
10138 if (PyModule_AddObject(m, "JoinedStr",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010139 astmodulestate_global->JoinedStr_type) < 0) {
10140 goto error;
10141 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010142 Py_INCREF(astmodulestate(m)->JoinedStr_type);
10143 if (PyModule_AddObject(m, "Constant", astmodulestate_global->Constant_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010144 < 0) {
10145 goto error;
10146 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010147 Py_INCREF(astmodulestate(m)->Constant_type);
10148 if (PyModule_AddObject(m, "Attribute",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010149 astmodulestate_global->Attribute_type) < 0) {
10150 goto error;
10151 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010152 Py_INCREF(astmodulestate(m)->Attribute_type);
10153 if (PyModule_AddObject(m, "Subscript",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010154 astmodulestate_global->Subscript_type) < 0) {
10155 goto error;
10156 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010157 Py_INCREF(astmodulestate(m)->Subscript_type);
10158 if (PyModule_AddObject(m, "Starred", astmodulestate_global->Starred_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010159 0) {
10160 goto error;
10161 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010162 Py_INCREF(astmodulestate(m)->Starred_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010163 if (PyModule_AddObject(m, "Name", astmodulestate_global->Name_type) < 0) {
10164 goto error;
10165 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010166 Py_INCREF(astmodulestate(m)->Name_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010167 if (PyModule_AddObject(m, "List", astmodulestate_global->List_type) < 0) {
10168 goto error;
10169 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010170 Py_INCREF(astmodulestate(m)->List_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010171 if (PyModule_AddObject(m, "Tuple", astmodulestate_global->Tuple_type) < 0) {
10172 goto error;
10173 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010174 Py_INCREF(astmodulestate(m)->Tuple_type);
Serhiy Storchaka13d52c22020-03-10 18:52:34 +020010175 if (PyModule_AddObject(m, "Slice", astmodulestate_global->Slice_type) < 0) {
10176 goto error;
10177 }
10178 Py_INCREF(astmodulestate(m)->Slice_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010179 if (PyModule_AddObject(m, "expr_context",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010180 astmodulestate_global->expr_context_type) < 0) {
10181 goto error;
10182 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010183 Py_INCREF(astmodulestate(m)->expr_context_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010184 if (PyModule_AddObject(m, "Load", astmodulestate_global->Load_type) < 0) {
10185 goto error;
10186 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010187 Py_INCREF(astmodulestate(m)->Load_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010188 if (PyModule_AddObject(m, "Store", astmodulestate_global->Store_type) < 0) {
10189 goto error;
10190 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010191 Py_INCREF(astmodulestate(m)->Store_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010192 if (PyModule_AddObject(m, "Del", astmodulestate_global->Del_type) < 0) {
10193 goto error;
10194 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010195 Py_INCREF(astmodulestate(m)->Del_type);
Dino Viehlandac46eb42019-09-11 10:16:34 -070010196 if (PyModule_AddObject(m, "boolop", astmodulestate_global->boolop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010197 0) {
10198 goto error;
10199 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010200 Py_INCREF(astmodulestate(m)->boolop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010201 if (PyModule_AddObject(m, "And", astmodulestate_global->And_type) < 0) {
10202 goto error;
10203 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010204 Py_INCREF(astmodulestate(m)->And_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010205 if (PyModule_AddObject(m, "Or", astmodulestate_global->Or_type) < 0) {
10206 goto error;
10207 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010208 Py_INCREF(astmodulestate(m)->Or_type);
10209 if (PyModule_AddObject(m, "operator", astmodulestate_global->operator_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010210 < 0) {
10211 goto error;
10212 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010213 Py_INCREF(astmodulestate(m)->operator_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010214 if (PyModule_AddObject(m, "Add", astmodulestate_global->Add_type) < 0) {
10215 goto error;
10216 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010217 Py_INCREF(astmodulestate(m)->Add_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010218 if (PyModule_AddObject(m, "Sub", astmodulestate_global->Sub_type) < 0) {
10219 goto error;
10220 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010221 Py_INCREF(astmodulestate(m)->Sub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010222 if (PyModule_AddObject(m, "Mult", astmodulestate_global->Mult_type) < 0) {
10223 goto error;
10224 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010225 Py_INCREF(astmodulestate(m)->Mult_type);
10226 if (PyModule_AddObject(m, "MatMult", astmodulestate_global->MatMult_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010227 0) {
10228 goto error;
10229 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010230 Py_INCREF(astmodulestate(m)->MatMult_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010231 if (PyModule_AddObject(m, "Div", astmodulestate_global->Div_type) < 0) {
10232 goto error;
10233 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010234 Py_INCREF(astmodulestate(m)->Div_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010235 if (PyModule_AddObject(m, "Mod", astmodulestate_global->Mod_type) < 0) {
10236 goto error;
10237 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010238 Py_INCREF(astmodulestate(m)->Mod_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010239 if (PyModule_AddObject(m, "Pow", astmodulestate_global->Pow_type) < 0) {
10240 goto error;
10241 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010242 Py_INCREF(astmodulestate(m)->Pow_type);
10243 if (PyModule_AddObject(m, "LShift", astmodulestate_global->LShift_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010244 0) {
10245 goto error;
10246 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010247 Py_INCREF(astmodulestate(m)->LShift_type);
10248 if (PyModule_AddObject(m, "RShift", astmodulestate_global->RShift_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)->RShift_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010253 if (PyModule_AddObject(m, "BitOr", astmodulestate_global->BitOr_type) < 0) {
10254 goto error;
10255 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010256 Py_INCREF(astmodulestate(m)->BitOr_type);
10257 if (PyModule_AddObject(m, "BitXor", astmodulestate_global->BitXor_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010258 0) {
10259 goto error;
10260 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010261 Py_INCREF(astmodulestate(m)->BitXor_type);
10262 if (PyModule_AddObject(m, "BitAnd", astmodulestate_global->BitAnd_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010263 0) {
10264 goto error;
10265 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010266 Py_INCREF(astmodulestate(m)->BitAnd_type);
10267 if (PyModule_AddObject(m, "FloorDiv", astmodulestate_global->FloorDiv_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010268 < 0) {
10269 goto error;
10270 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010271 Py_INCREF(astmodulestate(m)->FloorDiv_type);
10272 if (PyModule_AddObject(m, "unaryop", astmodulestate_global->unaryop_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010273 0) {
10274 goto error;
10275 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010276 Py_INCREF(astmodulestate(m)->unaryop_type);
10277 if (PyModule_AddObject(m, "Invert", astmodulestate_global->Invert_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010278 0) {
10279 goto error;
10280 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010281 Py_INCREF(astmodulestate(m)->Invert_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010282 if (PyModule_AddObject(m, "Not", astmodulestate_global->Not_type) < 0) {
10283 goto error;
10284 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010285 Py_INCREF(astmodulestate(m)->Not_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010286 if (PyModule_AddObject(m, "UAdd", astmodulestate_global->UAdd_type) < 0) {
10287 goto error;
10288 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010289 Py_INCREF(astmodulestate(m)->UAdd_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010290 if (PyModule_AddObject(m, "USub", astmodulestate_global->USub_type) < 0) {
10291 goto error;
10292 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010293 Py_INCREF(astmodulestate(m)->USub_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010294 if (PyModule_AddObject(m, "cmpop", astmodulestate_global->cmpop_type) < 0) {
10295 goto error;
10296 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010297 Py_INCREF(astmodulestate(m)->cmpop_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010298 if (PyModule_AddObject(m, "Eq", astmodulestate_global->Eq_type) < 0) {
10299 goto error;
10300 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010301 Py_INCREF(astmodulestate(m)->Eq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010302 if (PyModule_AddObject(m, "NotEq", astmodulestate_global->NotEq_type) < 0) {
10303 goto error;
10304 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010305 Py_INCREF(astmodulestate(m)->NotEq_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010306 if (PyModule_AddObject(m, "Lt", astmodulestate_global->Lt_type) < 0) {
10307 goto error;
10308 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010309 Py_INCREF(astmodulestate(m)->Lt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010310 if (PyModule_AddObject(m, "LtE", astmodulestate_global->LtE_type) < 0) {
10311 goto error;
10312 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010313 Py_INCREF(astmodulestate(m)->LtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010314 if (PyModule_AddObject(m, "Gt", astmodulestate_global->Gt_type) < 0) {
10315 goto error;
10316 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010317 Py_INCREF(astmodulestate(m)->Gt_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010318 if (PyModule_AddObject(m, "GtE", astmodulestate_global->GtE_type) < 0) {
10319 goto error;
10320 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010321 Py_INCREF(astmodulestate(m)->GtE_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010322 if (PyModule_AddObject(m, "Is", astmodulestate_global->Is_type) < 0) {
10323 goto error;
10324 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010325 Py_INCREF(astmodulestate(m)->Is_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010326 if (PyModule_AddObject(m, "IsNot", astmodulestate_global->IsNot_type) < 0) {
10327 goto error;
10328 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010329 Py_INCREF(astmodulestate(m)->IsNot_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010330 if (PyModule_AddObject(m, "In", astmodulestate_global->In_type) < 0) {
10331 goto error;
10332 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010333 Py_INCREF(astmodulestate(m)->In_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010334 if (PyModule_AddObject(m, "NotIn", astmodulestate_global->NotIn_type) < 0) {
10335 goto error;
10336 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010337 Py_INCREF(astmodulestate(m)->NotIn_type);
10338 if (PyModule_AddObject(m, "comprehension",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010339 astmodulestate_global->comprehension_type) < 0) {
10340 goto error;
10341 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010342 Py_INCREF(astmodulestate(m)->comprehension_type);
10343 if (PyModule_AddObject(m, "excepthandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010344 astmodulestate_global->excepthandler_type) < 0) {
10345 goto error;
10346 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010347 Py_INCREF(astmodulestate(m)->excepthandler_type);
10348 if (PyModule_AddObject(m, "ExceptHandler",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010349 astmodulestate_global->ExceptHandler_type) < 0) {
10350 goto error;
10351 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010352 Py_INCREF(astmodulestate(m)->ExceptHandler_type);
10353 if (PyModule_AddObject(m, "arguments",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010354 astmodulestate_global->arguments_type) < 0) {
10355 goto error;
10356 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010357 Py_INCREF(astmodulestate(m)->arguments_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010358 if (PyModule_AddObject(m, "arg", astmodulestate_global->arg_type) < 0) {
10359 goto error;
10360 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010361 Py_INCREF(astmodulestate(m)->arg_type);
10362 if (PyModule_AddObject(m, "keyword", astmodulestate_global->keyword_type) <
Brandt Bucherd2f96672020-02-06 06:45:46 -080010363 0) {
10364 goto error;
10365 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010366 Py_INCREF(astmodulestate(m)->keyword_type);
Brandt Bucherd2f96672020-02-06 06:45:46 -080010367 if (PyModule_AddObject(m, "alias", astmodulestate_global->alias_type) < 0) {
10368 goto error;
10369 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010370 Py_INCREF(astmodulestate(m)->alias_type);
10371 if (PyModule_AddObject(m, "withitem", astmodulestate_global->withitem_type)
Brandt Bucherd2f96672020-02-06 06:45:46 -080010372 < 0) {
10373 goto error;
10374 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010375 Py_INCREF(astmodulestate(m)->withitem_type);
10376 if (PyModule_AddObject(m, "type_ignore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010377 astmodulestate_global->type_ignore_type) < 0) {
10378 goto error;
10379 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010380 Py_INCREF(astmodulestate(m)->type_ignore_type);
10381 if (PyModule_AddObject(m, "TypeIgnore",
Brandt Bucherd2f96672020-02-06 06:45:46 -080010382 astmodulestate_global->TypeIgnore_type) < 0) {
10383 goto error;
10384 }
Dino Viehlandac46eb42019-09-11 10:16:34 -070010385 Py_INCREF(astmodulestate(m)->TypeIgnore_type);
Victor Stinnerce72e1c2013-07-27 00:00:36 +020010386 return m;
Brandt Bucherd2f96672020-02-06 06:45:46 -080010387error:
10388 Py_DECREF(m);
10389 return NULL;
Martin v. Löwis577b5b92006-02-27 15:23:19 +000010390}
10391
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010392
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010393PyObject* PyAST_mod2obj(mod_ty t)
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010394{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010395 if (!init_types())
10396 return NULL;
Martin v. Löwisbd260da2006-02-26 19:42:26 +000010397 return ast2obj_mod(t);
Jeremy Hylton3e0055f2005-10-20 19:59:25 +000010398}
Martin v. Löwis5b222132007-06-10 09:51:05 +000010399
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010400/* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
10401mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010402{
Benjamin Petersonc2f665e2014-02-10 22:19:02 -050010403 PyObject *req_type[3];
Serhiy Storchaka43c97312019-09-10 13:02:30 +030010404 const char * const req_name[] = {"Module", "Expression", "Interactive"};
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010405 int isinstance;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010406
Steve Dowerb82e17e2019-05-23 08:45:22 -070010407 if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
10408 return NULL;
10409 }
10410
Dino Viehlandac46eb42019-09-11 10:16:34 -070010411 req_type[0] = astmodulestate_global->Module_type;
10412 req_type[1] = astmodulestate_global->Expression_type;
10413 req_type[2] = astmodulestate_global->Interactive_type;
Benjamin Peterson42ec0312014-02-10 22:41:40 -050010414
Guido van Rossum3a32e3b2019-02-01 11:37:34 -080010415 assert(0 <= mode && mode <= 2);
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010416
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010417 if (!init_types())
10418 return NULL;
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010419
Benjamin Peterson0496c9e2009-12-13 01:24:58 +000010420 isinstance = PyObject_IsInstance(ast, req_type[mode]);
10421 if (isinstance == -1)
10422 return NULL;
10423 if (!isinstance) {
Neal Norwitzdb4115f2008-03-31 04:20:05 +000010424 PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
Dino Viehlandac46eb42019-09-11 10:16:34 -070010425 req_name[mode], _PyType_Name(Py_TYPE(ast)));
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010426 return NULL;
10427 }
Dong-hee Naa05fcd32019-10-10 16:41:26 +090010428
10429 mod_ty res = NULL;
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010430 if (obj2ast_mod(ast, &res, arena) != 0)
10431 return NULL;
10432 else
10433 return res;
10434}
10435
10436int PyAST_Check(PyObject* obj)
10437{
Victor Stinnerbdf630c2013-07-17 00:17:15 +020010438 if (!init_types())
10439 return -1;
Dino Viehlandac46eb42019-09-11 10:16:34 -070010440 return PyObject_IsInstance(obj, astmodulestate_global->AST_type);
Martin v. Löwis618dc5e2008-03-30 20:03:44 +000010441}
10442
Martin v. Löwis5b222132007-06-10 09:51:05 +000010443